]> granicus.if.org Git - python/commitdiff
Use PyThreadState_GET() in performance critical code
authorVictor Stinner <victor.stinner@gmail.com>
Fri, 11 Nov 2016 00:43:56 +0000 (01:43 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Fri, 11 Nov 2016 00:43:56 +0000 (01:43 +0100)
It seems like _PyThreadState_UncheckedGet() is not inlined as expected, even
when using gcc -O3.

Objects/dictobject.c
Python/errors.c
Python/sysmodule.c

index cb67dda33f783d5855f619f3718f2d0180f5cace..290686b88faa45265b914686142360db15c7b289 100644 (file)
@@ -1409,7 +1409,7 @@ PyDict_GetItem(PyObject *op, PyObject *key)
        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. */
-    tstate = _PyThreadState_UncheckedGet();
+    tstate = PyThreadState_GET();
     if (tstate != NULL && tstate->curexc_type != NULL) {
         /* preserve the existing exception */
         PyObject *err_type, *err_value, *err_tb;
index 918f4dffab275df4509c510f35e757f8d509a8e5..0c38f7cf0cd2b99f53a1c0e200fdf2ad6f0b5349 100644 (file)
@@ -161,7 +161,7 @@ PyErr_SetString(PyObject *exception, const char *string)
 PyObject *
 PyErr_Occurred(void)
 {
-    PyThreadState *tstate = _PyThreadState_UncheckedGet();
+    PyThreadState *tstate = PyThreadState_GET();
     return tstate == NULL ? NULL : tstate->curexc_type;
 }
 
index e348b3873e7e07287a9f6562a60392fa237947ec..9247d4ed69d1b37142352edf55a1c0adf96a7a76 100644 (file)
@@ -1547,8 +1547,9 @@ error:
     Py_XDECREF(name);
     Py_XDECREF(value);
     /* No return value, therefore clear error state if possible */
-    if (_PyThreadState_UncheckedGet())
+    if (_PyThreadState_UncheckedGet()) {
         PyErr_Clear();
+    }
 }
 
 PyObject *