Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-103092: Isolate _ctypes, part 1#103893

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
Adapt PyCField type
  • Loading branch information
@erlend-aasland
erlend-aasland committedApr 26, 2023
commitbcd391fc950bbbae96bed8808f74802a62f3a1c4
3 changes: 1 addition & 2 deletionsModules/_ctypes/_ctypes.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5686,8 +5686,7 @@ _ctypes_add_types(PyObject *mod)
* Simple classes
*/

/* PyCField_Type is derived from PyBaseObject_Type */
TYPE_READY(&PyCField_Type);
CREATE_TYPE(mod, st->PyCField_Type, &cfield_spec);

/*************************************************
*
Expand Down
67 changes: 25 additions & 42 deletionsModules/_ctypes/cfield.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -61,7 +61,9 @@ PyCField_FromDesc(PyObject *desc, Py_ssize_t index,
#define CONT_BITFIELD 2
#define EXPAND_BITFIELD 3

self = (CFieldObject *)PyCField_Type.tp_alloc((PyTypeObject *)&PyCField_Type, 0);
ctypes_state *st = GLOBAL_STATE();
PyTypeObject *tp = st->PyCField_Type;
self = (CFieldObject *)tp->tp_alloc(tp, 0);
if (self == NULL)
return NULL;
dict = PyType_stgdict(desc);
Expand DownExpand Up@@ -256,6 +258,7 @@ static PyGetSetDef PyCField_getset[] = {
static int
PyCField_traverse(CFieldObject *self, visitproc visit, void *arg)
{
Py_VISIT(Py_TYPE(self));
Py_VISIT(self->proto);
return 0;
}
Expand All@@ -270,9 +273,11 @@ PyCField_clear(CFieldObject *self)
static void
PyCField_dealloc(PyObject *self)
{
PyTypeObject *tp = Py_TYPE(self);
PyObject_GC_UnTrack(self);
PyCField_clear((CFieldObject *)self);
(void)PyCField_clear((CFieldObject *)self);
Py_TYPE(self)->tp_free((PyObject *)self);
Py_DECREF(tp);
}

static PyObject *
Expand All@@ -296,46 +301,24 @@ PyCField_repr(CFieldObject *self)
return result;
}

PyTypeObject PyCField_Type = {
PyVarObject_HEAD_INIT(NULL, 0)
"_ctypes.CField", /* tp_name */
sizeof(CFieldObject), /* tp_basicsize */
0, /* tp_itemsize */
PyCField_dealloc, /* tp_dealloc */
0, /* tp_vectorcall_offset */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_as_async */
(reprfunc)PyCField_repr, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */
PyDoc_STR("Structure/Union member"), /* tp_doc */
(traverseproc)PyCField_traverse, /* tp_traverse */
(inquiry)PyCField_clear, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
PyCField_getset, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
(descrgetfunc)PyCField_get, /* tp_descr_get */
(descrsetfunc)PyCField_set, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
0, /* tp_free */
static PyType_Slot cfield_slots[] = {
{Py_tp_dealloc, PyCField_dealloc},
{Py_tp_repr, PyCField_repr},
{Py_tp_doc, (void *)PyDoc_STR("Structure/Union member")},
{Py_tp_traverse, PyCField_traverse},
{Py_tp_clear, PyCField_clear},
{Py_tp_getset, PyCField_getset},
{Py_tp_descr_get, PyCField_get},
{Py_tp_descr_set, PyCField_set},
{0, NULL},
};

PyType_Spec cfield_spec = {
.name = "_ctypes.CField",
.basicsize = sizeof(CFieldObject),
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_DISALLOW_INSTANTIATION),
.slots = cfield_slots,
};


Expand Down
3 changes: 2 additions & 1 deletionModules/_ctypes/ctypes.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,6 +35,7 @@
typedef struct {
PyTypeObject *DictRemover_Type;
PyTypeObject *PyCArg_Type;
PyTypeObject *PyCField_Type;
PyTypeObject *PyCThunk_Type;
} ctypes_state;

Expand All@@ -43,6 +44,7 @@ extern ctypes_state global_state;
#define GLOBAL_STATE() (&global_state)

extern PyType_Spec carg_spec;
extern PyType_Spec cfield_spec;
extern PyType_Spec cthunk_spec;

