Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(206822)

Side by Side Diff: Modules/_ctypes/callbacks.c

Issue 10915: Make the PyGILState API compatible with multiple interpreters
Patch Set: Created 8 years, 9 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Include/pystate.h ('k') | Modules/_ctypes/ctypes.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #include "Python.h" 1 #include "Python.h"
2 #include "frameobject.h" 2 #include "frameobject.h"
3 3
4 #include <ffi.h> 4 #include <ffi.h>
5 #ifdef MS_WIN32 5 #ifdef MS_WIN32
6 #include <windows.h> 6 #include <windows.h>
7 #endif 7 #endif
8 #include "ctypes.h" 8 #include "ctypes.h"
9 9
10 /**************************************************************/ 10 /**************************************************************/
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 #endif 144 #endif
145 145
146 /****************************************************************************** 146 /******************************************************************************
147 * 147 *
148 * Call the python object with all arguments 148 * Call the python object with all arguments
149 * 149 *
150 */ 150 */
151 static void _CallPythonObject(void *mem, 151 static void _CallPythonObject(void *mem,
152 ffi_type *restype, 152 ffi_type *restype,
153 SETFUNC setfunc, 153 SETFUNC setfunc,
154 PyInterpreterState *interp,
154 PyObject *callable, 155 PyObject *callable,
155 PyObject *converters, 156 PyObject *converters,
156 int flags, 157 int flags,
157 void **pArgs) 158 void **pArgs)
158 { 159 {
159 Py_ssize_t i; 160 Py_ssize_t i;
160 PyObject *result; 161 PyObject *result;
161 PyObject *arglist = NULL; 162 PyObject *arglist = NULL;
162 Py_ssize_t nArgs; 163 Py_ssize_t nArgs;
163 PyObject *error_object = NULL; 164 PyObject *error_object = NULL;
164 int *space; 165 int *space;
165 #ifdef WITH_THREAD 166 #ifdef WITH_THREAD
166 PyGILState_STATE state = PyGILState_Ensure(); 167 PyGILState_STATE state = PyGILState_EnsureEx(interp);
167 #endif 168 #endif
168 169
169 nArgs = PySequence_Length(converters); 170 nArgs = PySequence_Length(converters);
170 /* Hm. What to return in case of error? 171 /* Hm. What to return in case of error?
171 For COM, 0xFFFFFFFF seems better than 0. 172 For COM, 0xFFFFFFFF seems better than 0.
172 */ 173 */
173 if (nArgs < 0) { 174 if (nArgs < 0) {
174 PrintError("BUG: PySequence_Length"); 175 PrintError("BUG: PySequence_Length");
175 goto Done; 176 goto Done;
176 } 177 }
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 if (-1 == PyErr_WarnEx(PyExc_RuntimeWarning, 301 if (-1 == PyErr_WarnEx(PyExc_RuntimeWarning,
301 "memory leak in callback function.", 302 "memory leak in callback function.",
302 1)) 303 1))
303 PyErr_WriteUnraisable(callable); 304 PyErr_WriteUnraisable(callable);
304 } 305 }
305 } 306 }
306 Py_XDECREF(result); 307 Py_XDECREF(result);
307 Done: 308 Done:
308 Py_XDECREF(arglist); 309 Py_XDECREF(arglist);
309 #ifdef WITH_THREAD 310 #ifdef WITH_THREAD
310 PyGILState_Release(state); 311 PyGILState_ReleaseEx(interp, state);
311 #endif 312 #endif
312 } 313 }
313 314
314 static void closure_fcn(ffi_cif *cif, 315 static void closure_fcn(ffi_cif *cif,
315 void *resp, 316 void *resp,
316 void **args, 317 void **args,
317 void *userdata) 318 void *userdata)
318 { 319 {
319 CThunkObject *p = (CThunkObject *)userdata; 320 CThunkObject *p = (CThunkObject *)userdata;
320 321
321 _CallPythonObject(resp, 322 _CallPythonObject(resp,
322 p->ffi_restype, 323 p->ffi_restype,
323 p->setfunc, 324 p->setfunc,
325 p->interp,
324 p->callable, 326 p->callable,
325 p->converters, 327 p->converters,
326 p->flags, 328 p->flags,
327 args); 329 args);
328 } 330 }
329 331
330 static CThunkObject* CThunkObject_new(Py_ssize_t nArgs) 332 static CThunkObject* CThunkObject_new(Py_ssize_t nArgs)
331 { 333 {
332 CThunkObject *p; 334 CThunkObject *p;
333 int i; 335 int i;
334 336
335 p = PyObject_GC_NewVar(CThunkObject, &PyCThunk_Type, nArgs); 337 p = PyObject_GC_NewVar(CThunkObject, &PyCThunk_Type, nArgs);
336 if (p == NULL) { 338 if (p == NULL) {
337 PyErr_NoMemory(); 339 PyErr_NoMemory();
338 return NULL; 340 return NULL;
339 } 341 }
340 342
343 p->interp = PyThreadState_Get()->interp;
341 p->pcl_exec = NULL; 344 p->pcl_exec = NULL;
342 p->pcl_write = NULL; 345 p->pcl_write = NULL;
343 memset(&p->cif, 0, sizeof(p->cif)); 346 memset(&p->cif, 0, sizeof(p->cif));
344 p->converters = NULL; 347 p->converters = NULL;
345 p->callable = NULL; 348 p->callable = NULL;
346 p->setfunc = NULL; 349 p->setfunc = NULL;
347 p->ffi_restype = NULL; 350 p->ffi_restype = NULL;
348 351
349 for (i = 0; i < nArgs + 1; ++i) 352 for (i = 0; i < nArgs + 1; ++i)
350 p->atypes[i] = NULL; 353 p->atypes[i] = NULL;
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 } 606 }
604 #endif 607 #endif
605 608
606 #endif 609 #endif
607 610
608 /* 611 /*
609 Local Variables: 612 Local Variables:
610 compile-command: "cd .. && python setup.py -q build_ext" 613 compile-command: "cd .. && python setup.py -q build_ext"
611 End: 614 End:
612 */ 615 */
OLDNEW
« no previous file with comments | « Include/pystate.h ('k') | Modules/_ctypes/ctypes.h » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+