Set general global handle for extension registration work

* When calling the register() function there is no frame or globals, so we need
  to set an internal handle external to that.
* This means functions that get wrapped know that there's a global handler for
  exceptions, which just prints to the log. Otherwise they think they're running
  synchronously and write to an invalid exception handling object.
This commit is contained in:
baldurk
2018-10-23 15:36:35 +01:00
parent 8447e43e78
commit 1720d321e5
3 changed files with 49 additions and 0 deletions
@@ -28,6 +28,7 @@
// this is defined elsewhere for managing the opaque global_handle object
extern "C" PyThreadState *GetExecutingThreadState(PyObject *global_handle);
extern "C" PyObject *GetCurrentGlobalHandle();
extern "C" void HandleException(PyObject *global_handle);
extern "C" bool IsThreadBlocking(PyObject *global_handle);
extern "C" void SetThreadBlocking(PyObject *global_handle, bool block);
@@ -249,6 +250,9 @@ funcType ConvertFunc(const char *funcname, PyObject *func, ExceptionHandling &ex
}
}
if(!global_internal_handle)
global_internal_handle = GetCurrentGlobalHandle();
// create a copy that will keep the function object alive as long as the lambda is
PyObjectRefCounter funcptr(func);