From c3e5b10ae76c3ffe8672e91a5478a19e35b60220 Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Sun, 7 Oct 2012 19:18:39 +0300 Subject: [PATCH 1/3] Issue #14900: Add aliases for sorting params for pstat to follow column names from pstat output. Patch by Arne Babenhauserheide. --- Lib/pstats.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Lib/pstats.py b/Lib/pstats.py index a41962aef62..bfbaa41386e 100644 --- a/Lib/pstats.py +++ b/Lib/pstats.py @@ -159,8 +159,11 @@ class Stats: # along with some printable description sort_arg_dict_default = { "calls" : (((1,-1), ), "call count"), + "ncalls" : (((1,-1), ), "call count"), + "cumtime" : (((3,-1), ), "cumulative time"), "cumulative": (((3,-1), ), "cumulative time"), "file" : (((4, 1), ), "file name"), + "filename" : (((4, 1), ), "file name"), "line" : (((5, 1), ), "line number"), "module" : (((4, 1), ), "file name"), "name" : (((6, 1), ), "function name"), @@ -168,6 +171,7 @@ class Stats: "pcalls" : (((0,-1), ), "primitive call count"), "stdname" : (((7, 1), ), "standard name"), "time" : (((2,-1), ), "internal time"), + "tottime" : (((2,-1), ), "internal time"), } def get_sort_arg_defs(self): From 8fb9f4cf7b4b39ee8f4992d338181377c60d5ddc Mon Sep 17 00:00:00 2001 From: Richard Oudkerk Date: Sun, 7 Oct 2012 18:08:47 +0100 Subject: [PATCH 2/3] Get rid of circular import and eliminate unprefixed exported symbols from _multiprocessing. --- Modules/_multiprocessing/multiprocessing.c | 21 ++++++--------------- Modules/_multiprocessing/multiprocessing.h | 6 ++---- Modules/_multiprocessing/semaphore.c | 14 +++++++------- 3 files changed, 15 insertions(+), 26 deletions(-) diff --git a/Modules/_multiprocessing/multiprocessing.c b/Modules/_multiprocessing/multiprocessing.c index eb05c62b0d0..110eff710ed 100644 --- a/Modules/_multiprocessing/multiprocessing.c +++ b/Modules/_multiprocessing/multiprocessing.c @@ -10,14 +10,12 @@ #include "multiprocessing.h" -PyObject *ProcessError, *BufferTooShort; - /* * Function which raises exceptions based on error codes */ PyObject * -mp_SetError(PyObject *Type, int num) +_PyMp_SetError(PyObject *Type, int num) { switch (num) { #ifdef MS_WINDOWS @@ -159,19 +157,12 @@ PyInit__multiprocessing(void) if (!module) return NULL; - /* Get copy of BufferTooShort */ - temp = PyImport_ImportModule("multiprocessing"); - if (!temp) - return NULL; - BufferTooShort = PyObject_GetAttrString(temp, "BufferTooShort"); - Py_XDECREF(temp); - #if defined(MS_WINDOWS) || \ (defined(HAVE_SEM_OPEN) && !defined(POSIX_SEMAPHORES_NOT_ENABLED)) - /* Add SemLock type to module */ - if (PyType_Ready(&SemLockType) < 0) + /* Add _PyMp_SemLock type to module */ + if (PyType_Ready(&_PyMp_SemLockType) < 0) return NULL; - Py_INCREF(&SemLockType); + Py_INCREF(&_PyMp_SemLockType); { PyObject *py_sem_value_max; /* Some systems define SEM_VALUE_MAX as an unsigned value that @@ -182,10 +173,10 @@ PyInit__multiprocessing(void) py_sem_value_max = PyLong_FromLong(SEM_VALUE_MAX); if (py_sem_value_max == NULL) return NULL; - PyDict_SetItemString(SemLockType.tp_dict, "SEM_VALUE_MAX", + PyDict_SetItemString(_PyMp_SemLockType.tp_dict, "SEM_VALUE_MAX", py_sem_value_max); } - PyModule_AddObject(module, "SemLock", (PyObject*)&SemLockType); + PyModule_AddObject(module, "SemLock", (PyObject*)&_PyMp_SemLockType); #endif /* Add configuration macros */ diff --git a/Modules/_multiprocessing/multiprocessing.h b/Modules/_multiprocessing/multiprocessing.h index e3de9baf1b3..0759a80e44b 100644 --- a/Modules/_multiprocessing/multiprocessing.h +++ b/Modules/_multiprocessing/multiprocessing.h @@ -91,15 +91,13 @@ #define MP_SOCKET_ERROR (-1002) #define MP_EXCEPTION_HAS_BEEN_SET (-1003) -PyObject *mp_SetError(PyObject *Type, int num); +PyObject *_PyMp_SetError(PyObject *Type, int num); /* * Externs - not all will really exist on all platforms */ -extern PyObject *BufferTooShort; -extern PyTypeObject SemLockType; -extern PyTypeObject PipeConnectionType; +extern PyTypeObject _PyMp_SemLockType; /* * Miscellaneous diff --git a/Modules/_multiprocessing/semaphore.c b/Modules/_multiprocessing/semaphore.c index 8ea92f2b588..ccd5f017eca 100644 --- a/Modules/_multiprocessing/semaphore.c +++ b/Modules/_multiprocessing/semaphore.c @@ -193,7 +193,7 @@ semlock_release(SemLockObject *self, PyObject *args) #ifndef HAVE_SEM_TIMEDWAIT # define sem_timedwait(sem,deadline) sem_timedwait_save(sem,deadline,_save) -int +static int sem_timedwait_save(sem_t *sem, struct timespec *deadline, PyThreadState *_save) { int res; @@ -444,7 +444,7 @@ semlock_new(PyTypeObject *type, PyObject *args, PyObject *kwds) failure: if (handle != SEM_FAILED) SEM_CLOSE(handle); - mp_SetError(NULL, MP_STANDARD_ERROR); + _PyMp_SetError(NULL, MP_STANDARD_ERROR); return NULL; } @@ -491,7 +491,7 @@ semlock_getvalue(SemLockObject *self) #else int sval; if (SEM_GETVALUE(self->handle, &sval) < 0) - return mp_SetError(NULL, MP_STANDARD_ERROR); + return _PyMp_SetError(NULL, MP_STANDARD_ERROR); /* some posix implementations use negative numbers to indicate the number of waiting threads */ if (sval < 0) @@ -507,16 +507,16 @@ semlock_iszero(SemLockObject *self) if (sem_trywait(self->handle) < 0) { if (errno == EAGAIN) Py_RETURN_TRUE; - return mp_SetError(NULL, MP_STANDARD_ERROR); + return _PyMp_SetError(NULL, MP_STANDARD_ERROR); } else { if (sem_post(self->handle) < 0) - return mp_SetError(NULL, MP_STANDARD_ERROR); + return _PyMp_SetError(NULL, MP_STANDARD_ERROR); Py_RETURN_FALSE; } #else int sval; if (SEM_GETVALUE(self->handle, &sval) < 0) - return mp_SetError(NULL, MP_STANDARD_ERROR); + return _PyMp_SetError(NULL, MP_STANDARD_ERROR); return PyBool_FromLong((long)sval == 0); #endif } @@ -574,7 +574,7 @@ static PyMemberDef semlock_members[] = { * Semaphore type */ -PyTypeObject SemLockType = { +PyTypeObject _PyMp_SemLockType = { PyVarObject_HEAD_INIT(NULL, 0) /* tp_name */ "_multiprocessing.SemLock", /* tp_basicsize */ sizeof(SemLockObject), From 2aa5f3cf510fd8e5f7fe2760a79618e1ae4c24cd Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Sun, 7 Oct 2012 23:21:15 +0300 Subject: [PATCH 3/3] Issue #16120: Use |yield from| in stdlib. Patch by Berker Peksag. --- Lib/pkgutil.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Lib/pkgutil.py b/Lib/pkgutil.py index 3117c177958..c695cf10815 100644 --- a/Lib/pkgutil.py +++ b/Lib/pkgutil.py @@ -455,8 +455,7 @@ def iter_importers(fullname=""): if path is None: return else: - for importer in sys.meta_path: - yield importer + yield from sys.meta_path path = sys.path for item in path: yield get_importer(item)