/* * Get the address of any C/C++ object waiting to be wrapped. */ void *sipGetPending(sipWrapper **op, int *fp) { pendingDef *pp; #ifdef WITH_THREAD threadDef *thread; if ((thread = currentThreadDef()) != NULL) pp = &thread->pending; else pp = &pending; #else pp = &pending; #endif if (pp->cpp != NULL) { if (op != NULL) *op = pp->owner; if (fp != NULL) *fp = pp->flags; } return pp->cpp; }
/* * Handle the termination of a thread. The thread state should already have * been handled by the last call to PyGILState_Release(). */ void sip_api_end_thread(void) { #ifdef WITH_THREAD threadDef *thread; /* We have the GIL at this point. */ if ((thread = currentThreadDef()) != NULL) thread->thr_ident = 0; #endif }
/* * Handle the termination of a thread. */ void sip_api_end_thread(void) { #ifdef WITH_THREAD threadDef *thread; PyGILState_STATE gil = PyGILState_Ensure(); if ((thread = currentThreadDef(FALSE)) != NULL) thread->thr_ident = 0; PyGILState_Release(gil); #endif }
/* * Return the pending data for the current thread, allocating it if necessary, * or NULL if there was an error. */ static pendingDef *get_pending(int auto_alloc) { #ifdef WITH_THREAD threadDef *thread; if ((thread = currentThreadDef(auto_alloc)) == NULL) return NULL; return &thread->pending; #else static pendingDef pending; return &pending; #endif }
/* * Convert a new C/C++ pointer to a Python instance. */ PyObject *sipWrapSimpleInstance(void *cppPtr, const sipTypeDef *td, sipWrapper *owner, int flags) { static PyObject *nullargs = NULL; pendingDef old_pending; PyObject *self; #ifdef WITH_THREAD threadDef *thread; #endif if (nullargs == NULL && (nullargs = PyTuple_New(0)) == NULL) return NULL; if (cppPtr == NULL) { Py_INCREF(Py_None); return Py_None; } /* * Object creation can trigger the Python garbage collector which in turn * can execute arbitrary Python code which can then call this function * recursively. Therefore we save any existing pending object before * setting the new one. */ #ifdef WITH_THREAD if ((thread = currentThreadDef()) != NULL) { old_pending = thread->pending; thread->pending.cpp = cppPtr; thread->pending.owner = owner; thread->pending.flags = flags; } else { old_pending = pending; pending.cpp = cppPtr; pending.owner = owner; pending.flags = flags; } #else old_pending = pending; pending.cpp = cppPtr; pending.owner = owner; pending.flags = flags; #endif self = PyObject_Call((PyObject *)sipTypeAsPyTypeObject(td), nullargs, NULL); #ifdef WITH_THREAD if (thread != NULL) thread->pending = old_pending; else pending = old_pending; #else pending = old_pending; #endif return self; }