[Python-Dev] What do PyAPI_FUNC & PyAPI_DATA mean?

2012-04-23 Thread Mark Shannon

Many (most?) of the function declarations in the CPython header files
are annotated with the PyAPI_FUNC declaration.
Similarly for data declarations and PyAPI_DATA

What do they mean, exactly? From the name I would expect that they are a 
way of declaring a function or datum to be part of the API, but their 
usage seems to be more to do with linkage.


The reason I am asking is that the new dictionary implementation 
declares a few functions used to communicate between dictobject.c, 
typeobject.c and ceval.c which cannot be static functions, but are not 
intended to be part of the API.


Cheers,
Mark.
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Suggested addition to PEP 8 for context managers

2012-04-23 Thread Floris Bruynooghe
[resent since I accidentally dropped the list]

Hi,

On 19 April 2012 15:55, Barry Warsaw  wrote:
> I'll make this change to the PEP.  I'm not entirely sure the Yes/No examples
> are great illustrations of this change in wording though.  Here's the diff so
> far (uncommitted):
>
> diff -r 34076bfed420 pep-0008.txt
> --- a/pep-0008.txt      Thu Apr 19 10:32:50 2012 +0200
> +++ b/pep-0008.txt      Thu Apr 19 10:53:15 2012 -0400
> @@ -305,7 +305,11 @@
>   ``>=``, ``in``, ``not in``, ``is``, ``is not``), Booleans (``and``,
>   ``or``, ``not``).
>
> -- Use spaces around arithmetic operators:
> +- If operators with different priorities are used, consider adding
> +  whitespace around the operators with the lowest priority(ies). This
> +  is very much to taste; however, never use more than one space, and
> +  always have the same amount of whitespace on both sides of a binary
> +  operator.

While the text is certainly an improvement it seems to me that right
now some of the examples following under the "No:" should be moved to
"Yes:"

"""
No:
i=i+1
submitted +=1
x = x*2 - 1
hypot2 = x*x + y*y
c = (a+b) * (a-b)
"""

In particular "x = x*2 -1" and "hypot2 = x*x + y*y" sound like they
should be under "Yes".

Regards,
Floris


-- 
Debian GNU/Linux -- The Power of Freedom
www.debian.org | www.gnu.org | www.kernel.org
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] [Python-checkins] cpython: issue2193 - Update docs about the legal characters allowed in Cookie name

2012-04-23 Thread Senthil Kumaran
On Sun, Apr 22, 2012 at 3:17 PM, Nick Coghlan  wrote:
>>  issue2193 - Update docs about the legal characters allowed in Cookie name
>
> You missed the dummy merge from 3.2 to indicate that this change had
> been applied to both branches independently.

Yes. Sorry for that. I was being little cautious of  having correct
message in each version and forgot the merge.

> Should be fixed in my commit for issue #14026

Thanks for this, Nick.

-- 
Senthil
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] What do PyAPI_FUNC & PyAPI_DATA mean?

2012-04-23 Thread Benjamin Peterson
2012/4/23 Mark Shannon :
> Many (most?) of the function declarations in the CPython header files
> are annotated with the PyAPI_FUNC declaration.
> Similarly for data declarations and PyAPI_DATA
>
> What do they mean, exactly? From the name I would expect that they are a way
> of declaring a function or datum to be part of the API, but their usage
> seems to be more to do with linkage.

They define linkage on Windows. I actually don't know if they should
be applied to internal functions.



-- 
Regards,
Benjamin
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] What do PyAPI_FUNC & PyAPI_DATA mean?

2012-04-23 Thread Kristján Valur Jónsson
IMHO, we are _much_ too generous at applying this to almost whatever gets 
exposed between .c files.
I have created something called the "restricted" api for our custom 
python27.dll where I use different
macros (PyAPI_RFUNC, pyAPI_RDATA) to mean that things aren't exported for 
"restricted" builds.  We
use it to remove some of the easier access points to the dll for hackers to 
exploit.

Also, once declared exported this way, things become more bothersome to remove 
again, since once could always argue that someone out there is using these 
thigns.

K

> -Original Message-
> From: [email protected]
> [mailto:[email protected]] On
> Behalf Of Benjamin Peterson
> Sent: 23. apríl 2012 12:59
> To: Mark Shannon
> Cc: Python Dev
> Subject: Re: [Python-Dev] What do PyAPI_FUNC & PyAPI_DATA mean?
> 
> 2012/4/23 Mark Shannon :
> > Many (most?) of the function declarations in the CPython header files
> > are annotated with the PyAPI_FUNC declaration.
> > Similarly for data declarations and PyAPI_DATA
> >
> > What do they mean, exactly? From the name I would expect that they are
> > a way of declaring a function or datum to be part of the API, but
> > their usage seems to be more to do with linkage.
> 
> They define linkage on Windows. I actually don't know if they should be
> applied to internal functions.
> 
> 
> 
> --
> Regards,
> Benjamin
> ___
> Python-Dev mailing list
> [email protected]
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: http://mail.python.org/mailman/options/python-
> dev/kristjan%40ccpgames.com


