]> granicus.if.org Git - python/commitdiff
Some changes in preparation of stricter rules about mixing str and bytes.
authorGuido van Rossum <guido@python.org>
Mon, 27 Aug 2007 15:02:28 +0000 (15:02 +0000)
committerGuido van Rossum <guido@python.org>
Mon, 27 Aug 2007 15:02:28 +0000 (15:02 +0000)
Python/bltinmodule.c
Python/import.c

index 22a57ea846e91ea7cc5f8e05d6490da9f58270d8..284910d9eae777cb20047520bc899fb8b0d4bc7b 100644 (file)
@@ -403,18 +403,16 @@ source_as_string(PyObject *cmd)
        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;
        }
index 8195bad2169a33774edaade97e33f58768de0f4c..2ef6aec9416e80f13bba419c8e07b63118996a86 100644 (file)
@@ -1247,8 +1247,15 @@ find_module(char *fullname, char *subname, PyObject *path, char *buf,
                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 */