Some changes in preparation of stricter rules about mixing str and bytes.

This commit is contained in:
Guido van Rossum 2007-08-27 15:02:28 +00:00
parent ddd25825c8
commit a4b8d1de7c
2 changed files with 14 additions and 9 deletions

View 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 */