diff options
author | Armin Rigo <arigo@tunes.org> | 2015-11-18 12:28:44 +0100 |
---|---|---|
committer | Armin Rigo <arigo@tunes.org> | 2015-11-18 12:28:44 +0100 |
commit | d995bf5eda3cd8dae5c86206ee44f4ccd77d70bb (patch) | |
tree | 14a0060a9d11803d4e629f4aa86bd668bd94faba /c | |
parent | 1b266852f4dc07efdca37f2fe495cc42b60c1a31 (diff) | |
download | cffi-d995bf5eda3cd8dae5c86206ee44f4ccd77d70bb.tar.gz |
Write one error message directly to stderr instead of sys.stderr. This
lets us avoid taking the GIL, which might crash in case the Python
interpreter is not initialized at all.
Diffstat (limited to 'c')
-rw-r--r-- | c/call_python.c | 22 |
1 files changed, 7 insertions, 15 deletions
diff --git a/c/call_python.c b/c/call_python.c index 8545ea8..4db966a 100644 --- a/c/call_python.c +++ b/c/call_python.c @@ -90,29 +90,21 @@ static void _cffi_call_python(struct _cffi_externpy_s *externpy, char *args) at least 8 bytes in size. */ save_errno(); - { -#ifdef WITH_THREAD - PyGILState_STATE state = PyGILState_Ensure(); -#endif if (externpy->reserved1 == NULL) { /* not initialized! */ - PyObject *f = PySys_GetObject("stderr"); - if (f != NULL) { - PyFile_WriteString("extern \"Python\": function ", f); - PyFile_WriteString(externpy->name, f); - PyFile_WriteString("() called, but no code was attached " - "to it yet with @ffi.def_extern(). " - "Returning 0.\n", f); - } + fprintf(stderr, "extern \"Python\": function %s() called, " + "but no code was attached to it yet with " + "@ffi.def_extern(). Returning 0.\n", externpy->name); memset(args, 0, externpy->size_of_result); } else { +#ifdef WITH_THREAD + PyGILState_STATE state = PyGILState_Ensure(); +#endif general_invoke_callback(0, args, args, externpy->reserved1); - } - #ifdef WITH_THREAD - PyGILState_Release(state); + PyGILState_Release(state); #endif } restore_errno(); |