Skip to content

Commit e1c9811

Browse files
committed
Merged revisions 60143-60149 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r60143 | georg.brandl | 2008-01-20 15:50:05 +0100 (Sun, 20 Jan 2008) | 3 lines Switch mmap from old Py_FindMethod to new PyObject_GenericGetAttr attribute access. Fixes #1087735. ........ r60145 | georg.brandl | 2008-01-20 20:40:58 +0100 (Sun, 20 Jan 2008) | 2 lines Add blurb about executable scripts on Windows. #760657. ........ r60146 | georg.brandl | 2008-01-20 20:48:40 +0100 (Sun, 20 Jan 2008) | 2 lines #1219903: fix tp_richcompare docs. ........ r60147 | georg.brandl | 2008-01-20 22:10:08 +0100 (Sun, 20 Jan 2008) | 2 lines Fix markup. ........ r60148 | gregory.p.smith | 2008-01-21 08:11:11 +0100 (Mon, 21 Jan 2008) | 14 lines Provide a sanity check during PyThreadState_DeleteCurrent() and PyThreadState_Delete() to avoid an infinite loop when the tstate list is messed up and has somehow becomes circular and does not contain the current thread. I don't know how this happens but it does, *very* rarely. On more than one hardware platform. I have not been able to reproduce it manually. Attaching to a process where its happening: it has always been in an infinite loop over a single element tstate list that is not the tstate we're looking to delete. It has been in t_bootstrap()'s call to PyThreadState_DeleteCurrent() as a pthread is exiting. ........ r60149 | georg.brandl | 2008-01-21 11:24:59 +0100 (Mon, 21 Jan 2008) | 2 lines python#1269: fix a bug in pstats.add_callers() and add a unit test file for pstats. ........
1 parent 9bd667a commit e1c9811

7 files changed

Lines changed: 97 additions & 22 deletions

File tree

Doc/c-api/typeobj.rst

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -649,13 +649,19 @@ The following three fields only exist if the
649649

650650
.. cmember:: richcmpfunc PyTypeObject.tp_richcompare
651651

652-
An optional pointer to the rich comparison function.
652+
An optional pointer to the rich comparison function, whose signature is
653+
``PyObject *tp_richcompare(PyObject *a, PyObject *b, int op)``.
653654

654-
The signature is the same as for :cfunc:`PyObject_RichCompare`. The function
655-
should return the result of the comparison (usually ``Py_True`` or
656-
``Py_False``). If the comparison is undefined, it must return
657-
``Py_NotImplemented``, if another error occurred it must return ``NULL`` and set
658-
an exception condition.
655+
The function should return the result of the comparison (usually ``Py_True``
656+
or ``Py_False``). If the comparison is undefined, it must return
657+
``Py_NotImplemented``, if another error occurred it must return ``NULL`` and
658+
set an exception condition.
659+
660+
.. note::
661+
662+
If you want to implement a type for which only a limited set of
663+
comparisons makes sense (e.g. ``==`` and ``!=``, but not ``<`` and
664+
friends), directly raise :exc:`TypeError` in the rich comparison function.
659665

660666
This field is inherited by subtypes together with :attr:`tp_compare` and
661667
:attr:`tp_hash`: a subtype inherits all three of :attr:`tp_compare`,
@@ -681,10 +687,10 @@ The following three fields only exist if the
681687
| :const:`Py_GE` | ``>=`` |
682688
+----------------+------------+
683689

690+
684691
The next field only exists if the :const:`Py_TPFLAGS_HAVE_WEAKREFS` flag bit is
685692
set.
686693

687-
688694
.. cmember:: long PyTypeObject.tp_weaklistoffset
689695

690696
If the instances of this type are weakly referenceable, this field is greater

Doc/tutorial/interpreter.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,12 @@ The script can be given an executable mode, or permission, using the
169169

170170
$ chmod +x myscript.py
171171

172+
On Windows systems, there is no notion of an "executable mode". The Python
173+
installer automatically associates ``.py`` files with ``python.exe`` so that
174+
a double-click on a Python file will run it as a script. The extension can
175+
also be ``.pyw``, in that case, the console window that normally appears is
176+
suppressed.
177+
172178

