Skip to content

Commit ef3e4c2

Browse files
committed
Merged revisions 70980,71059,71225,71234,71241,71243,71249,71251,71255,71266,71299,71329,71397-71398,71486 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r70980 | jack.diederich | 2009-04-01 15:26:13 -0500 (Wed, 01 Apr 2009) | 3 lines bounds check arguments to mmap.move(). All of them. Really. fixes crasher on OS X 10.5 ........ r71059 | mark.dickinson | 2009-04-02 13:39:37 -0500 (Thu, 02 Apr 2009) | 2 lines sys.long_info attributes should be ints, not longs ........ r71225 | georg.brandl | 2009-04-05 06:54:07 -0500 (Sun, 05 Apr 2009) | 1 line #5580: no need to use parentheses when converterr() argument is actually a type description. ........ r71234 | georg.brandl | 2009-04-05 08:16:35 -0500 (Sun, 05 Apr 2009) | 1 line Whitespace normalization. ........ r71241 | georg.brandl | 2009-04-05 09:48:49 -0500 (Sun, 05 Apr 2009) | 1 line #5471: fix expanduser() for $HOME set to "/". ........ r71243 | georg.brandl | 2009-04-05 10:14:29 -0500 (Sun, 05 Apr 2009) | 1 line #5432: make plistlib docstring a raw string, since it contains examples with backslash escapes. ........ r71249 | georg.brandl | 2009-04-05 11:30:43 -0500 (Sun, 05 Apr 2009) | 1 line #5444: adapt make.bat to new htmlhelp output file name. ........ r71251 | georg.brandl | 2009-04-05 12:17:42 -0500 (Sun, 05 Apr 2009) | 1 line #5298: clarify docs about GIL by using more consistent wording. ........ r71255 | georg.brandl | 2009-04-05 13:34:58 -0500 (Sun, 05 Apr 2009) | 1 line #602893: add indicator for current line in cgitb that doesnt rely on styling alone. ........ r71266 | georg.brandl | 2009-04-05 15:23:13 -0500 (Sun, 05 Apr 2009) | 1 line Normalize issue referencing style. ........ r71299 | gregory.p.smith | 2009-04-05 18:43:58 -0500 (Sun, 05 Apr 2009) | 3 lines Fixes issue5705: os.setuid() and friends did not accept the same range of values that pwd.getpwnam() returns. ........ r71329 | benjamin.peterson | 2009-04-06 16:53:33 -0500 (Mon, 06 Apr 2009) | 1 line add create_connection to __all__ #5711 ........ r71397 | georg.brandl | 2009-04-08 11:36:39 -0500 (Wed, 08 Apr 2009) | 1 line Remove redundant backtick. ........ r71398 | georg.brandl | 2009-04-08 11:39:04 -0500 (Wed, 08 Apr 2009) | 1 line Update ignore file for suspicious builder. ........ r71486 | andrew.kuchling | 2009-04-11 11:18:14 -0500 (Sat, 11 Apr 2009) | 1 line Re-word ........
1 parent da2ba33 commit ef3e4c2

17 files changed

+235
-132
lines changed

