summaryrefslogtreecommitdiffstats
path: root/Modules/_threadmodule.c
diff options
context:
space:
mode:
Diffstat (limited to 'Modules/_threadmodule.c')
-rw-r--r--Modules/_threadmodule.c33
1 files changed, 29 insertions, 4 deletions
diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c
index 99f97eb..5cceb84 100644
--- a/Modules/_threadmodule.c
+++ b/Modules/_threadmodule.c
@@ -5,6 +5,7 @@
#include "Python.h"
#include "pycore_interp.h" // _PyInterpreterState.threads.count
#include "pycore_moduleobject.h" // _PyModule_GetState()
+#include "pycore_modsupport.h" // _PyArg_NoKeywords()
#include "pycore_pylifecycle.h"
#include "pycore_pystate.h" // _PyThreadState_SetCurrent()
#include "pycore_sysmodule.h" // _PySys_GetAttr()
@@ -349,6 +350,27 @@ lock__at_fork_reinit(lockobject *self, PyObject *Py_UNUSED(args))
}
#endif /* HAVE_FORK */
+static lockobject *newlockobject(PyObject *module);
+
+static PyObject *
+lock_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
+{
+ // convert to AC?
+ if (!_PyArg_NoKeywords("lock", kwargs)) {
+ goto error;
+ }
+ if (!_PyArg_CheckPositional("lock", PyTuple_GET_SIZE(args), 0, 0)) {
+ goto error;
+ }
+
+ PyObject *module = PyType_GetModuleByDef(type, &thread_module);
+ assert(module != NULL);
+ return (PyObject *)newlockobject(module);
+
+error:
+ return NULL;
+}
+
static PyMethodDef lock_methods[] = {
{"acquire_lock", _PyCFunction_CAST(lock_PyThread_acquire_lock),
@@ -398,6 +420,7 @@ static PyType_Slot lock_type_slots[] = {
{Py_tp_methods, lock_methods},
{Py_tp_traverse, lock_traverse},
{Py_tp_members, lock_type_members},
+ {Py_tp_new, lock_new},
{0, 0}
};
@@ -405,7 +428,7 @@ static PyType_Spec lock_type_spec = {
.name = "_thread.lock",
.basicsize = sizeof(lockobject),
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
- Py_TPFLAGS_DISALLOW_INSTANTIATION | Py_TPFLAGS_IMMUTABLETYPE),
+ Py_TPFLAGS_IMMUTABLETYPE),
.slots = lock_type_slots,
};
@@ -1442,8 +1465,6 @@ A subthread can use this function to interrupt the main thread.\n\
Note: the default signal handler for SIGINT raises ``KeyboardInterrupt``."
);
-static lockobject *newlockobject(PyObject *module);
-
static PyObject *
thread_PyThread_allocate_lock(PyObject *module, PyObject *Py_UNUSED(ignored))
{
@@ -1841,10 +1862,14 @@ thread_module_exec(PyObject *module)
}
// Lock
- state->lock_type = (PyTypeObject *)PyType_FromSpec(&lock_type_spec);
+ state->lock_type = (PyTypeObject *)PyType_FromModuleAndSpec(module, &lock_type_spec, NULL);
if (state->lock_type == NULL) {
return -1;
}
+ if (PyModule_AddType(module, state->lock_type) < 0) {
+ return -1;
+ }
+ // Old alias: lock -> LockType
if (PyDict_SetItemString(d, "LockType", (PyObject *)state->lock_type) < 0) {
return -1;
}