typedef struct tagPyCArgObject PyCArgObject;
Expand DownExpand Up@@ -153,7 +155,6 @@ extern PyTypeObject PyCSimpleType_Type;
#define PyCSimpleTypeObject_CheckExact(v) Py_IS_TYPE(v, &PyCSimpleType_Type)
#define PyCSimpleTypeObject_Check(v) PyObject_TypeCheck(v, &PyCSimpleType_Type)

extern PyTypeObject PyCField_Type;
extern struct fielddesc *_ctypes_get_fielddesc(const char *fmt);


Expand Down
12 changes: 8 additions & 4 deletionsModules/_ctypes/stgdict.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -225,6 +225,8 @@ MakeFields(PyObject *type, CFieldObject *descr,
if (fieldlist == NULL)
return -1;

ctypes_state *st = GLOBAL_STATE();
PyTypeObject *cfield_tp = st->PyCField_Type;
for (i = 0; i < PySequence_Fast_GET_SIZE(fieldlist); ++i) {
PyObject *pair = PySequence_Fast_GET_ITEM(fieldlist, i); /* borrowed */
PyObject *fname, *ftype, *bits;
Expand All@@ -240,7 +242,7 @@ MakeFields(PyObject *type, CFieldObject *descr,
Py_DECREF(fieldlist);
return -1;
}
if (!Py_IS_TYPE(fdescr,&PyCField_Type)) {
if (!Py_IS_TYPE(fdescr,cfield_tp)) {
PyErr_SetString(PyExc_TypeError, "unexpected type");
Py_DECREF(fdescr);
Py_DECREF(fieldlist);
Expand All@@ -257,13 +259,13 @@ MakeFields(PyObject *type, CFieldObject *descr,
}
continue;
}
new_descr = (CFieldObject *)PyCField_Type.tp_alloc((PyTypeObject *)&PyCField_Type, 0);
new_descr = (CFieldObject *)cfield_tp->tp_alloc(cfield_tp, 0);
if (new_descr == NULL) {
Py_DECREF(fdescr);
Py_DECREF(fieldlist);
return -1;
}
assert(Py_IS_TYPE(new_descr,&PyCField_Type));
assert(Py_IS_TYPE(new_descr,cfield_tp));
new_descr->size = fdescr->size;
new_descr->offset = fdescr->offset + offset;
new_descr->index = fdescr->index + index;
Expand DownExpand Up@@ -304,14 +306,16 @@ MakeAnonFields(PyObject *type)
if (anon_names == NULL)
return -1;

ctypes_state *st = GLOBAL_STATE();
PyTypeObject *cfield_tp = st->PyCField_Type;
for (i = 0; i < PySequence_Fast_GET_SIZE(anon_names); ++i) {
PyObject *fname = PySequence_Fast_GET_ITEM(anon_names, i); /* borrowed */
CFieldObject *descr = (CFieldObject *)PyObject_GetAttr(type, fname);
if (descr == NULL) {
Py_DECREF(anon_names);
return -1;
}
if (!Py_IS_TYPE(descr,&PyCField_Type)) {
if (!Py_IS_TYPE(descr,cfield_tp)) {
PyErr_Format(PyExc_AttributeError,
"'%U' is specified in _anonymous_ but not in "
"_fields_",
Expand Down
2 changes: 0 additions & 2 deletionsTools/c-analyzer/cpython/globals-to-fix.tsv
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -356,12 +356,10 @@ Modules/_ctypes/_ctypes.c-Struct_Type-
Modules/_ctypes/_ctypes.c-UnionType_Type-
Modules/_ctypes/_ctypes.c-Union_Type-
Modules/_ctypes/callproc.c-PyCArg_Type-
Modules/_ctypes/cfield.c-PyCField_Type-
Modules/_ctypes/ctypes.h-PyCArg_Type-
Modules/_ctypes/ctypes.h-PyCArrayType_Type-
Modules/_ctypes/ctypes.h-PyCArray_Type-
Modules/_ctypes/ctypes.h-PyCData_Type-
Modules/_ctypes/ctypes.h-PyCField_Type-
Modules/_ctypes/ctypes.h-PyCFuncPtrType_Type-
Modules/_ctypes/ctypes.h-PyCFuncPtr_Type-
Modules/_ctypes/ctypes.h-PyCPointerType_Type-
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp