[Python-checkins] CVS: python/dist/src/Objects classobject.c,2.149,2.150 descrobject.c,2.12,2.13 fileobject.c,2.129,2.130 frameobject.c,2.57,2.58 funcobject.c,2.44,2.45 methodobject.c,2.39,2.40 typeobject.c,2.66,2.67

Guido van Rossum gvanrossum@users.sourceforge.net
Thu, 20 Sep 2001 14:45:29 -0700


Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv5414/Objects

Modified Files:
	classobject.c descrobject.c fileobject.c frameobject.c 
	funcobject.c methodobject.c typeobject.c 
Log Message:
Add optional docstrings to getset descriptors.  Fortunately, there's
no backwards compatibility to worry about, so I just pushed the
'closure' struct member to the back -- it's never used in the current
code base (I may eliminate it, but that's more work because the getter
and setter signatures would have to change.)

As examples, I added actual docstrings to the getset attributes of a
few types: file.closed, xxsubtype.spamdict.state.



Index: classobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/classobject.c,v
retrieving revision 2.149
retrieving revision 2.150
diff -C2 -d -r2.149 -r2.150
*** classobject.c	2001/09/20 20:46:18	2.149
--- classobject.c	2001/09/20 21:45:26	2.150
***************
*** 2037,2044 ****
  }
  
! static struct getsetlist instancemethod_getsetlist[] = {
! 	{"__dict__", (getter)im_get_dict},
! 	{"__doc__", (getter)im_get_doc},
! 	{"__name__", (getter)im_get_name},
  	{NULL}  /* Sentinel */
  };
--- 2037,2044 ----
  }
  
! static PyGetSetDef instancemethod_getsetlist[] = {
! 	{"__dict__", (getter)im_get_dict, NULL, "same as im_func.__dict__"},
! 	{"__doc__", (getter)im_get_doc, NULL, "same as im_func.__doc__"},
! 	{"__name__", (getter)im_get_name, NULL, "same as im_func.__name__"},
  	{NULL}  /* Sentinel */
  };

Index: descrobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/descrobject.c,v
retrieving revision 2.12
retrieving revision 2.13
diff -C2 -d -r2.12 -r2.13
*** descrobject.c	2001/09/20 20:46:18	2.12
--- descrobject.c	2001/09/20 21:45:26	2.13
***************
*** 27,31 ****
  typedef struct {
  	COMMON;
! 	struct getsetlist *d_getset;
  } PyGetSetDescrObject;
  
--- 27,31 ----
  typedef struct {
  	COMMON;
! 	PyGetSetDef *d_getset;
  } PyGetSetDescrObject;
  
***************
*** 303,307 ****
  };
  
! static struct getsetlist method_getset[] = {
  	{"__doc__", (getter)method_get_doc},
  	{0}
--- 303,307 ----
  };
  
! static PyGetSetDef method_getset[] = {
  	{"__doc__", (getter)method_get_doc},
  	{0}
***************
*** 318,322 ****
  }
  
! static struct getsetlist member_getset[] = {
  	{"__doc__", (getter)member_get_doc},
  	{0}
--- 318,322 ----
  }
  
