8000 gh-117142: ctypes: Unify meta tp slot functions by neonene · Pull Request #117143 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-117142: ctypes: Unify meta tp slot functions #117143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Apr 1, 2024
Prev Previous commit
Next Next commit
mix CDataType_methods into ctype_methods / nit
  • Loading branch information
neonene committed Mar 22, 2024
commit 26bc72a0631efcf6a03e346339e92921749b98e5
34 changes: 15 additions & 19 deletions Modules/_ctypes/_ctypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -537,12 +537,6 @@ CType_Type_sizeof(PyObject *self)
return PyLong_FromSsize_t(size);
}

static PyMethodDef ctype_methods[] = {
{"__sizeof__", _PyCFunction_CAST(CType_Type_sizeof),
METH_NOARGS, PyDoc_STR("Return memory consumption of the type object.")},
{0},
};

/*
PyCStructType_Type - a meta type/class. Creating a new class using this one as
__metaclass__ will call the constructor StructUnionType_new.
Expand Down Expand Up @@ -972,6 +966,17 @@ CTypeType_repeat(PyObject *self, Py_ssize_t length)
return PyCArrayType_from_ctype(self, length);
}

static PyMethodDef ctype_methods[] = {
{"__sizeof__", _PyCFunction_CAST(CType_Type_sizeof),
METH_NOARGS, PyDoc_STR("Return memory consumption of the type object.")},
{ "from_param", CTypeType_from_param, METH_O, from_param_doc },
{ "from_address", CTypeType_from_address, METH_O, from_address_doc },
{ "from_buffer", CTypeType_from_buffer, METH_VARARGS, from_buffer_doc, },
{ "from_buffer_copy", CTypeType_from_buffer_copy, METH_VARARGS, from_buffer_copy_doc, },
{ "in_dll", CTypeType_in_dll, METH_VARARGS, in_dll_doc },
{ NULL, NULL },
};

static PyType_Slot ctype_type_slots[] = {
{Py_tp_traverse, CType_Type_traverse},
{Py_tp_clear, CType_Type_clear},
Expand All @@ -992,15 +997,6 @@ static PyType_Spec pyctype_type_spec = {
.slots = ctype_type_slots,
};

static PyMethodDef CTypeType_methods[] = {
{ "from_param", CTypeType_from_param, METH_O, from_param_doc },
{ "from_address", CTypeType_from_address, METH_O, from_address_doc },
{ "from_buffer", CTypeType_from_buffer, METH_VARARGS, from_buffer_doc, },
{ "from_buffer_copy", CTypeType_from_buffer_copy, METH_VARARGS, from_buffer_copy_doc, },
{ "in_dll", CTypeType_in_dll, METH_VARARGS, in_dll_doc },
{ NULL, NULL },
};


static int
PyCStructType_setattro(PyObject *self, PyObject *key, PyObject *value)
Expand Down Expand Up @@ -1032,7 +1028,7 @@ UnionType_setattro(PyObject *self, PyObject *key, PyObject *value)
static PyType_Slot pycstruct_type_slots[] = {
{Py_tp_setattro, PyCStructType_setattro},
{Py_tp_doc, PyDoc_STR("metatype for the CData Objects")},
{Py_tp_methods, CTypeType_methods},
{Py_tp_methods, ctype_methods},
{Py_tp_init, PyCStructType_init},
{0, NULL},
};
Expand All @@ -1047,7 +1043,7 @@ static PyType_Spec pycstruct_type_spec = {
static PyType_Slot union_type_slots[] = {
{Py_tp_setattro, UnionType_setattro},
{Py_tp_doc, PyDoc_STR("metatype for the Union Objects")},
{Py_tp_methods, CTypeType_methods},
{Py_tp_methods, ctype_methods},
{Py_tp_init, UnionType_init},
{0, NULL},
};
Expand Down Expand Up @@ -1611,7 +1607,7 @@ PyCArrayType_init(PyObject *self, PyObject *args, PyObject *kwds)

static PyType_Slot pycarray_type_slots[] = {
{Py_tp_doc, PyDoc_STR("metatype for the Array Objects")},
{Py_tp_methods, CTypeType_methods},
{Py_tp_methods, ctype_methods},
{Py_tp_init, PyCArrayType_init},
{0, NULL},
};
Expand Down Expand Up @@ -2533,7 +2529,7 @@ PyCFuncPtrType_init(PyObject *self, PyObject *args, PyObject *kwds)

static PyType_Slot pycfuncptr_type_slots[] = {
{Py_tp_doc, PyDoc_STR("metatype for C function pointers")},
{Py_tp_methods, CTypeType_methods},
{Py_tp_methods, ctype_methods},
{Py_tp_init, PyCFuncPtrType_init},
{0, NULL},
};
Expand Down
2 changes: 1 addition & 1 deletion Modules/_ctypes/callproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2017,7 +2017,7 @@ create_pointer_inst(PyObject *module, PyObject *arg)
return NULL;
}
if (typ == NULL) {
typ = create_pointer_type(NULL, (PyObject *)Py_TYPE(arg));
typ = create_pointer_type(module, (PyObject *)Py_TYPE(arg));
if (typ == NULL)
return NULL;
}
Expand Down
0