summaryrefslogtreecommitdiffstats
path: root/Objects/stringobject.c
diff options
context:
space:
mode:
authorNeil Schemenauer <nascheme@enme.ucalgary.ca>2002-11-18 16:09:38 (GMT)
committerNeil Schemenauer <nascheme@enme.ucalgary.ca>2002-11-18 16:09:38 (GMT)
commita6cd4e65d7faef4928f86ad728c32dcf24b80fb5 (patch)
tree237ab3b0601fa5d6eed393e6c37069582dbdae42 /Objects/stringobject.c
parent2c77e90804bbce12ca0e724b4138b9911f7b712e (diff)
downloadcpython-a6cd4e65d7faef4928f86ad728c32dcf24b80fb5.zip
cpython-a6cd4e65d7faef4928f86ad728c32dcf24b80fb5.tar.gz
cpython-a6cd4e65d7faef4928f86ad728c32dcf24b80fb5.tar.bz2
Add nb_remainder (i.e. __mod__) slot to str type. Fixes SF bug #615506.
Diffstat (limited to 'Objects/stringobject.c')
-rw-r--r--Objects/stringobject.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/Objects/stringobject.c b/Objects/stringobject.c
index bf8bad5..c234b04 100644
--- a/Objects/stringobject.c
+++ b/Objects/stringobject.c
@@ -3126,9 +3126,28 @@ basestring_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return NULL;
}
+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)
0,
@@ -3190,7 +3209,7 @@ PyTypeObject PyString_Type = {
0, /* tp_setattr */
0, /* tp_compare */
(reprfunc)string_repr, /* tp_repr */
- 0, /* tp_as_number */
+ &string_as_number, /* tp_as_number */
&string_as_sequence, /* tp_as_sequence */
&string_as_mapping, /* tp_as_mapping */
(hashfunc)string_hash, /* tp_hash */
@@ -3199,7 +3218,8 @@ PyTypeObject PyString_Type = {
PyObject_GenericGetAttr, /* tp_getattro */
0, /* tp_setattro */
&string_as_buffer, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES |
+ Py_TPFLAGS_BASETYPE, /* tp_flags */
string_doc, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */