cpython: f9461f1e0559 (original) (raw)

Mercurial > cpython

changeset 99999:f9461f1e0559 3.5

Add _PyThreadState_UncheckedGet() Issue #26154: Add a new private _PyThreadState_UncheckedGet() function which gets the current thread state, but don't call Py_FatalError() if it is NULL. Python 3.5.1 removed the _PyThreadState_Current symbol from the Python C API to no more expose complex and private atomic types. Atomic types depends on the compiler or can even depend on compiler options. The new function _PyThreadState_UncheckedGet() allows to get the variable value without having to care of the exact implementation of atomic types. Changes: * Replace direct usage of the _PyThreadState_Current variable with a call to _PyThreadState_UncheckedGet(). * In pystate.c, replace direct usage of the _PyThreadState_Current variable with the PyThreadState_GET() macro for readability. * Document also PyThreadState_Get() in pystate.h [#26154]

Victor Stinner victor.stinner@gmail.com
date Wed, 20 Jan 2016 11:12:38 +0100
parents 6c624ba1b61e
children d4f13c9a2b07 32ee5d197500
files Include/pystate.h Misc/NEWS Modules/faulthandler.c Objects/dictobject.c Python/errors.c Python/pystate.c Python/sysmodule.c
diffstat 7 files changed, 42 insertions(+), 26 deletions(-)[+] [-] Include/pystate.h 10 Misc/NEWS 7 Modules/faulthandler.c 2 Objects/dictobject.c 6 Python/errors.c 8 Python/pystate.c 33 Python/sysmodule.c 2

line wrap: on

line diff

--- a/Include/pystate.h +++ b/Include/pystate.h @@ -168,7 +168,17 @@ PyAPI_FUNC(void) PyThreadState_DeleteCur PyAPI_FUNC(void) _PyGILState_Reinit(void); #endif +/* Return the current thread state. The global interpreter lock must be held.

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,13 @@ Release date: tba Core and Builtins ----------------- +- Issue #26154: Add a new private _PyThreadState_UncheckedGet() function to get

--- a/Modules/faulthandler.c +++ b/Modules/faulthandler.c @@ -490,7 +490,7 @@ faulthandler_thread(void unused) assert(st == PY_LOCK_FAILURE); / get the thread holding the GIL, NULL if no thread hold the GIL */

_Py_write_noraise(thread.fd, thread.header, (int)thread.header_len);

--- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -1064,8 +1064,7 @@ PyDict_GetItem(PyObject *op, PyObject *k Let's just hope that no exception occurs then... This must be _PyThreadState_Current and not PyThreadState_GET() because in debug mode, the latter complains if tstate is NULL. */

@@ -1102,8 +1101,7 @@ PyObject * Let's just hope that no exception occurs then... This must be _PyThreadState_Current and not PyThreadState_GET() because in debug mode, the latter complains if tstate is NULL. */

--- a/Python/errors.c +++ b/Python/errors.c @@ -152,13 +152,7 @@ PyErr_SetString(PyObject *exception, con PyObject * PyErr_Occurred(void) {

-

--- a/Python/pystate.c +++ b/Python/pystate.c @@ -3,6 +3,12 @@ #include "Python.h" +#ifndef Py_BUILD_CORE +/* ensure that PyThreadState_GET() is a macro, not an alias to

#ifdef WITH_THREAD if (autoInterpreterState && PyThread_get_key_value(autoTLSkey) == tstate) @@ -437,8 +443,7 @@ PyThreadState_Delete(PyThreadState *tsta void PyThreadState_DeleteCurrent() {

@@ -489,10 +494,16 @@ void PyThreadState * +_PyThreadState_UncheckedGet(void) +{

+} + + +PyThreadState * PyThreadState_Get(void) {

@@ -503,8 +514,7 @@ PyThreadState_Get(void) PyThreadState * PyThreadState_Swap(PyThreadState *newts) {

_Py_atomic_store_relaxed(&_PyThreadState_Current, newts); /* It should not be possible for more than one thread state @@ -535,8 +545,7 @@ PyThreadState_Swap(PyThreadState *newts) PyObject * PyThreadState_GetDict(void) {

@@ -682,7 +691,7 @@ PyThreadState_IsCurrent(PyThreadState t { / Must be the tstate for this thread */ assert(PyGILState_GetThisThreadState()==tstate);

} /* Internal initialization/finalization functions called by @@ -774,9 +783,7 @@ PyGILState_GetThisThreadState(void) int PyGILState_Check(void) {

--- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -1397,7 +1397,7 @@ error: Py_XDECREF(name); Py_XDECREF(value); /* No return value, therefore clear error state if possible */

}