[pypy-commit] pypy py3k: test_capi expects a fatal error when PyThreadState_Get would have been NULL

pjenvey noreply at buildbot.pypy.org
Sun Apr 14 01:40:08 CEST 2013


Author: Philip Jenvey <pjenvey at underboss.org>
Branch: py3k
Changeset: r63329:0ac0a778e15b
Date: 2013-04-13 16:36 -0700
http://bitbucket.org/pypy/pypy/changeset/0ac0a778e15b/

Log:	test_capi expects a fatal error when PyThreadState_Get would have
	been NULL

diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -651,12 +651,13 @@
         lambda space: init_capsule(),
     ])
     from pypy.module.posix.interp_posix import add_fork_hook
-    if translating:
-        reinit_tls = rffi.llexternal('PyThread_ReInitTLS', [], lltype.Void,
-                                     compilation_info=eci)
-    else:
-        reinit_tls = rffi.llexternal('PyPyThread_ReInitTLS', [], lltype.Void,
-                                     compilation_info=eci)
+    prefix = 'Py' if translating else 'PyPy'
+    reinit_tls = rffi.llexternal(prefix + 'Thread_ReInitTLS', [], lltype.Void,
+                                 compilation_info=eci)
+    global py_fatalerror
+    py_fatalerror = rffi.llexternal(prefix + '_FatalError',
+                                    [CONST_STRING], lltype.Void,
+                                    compilation_info=eci)
     add_fork_hook('child', reinit_tls)
 
 def init_function(func):
diff --git a/pypy/module/cpyext/include/pythonrun.h b/pypy/module/cpyext/include/pythonrun.h
--- a/pypy/module/cpyext/include/pythonrun.h
+++ b/pypy/module/cpyext/include/pythonrun.h
@@ -6,7 +6,7 @@
 extern "C" {
 #endif
 
-  void Py_FatalError(const char *msg);
+PyAPI_FUNC(void) Py_FatalError(const char *message);
 
 /* the -3 option will probably not be implemented */
 #define Py_Py3kWarningFlag 0
diff --git a/pypy/module/cpyext/pystate.py b/pypy/module/cpyext/pystate.py
--- a/pypy/module/cpyext/pystate.py
+++ b/pypy/module/cpyext/pystate.py
@@ -161,7 +161,11 @@
 @cpython_api([], PyThreadState, error=CANNOT_FAIL)
 def PyThreadState_Get(space):
     state = space.fromcache(InterpreterState)
-    return state.get_thread_state(space)
+    ts = state.get_thread_state(space)
+    if not ts:
+        from pypy.module.cpyext.api import py_fatalerror
+        py_fatalerror("PyThreadState_Get: no current thread")
+    return ts
 
 @cpython_api([], PyObject, error=CANNOT_FAIL)
 def PyThreadState_GetDict(space):


More information about the pypy-commit mailing list