Repository navigation
gh-114314: ctypes: remove stgdict and switch to heap types #116458
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
Changes from 1 commit
6155211
0171c30
acd91e9
55af504
27e5c50
01bc637
c8017e9
40b012f
537defb
ace6623
6f775b9
4aaa06a
6808524
f031c00
535176c
5260003
0d3017e
269b825
946f474
607ed23
cb126b7
fd04c91
8dce549
6705e0e
8f99377
daea3e5
f67211f
02aa9e1
13feac7
a68417b
ad5d7b4
8d5e230
cdfae13
2d80960
3337ba4
596cb89
91feb64
77c64fe
0be46a1
9be3520
e523c2f
fb70e43
cc59dea
9bd9eb1
946a0b1
970b41d
2a450ad
9878809
b2ba89a
605c30c
41dea1b
be0888f
ac6eb38
33be37f
0b9d0a7
f02bad6
16faac7
2461e50
ab90768
de054af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -486,10 +486,38 @@ CType_Type_dealloc(PyObject *self) | |||||||
| Py_DECREF(tp); | ||||||||
| } | ||||||||
|
|
||||||||
| static PyObject * | ||||||||
| CType_Type_sizeof(PyObject *self) { | ||||||||
|
encukou marked this conversation as resolved.
Outdated
|
||||||||
| Py_ssize_t size = Py_TYPE(self)->tp_basicsize; | ||||||||
| size += Py_TYPE(self)->tp_itemsize * Py_SIZE(self); | ||||||||
|
|
||||||||
| ctypes_state *st = GLOBAL_STATE(); | ||||||||
| StgInfo *info; | ||||||||
| if (PyStgInfo_FromType(st, self, &info) < 0) { | ||||||||
| return NULL; | ||||||||
| } | ||||||||
| if (info) { | ||||||||
| StgDictObject *dict = PyType_stgdict(self); | ||||||||
| assert(dict); | ||||||||
| if (dict->ffi_type_pointer.elements) { | ||||||||
| size += (info->length + 1) * sizeof(ffi_type *); | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| 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}, | ||||||||
| }; | ||||||||
|
|
||||||||
| static PyType_Slot ctype_type_slots[] = { | ||||||||
| {Py_tp_traverse, CType_Type_traverse}, | ||||||||
| {Py_tp_clear, CType_Type_clear}, | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Previously, cpython/Modules/_ctypes/stgdict.c Lines 161 to 162 in 7cee276
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alternatively, it would be less confusing to integrate Details static int
CType_Type_traverse(PyObject *self, visitproc visit, void *arg)
{
+ ctypes_state *st = GLOBAL_STATE();
+ StgInfo *info;
+ if (PyStgInfo_FromType(st, self, &info) < 0) {
+ return -1;
+ }
+ if (info) {
+ Py_VISIT(info->proto); // GC-related
+ Py_VISIT(info->argtypes);
+ Py_VISIT(info->converters);
+ Py_VISIT(info->restype);
+ Py_VISIT(info->checker);
+ }
Py_VISIT(Py_TYPE(self));
- return 0;
+ return PyType_Type.tp_traverse(self, visit, arg);
}
static int
CType_Type_clear(PyObject *self)
{
ctypes_state *st = GLOBAL_STATE();
StgInfo *info;
if (PyStgInfo_FromType(st, self, &info) < 0) {
return -1;
}
if (info) {
Py_CLEAR(info->proto); // GC-related
Py_CLEAR(info->argtypes);
Py_CLEAR(info->converters);
Py_CLEAR(info->restype);
Py_CLEAR(info->checker);
}
- return 0;
+ return PyType_Type.tp_clear(self);
}
static PyType_Slot foo_type_slots[] = {
...
- {Py_tp_traverse, CDataType_traverse},
- {Py_tp_clear, CDataType_clear},
...
};
PyType_Spec foo_type_spec = {
...
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
+ .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
...
};
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That would indeed be clearer! I'd prefer leaving it to a follow-up PR though: it'll be easier to debug when we get to isolating the module state. |
||||||||
| {Py_tp_dealloc, CType_Type_dealloc}, | ||||||||
| {Py_tp_methods, ctype_methods}, | ||||||||
| {0, NULL}, | ||||||||
| }; | ||||||||
|
|
||||||||
|
|
||||||||
Uh oh!
There was an error while loading. Please reload this page.