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 StructParam type
  • Loading branch information
@erlend-aasland
erlend-aasland committedApr 26, 2023
commita0d3a681bf5bfce96ca8f2586f2a62deb23ceee7
44 changes: 34 additions & 10 deletionsModules/_ctypes/_ctypes.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -413,23 +413,45 @@ typedef struct {
PyObject *keep; // If set, a reference to the original CDataObject.
} StructParamObject;

static int
StructParam_traverse(StructParamObject *self, visitproc visit, void *arg)
{
Py_VISIT(Py_TYPE(self));
return 0;
}

static int
StructParam_clear(StructParamObject *self)
{
Py_CLEAR(self->keep);
return 0;
}

static void
StructParam_dealloc(PyObject *myself)
{
StructParamObject *self = (StructParamObject *)myself;
Py_XDECREF(self->keep);
PyTypeObject *tp = Py_TYPE(self);
PyObject_GC_UnTrack(myself);
(void)StructParam_clear(self);
PyMem_Free(self->ptr);
Py_TYPE(self)->tp_free(myself);
tp->tp_free(myself);
Py_DECREF(tp);
}

static PyType_Slot structparam_slots[] = {
{Py_tp_traverse, StructParam_traverse},
{Py_tp_clear, StructParam_clear},
{Py_tp_dealloc, StructParam_dealloc},
{0, NULL},
};

staticPyTypeObject StructParam_Type = {
PyVarObject_HEAD_INIT(NULL, 0)
.tp_name ="_ctypes.StructParam_Type",
.tp_basicsize =sizeof(StructParamObject),
.tp_dealloc = StructParam_dealloc,
.tp_flags =Py_TPFLAGS_DEFAULT,
staticPyType_Spec structparam_spec = {
.name = "_ctypes.StructParam_Type",
.basicsize =sizeof(StructParamObject),
.flags =(Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE |
Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_DISALLOW_INSTANTIATION),
.slots =structparam_slots,
};


Expand DownExpand Up@@ -458,7 +480,9 @@ StructUnionType_paramfunc(CDataObject *self)
/* Create a Python object which calls PyMem_Free(ptr) in
its deallocator. The object will be destroyed
at _ctypes_callproc() cleanup. */
obj = (&StructParam_Type)->tp_alloc(&StructParam_Type, 0);
ctypes_state *st = GLOBAL_STATE();
PyTypeObject *tp = st->StructParam_Type;
obj = tp->tp_alloc(tp, 0);
if (obj == NULL) {
PyMem_Free(ptr);
return NULL;
Expand DownExpand Up@@ -5694,7 +5718,7 @@ _ctypes_add_types(PyObject *mod)
*/

CREATE_TYPE(mod, st->DictRemover_Type, &dictremover_spec);
TYPE_READY(&StructParam_Type);
CREATE_TYPE(mod, st->StructParam_Type, &structparam_spec);

#ifdef MS_WIN32
TYPE_READY_BASE(&PyComError_Type, (PyTypeObject*)PyExc_Exception);
Expand Down
1 change: 1 addition & 0 deletionsModules/_ctypes/ctypes.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,6 +37,7 @@ typedef struct {
PyTypeObject *PyCArg_Type;
PyTypeObject *PyCField_Type;
PyTypeObject *PyCThunk_Type;
PyTypeObject *StructParam_Type;
} ctypes_state;

extern ctypes_state global_state;
Expand Down
1 change: 0 additions & 1 deletionTools/c-analyzer/cpython/globals-to-fix.tsv
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -351,7 +351,6 @@ Modules/_ctypes/_ctypes.c-PyCPointer_Type-
Modules/_ctypes/_ctypes.c-PyCSimpleType_Type-
Modules/_ctypes/_ctypes.c-PyCStructType_Type-
Modules/_ctypes/_ctypes.c-Simple_Type-
Modules/_ctypes/_ctypes.c-StructParam_Type-
Modules/_ctypes/_ctypes.c-Struct_Type-
Modules/_ctypes/_ctypes.c-UnionType_Type-
Modules/_ctypes/_ctypes.c-Union_Type-
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp