Author: thomas.heller
Date: Wed Jul 11 21:57:40 2007
New Revision: 56282

Modified:
   python/branches/py3k-struni/Objects/typeobject.c
   python/branches/py3k-struni/Python/errors.c
Log:
Must create heaptypes with unicode names.

Modified: python/branches/py3k-struni/Objects/typeobject.c
==============================================================================
--- python/branches/py3k-struni/Objects/typeobject.c    (original)
+++ python/branches/py3k-struni/Objects/typeobject.c    Wed Jul 11 21:57:40 2007
@@ -44,6 +44,7 @@
 type_set_name(PyTypeObject *type, PyObject *value, void *context)
 {
        PyHeapTypeObject* et;
+       char *name;
 
        if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE)) {
                PyErr_Format(PyExc_TypeError,
@@ -55,19 +56,25 @@
                             "can't delete %s.__name__", type->tp_name);
                return -1;
        }
-       if (PyUnicode_Check(value)) {
-               value = _PyUnicode_AsDefaultEncodedString(value, NULL);
+       if (PyString_Check(value)) {
+               value = PyUnicode_FromStringAndSize(PyString_AS_STRING(value),
+                                                   PyString_GET_SIZE(value));
                if (value == NULL)
                        return -1;
+               /* XXX Isn't here a refcount leak? */
        }
-       if (!PyString_Check(value)) {
+       if (!PyUnicode_Check(value)) {
                PyErr_Format(PyExc_TypeError,
                             "can only assign string to %s.__name__, not '%s'",
                             type->tp_name, value->ob_type->tp_name);
                return -1;
        }
-       if (strlen(PyString_AS_STRING(value))
-           != (size_t)PyString_GET_SIZE(value)) {
+
+       name = PyUnicode_AsString(value);
+       if (name == NULL)
+               return -1;
+
+       if (strlen(name) != PyUnicode_GET_SIZE(value)) {
                PyErr_Format(PyExc_ValueError,
                             "__name__ must not contain null bytes");
                return -1;
@@ -80,7 +87,7 @@
        Py_DECREF(et->ht_name);
        et->ht_name = value;
 
-       type->tp_name = PyString_AS_STRING(value);
+       type->tp_name = name;
 
        return 0;
 }
@@ -1658,7 +1665,7 @@
        }
 
        /* Check arguments: (name, bases, dict) */
-       if (!PyArg_ParseTupleAndKeywords(args, kwds, "SO!O!:type", kwlist,
+       if (!PyArg_ParseTupleAndKeywords(args, kwds, "UO!O!:type", kwlist,
                                         &name,
                                         &PyTuple_Type, &bases,
                                         &PyDict_Type, &dict))

Modified: python/branches/py3k-struni/Python/errors.c
==============================================================================
--- python/branches/py3k-struni/Python/errors.c (original)
+++ python/branches/py3k-struni/Python/errors.c Wed Jul 11 21:57:40 2007
@@ -575,7 +575,7 @@
                        goto failure;
        }
        /* Create a real new-style class. */
-       result = PyObject_CallFunction((PyObject *)&PyType_Type, "sOO",
+       result = PyObject_CallFunction((PyObject *)&PyType_Type, "UOO",
                                       dot+1, bases, dict);
   failure:
        Py_XDECREF(bases);
_______________________________________________
Python-3000-checkins mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000-checkins

Reply via email to