[Python-checkins] r47161 - in python/trunk: Misc/NEWS Modules/_ctypes/_ctypes.c Modules/_ctypes/callbacks.c Modules/_ctypes/callproc.c

thomas.heller python-checkins at python.org
Thu Jun 29 20:34:17 CEST 2006


Author: thomas.heller
Date: Thu Jun 29 20:34:15 2006
New Revision: 47161
Modified:
 python/trunk/Misc/NEWS
 python/trunk/Modules/_ctypes/_ctypes.c
 python/trunk/Modules/_ctypes/callbacks.c
 python/trunk/Modules/_ctypes/callproc.c
Log:
Protect the thread api calls in the _ctypes extension module within
#ifdef WITH_THREADS/#endif blocks. Found by Sam Rushing.
Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Thu Jun 29 20:34:15 2006
@@ -19,6 +19,9 @@
 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.
 
Modified: python/trunk/Modules/_ctypes/_ctypes.c
==============================================================================
--- python/trunk/Modules/_ctypes/_ctypes.c	(original)
+++ python/trunk/Modules/_ctypes/_ctypes.c	Thu Jun 29 20:34:15 2006
@@ -4555,7 +4555,9 @@
 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;
Modified: python/trunk/Modules/_ctypes/callbacks.c
==============================================================================
--- python/trunk/Modules/_ctypes/callbacks.c	(original)
+++ python/trunk/Modules/_ctypes/callbacks.c	Thu Jun 29 20:34:15 2006
@@ -127,7 +127,9 @@
 	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 @@
 	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 @@
 			 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 @@
 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;
 }
 
Modified: python/trunk/Modules/_ctypes/callproc.c
==============================================================================
--- python/trunk/Modules/_ctypes/callproc.c	(original)
+++ python/trunk/Modules/_ctypes/callproc.c	Thu Jun 29 20:34:15 2006
@@ -617,7 +617,9 @@
 				 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 @@
 		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 @@
 	}
 #endif
 #endif
+#ifdef WITH_THREADS
 	if ((flags & FUNCFLAG_PYTHONAPI) == 0)
 		Py_BLOCK_THREADS
+#endif
 #ifdef MS_WIN32
 #ifndef DONT_USE_SEH
 	if (dwExceptionCode) {


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /