/
githubmirror
/
cpython
Обзор
Документация
Войти
/
githubmirror
/
cpython
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
Modules/_testlimitedcapi/weakref.c
78 строк
2 KB
Serhiy Storchaka
gh-151130: Add more tests for PyWeakref_* C API (GH-151131)
09 июн 2026, 14:11
Не верифицирован
09 июн 2026, 14:11
c3cd75a
Код
Авторство
О чём код?
#include "pyconfig.h" // Py_GIL_DISABLED #ifndef Py_GIL_DISABLED // Need limited C API 3.5 for PyModule_AddFunctions() # define Py_LIMITED_API 0x03050000 #endif #include "parts.h" #include "util.h" static PyObject * pyweakref_check(PyObject *module, PyObject *obj) { NULLABLE(obj); return PyLong_FromLong(PyWeakref_Check(obj)); } static PyObject * pyweakref_checkref(PyObject *module, PyObject *obj) { NULLABLE(obj); return PyLong_FromLong(PyWeakref_CheckRef(obj)); } static PyObject * pyweakref_checkrefexact(PyObject *module, PyObject *obj) { NULLABLE(obj); return PyLong_FromLong(PyWeakref_CheckRefExact(obj)); } static PyObject * pyweakref_checkproxy(PyObject *module, PyObject *obj) { NULLABLE(obj); return PyLong_FromLong(PyWeakref_CheckProxy(obj)); } static PyObject * pyweakref_newref(PyObject *module, PyObject *args) { PyObject *obj; PyObject *callback = NULL; if (!PyArg_ParseTuple(args, "O|O", &obj, &callback)) { return NULL; } NULLABLE(obj); return PyWeakref_NewRef(obj, callback); } static PyObject * pyweakref_newproxy(PyObject *module, PyObject *args) { PyObject *obj; PyObject *callback = NULL; if (!PyArg_ParseTuple(args, "O|O", &obj, &callback)) { return NULL; } NULLABLE(obj); return PyWeakref_NewProxy(obj, callback); } static PyMethodDef test_methods[] = { {"pyweakref_check", pyweakref_check, METH_O}, {"pyweakref_checkref", pyweakref_checkref, METH_O}, {"pyweakref_checkrefexact", pyweakref_checkrefexact, METH_O}, {"pyweakref_checkproxy", pyweakref_checkproxy, METH_O}, {"pyweakref_newref", pyweakref_newref, METH_VARARGS}, {"pyweakref_newproxy", pyweakref_newproxy, METH_VARARGS}, {NULL}, }; int _PyTestLimitedCAPI_Init_Weakref(PyObject *m) { return PyModule_AddFunctions(m, test_methods); }