Skip to content

Commit

Permalink
Fix c extension on python 3.12
Browse files Browse the repository at this point in the history
Workaround for [1].

[1] python/cpython#103940

Signed-off-by: Sean Anderson <seanga2@gmail.com>
  • Loading branch information
Forty-Bot committed Nov 19, 2023
1 parent 2a22a9f commit 8f76168
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,17 @@ 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;

if (PyType_AddSizeConstant(&LockType, "align",
alignof(pthread_mutex_t)))
return -1;

LockType.tp_base = &BufferType;
Py_INCREF(&BufferType);
err = PyModule_AddType(m, &LockType);
Py_DECREF(&BufferType);
Expand Down

0 comments on commit 8f76168

Please sign in to comment.