Doc/c-api/buffer.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ Buffer related functions
239239
| :cmacro:`PyBUF_FULL` | This is equivalent to ``(PyBUF_INDIRECT | |
240240
| | PyBUF_FORMAT | PyBUF_WRITABLE)``. |
241241
+------------------------------+---------------------------------------------------+
242-
| :cmacro:`PyBUF_FULL_RO`` | This is equivalent to ``(PyBUF_INDIRECT | |
242+
| :cmacro:`PyBUF_FULL_RO` | This is equivalent to ``(PyBUF_INDIRECT | |
243243
| | PyBUF_FORMAT)``. |
244244
+------------------------------+---------------------------------------------------+
245245
| :cmacro:`PyBUF_CONTIG` | This is equivalent to ``(PyBUF_ND | |

Doc/c-api/init.rst

Lines changed: 79 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -391,12 +391,12 @@ Thread State and the Global Interpreter Lock
391391
single: lock, interpreter
392392

393393
The Python interpreter is not fully thread safe. In order to support
394-
multi-threaded Python programs, there's a global lock that must be held by the
395-
current thread before it can safely access Python objects. Without the lock,
396-
even the simplest operations could cause problems in a multi-threaded program:
397-
for example, when two threads simultaneously increment the reference count of
398-
the same object, the reference count could end up being incremented only once
399-
instead of twice.
394+
multi-threaded Python programs, there's a global lock, called the :dfn:`global
395+
interpreter lock` or :dfn:`GIL`, that must be held by the current thread before
396+
it can safely access Python objects. Without the lock, even the simplest
397+
operations could cause problems in a multi-threaded program: for example, when
398+
two threads simultaneously increment the reference count of the same object, the
399+
reference count could end up being incremented only once instead of twice.
400400

401401
.. index:: single: setcheckinterval() (in module sys)
402402

@@ -425,9 +425,9 @@ This is easy enough in most cases. Most code manipulating the global
425425
interpreter lock has the following simple structure::
426426

427427
Save the thread state in a local variable.
428-
Release the interpreter lock.
428+
Release the global interpreter lock.
429429
...Do some blocking I/O operation...
430-
Reacquire the interpreter lock.
430+
Reacquire the global interpreter lock.
431431
Restore the thread state from the local variable.
432432

433433
This is so common that a pair of macros exists to simplify it::
@@ -444,7 +444,7 @@ The :cmacro:`Py_BEGIN_ALLOW_THREADS` macro opens a new block and declares a
444444
hidden local variable; the :cmacro:`Py_END_ALLOW_THREADS` macro closes the
445445
block. Another advantage of using these two macros is that when Python is
446446
compiled without thread support, they are defined empty, thus saving the thread
447-
state and lock manipulations.
447+
state and GIL manipulations.
448448

449449
When thread support is enabled, the block above expands to the following code::
450450

@@ -476,7 +476,7 @@ There are some subtle differences; in particular, :cfunc:`PyEval_RestoreThread`
476476
saves and restores the value of the global variable :cdata:`errno`, since the
477477
lock manipulation does not guarantee that :cdata:`errno` is left alone. Also,
478478
when thread support is disabled, :cfunc:`PyEval_SaveThread` and
479-
:cfunc:`PyEval_RestoreThread` don't manipulate the lock; in this case,
479+
:cfunc:`PyEval_RestoreThread` don't manipulate the GIL; in this case,
480480
:cfunc:`PyEval_ReleaseLock` and :cfunc:`PyEval_AcquireLock` are not available.
481481
This is done so that dynamically loaded extensions compiled with thread support
482482
enabled can be loaded by an interpreter that was compiled with disabled thread
@@ -559,16 +559,16 @@ supports the creation of additional interpreters (using
559559

560560
.. index:: module: _thread
561561

562-
When only the main thread exists, no lock operations are needed. This is a
562+
When only the main thread exists, no GIL operations are needed. This is a
563563
common situation (most Python programs do not use threads), and the lock
564-
operations slow the interpreter down a bit. Therefore, the lock is not created
565-
initially. This situation is equivalent to having acquired the lock: when
566-
there is only a single thread, all object accesses are safe. Therefore, when
567-
this function initializes the lock, it also acquires it. Before the Python
568-
:mod:`_thread` module creates a new thread, knowing that either it has the lock
569-
or the lock hasn't been created yet, it calls :cfunc:`PyEval_InitThreads`. When
570-
this call returns, it is guaranteed that the lock has been created and that the
571-
calling thread has acquired it.
564+
operations slow the interpreter down a bit. Therefore, the lock is not
565+
created initially. This situation is equivalent to having acquired the lock:
566+
when there is only a single thread, all object accesses are safe. Therefore,
567+
when this function initializes the global interpreter lock, it also acquires
568+
it. Before the Python :mod:`_thread` module creates a new thread, knowing
569+
that either it has the lock or the lock hasn't been created yet, it calls
570+
:cfunc:`PyEval_InitThreads`. When this call returns, it is guaranteed that
571+
the lock has been created and that the calling thread has acquired it.
572572

573573
It is **not** safe to call this function when it is unknown which thread (if
574574
any) currently has the global interpreter lock.
@@ -579,7 +579,7 @@ supports the creation of additional interpreters (using
579579
.. cfunction:: int PyEval_ThreadsInitialized()
580580

581581
Returns a non-zero value if :cfunc:`PyEval_InitThreads` has been called. This
582-
function can be called without holding the lock, and therefore can be used to
582+
function can be called without holding the GIL, and therefore can be used to
583583
avoid calls to the locking API when running single-threaded. This function is
584584
not available when thread support is disabled at compile time.
585585

@@ -617,20 +617,20 @@ supports the creation of additional interpreters (using
617617

618618
.. cfunction:: PyThreadState* PyEval_SaveThread()
619619

620-
Release the interpreter lock (if it has been created and thread support is
621-
enabled) and reset the thread state to *NULL*, returning the previous thread
622-
state (which is not *NULL*). If the lock has been created, the current thread
623-
must have acquired it. (This function is available even when thread support is
624-
disabled at compile time.)
620+
Release the global interpreter lock (if it has been created and thread
621+
support is enabled) and reset the thread state to *NULL*, returning the
622+
previous thread state (which is not *NULL*). If the lock has been created,
623+
the current thread must have acquired it. (This function is available even
624+
when thread support is disabled at compile time.)
625625

626626

627627
.. cfunction:: void PyEval_RestoreThread(PyThreadState *tstate)
628628

629-
Acquire the interpreter lock (if it has been created and thread support is
630-
enabled) and set the thread state to *tstate*, which must not be *NULL*. If the
631-
lock has been created, the current thread must not have acquired it, otherwise
632-
deadlock ensues. (This function is available even when thread support is
633-
disabled at compile time.)
629+
Acquire the global interpreter lock (if it has been created and thread
630+
support is enabled) and set the thread state to *tstate*, which must not be
631+
*NULL*. If the lock has been created, the current thread must not have
632+
acquired it, otherwise deadlock ensues. (This function is available even
633+
when thread support is disabled at compile time.)
634634

635635

636636
.. cfunction:: void PyEval_ReInitThreads()
@@ -674,60 +674,61 @@ example usage in the Python source distribution.
674674
declaration. It is a no-op when thread support is disabled at compile time.
675675

676676
All of the following functions are only available when thread support is enabled
677-
at compile time, and must be called only when the interpreter lock has been
678-
created.
677+
at compile time, and must be called only when the global interpreter lock has
678+
been created.
679679

680680

681681
.. cfunction:: PyInterpreterState* PyInterpreterState_New()
682682

683-
Create a new interpreter state object. The interpreter lock need not be held,
684-
but may be held if it is necessary to serialize calls to this function.
683+
Create a new interpreter state object. The global interpreter lock need not
684+
be held, but may be held if it is necessary to serialize calls to this
685+
function.
685686

686687

687688
.. cfunction:: void PyInterpreterState_Clear(PyInterpreterState *interp)
688689

689-
Reset all information in an interpreter state object. The interpreter lock must
690-
be held.
690+
Reset all information in an interpreter state object. The global interpreter
691+
lock must be held.
691692

692693

693694
.. cfunction:: void PyInterpreterState_Delete(PyInterpreterState *interp)
694695

695-
Destroy an interpreter state object. The interpreter lock need not be held.
696-
The interpreter state must have been reset with a previous call to
696+
Destroy an interpreter state object. The global interpreter lock need not be
697+
held. The interpreter state must have been reset with a previous call to
697698
:cfunc:`PyInterpreterState_Clear`.
698699

699700

700701
.. cfunction:: PyThreadState* PyThreadState_New(PyInterpreterState *interp)
701702

702-
Create a new thread state object belonging to the given interpreter object. The
703-
interpreter lock need not be held, but may be held if it is necessary to
704-
serialize calls to this function.
703+
Create a new thread state object belonging to the given interpreter object.
704+
The global interpreter lock need not be held, but may be held if it is
705+
necessary to serialize calls to this function.
705706

706707

707708
.. cfunction:: void PyThreadState_Clear(PyThreadState *tstate)
708709

709-
Reset all information in a thread state object. The interpreter lock must be
710-
held.
710+
Reset all information in a thread state object. The global interpreter lock
711+
must be held.
711712

712713

713714
.. cfunction:: void PyThreadState_Delete(PyThreadState *tstate)
714715

715-
Destroy a thread state object. The interpreter lock need not be held. The
716-
thread state must have been reset with a previous call to
716+
Destroy a thread state object. The global interpreter lock need not be held.
717+
The thread state must have been reset with a previous call to
717718
:cfunc:`PyThreadState_Clear`.
718719

719720

720721
.. cfunction:: PyThreadState* PyThreadState_Get()
721722

722-
Return the current thread state. The interpreter lock must be held. When the
723-
current thread state is *NULL*, this issues a fatal error (so that the caller
724-
needn't check for *NULL*).
723+
Return the current thread state. The global interpreter lock must be held.
724+
When the current thread state is *NULL*, this issues a fatal error (so that
725+
the caller needn't check for *NULL*).
725726

726727

727728
.. cfunction:: PyThreadState* PyThreadState_Swap(PyThreadState *tstate)
728729

729730
Swap the current thread state with the thread state given by the argument
730-
*tstate*, which may be *NULL*. The interpreter lock must be held.
731+
*tstate*, which may be *NULL*. The global interpreter lock must be held.
731732

732733

733734
.. cfunction:: PyObject* PyThreadState_GetDict()
@@ -752,14 +753,15 @@ created.
752753

753754
.. cfunction:: PyGILState_STATE PyGILState_Ensure()
754755

755-
Ensure that the current thread is ready to call the Python C API regardless of
756-
the current state of Python, or of its thread lock. This may be called as many
757-
times as desired by a thread as long as each call is matched with a call to
758-
:cfunc:`PyGILState_Release`. In general, other thread-related APIs may be used
759-
between :cfunc:`PyGILState_Ensure` and :cfunc:`PyGILState_Release` calls as long
760-
as the thread state is restored to its previous state before the Release(). For
761-
example, normal usage of the :cmacro:`Py_BEGIN_ALLOW_THREADS` and
762-
:cmacro:`Py_END_ALLOW_THREADS` macros is acceptable.
756+
Ensure that the current thread is ready to call the Python C API regardless
757+
of the current state of Python, or of the global interpreter lock. This may
758+
be called as many times as desired by a thread as long as each call is
759+
matched with a call to :cfunc:`PyGILState_Release`. In general, other
760+
thread-related APIs may be used between :cfunc:`PyGILState_Ensure` and
761+
:cfunc:`PyGILState_Release` calls as long as the thread state is restored to
762+
its previous state before the Release(). For example, normal usage of the
763+
:cmacro:`Py_BEGIN_ALLOW_THREADS` and :cmacro:`Py_END_ALLOW_THREADS` macros is
764+
acceptable.
763765

764766
The return value is an opaque "handle" to the thread state when
765767
:cfunc:`PyGILState_Ensure` was called, and must be passed to
@@ -793,35 +795,34 @@ pointer and a void argument.
793795

794796
.. index:: single: setcheckinterval() (in module sys)
795797

796-
Every check interval, when the interpreter lock is released and reacquired,
797-
python will also call any such provided functions. This can be used for
798-
example by asynchronous IO handlers. The notification can be scheduled
799-
from a worker thread and the actual call than made at the earliest
800-
convenience by the main thread where it has possession of the global
801-
interpreter lock and can perform any Python API calls.
798+
Every check interval, when the global interpreter lock is released and
799+
reacquired, python will also call any such provided functions. This can be used
800+
for example by asynchronous IO handlers. The notification can be scheduled from
801+
a worker thread and the actual call than made at the earliest convenience by the
802+
main thread where it has possession of the global interpreter lock and can
803+
perform any Python API calls.
802804

803805
.. cfunction:: void Py_AddPendingCall( int (*func)(void *, void *arg) )
804806

805807
.. index:: single: Py_AddPendingCall()
806808

807-
Post a notification to the Python main thread. If successful,
808-
*func* will be called with the argument *arg* at the earliest
809-
convenience. *func* will be called having the global interpreter
810-
lock held and can thus use the full Python API and can take any
811-
action such as setting object attributes to signal IO completion.
812-
It must return 0 on success, or -1 signalling an exception.
813-
The notification function won't be interrupted to perform another
814-
asynchronous notification recursively,
815-
but it can still be interrupted to switch threads if the interpreter
816-
lock is released, for example, if it calls back into python code.
809+
Post a notification to the Python main thread. If successful, *func* will be
810+
called with the argument *arg* at the earliest convenience. *func* will be
811+
called having the global interpreter lock held and can thus use the full
812+
Python API and can take any action such as setting object attributes to
813+
signal IO completion. It must return 0 on success, or -1 signalling an
814+
exception. The notification function won't be interrupted to perform another
815+
asynchronous notification recursively, but it can still be interrupted to
816+
switch threads if the global interpreter lock is released, for example, if it
817+
calls back into python code.
817818

818819
This function returns 0 on success in which case the notification has been
819-
scheduled. Otherwise, for example if the notification buffer is full,
820-
it returns -1 without setting any exception.
820+
scheduled. Otherwise, for example if the notification buffer is full, it
821+
returns -1 without setting any exception.
821822

822-
This function can be called on any thread, be it a Python thread or
823-
some other system thread. If it is a Python thread, it doesn't matter if
824-
it holds the global interpreter lock or not.
823+
This function can be called on any thread, be it a Python thread or some
824+
other system thread. If it is a Python thread, it doesn't matter if it holds
825+
the global interpreter lock or not.
825826

826827
.. versionadded:: 2.7
827828

Doc/distutils/setupscript.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,9 @@ Other options
334334

335335
There are still some other options which can be used to handle special cases.
336336

337-
The :option:`optional` option is a boolean; if it is true, that specifies that
338-
a build failure in the extension should not abort the build process, but simply
339-
not install the failing extension.
337+
The :option:`optional` option is a boolean; if it is true,
338+
a build failure in the extension will not abort the build process, but
339+
instead simply not install the failing extension.
340340

341341
The :option:`extra_objects` option is a list of object files to be passed to the
342342
linker. These files must not have extensions, as the default extension for the

Doc/make.bat

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ setlocal
44
set SVNROOT=http://svn.python.org/projects
55
if "%PYTHON%" EQU "" set PYTHON=..\pcbuild\python
66
if "%HTMLHELP%" EQU "" set HTMLHELP=%ProgramFiles%\HTML Help Workshop\hhc.exe
7+
if "%DISTVERSION%" EQU "" for /f "usebackq" %%v in (`%PYTHON% tools/sphinxext/patchlevel.py`) do set DISTVERSION=%%v
78

89
if "%1" EQU "" goto help
910
if "%1" EQU "html" goto build
@@ -52,7 +53,7 @@ if not exist build\%1 mkdir build\%1
5253
if not exist build\doctrees mkdir build\doctrees
5354
cmd /C %PYTHON% --version
5455
cmd /C %PYTHON% tools\sphinx-build.py -b%1 -dbuild\doctrees . build\%*
55-
if "%1" EQU "htmlhelp" "%HTMLHELP%" build\htmlhelp\pydoc.hhp
56+
if "%1" EQU "htmlhelp" "%HTMLHELP%" build\htmlhelp\python%DISTVERSION:.=%.hhp
5657
goto end
5758

5859
:end

Doc/tools/sphinxext/susp-ignored.csv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ library/hotshot,,:lineno,"ncalls tottime percall cumtime percall filename:li
4848
library/httplib,,:port,host:port
4949
library/imaplib,,:MM,"""DD-Mmm-YYYY HH:MM:SS +HHMM"""
5050
library/imaplib,,:SS,"""DD-Mmm-YYYY HH:MM:SS +HHMM"""
51+
library/itertools,,:stop,elements from seq[start:stop:step]
52+
library/itertools,,:step,elements from seq[start:stop:step]
5153
library/linecache,,:sys,"sys:x:3:3:sys:/dev:/bin/sh"
5254
library/logging,,:And,
5355
library/logging,,:package1,

Lib/cgitb.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,11 @@ def reader(lnum=[lnum]):
142142
i = lnum - index
143143
for line in lines:
144144
num = small(' ' * (5-len(str(i))) + str(i)) + ' '
145-
line = '<tt>%s%s</tt>' % (num, pydoc.html.preformat(line))
146145
if i in highlight:
146+
line = '<tt>=&gt;%s%s</tt>' % (num, pydoc.html.preformat(line))
147147
rows.append('<tr><td bgcolor="#ffccee">%s</td></tr>' % line)
148148
else:
149+
line = '<tt>&nbsp;&nbsp;%s%s</tt>' % (num, pydoc.html.preformat(line))
149150
rows.append('<tr><td>%s</td></tr>' % grey(line))
150151
i += 1
151152

Lib/plistlib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""plistlib.py -- a tool to generate and parse MacOSX .plist files.
1+
r"""plistlib.py -- a tool to generate and parse MacOSX .plist files.
22
33
The PropertList (.plist) file format is a simple XML pickle supporting
44
basic object types, like dictionaries, lists, numbers and strings.

Lib/posixpath.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,10 @@ def expanduser(path):
257257
userhome = pwent.pw_dir
258258
if isinstance(path, bytes):
259259
userhome = userhome.encode(sys.getfilesystemencoding())
260-
userhome = userhome.rstrip(sep)
260+
root = b'/'
261+
else:
262+
root = '/'
263+
userhome = userhome.rstrip(root) or userhome
261264
return userhome + path[i:]
262265

263266

Lib/socket.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
except ImportError:
5353
EBADF = 9
5454

55-
__all__ = ["getfqdn"]
55+
__all__ = ["getfqdn", "create_connection"]
5656
__all__.extend(os._get_exports_list(_socket))
5757

5858

Lib/test/test_mmap.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -357,15 +357,22 @@ def test_move(self):
357357
m.move(source, dest, size)
358358
except ValueError:
359359
pass
360-
self.assertRaises(ValueError, m.move, -1, -1, -1)
361-
self.assertRaises(ValueError, m.move, -1, -1, 0)
362-
self.assertRaises(ValueError, m.move, -1, 0, -1)
363-
self.assertRaises(ValueError, m.move, 0, -1, -1)
364-
self.assertRaises(ValueError, m.move, -1, 0, 0)
365-
self.assertRaises(ValueError, m.move, 0, -1, 0)
366-
self.assertRaises(ValueError, m.move, 0, 0, -1)
360+
361+
offsets = [(-1, -1, -1), (-1, -1, 0), (-1, 0, -1), (0, -1, -1),
362+
(-1, 0, 0), (0, -1, 0), (0, 0, -1)]
363+
for source, dest, size in offsets:
364+
self.assertRaises(ValueError, m.move, source, dest, size)
365+
367366
m.close()
368367

368+
m = mmap.mmap(-1, 1) # single byte
369+
self.assertRaises(ValueError, m.move, 0, 0, 2)
370+
self.assertRaises(ValueError, m.move, 1, 0, 1)
371+
self.assertRaises(ValueError, m.move, 0, 1, 1)
372+
m.move(0, 0, 1)
373+
m.move(0, 0, 0)
374+
375+
369376
def test_anonymous(self):
370377
# anonymous mmap.mmap(-1, PAGE)
371378
m = mmap.mmap(-1, PAGESIZE)

0 commit comments

Comments
 (0)