___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] cpython: Implement PEP 412: Key-sharing dictionaries (closes #13903)

2012-04-23 Thread Antoine Pitrou
On Mon, 23 Apr 2012 17:24:57 +0200
benjamin.peterson  wrote:
> http://hg.python.org/cpython/rev/6e5855854a2e
> changeset:   76485:6e5855854a2e
> user:Benjamin Peterson 
> date:Mon Apr 23 11:24:50 2012 -0400
> summary:
>   Implement PEP 412: Key-sharing dictionaries (closes #13903)

I hope someone can measure the results of this change on real-world
code. Benchmark results with http://hg.python.org/benchmarks/ are not
overly promising.

Regards

Antoine.


___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] cpython: Implement PEP 412: Key-sharing dictionaries (closes #13903)

2012-04-23 Thread R. David Murray
On Mon, 23 Apr 2012 22:22:18 +0200, Antoine Pitrou  wrote:
> On Mon, 23 Apr 2012 17:24:57 +0200
> benjamin.peterson  wrote:
> > http://hg.python.org/cpython/rev/6e5855854a2e
> > changeset:   76485:6e5855854a2e
> > user:Benjamin Peterson 
> > date:Mon Apr 23 11:24:50 2012 -0400
> > summary:
> >   Implement PEP 412: Key-sharing dictionaries (closes #13903)
> 
> I hope someone can measure the results of this change on real-world
> code. Benchmark results with http://hg.python.org/benchmarks/ are not
> overly promising.

I'm pretty sure that anything heavily using sqlalchemy will benefit,
so that would be a good place to look for a real-world benchmark.

--David
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


[Python-Dev] (time) PEP 418 glossary V2

2012-04-23 Thread Jim Jewett
Glossary


Absolute Time
-

A measurement of time since a specific Epoch_, typically far in the
past.  Civil Time is the most common example.  Typically contrasted
with a `Duration`_, as (now - epoch) is generally much larger than
any duration that can be appropriately measured with the clock in
question.

Accuracy


The amount of deviation of measurements by a given instrument from true
values. See also the wikipedia article on `Accuracy and precision
`_.

Inaccuracy in clocks may be caused by lack of `Precision`_, by
`Drift`_, or by an incorrect initial setting of the clock (e.g., timing
of threads is inherently inaccurate because perfect synchronization in
resetting counters is quite difficult).

Adjusted


Resetting a clock, presumably to the correct time.  This may be done
either with a `Step`_ or with `Slew`_.  Adjusting a clock normally
makes it more accurate with respect to the `Absolute Time`_.  The cost
is that any durations currently being measured will show a `Bias`_.
(17 ticks is not the same Duration_ as 17 ticks plus an adjustment.)

Bias


Lack of accuracy that is systematically in one direction, as opposed to
random errors.  When a clock is `Adjusted`_, durations overlapping the
adjustment will show a Bias.

Civil Time
--

Time of day; external to the system.  10:45:13am is a Civil time;
A Duration_ like "45 seconds" is not a Civil time.  Provided by
existing functions ``time.localtime()`` and ``time.gmtime()``, which
are not changed by this PEP.

Clock
-

An instrument for measuring time.  Different clocks have different
characteristics; for example, a clock with nanosecond Precision_ may
start to Drift_ after a few minutes, while a less precise clock
remained accurate for days.

This PEP is primarily concerned with clocks which use a unit of
seconds, rather than years, or arbitrary units such as a Tick_.

Counter
---

A clock which increments each time a certain event occurs.  A counter
is strictly monotonic in the mathematical sense, but does not meet
the typical definitions of Monotonic_ when used of a computer clock.
It can be used to generate a unique (and ordered) timestamp, but these
timestamps cannot be mapped to `Civil Time`_; Tick_ creation may well
be bursty, with several advances in the same millisecond followed
by several days without any advance.

CPU Time


A measure of how much CPU effort has been spent on a certain task.
CPU seconds are often normalized (so that a variable number can
occur in the same actual second).  CPU seconds can be important
when profiling, but they do not map directly to user response time,
nor are they directly comparable to (real time) seconds.

Drift
-

The accumulated error against "true" time, as defined externally to the
system.  Drift may be due to imprecision, or to a difference between
the average rate at which clock time advances and that of real time.

Drift does not include intentional adjustments, but clocks providing
`Absolute Time`_ will eventually have to be Adjusted_ to compensate
for drift.

Duration


Elapsed time.  The difference between the starting and ending times.
Also called Relative Time.  Normally contrasted with `Absolute Time`_.

While a defined Epoch_ technically creates an implicit duration, this
duration is normally too large to be of practical use.

Computers can often supply a clock with better Precision_ or higher
Resolution_ if they do not have to guarantee meaningful comparisons to
any times not generated by the clock itself.

Epoch
-

The reference point of a clock.  For clocks providing `Civil Time`_,
this is often midnight as the day (and year) rolled over to
January 1, 1970.  A Monotonic_ clock will typically have an undefined
epoch (represented as None).

Latency
---

Delay.  By the time a call to a clock function returns, `Real Time`_
has advanced, possibly by more than the precision of the clock.

Monotonic
-

This is a particularly tricky term, as there are several subtly
incompatible definitions in use.  C++ followed the mathematical
definition, so that a monotonic clock only promises not to go
backwards.  In practice, that is not sufficient to be useful, and no
Operating System provides such a weak guarantee.  Most discussions
of a "Monotonic *Clock*" will also assume several additional
guarantees, some of which are explicitly required by the POSIX
specification.

Within this PEP (and Python), the intended meaning is closer to
"the characteristics expected of a monotonic clock in practice".
In addition to not moving backward, a Monotonic Clock should also be
Steady_, and should be convertible to a unit of seconds.  The tradeoffs
often include lack of a defined Epoch_ or mapping to `Civil Time`_,
and being more expensive (in `Latency`_, power usage, or duration spent
within calls to the clock itself) to use.  For example, the clock may
represent (a constant mult

Re: [Python-Dev] PEP 418: Add monotonic time, performance counter and process time functions

2012-04-23 Thread Victor Stinner
>> Well, I asked on IRC what I should do for these definitions because
>> I'm too tired to decide what to do. [[...]] I replaced these definitions 
>> with yours.
>
> That was nice of you.  In return, I'll go over the PEP to check that
> usage is appropriate (eg, in some places "resolution" was used in the
> sense of computer science's "precision" == reported digits).  Please
> give me 24 hours.

As you asked me in private, I replaced "Precision" with "Resolution"
almost everywhere in the PEP. I removed the "precision" key of
time.get_clock_info(): use the "resolution" key instead.

No OS provides any information on the precision, accuracy, drift or
anything else of a specific clock. Only the resolution of a clock is
known.

Victor
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] (time) PEP 418 glossary V2

2012-04-23 Thread Nick Coghlan
I like the updated glossary - very good summary of the relevant
terminology and common points of confusion. One minor gripe below (and
it *is* minor, despite the amount of text explaining my point of
view...)

On Tue, Apr 24, 2012 at 11:58 AM, Jim Jewett  wrote:
> Real Time
> -
>
> Time in the real world.  This differs from `Civil time`_ in that it is
> not `Adjusted`_, but they should otherwise advance in lockstep.
>
> It is not related to the "real time" of "Real Time [Operating]
> Systems".  It is sometimes called "wall clock time" to avoid that
> ambiguity; unfortunately, that introduces different ambiguities.

"Not related" is simply not true, as this is the exact meaning of
"Real Time" in the term "Real Time Operating System". In the PEP's
terms, a Real Time OS is simply an operating system specifically
designed to allow developers to meet deadlines expressed as the
maximum permitted Real Time Duration between an event occurring and
the system responding to that event.

The power an RTOS gives you over an ordinary OS is sufficiently low
level control over the scheduler (if there's even an entity worth of
the name "scheduler" at all) such that you can *demonstrably* meet
hard real time deadlines (down to a certain lower limit, generally
constrained by hardware). It's a pain to program that way though (and
adequately demonstrating correctness gets harder as the code gets more
complicated), so you often want to use a dedicated processor for the
RTOS bits and a separate processor (with an ordinary OS) for
everything else. (There's a good explanation of many of these
concepts, include separating the hard realtime parts from everything
else, in the Giant Robots of Doom talk from PyCon AU 2010:
http://pyvideo.org/video/481/pyconau-2010--hard-real-time-python--or--giant-ro)

One interesting aspect of using a normal OS is that you can *never*
reliably read a Real Time clock in user level code - the scheduler
doesn't provide adequate guarantees of responsiveness, so there's
always going to be some scheduling jitter in the results. This
generally doesn't matter for measuring durations within a machine
(since the jitter will, with a sufficiently large number of samples,
cancel out between the two measurements), but can be a problem for
absolute time measurements that are intended to be compared with high
precision across different machines.

Cheers,
Nick.

-- 
Nick Coghlan   |   [email protected]   |   Brisbane, Australia
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com