Skip to content

Commit 47957b8

Browse files
committed
Move weakref test to internal C API.
1 parent 79a1852 commit 47957b8

2 files changed

Lines changed: 22 additions & 21 deletions

File tree

Modules/_testcapimodule.c

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2556,26 +2556,6 @@ get_strong_ref(void)
25562556
return ref;
25572557
}
25582558

2559-
static PyObject *
2560-
test_interp_weak_ref(PyObject *self, PyObject *unused)
2561-
{
2562-
PyInterpreterState *interp = PyInterpreterState_Get();
2563-
PyInterpreterWeakRef wref;
2564-
if (PyInterpreterWeakRef_Get(&wref) < 0) {
2565-
return NULL;
2566-
}
2567-
assert(_PyInterpreterState_Refcount(interp) == 0);
2568-
2569-
PyInterpreterRef ref;
2570-
int res = PyInterpreterWeakRef_AsStrong(wref, &ref);
2571-
assert(res == 0);
2572-
assert(PyInterpreterRef_AsInterpreter(ref) == interp);
2573-
PyInterpreterWeakRef_Close(wref);
2574-
PyInterpreterRef_Close(ref);
2575-
2576-
Py_RETURN_NONE;
2577-
}
2578-
25792559
static PyObject *
25802560
test_interp_ensure(PyObject *self, PyObject *unused)
25812561
{
@@ -2704,7 +2684,6 @@ static PyMethodDef TestMethods[] = {
27042684
{"test_atexit", test_atexit, METH_NOARGS},
27052685
{"code_offset_to_line", _PyCFunction_CAST(code_offset_to_line), METH_FASTCALL},
27062686
{"toggle_reftrace_printer", toggle_reftrace_printer, METH_O},
2707-
{"test_interp_weak_ref", test_interp_weak_ref, METH_NOARGS},
27082687
{"test_interp_ensure", test_interp_ensure, METH_NOARGS},
27092688
{NULL, NULL} /* sentinel */
27102689
};

Modules/_testinternalcapi.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2382,6 +2382,27 @@ test_interp_refcount(PyObject *self, PyObject *unused)
23822382
Py_RETURN_NONE;
23832383
}
23842384

2385+
static PyObject *
2386+
test_interp_weakref_incref(PyObject *self, PyObject *unused)
2387+
{
2388+
PyInterpreterState *interp = PyInterpreterState_Get();
2389+
PyInterpreterWeakRef wref;
2390+
if (PyInterpreterWeakRef_Get(&wref) < 0) {
2391+
return NULL;
2392+
}
2393+
assert(_PyInterpreterState_Refcount(interp) == 0);
2394+
2395+
PyInterpreterRef ref;
2396+
int res = PyInterpreterWeakRef_AsStrong(wref, &ref);
2397+
assert(res == 0);
2398+
assert(PyInterpreterRef_AsInterpreter(ref) == interp);
2399+
assert(_PyInterpreterState_Refcount(interp) == 1);
2400+
PyInterpreterWeakRef_Close(wref);
2401+
PyInterpreterRef_Close(ref);
2402+
2403+
Py_RETURN_NONE;
2404+
}
2405+
23852406
static PyMethodDef module_functions[] = {
23862407
{"get_configs", get_configs, METH_NOARGS},
23872408
{"get_recursion_depth", get_recursion_depth, METH_NOARGS},
@@ -2485,6 +2506,7 @@ static PyMethodDef module_functions[] = {
24852506
{"incref_decref_delayed", incref_decref_delayed, METH_O},
24862507
GET_NEXT_DICT_KEYS_VERSION_METHODDEF
24872508
{"test_interp_refcount", test_interp_refcount, METH_NOARGS},
2509+
{"test_interp_weakref_incref", test_interp_weakref_incref, METH_NOARGS},
24882510
{NULL, NULL} /* sentinel */
24892511
};
24902512

0 commit comments

Comments
 (0)