173179
Source Code Encoding
174180
--------------------

Doc/using/cmdline.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,14 +297,14 @@ These environment variables influence Python's behavior.
297297
.. envvar:: PYTHONHOME
298298

299299
Change the location of the standard Python libraries. By default, the
300-
libraries are searched in :file:`{prefix}/lib/python<version>` and
301-
:file:`{exec_prefix}/lib/python<version>`, where :file:`{prefix}` and
300+
libraries are searched in :file:`{prefix}/lib/python{version}` and
301+
:file:`{exec_prefix}/lib/python{version}`, where :file:`{prefix}` and
302302
:file:`{exec_prefix}` are installation-dependent directories, both defaulting
303303
to :file:`/usr/local`.
304304

305305
When :envvar:`PYTHONHOME` is set to a single directory, its value replaces
306306
both :file:`{prefix}` and :file:`{exec_prefix}`. To specify different values
307-
for these, set :envvar:`PYTHONHOME` to :file:`{prefix}:{exec_prefix}``.
307+
for these, set :envvar:`PYTHONHOME` to :file:`{prefix}:{exec_prefix}`.
308308

309309

310310
.. envvar:: PYTHONPATH
@@ -314,7 +314,7 @@ These environment variables influence Python's behavior.
314314
colons. Non-existent directories are silently ignored.
315315

316316
The default search path is installation dependent, but generally begins with
317-
:file:`{prefix}/lib/python<version>`` (see :envvar:`PYTHONHOME` above). It
317+
:file:`{prefix}/lib/python{version}`` (see :envvar:`PYTHONHOME` above). It
318318
is *always* appended to :envvar:`PYTHONPATH`.
319319

320320
If a script argument is given, the directory containing the script is

Lib/pstats.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,8 @@ def add_callers(target, source):
511511
new_callers[func] = caller
512512
for func, caller in source.items():
513513
if func in new_callers:
514-
new_callers[func] = caller + new_callers[func]
514+
new_callers[func] = tuple([i[0] + i[1] for i in
515+
zip(caller, new_callers[func])])
515516
else:
516517
new_callers[func] = caller
517518
return new_callers

Lib/test/test_pstats.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import unittest
2+
from test import test_support
3+
import pstats
4+
5+
6+
7+
class AddCallersTestCase(unittest.TestCase):
8+
"""Tests for pstats.add_callers helper."""
9+
10+
def test_combine_results(self):
11+
"""pstats.add_callers should combine the call results of both target
12+
and source by adding the call time. See issue1269."""
13+
target = {"a": (1, 2, 3, 4)}
14+
source = {"a": (1, 2, 3, 4), "b": (5, 6, 7, 8)}
15+
new_callers = pstats.add_callers(target, source)
16+
self.assertEqual(new_callers, {'a': (2, 4, 6, 8), 'b': (5, 6, 7, 8)})
17+
18+
19+
def test_main():
20+
test_support.run_unittest(
21+
AddCallersTestCase
22+
)
23+
24+
25+
if __name__ == "__main__":
26+
test_main()

Modules/mmapmodule.c

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -666,12 +666,6 @@ mmap_buffer_releasebuf(mmap_object *self, Py_buffer *view)
666666
self->exports--;
667667
}
668668

669-
static PyObject *
670-
mmap_object_getattr(mmap_object *self, char *name)
671-
{
672-
return Py_FindMethod(mmap_object_methods, (PyObject *)self, name);
673-
}
674-
675669
static Py_ssize_t
676670
mmap_length(mmap_object *self)
677671
{
@@ -901,6 +895,30 @@ static PyBufferProcs mmap_as_buffer = {
901895
(releasebufferproc)mmap_buffer_releasebuf,
902896
};
903897

898+
PyDoc_STRVAR(mmap_doc,
899+
"Windows: mmap(fileno, length[, tagname[, access[, offset]]])\n\
900+
\n\
901+
Maps length bytes from the file specified by the file handle fileno,\n\
902+
and returns a mmap object. If length is larger than the current size\n\
903+
of the file, the file is extended to contain length bytes. If length\n\
904+
is 0, the maximum length of the map is the current size of the file,\n\
905+
except that if the file is empty Windows raises an exception (you cannot\n\
906+
create an empty mapping on Windows).\n\
907+
\n\
908+
Unix: mmap(fileno, length[, flags[, prot[, access[, offset]]]])\n\
909+
\n\
910+
Maps length bytes from the file specified by the file descriptor fileno,\n\
911+
and returns a mmap object. If length is 0, the maximum length of the map\n\
912+
will be the current size of the file when mmap is called.\n\
913+
flags specifies the nature of the mapping. MAP_PRIVATE creates a\n\
914+
private copy-on-write mapping, so changes to the contents of the mmap\n\
915+
object will be private to this process, and MAP_SHARED`creates a mapping\n\
916+
that's shared with all other processes mapping the same areas of the file.\n\
917+
The default value is MAP_SHARED.\n\
918+
\n\
919+
To map anonymous memory, pass -1 as the fileno (both versions).");
920+
921+
904922
static PyTypeObject mmap_object_type = {
905923
PyVarObject_HEAD_INIT(0, 0) /* patched in module init */
906924
"mmap.mmap", /* tp_name */
@@ -909,7 +927,7 @@ static PyTypeObject mmap_object_type = {
909927
/* methods */
910928
(destructor) mmap_object_dealloc, /* tp_dealloc */
911929
0, /* tp_print */
912-
(getattrfunc) mmap_object_getattr, /* tp_getattr */
930+
0, /* tp_getattr */
913931
0, /* tp_setattr */
914932
0, /* tp_compare */
915933
0, /* tp_repr */
@@ -919,11 +937,19 @@ static PyTypeObject mmap_object_type = {
919937
0, /*tp_hash*/
920938
0, /*tp_call*/
921939
0, /*tp_str*/
922-
0, /*tp_getattro*/
940+
PyObject_GenericGetAttr, /*tp_getattro*/
923941
0, /*tp_setattro*/
924942
&mmap_as_buffer, /*tp_as_buffer*/
925943
Py_TPFLAGS_DEFAULT, /*tp_flags*/
926-
0, /*tp_doc*/
944+
mmap_doc, /*tp_doc*/
945+
0, /* tp_traverse */
946+
0, /* tp_clear */
947+
0, /* tp_richcompare */
948+
0, /* tp_weaklistoffset */
949+
0, /* tp_iter */
950+
0, /* tp_iternext */
951+
mmap_object_methods, /* tp_methods */
952+
927953
};
928954

929955

@@ -1265,7 +1291,7 @@ new_mmap_object(PyObject *self, PyObject *args, PyObject *kwdict)
12651291
/* List of functions exported by this module */
12661292
static struct PyMethodDef mmap_functions[] = {
12671293
{"mmap", (PyCFunction) new_mmap_object,
1268-
METH_VARARGS|METH_KEYWORDS},
1294+
METH_VARARGS|METH_KEYWORDS, mmap_doc},
12691295
{NULL, NULL} /* Sentinel */
12701296
};
12711297

Python/pystate.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ tstate_delete_common(PyThreadState *tstate)
242242
{
243243
PyInterpreterState *interp;
244244
PyThreadState **p;
245+
PyThreadState *prev_p = NULL;
245246
if (tstate == NULL)
246247
Py_FatalError("PyThreadState_Delete: NULL tstate");
247248
interp = tstate->interp;
@@ -254,6 +255,15 @@ tstate_delete_common(PyThreadState *tstate)
254255
"PyThreadState_Delete: invalid tstate");
255256
if (*p == tstate)
256257
break;
258+
if (*p == prev_p)
259+
Py_FatalError(
260+
"PyThreadState_Delete: small circular list(!)"
261+
" and tstate not found.");
262+
prev_p = *p;
263+
if ((*p)->next == interp->tstate_head)
264+
Py_FatalError(
265+
"PyThreadState_Delete: circular list(!) and"
266+
" tstate not found.");
257267
}
258268
*p = tstate->next;
259269
HEAD_UNLOCK();

0 commit comments

Comments
 (0)