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 DictRemover type
  • Loading branch information
@erlend-aasland
erlend-aasland committedApr 26, 2023
commit1371dbd9d1336966e0bf260718c51dbb2198b88c
100 changes: 53 additions & 47 deletionsModules/_ctypes/_ctypes.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -152,13 +152,32 @@ typedef struct {
PyObject *dict;
} DictRemoverObject;

static int
_DictRemover_traverse(DictRemoverObject *self, visitproc visit, void *arg)
{
Py_VISIT(Py_TYPE(self));
Py_VISIT(self->key);
Py_VISIT(self->dict);
return 0;
}

static int
_DictRemover_clear(DictRemoverObject *self)
{
Py_CLEAR(self->key);
Py_CLEAR(self->dict);
return 0;
}

static void
_DictRemover_dealloc(PyObject *myself)
{
PyTypeObject *tp = Py_TYPE(myself);
DictRemoverObject *self = (DictRemoverObject *)myself;
Py_XDECREF(self->key);
Py_XDECREF(self->dict);
Py_TYPE(self)->tp_free(myself);
PyObject_GC_UnTrack(myself);
(void)_DictRemover_clear(self);
tp->tp_free(myself);
Py_DECREF(tp);
}

static PyObject *
Expand All@@ -175,47 +194,23 @@ _DictRemover_call(PyObject *myself, PyObject *args, PyObject *kw)
Py_RETURN_NONE;
}

static PyTypeObject DictRemover_Type = {
PyVarObject_HEAD_INIT(NULL, 0)
"_ctypes.DictRemover", /* tp_name */
sizeof(DictRemoverObject), /* tp_basicsize */
0, /* tp_itemsize */
_DictRemover_dealloc, /* tp_dealloc */
0, /* tp_vectorcall_offset */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_as_async */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
_DictRemover_call, /* tp_call */
0, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
/* XXX should participate in GC? */
Py_TPFLAGS_DEFAULT, /* tp_flags */
PyDoc_STR("deletes a key from a dictionary"), /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
0, /* tp_free */
PyDoc_STRVAR(dictremover_doc, "deletes a key from a dictionary");

static PyType_Slot dictremover_slots[] = {
{Py_tp_dealloc, _DictRemover_dealloc},
{Py_tp_traverse, _DictRemover_traverse},
{Py_tp_clear, _DictRemover_clear},
{Py_tp_call, _DictRemover_call},
{Py_tp_doc, (void *)dictremover_doc},
{0, NULL},
};

static PyType_Spec dictremover_spec = {
.name = "_ctypes.DictRemover",
.basicsize = sizeof(DictRemoverObject),
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_IMMUTABLETYPE),
.slots = dictremover_slots,
};

int
Expand All@@ -226,7 +221,8 @@ PyDict_SetItemProxy(PyObject *dict, PyObject *key, PyObject *item)
PyObject *proxy;
int result;

obj = _PyObject_CallNoArgs((PyObject *)&DictRemover_Type);
ctypes_state *st = GLOBAL_STATE();
obj = _PyObject_CallNoArgs((PyObject *)st->DictRemover_Type);
if (obj == NULL)
return -1;

Expand DownExpand Up@@ -5637,6 +5633,15 @@ _ctypes_add_types(PyObject *mod)
} \
} while (0)

#define CREATE_TYPE(MOD, TP, SPEC) \
do { \
PyObject *type = PyType_FromMetaclass(NULL, MOD, SPEC, NULL); \
if (type == NULL) { \
return -1; \
} \
TP = (PyTypeObject *)type; \
} while (0)

/* Note:
ob_type is the metatype (the 'type'), defaults to PyType_Type,
tp_base is the base type, defaults to 'object' aka PyBaseObject_Type.
Expand DownExpand Up@@ -5683,8 +5688,8 @@ _ctypes_add_types(PyObject *mod)
* Other stuff
*/

DictRemover_Type.tp_new = PyType_GenericNew;
TYPE_READY(&DictRemover_Type);
ctypes_state *st = GLOBAL_STATE();
CREATE_TYPE(mod, st->DictRemover_Type, &dictremover_spec);
TYPE_READY(&StructParam_Type);

#ifdef MS_WIN32
Expand All@@ -5694,6 +5699,7 @@ _ctypes_add_types(PyObject *mod)
#undef TYPE_READY
#undef TYPE_READY_BASE
#undef MOD_ADD_TYPE
#undef CREATE_TYPE
return 0;
}

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@@ -33,6 +33,7 @@
#endif

typedef struct {
PyTypeObject *DictRemover_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@@ -341,7 +341,6 @@ Modules/_testcapi/vectorcall.c-MethodDescriptor2_Type-
##-----------------------
## static types

Modules/_ctypes/_ctypes.c-DictRemover_Type-
Modules/_ctypes/_ctypes.c-PyCArrayType_Type-
Modules/_ctypes/_ctypes.c-PyCArray_Type-
Modules/_ctypes/_ctypes.c-PyCData_Type-
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp