From d995bf5eda3cd8dae5c86206ee44f4ccd77d70bb Mon Sep 17 00:00:00 2001 From: Armin Rigo Date: Wed, 18 Nov 2015 12:28:44 +0100 Subject: 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. --- c/call_python.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) (limited to 'c/call_python.c') 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(); -- cgit v1.2.1