Skip to content

Commit 9f4e7f2

Browse files
committed
Change runtime implementation to a lambda
1 parent 0d12c5f commit 9f4e7f2

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

‎src/newtype/newtype.c‎

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ newtype_foo(PyObject *self, PyObject *obj)
1111
return obj;
1212
}
1313

14-
static int
15-
newtype_mod_exec(PyObject *module)
14+
static PyObject *
15+
newtype_FooType(PyObject *self, PyObject *obj)
1616
{
17-
PyObject *int_obj = (PyObject *)&PyLong_Type;
18-
return PyModule_AddObjectRef(module, "FooType", int_obj);
17+
Py_XINCREF(obj);
18+
return obj;
1919
}
2020

2121
static PyMethodDef newtype_methods[] = {
@@ -24,19 +24,18 @@ static PyMethodDef newtype_methods[] = {
2424
.ml_meth = &newtype_foo,
2525
.ml_flags = METH_O,
2626
},
27+
{
28+
.ml_name = "FooType",
29+
.ml_meth = &newtype_FooType,
30+
.ml_flags = METH_O,
31+
},
2732
{ NULL, NULL, 0, NULL }
2833
};
2934

30-
static PyModuleDef_Slot newtype_slots[] = {
31-
{Py_mod_exec, &newtype_mod_exec},
32-
{ 0, NULL }
33-
};
34-
3535
static struct PyModuleDef newtype_module = {
3636
.m_base = PyModuleDef_HEAD_INIT,
3737
.m_name = "newtype",
3838
.m_methods = newtype_methods,
39-
.m_slots = newtype_slots,
4039
};
4140

4241
PyMODINIT_FUNC

0 commit comments

Comments
 (0)