Author: guido.van.rossum
Date: Mon Aug 27 17:02:28 2007
New Revision: 57558

Modified:
   python/branches/py3k/Python/bltinmodule.c
   python/branches/py3k/Python/import.c
Log:
Some changes in preparation of stricter rules about mixing str and bytes.


Modified: python/branches/py3k/Python/bltinmodule.c
==============================================================================
--- python/branches/py3k/Python/bltinmodule.c   (original)
+++ python/branches/py3k/Python/bltinmodule.c   Mon Aug 27 17:02:28 2007
@@ -403,18 +403,16 @@
        char *str;
        Py_ssize_t size;
 
-       if (!PyObject_CheckReadBuffer(cmd) &&
-           !PyUnicode_Check(cmd)) {
-               PyErr_SetString(PyExc_TypeError,
-                          "eval()/exec() arg 1 must be a string, bytes or code 
object");
-               return NULL;
-       }
-
        if (PyUnicode_Check(cmd)) {
                cmd = _PyUnicode_AsDefaultEncodedString(cmd, NULL);
                if (cmd == NULL)
                        return NULL;
        }
+       else if (!PyObject_CheckReadBuffer(cmd)) {
+               PyErr_SetString(PyExc_TypeError,
+                 "eval()/exec() arg 1 must be a string, bytes or code object");
+               return NULL;
+       }
        if (PyObject_AsReadBuffer(cmd, (const void **)&str, &size) < 0) {
                return NULL;
        }

Modified: python/branches/py3k/Python/import.c
==============================================================================
--- python/branches/py3k/Python/import.c        (original)
+++ python/branches/py3k/Python/import.c        Mon Aug 27 17:02:28 2007
@@ -1247,8 +1247,15 @@
                Py_ssize_t size;
                if (!v)
                        return NULL;
-               if (PyObject_AsCharBuffer(v, &base, &size) < 0)
-                       return NULL;
+               if (PyUnicode_Check(v)) {
+                       v = _PyUnicode_AsDefaultEncodedString(v, NULL);
+                       if (v == NULL)
+                               return NULL;
+               }
+               if (!PyString_Check(v))
+                       continue;
+               base = PyString_AS_STRING(v);
+               size = PyString_GET_SIZE(v);
                len = size;
                if (len + 2 + namelen + MAXSUFFIXSIZE >= buflen) {
                        continue; /* Too long */
_______________________________________________
Python-3000-checkins mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000-checkins

Reply via email to