Author: guido.van.rossum
Date: Sat Nov  3 00:07:07 2007
New Revision: 58815

Modified:
   python/branches/py3k/Objects/typeobject.c
   python/branches/py3k/Parser/asdl_c.py
   python/branches/py3k/Python/Python-ast.c
   python/branches/py3k/Python/errors.c
Log:
Fixes for issue 1752184, ensuring type objects are always created
with a PyUnicode name.


Modified: python/branches/py3k/Objects/typeobject.c
==============================================================================
--- python/branches/py3k/Objects/typeobject.c   (original)
+++ python/branches/py3k/Objects/typeobject.c   Sat Nov  3 00:07:07 2007
@@ -45,6 +45,7 @@
 {
        PyHeapTypeObject* et;
        char *tp_name;
+        PyObject *tmp;
 
        if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE)) {
                PyErr_Format(PyExc_TypeError,
@@ -62,14 +63,22 @@
                             type->tp_name, Py_Type(value)->tp_name);
                return -1;
        }
-       tp_name = PyUnicode_AsString(value);
-       if (tp_name == NULL)
+
+        /* Check absence of null characters */
+        tmp = PyUnicode_FromStringAndSize("\0", 1);
+        if (tmp == NULL)
                return -1;
-       if (strlen(tp_name) != (size_t)PyUnicode_GET_SIZE(value)) {
+       if (PyUnicode_Contains(value, tmp) != 0) {
+               Py_DECREF(tmp);
                PyErr_Format(PyExc_ValueError,
                             "__name__ must not contain null bytes");
                return -1;
        }
+       Py_DECREF(tmp);
+
+       tp_name = PyUnicode_AsString(value);
+       if (tp_name == NULL)
+               return -1;
 
        et = (PyHeapTypeObject*)type;
 

Modified: python/branches/py3k/Parser/asdl_c.py
==============================================================================
--- python/branches/py3k/Parser/asdl_c.py       (original)
+++ python/branches/py3k/Parser/asdl_c.py       Sat Nov  3 00:07:07 2007
@@ -415,7 +415,7 @@
         }
         PyTuple_SET_ITEM(fnames, i, field);
     }
-    result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}",
+    result = PyObject_CallFunction((PyObject*)&PyType_Type, "U(O){sOss}",
                     type, base, "_fields", fnames, "__module__", "_ast");
     Py_DECREF(fnames);
     return (PyTypeObject*)result;

Modified: python/branches/py3k/Python/Python-ast.c
==============================================================================
--- python/branches/py3k/Python/Python-ast.c    (original)
+++ python/branches/py3k/Python/Python-ast.c    Sat Nov  3 00:07:07 2007
@@ -410,7 +410,7 @@
         }
         PyTuple_SET_ITEM(fnames, i, field);
     }
-    result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}",
+    result = PyObject_CallFunction((PyObject*)&PyType_Type, "U(O){sOss}",
                     type, base, "_fields", fnames, "__module__", "_ast");
     Py_DECREF(fnames);
     return (PyTypeObject*)result;

Modified: python/branches/py3k/Python/errors.c
==============================================================================
--- python/branches/py3k/Python/errors.c        (original)
+++ python/branches/py3k/Python/errors.c        Sat Nov  3 00:07:07 2007
@@ -608,7 +608,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