]> granicus.if.org Git - python/commitdiff
Protect the thread api calls in the _ctypes extension module within
authorThomas Heller <theller@ctypes.org>
Thu, 29 Jun 2006 18:34:15 +0000 (18:34 +0000)
committerThomas Heller <theller@ctypes.org>
Thu, 29 Jun 2006 18:34:15 +0000 (18:34 +0000)
#ifdef WITH_THREADS/#endif blocks.  Found by Sam Rushing.

Misc/NEWS
Modules/_ctypes/_ctypes.c
Modules/_ctypes/callbacks.c
Modules/_ctypes/callproc.c

index 8e83867b3c2478b29a5743bb60924ed4edf4875f..2b3a8df005bf2b7a695ac1729794b9b925013aa6 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -19,6 +19,9 @@ Core and builtins
 Library
 -------
 
+- The '_ctypes' extension module now works when Python is configured
+  with the --without-threads option.
+
 - Bug #1504333: Make sgmllib support angle brackets in quoted
   attribute values.
 
index 4b075913075f5f7db27f0d0ff3d004b4222c89c7..a36166db71359b46593848c196c6372e26a98f3a 100644 (file)
@@ -4555,7 +4555,9 @@ init_ctypes(void)
    ob_type is the metatype (the 'type'), defaults to PyType_Type,
    tp_base is the base type, defaults to 'object' aka PyBaseObject_Type.
 */
+#ifdef WITH_THREADS
        PyEval_InitThreads();
+#endif
        m = Py_InitModule3("_ctypes", module_methods, module_docs);
        if (!m)
                return;
index b4f09e0361bfa519d2640c63cfe2870c25ef6c62..9d08f1a3dc3207b253985b26b9013e53148ccb3c 100644 (file)
@@ -127,7 +127,9 @@ static void _CallPythonObject(void *mem,
        PyObject *result;
        PyObject *arglist = NULL;
        int nArgs;
+#ifdef WITH_THREADS
        PyGILState_STATE state = PyGILState_Ensure();
+#endif
 
        nArgs = PySequence_Length(converters);
        /* Hm. What to return in case of error?
@@ -235,8 +237,9 @@ if (x == NULL) _AddTraceback(what, __FILE__, __LINE__ - 1), PyErr_Print()
        Py_XDECREF(result);
   Done:
        Py_XDECREF(arglist);
-       
+#ifdef WITH_THREADS    
        PyGILState_Release(state);
+#endif
 }
 
 static void closure_fcn(ffi_cif *cif,
@@ -397,12 +400,18 @@ STDAPI DllGetClassObject(REFCLSID rclsid,
                         LPVOID *ppv)
 {
        long result;
+#ifdef WITH_THREADS
        PyGILState_STATE state;
+#endif
 
        LoadPython();
+#ifdef WITH_THREADS
        state = PyGILState_Ensure();
+#endif
        result = Call_GetClassObject(rclsid, riid, ppv);
+#ifdef WITH_THREADS
        PyGILState_Release(state);
+#endif
        return result;
 }
 
@@ -454,9 +463,13 @@ long Call_CanUnloadNow(void)
 STDAPI DllCanUnloadNow(void)
 {
        long result;
+#ifdef WITH_THREADS
        PyGILState_STATE state = PyGILState_Ensure();
+#endif
        result = Call_CanUnloadNow();
+#ifdef WITH_THREADS
        PyGILState_Release(state);
+#endif
        return result;
 }
 
index c229106c7af620614af63e104b33df28514e03db..a084f812f60c719c765c63da061e732270b27ddc 100644 (file)
@@ -617,7 +617,9 @@ static int _call_function_pointer(int flags,
                                  void *resmem,
                                  int argcount)
 {
+#ifdef WITH_THREADS
        PyThreadState *_save = NULL; /* For Py_BLOCK_THREADS and Py_UNBLOCK_THREADS */
+#endif
        ffi_cif cif;
        int cc;
 #ifdef MS_WIN32
@@ -649,8 +651,10 @@ static int _call_function_pointer(int flags,
                return -1;
        }
 
+#ifdef WITH_THREADS
        if ((flags & FUNCFLAG_PYTHONAPI) == 0)
                Py_UNBLOCK_THREADS
+#endif
 #ifdef MS_WIN32
 #ifndef DONT_USE_SEH
        __try {
@@ -667,8 +671,10 @@ static int _call_function_pointer(int flags,
        }
 #endif
 #endif
+#ifdef WITH_THREADS
        if ((flags & FUNCFLAG_PYTHONAPI) == 0)
                Py_BLOCK_THREADS
+#endif
 #ifdef MS_WIN32
 #ifndef DONT_USE_SEH
        if (dwExceptionCode) {