[Python-Dev] import screwiness

Neal Norwitz nnorwitz at gmail.com
Thu Jul 6 06:39:08 CEST 2006


In import.c starting around line 1210 (I removed a bunch of code that
doesn't matter for the problem):

                if (PyUnicode_Check(v)) {
                        copy = PyUnicode_Encode(PyUnicode_AS_UNICODE(v),
                                PyUnicode_GET_SIZE(v),
Py_FileSystemDefaultEncoding, NULL);
                        v = copy;
                }
                len = PyString_GET_SIZE(v);
                if (len + 2 + namelen + MAXSUFFIXSIZE >= buflen) {
                        Py_XDECREF(copy);
                        continue; /* Too long */
                }
                strcpy(buf, PyString_AS_STRING(v));

***
So if v is originally unicode, then copy is unicode from the second
line, right?  Then we assign v to copy, so v is still unicode.  Then
later on we do PyString_GET_SIZE and PyString_AS_STRING.  That doesn't
work, does it?  What am I missing?

n


More information about the Python-Dev mailing list