From 8f76168f9b60c9f1dd676849485febd8dc408f63 Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Sat, 18 Nov 2023 20:50:09 -0500 Subject: [PATCH] Fix c extension on python 3.12 Workaround for [1]. [1] https://github.com/python/cpython/pull/103940 Signed-off-by: Sean Anderson --- atomic.h | 5 ++++- lock.c | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/atomic.h b/atomic.h index 1a643d3..995231f 100644 --- a/atomic.h +++ b/atomic.h @@ -165,6 +165,10 @@ static int TYPE_ADD(PyObject *m) return ret; } + TYPE.tp_base = &BufferType; + if (PyType_Ready(&TYPE)) + return -1; + if (PyType_AddSizeConstant(&TYPE, "size", sizeof(PTYPE))) return -1; @@ -192,7 +196,6 @@ static int TYPE_ADD(PyObject *m) #endif #endif - TYPE.tp_base = &BufferType; Py_INCREF(&BufferType); ret = PyModule_AddType(m, &TYPE); Py_DECREF(&BufferType); diff --git a/lock.c b/lock.c index d6c5543..1d59a04 100644 --- a/lock.c +++ b/lock.c @@ -217,6 +217,10 @@ int LockType_Add(PyObject *m) return -1; } + LockType.tp_base = &BufferType; + if (PyType_Ready(&LockType)) + return -1; + if (PyType_AddSizeConstant(&LockType, "size", sizeof(pthread_mutex_t))) return -1; @@ -224,7 +228,6 @@ int LockType_Add(PyObject *m) alignof(pthread_mutex_t))) return -1; - LockType.tp_base = &BufferType; Py_INCREF(&BufferType); err = PyModule_AddType(m, &LockType); Py_DECREF(&BufferType);