[Python-checkins] python/dist/src/Objects stringobject.c,2.196,2.197

nascheme@projects.sourceforge.net nascheme@projects.sourceforge.net
Mon, 18 Nov 2002 08:09:50 -0800


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

Modified Files:
	stringobject.c 
Log Message:
Add nb_remainder (i.e. __mod__) slot to str type.  Fixes SF bug #615506.


Index: stringobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/stringobject.c,v
retrieving revision 2.196
retrieving revision 2.197
diff -C2 -d -r2.196 -r2.197
*** stringobject.c	12 Nov 2002 23:01:11 -0000	2.196
--- stringobject.c	18 Nov 2002 16:09:38 -0000	2.197
***************
*** 3127,3133 ****
--- 3127,3152 ----
  }
  
+ static PyObject *
+ string_mod(PyObject *v, PyObject *w)
+ {
+ 	if (!PyString_Check(v)) {
+ 		Py_INCREF(Py_NotImplemented);
+ 		return Py_NotImplemented;
+ 	}
+ 	return PyString_Format(v, w);
+ }
+ 
  PyDoc_STRVAR(basestring_doc,
  "Type basestring cannot be instantiated; it is the base for str and unicode.");
  
+ static PyNumberMethods string_as_number = {
+ 	0,			/*nb_add*/
+ 	0,			/*nb_subtract*/
+ 	0,			/*nb_multiply*/
+ 	0, 			/*nb_divide*/
+ 	string_mod,		/*nb_remainder*/
+ };
+ 
+ 
  PyTypeObject PyBaseString_Type = {
  	PyObject_HEAD_INIT(&PyType_Type)
***************
*** 3191,3195 ****
  	0,					/* tp_compare */
  	(reprfunc)string_repr, 			/* tp_repr */
! 	0,					/* tp_as_number */
  	&string_as_sequence,			/* tp_as_sequence */
  	&string_as_mapping,			/* tp_as_mapping */
--- 3210,3214 ----
  	0,					/* tp_compare */
  	(reprfunc)string_repr, 			/* tp_repr */
! 	&string_as_number,			/* tp_as_number */
  	&string_as_sequence,			/* tp_as_sequence */
  	&string_as_mapping,			/* tp_as_mapping */
***************
*** 3200,3204 ****
  	0,					/* tp_setattro */
  	&string_as_buffer,			/* tp_as_buffer */
! 	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
  	string_doc,				/* tp_doc */
  	0,					/* tp_traverse */
--- 3219,3224 ----
  	0,					/* tp_setattro */
  	&string_as_buffer,			/* tp_as_buffer */
! 	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES | 
! 		Py_TPFLAGS_BASETYPE,		/* tp_flags */
  	string_doc,				/* tp_doc */
  	0,					/* tp_traverse */