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 PyCThunk type
  • Loading branch information
@erlend-aasland
erlend-aasland committedApr 26, 2023
commit90b5c8fa4531aacf20d64212798a3aaf52e16337
2 changes: 1 addition & 1 deletionModules/_ctypes/_ctypes.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5653,7 +5653,7 @@ _ctypes_add_types(PyObject *mod)
tp_base is the base type, defaults to 'object' aka PyBaseObject_Type.
*/
CREATE_TYPE(mod, st->PyCArg_Type, &carg_spec);
TYPE_READY(&PyCThunk_Type);
CREATE_TYPE(mod, st->PyCThunk_Type, &cthunk_spec);
TYPE_READY(&PyCData_Type);
/* StgDict is derived from PyDict_Type */
TYPE_READY_BASE(&PyCStgDict_Type, &PyDict_Type);
Expand Down
81 changes: 36 additions & 45 deletionsModules/_ctypes/callbacks.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -28,23 +28,11 @@

/**************************************************************/

static void
CThunkObject_dealloc(PyObject *myself)
{
CThunkObject *self = (CThunkObject *)myself;
PyObject_GC_UnTrack(self);
Py_XDECREF(self->converters);
Py_XDECREF(self->callable);
Py_XDECREF(self->restype);
if (self->pcl_write)
Py_ffi_closure_free(self->pcl_write);
PyObject_GC_Del(self);
}

static int
CThunkObject_traverse(PyObject *myself, visitproc visit, void *arg)
{
CThunkObject *self = (CThunkObject *)myself;
Py_VISIT(Py_TYPE(self));
Py_VISIT(self->converters);
Py_VISIT(self->callable);
Py_VISIT(self->restype);
Expand All@@ -61,36 +49,35 @@ CThunkObject_clear(PyObject *myself)
return 0;
}

PyTypeObject PyCThunk_Type = {
PyVarObject_HEAD_INIT(NULL, 0)
"_ctypes.CThunkObject",
sizeof(CThunkObject), /* tp_basicsize */
sizeof(ffi_type), /* tp_itemsize */
CThunkObject_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 */
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("CThunkObject"), /* tp_doc */
CThunkObject_traverse, /* tp_traverse */
CThunkObject_clear, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
static void
CThunkObject_dealloc(PyObject *myself)
{
CThunkObject *self = (CThunkObject *)myself;
PyTypeObject *tp = Py_TYPE(myself);
PyObject_GC_UnTrack(self);
(void)CThunkObject_clear(myself);
if (self->pcl_write) {
Py_ffi_closure_free(self->pcl_write);
}
PyObject_GC_Del(self);
Py_DECREF(tp);
}

static PyType_Slot cthunk_slots[] = {
{Py_tp_doc, (void *)PyDoc_STR("CThunkObject")},
{Py_tp_dealloc, CThunkObject_dealloc},
{Py_tp_traverse, CThunkObject_traverse},
{Py_tp_clear, CThunkObject_clear},
{0, NULL},
};

PyType_Spec cthunk_spec = {
.name = "_ctypes.CThunkObject",
.basicsize = sizeof(CThunkObject),
.itemsize = sizeof(ffi_type),
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_DISALLOW_INSTANTIATION),
.slots = cthunk_slots,
};

/**************************************************************/
Expand DownExpand Up@@ -320,7 +307,8 @@ static CThunkObject* CThunkObject_new(Py_ssize_t nargs)
CThunkObject *p;
Py_ssize_t i;

p = PyObject_GC_NewVar(CThunkObject, &PyCThunk_Type, nargs);
ctypes_state *st = GLOBAL_STATE();
p = PyObject_GC_NewVar(CThunkObject, st->PyCThunk_Type, nargs);
if (p == NULL) {
return NULL;
}
Expand DownExpand Up@@ -357,7 +345,10 @@ CThunkObject *_ctypes_alloc_callback(PyObject *callable,
if (p == NULL)
return NULL;

assert(CThunk_CheckExact((PyObject *)p));
#ifdef Py_DEBUG
ctypes_state *st = GLOBAL_STATE();
assert(CThunk_CheckExact(st, (PyObject *)p));
#endif

p->pcl_write = Py_ffi_closure_alloc(sizeof(ffi_closure), &p->pcl_exec);
if (p->pcl_write == NULL) {
Expand Down
5 changes: 3 additions & 2 deletionsModules/_ctypes/ctypes.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,13 +35,15 @@
typedef struct {
PyTypeObject *DictRemover_Type;
PyTypeObject *PyCArg_Type;
PyTypeObject *PyCThunk_Type;
} ctypes_state;

extern ctypes_state global_state;

#define GLOBAL_STATE() (&global_state)

extern PyType_Spec carg_spec;
extern PyType_Spec cthunk_spec;

typedef struct tagPyCArgObject PyCArgObject;
typedef struct tagCDataObject CDataObject;
Expand DownExpand Up@@ -99,8 +101,7 @@ typedef struct {
ffi_type *ffi_restype;
ffi_type *atypes[1];
} CThunkObject;
extern PyTypeObject PyCThunk_Type;
#define CThunk_CheckExact(v) Py_IS_TYPE(v, &PyCThunk_Type)
#define CThunk_CheckExact(st, v) Py_IS_TYPE(v, st->PyCThunk_Type)

typedef struct {
/* First part identical to tagCDataObject */
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@@ -355,7 +355,6 @@ Modules/_ctypes/_ctypes.c-StructParam_Type-
Modules/_ctypes/_ctypes.c-Struct_Type-
Modules/_ctypes/_ctypes.c-UnionType_Type-
Modules/_ctypes/_ctypes.c-Union_Type-
Modules/_ctypes/callbacks.c-PyCThunk_Type-
Modules/_ctypes/callproc.c-PyCArg_Type-
Modules/_ctypes/cfield.c-PyCField_Type-
Modules/_ctypes/ctypes.h-PyCArg_Type-
Expand All@@ -370,7 +369,6 @@ Modules/_ctypes/ctypes.h-PyCPointer_Type-
Modules/_ctypes/ctypes.h-PyCSimpleType_Type-
Modules/_ctypes/ctypes.h-PyCStgDict_Type-
Modules/_ctypes/ctypes.h-PyCStructType_Type-
Modules/_ctypes/ctypes.h-PyCThunk_Type-
Modules/_ctypes/ctypes.h-PyExc_ArgError-
Modules/_ctypes/ctypes.h-_ctypes_conversion_encoding-
Modules/_ctypes/ctypes.h-_ctypes_conversion_errors-
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp