mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
This is my patch
[ 1004703 ] Make func_name writable plus fixing a couple of nits in the documentation changes spotted by MvL and a Misc/NEWS entry.
This commit is contained in:
parent
5523c2517f
commit
5e897959db
5 changed files with 94 additions and 46 deletions
|
@ -163,8 +163,6 @@ static PyMemberDef func_memberlist[] = {
|
|||
{"__doc__", T_OBJECT, OFF(func_doc), WRITE_RESTRICTED},
|
||||
{"func_globals", T_OBJECT, OFF(func_globals),
|
||||
RESTRICTED|READONLY},
|
||||
{"func_name", T_OBJECT, OFF(func_name), READONLY},
|
||||
{"__name__", T_OBJECT, OFF(func_name), READONLY},
|
||||
{"__module__", T_OBJECT, OFF(func_module), WRITE_RESTRICTED},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
@ -249,6 +247,36 @@ func_set_code(PyFunctionObject *op, PyObject *value)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
func_get_name(PyFunctionObject *op)
|
||||
{
|
||||
if (restricted())
|
||||
return NULL;
|
||||
Py_INCREF(op->func_name);
|
||||
return op->func_name;
|
||||
}
|
||||
|
||||
static int
|
||||
func_set_name(PyFunctionObject *op, PyObject *value)
|
||||
{
|
||||
PyObject *tmp;
|
||||
|
||||
if (restricted())
|
||||
return -1;
|
||||
/* Not legal to del f.func_name or to set it to anything
|
||||
* other than a string object. */
|
||||
if (value == NULL || !PyString_Check(value)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"func_name must be set to a string object");
|
||||
return -1;
|
||||
}
|
||||
tmp = op->func_name;
|
||||
Py_INCREF(value);
|
||||
op->func_name = value;
|
||||
Py_DECREF(tmp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
func_get_defaults(PyFunctionObject *op)
|
||||
{
|
||||
|
@ -291,6 +319,8 @@ static PyGetSetDef func_getsetlist[] = {
|
|||
(setter)func_set_defaults},
|
||||
{"func_dict", (getter)func_get_dict, (setter)func_set_dict},
|
||||
{"__dict__", (getter)func_get_dict, (setter)func_set_dict},
|
||||
{"func_name", (getter)func_get_name, (setter)func_set_name},
|
||||
{"__name__", (getter)func_get_name, (setter)func_set_name},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
@ -416,8 +446,6 @@ func_dealloc(PyFunctionObject *op)
|
|||
static PyObject*
|
||||
func_repr(PyFunctionObject *op)
|
||||
{
|
||||
if (op->func_name == Py_None)
|
||||
return PyString_FromFormat("<anonymous function at %p>", op);
|
||||
return PyString_FromFormat("<function %s at %p>",
|
||||
PyString_AsString(op->func_name),
|
||||
op);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue