mirror of
https://github.com/python/cpython.git
synced 2025-12-31 04:23:37 +00:00
gh-94808: add tests covering PyFunction_{Get,Set}Closure (GH-99429)
This commit is contained in:
parent
15309329b6
commit
8182319de3
2 changed files with 148 additions and 1 deletions
|
|
@ -3094,6 +3094,33 @@ function_set_kw_defaults(PyObject *self, PyObject *args)
|
|||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
function_get_closure(PyObject *self, PyObject *func)
|
||||
{
|
||||
PyObject *closure = PyFunction_GetClosure(func);
|
||||
if (closure != NULL) {
|
||||
return Py_NewRef(closure);
|
||||
} else if (PyErr_Occurred()) {
|
||||
return NULL;
|
||||
} else {
|
||||
Py_RETURN_NONE; // This can happen when `closure` is set to `None`
|
||||
}
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
function_set_closure(PyObject *self, PyObject *args)
|
||||
{
|
||||
PyObject *func = NULL, *closure = NULL;
|
||||
if (!PyArg_ParseTuple(args, "OO", &func, &closure)) {
|
||||
return NULL;
|
||||
}
|
||||
int result = PyFunction_SetClosure(func, closure);
|
||||
if (result == -1) {
|
||||
return NULL;
|
||||
}
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
check_pyimport_addmodule(PyObject *self, PyObject *args)
|
||||
{
|
||||
|
|
@ -3379,6 +3406,8 @@ static PyMethodDef TestMethods[] = {
|
|||
{"function_set_defaults", function_set_defaults, METH_VARARGS, NULL},
|
||||
{"function_get_kw_defaults", function_get_kw_defaults, METH_O, NULL},
|
||||
{"function_set_kw_defaults", function_set_kw_defaults, METH_VARARGS, NULL},
|
||||
{"function_get_closure", function_get_closure, METH_O, NULL},
|
||||
{"function_set_closure", function_set_closure, METH_VARARGS, NULL},
|
||||
{"check_pyimport_addmodule", check_pyimport_addmodule, METH_VARARGS},
|
||||
{"test_weakref_capi", test_weakref_capi, METH_NOARGS},
|
||||
{NULL, NULL} /* sentinel */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue