Skip to content

Commit 3c1b9db

Browse files
emontnemerymattip
authored andcommitted
Move initialization
1 parent 2e63a16 commit 3c1b9db

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

‎src/c/misc_thread_common.h‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,10 @@ thread_canary_register(PyThreadState *tstate)
204204
if (tdict == NULL)
205205
goto ignore_error;
206206

207+
/* Give ThreadCanary_Type a valid metatype before instantiating it. */
208+
if (PyType_Ready(&ThreadCanary_Type) < 0)
209+
goto ignore_error;
210+
207211
canary = PyObject_New(ThreadCanaryObj, &ThreadCanary_Type);
208212
//fprintf(stderr, "thread_canary_register(%p): tstate=%p tls=%p\n", canary, tstate, tls);
209213
if (canary == NULL)
@@ -265,13 +269,6 @@ static PyTypeObject ThreadCanary_Type = {
265269

266270
static void init_cffi_tls_zombie(void)
267271
{
268-
/* thread_canary objects are created with PyObject_New(&ThreadCanary_Type);
269-
the type must be readied so it has a valid metatype (ob_type). Otherwise
270-
introspection of a canary from another module dereferences a NULL metatype
271-
and crashes. */
272-
if (PyType_Ready(&ThreadCanary_Type) < 0)
273-
return; /* error set; PyInit__cffi_backend checks PyErr_Occurred() */
274-
275272
cffi_zombie_head.zombie_next = &cffi_zombie_head;
276273
cffi_zombie_head.zombie_prev = &cffi_zombie_head;
277274
cffi_zombie_lock = PyThread_allocate_lock();

0 commit comments

Comments
 (0)