summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorMichael W. Hudson <mwh@python.net>2004-08-12 18:12:44 (GMT)
committerMichael W. Hudson <mwh@python.net>2004-08-12 18:12:44 (GMT)
commit5e897959db37752da4c6b476903cdc5e1357093c (patch)
tree73745bf828ac5d8d77254a9d2895169ae6bbae3c /Objects
parent5523c2517f14aed04f94865189ce986040652415 (diff)
downloadcpython-5e897959db37752da4c6b476903cdc5e1357093c.zip
cpython-5e897959db37752da4c6b476903cdc5e1357093c.tar.gz
cpython-5e897959db37752da4c6b476903cdc5e1357093c.tar.bz2
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.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/funcobject.c36
1 files changed, 32 insertions, 4 deletions
diff --git a/Objects/funcobject.c b/Objects/funcobject.c
index 971eb1c..c46887c 100644
--- a/Objects/funcobject.c
+++ b/Objects/funcobject.c
@@ -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 */
};
@@ -250,6 +248,36 @@ func_set_code(PyFunctionObject *op, PyObject *value)
}
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)
{
if (restricted())
@@ -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);