8000 gh-117142: ctypes: Migrate global closure freelist to thunk-type state by neonene · Pull Request #117874 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-117142: ctypes: Migrate global closure freelist to thunk-type state #117874

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

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 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
Prev Previous commit
Next Next commit
check USING_MALLOC_CLOSURE_DOT_C
  • Loading branch information
neonene committed Apr 14, 2024
commit 71d12e3219c16c2231f04050b05653be9e116ae5
5 changes: 3 additions & 2 deletions Lib/test/test_ctypes/test_refcounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,9 @@ def test_many_closures_per_module(self):
"pyfunc = lambda: 0;"
"cfunc_type = ctypes.CFUNCTYPE(ctypes.c_int);"
"cfuncs = [cfunc_type(pyfunc) for i in range(500)];"
"cthunk = cfuncs[0]._objects['0'];"
"n_containers = type(cthunk).ffi_closure_containers_count;"
"cthunk_tp = type(cfuncs[0]._objects['0']);"
"ismeta = type(cthunk_tp) is not type;"
"n_containers = ismeta and cthunk_tp.ffi_closure_containers_count;"
"exit(n_containers and n_containers < 2)"
)
script_helper.assert_python_ok("-c", script)
Expand Down
4 changes: 4 additions & 0 deletions Modules/_ctypes/_ctypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -5721,7 +5721,11 @@ _ctypes_add_types(PyObject *mod)
tp_base is the base type, defaults to 'object' aka PyBaseObject_Type.
*/
CREATE_TYPE(st->PyCArg_Type, &carg_spec, NULL, NULL);
#ifdef USING_MALLOC_CLOSURE_DOT_C
CREATE_TYPE(st->PyCThunkType_Type, &cthunk_type_spec, NULL, &PyType_Type);
#else
st->PyCThunkType_Type = NULL;
#endif
CREATE_TYPE(st->PyCThunk_Type, &cthunk_spec, st->PyCThunkType_Type, NULL);
CREATE_TYPE(st->PyCData_Type, &pycdata_spec, NULL, NULL);

Expand Down
4 changes: 3 additions & 1 deletion Modules/_ctypes/ctypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,10 @@ get_module_state_by_def_final(PyTypeObject *cls)

extern PyType_Spec carg_spec;
extern PyType_Spec cfield_spec;
extern PyType_Spec cthunk_type_spec;
extern PyType_Spec cthunk_spec;
#ifdef USING_MALLOC_CLOSURE_DOT_C
extern PyType_Spec cthunk_type_spec;
#endif

typedef struct tagPyCArgObject PyCArgObject;
typedef struct tagCDataObject CDataObject;
Expand Down
0