[Python-checkins] python/dist/src/Objects typeobject.c,2.179,2.180
loewis@users.sourceforge.net
loewis@users.sourceforge.net
Mon, 14 Oct 2002 14:07:32 -0700
Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv31900
Modified Files:
typeobject.c
Log Message:
Allow Unicode strings in __slots__, converting them to byte strings.
Index: typeobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/typeobject.c,v
retrieving revision 2.179
retrieving revision 2.180
diff -C2 -d -r2.179 -r2.180
*** typeobject.c 16 Aug 2002 17:01:08 -0000 2.179
--- typeobject.c 14 Oct 2002 21:07:28 -0000 2.180
***************
*** 1004,1007 ****
--- 1004,1039 ----
}
+ #ifdef Py_USING_UNICODE
+ /* Replace Unicode objects in slots. */
+
+ static PyObject *
+ _unicode_to_string(PyObject *slots, int nslots)
+ {
+ PyObject *tmp = slots;
+ PyObject *o, *o1;
+ int i;
+ intintargfunc copy = slots->ob_type->tp_as_sequence->sq_slice;
+ for (i = 0; i < nslots; i++) {
+ if (PyUnicode_Check(o = PyTuple_GET_ITEM(tmp, i))) {
+ if (tmp == slots) {
+ tmp = copy(slots, 0, PyTuple_GET_SIZE(slots));
+ if (tmp == NULL)
+ return NULL;
+ }
+ o1 = _PyUnicode_AsDefaultEncodedString
+ (o, NULL);
+ if (o1 == NULL) {
+ Py_DECREF(tmp);
+ return 0;
+ }
+ Py_INCREF(o1);
+ Py_DECREF(o);
+ PyTuple_SET_ITEM(tmp, i, o1);
+ }
+ }
+ return tmp;
+ }
+ #endif
+
static PyObject *
type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
***************
*** 1136,1139 ****
--- 1168,1178 ----
}
+ #ifdef Py_USING_UNICODE
+ tmp = _unicode_to_string(slots, nslots);
+ Py_DECREF(slots);
+ slots = tmp;
+ if (!tmp)
+ return NULL;
+ #endif
/* Check for valid slot names and two special cases */
for (i = 0; i < nslots; i++) {