! static PyGetSetDef member_getset[] = {
  	{"__doc__", (getter)member_get_doc},
  	{0}
***************
*** 324,327 ****
--- 324,342 ----
  
  static PyObject *
+ getset_get_doc(PyGetSetDescrObject *descr, void *closure)
+ {
+ 	if (descr->d_getset->doc == NULL) {
+ 		Py_INCREF(Py_None);
+ 		return Py_None;
+ 	}
+ 	return PyString_FromString(descr->d_getset->doc);
+ }
+ 
+ static PyGetSetDef getset_getset[] = {
+ 	{"__doc__", (getter)getset_get_doc},
+ 	{0}
+ };
+ 
+ static PyObject *
  wrapper_get_doc(PyWrapperDescrObject *descr, void *closure)
  {
***************
*** 333,337 ****
  }
  
! static struct getsetlist wrapper_getset[] = {
  	{"__doc__", (getter)wrapper_get_doc},
  	{0}
--- 348,352 ----
  }
  
! static PyGetSetDef wrapper_getset[] = {
  	{"__doc__", (getter)wrapper_get_doc},
  	{0}
***************
*** 445,449 ****
  	0,					/* tp_methods */
  	descr_members,				/* tp_members */
! 	0,					/* tp_getset */
  	0,					/* tp_base */
  	0,					/* tp_dict */
--- 460,464 ----
  	0,					/* tp_methods */
  	descr_members,				/* tp_members */
! 	getset_getset,				/* tp_getset */
  	0,					/* tp_base */
  	0,					/* tp_dict */
***************
*** 533,537 ****
  
  PyObject *
! PyDescr_NewGetSet(PyTypeObject *type, struct getsetlist *getset)
  {
  	PyGetSetDescrObject *descr;
--- 548,552 ----
  
  PyObject *
! PyDescr_NewGetSet(PyTypeObject *type, PyGetSetDef *getset)
  {
  	PyGetSetDescrObject *descr;
***************
*** 779,783 ****
  }
  
! static struct getsetlist wrapper_getsets[] = {
  	{"__name__", (getter)wrapper_name},
  	{"__doc__", (getter)wrapper_doc},
--- 794,798 ----
  }
  
! static PyGetSetDef wrapper_getsets[] = {
  	{"__name__", (getter)wrapper_name},
  	{"__doc__", (getter)wrapper_doc},

Index: fileobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/fileobject.c,v
retrieving revision 2.129
retrieving revision 2.130
diff -C2 -d -r2.129 -r2.130
*** fileobject.c	2001/09/20 20:46:19	2.129
--- fileobject.c	2001/09/20 21:45:26	2.130
***************
*** 1401,1406 ****
  }
  
! static struct getsetlist file_getsetlist[] = {
! 	{"closed", (getter)get_closed, NULL, NULL},
  	{0},
  };
--- 1401,1406 ----
  }
  
! static PyGetSetDef file_getsetlist[] = {
! 	{"closed", (getter)get_closed, NULL, "flag set if the file is closed"},
  	{0},
  };

Index: frameobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/frameobject.c,v
retrieving revision 2.57
retrieving revision 2.58
diff -C2 -d -r2.57 -r2.58
*** frameobject.c	2001/09/20 20:46:19	2.57
--- frameobject.c	2001/09/20 21:45:26	2.58
***************
*** 34,38 ****
  }
  
! static struct getsetlist frame_getsetlist[] = {
  	{"f_locals",	(getter)frame_getlocals, NULL, NULL},
  	{0}
--- 34,38 ----
  }
  
! static PyGetSetDef frame_getsetlist[] = {
  	{"f_locals",	(getter)frame_getlocals, NULL, NULL},
  	{0}

Index: funcobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/funcobject.c,v
retrieving revision 2.44
retrieving revision 2.45
diff -C2 -d -r2.44 -r2.45
*** funcobject.c	2001/09/20 20:46:19	2.44
--- funcobject.c	2001/09/20 21:45:26	2.45
***************
*** 258,262 ****
  }
  
! static struct getsetlist func_getsetlist[] = {
          {"func_code", (getter)func_get_code, (setter)func_set_code},
          {"func_defaults", (getter)func_get_defaults,
--- 258,262 ----
  }
  
! static PyGetSetDef func_getsetlist[] = {
          {"func_code", (getter)func_get_code, (setter)func_set_code},
          {"func_defaults", (getter)func_get_defaults,

Index: methodobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/methodobject.c,v
retrieving revision 2.39
retrieving revision 2.40
diff -C2 -d -r2.39 -r2.40
*** methodobject.c	2001/08/30 13:58:58	2.39
--- methodobject.c	2001/09/20 21:45:26	2.40
***************
*** 160,164 ****
  }
  
! static struct getsetlist meth_getsets [] = {
  	{"__doc__",  (getter)meth_get__doc__,  NULL, NULL},
  	{"__name__", (getter)meth_get__name__, NULL, NULL},
--- 160,164 ----
  }
  
! static PyGetSetDef meth_getsets [] = {
  	{"__doc__",  (getter)meth_get__doc__,  NULL, NULL},
  	{"__name__", (getter)meth_get__name__, NULL, NULL},

Index: typeobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/typeobject.c,v
retrieving revision 2.66
retrieving revision 2.67
diff -C2 -d -r2.66 -r2.67
*** typeobject.c	2001/09/20 20:46:19	2.66
--- typeobject.c	2001/09/20 21:45:26	2.67
***************
*** 92,96 ****
  }
  
! struct getsetlist type_getsets[] = {
  	{"__name__", (getter)type_name, NULL, NULL},
  	{"__module__", (getter)type_module, NULL, NULL},
--- 92,96 ----
  }
  
! PyGetSetDef type_getsets[] = {
  	{"__name__", (getter)type_name, NULL, NULL},
  	{"__module__", (getter)type_module, NULL, NULL},
***************
*** 660,664 ****
  }
  
! struct getsetlist subtype_getsets[] = {
  	{"__dict__", subtype_dict, NULL, NULL},
  	{0},
--- 660,664 ----
  }
  
! PyGetSetDef subtype_getsets[] = {
  	{"__dict__", subtype_dict, NULL, NULL},
  	{0},
***************
*** 1283,1287 ****
  
  static int
! add_getset(PyTypeObject *type, struct getsetlist *gsp)
  {
  	PyObject *dict = type->tp_defined;
--- 1283,1287 ----
  
  static int
! add_getset(PyTypeObject *type, PyGetSetDef *gsp)
  {
  	PyObject *dict = type->tp_defined;