[Python-checkins] python/dist/src/Objects funcobject.c,2.65,2.66

mwh at users.sourceforge.net mwh at users.sourceforge.net
Thu Aug 12 20:12:47 CEST 2004


Update of /cvsroot/python/python/dist/src/Objects
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2096/Objects

Modified Files:
	funcobject.c 
Log Message:
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.


Index: funcobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/funcobject.c,v
retrieving revision 2.65
retrieving revision 2.66
diff -C2 -d -r2.65 -r2.66
*** funcobject.c	8 Jul 2004 01:48:59 -0000	2.65
--- funcobject.c	12 Aug 2004 18:12:44 -0000	2.66
***************
*** 164,169 ****
          {"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 */
--- 164,167 ----
***************
*** 251,254 ****
--- 249,282 ----
  
  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)
  {
***************
*** 292,295 ****
--- 320,325 ----
  	{"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 */
  };
***************
*** 417,422 ****
  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),
--- 447,450 ----



More information about the Python-checkins mailing list