Add API for static strings, primarily good for identifiers.

Thanks to Konrad Schöbel and Jasper Schulz for helping with the mass-editing.
This commit is contained in:
Martin v. Löwis 2011-10-09 10:38:36 +02:00
parent 67df285a33
commit afe55bba33
50 changed files with 578 additions and 240 deletions

View file

@ -152,6 +152,7 @@ _Py_FindSourceFile(PyObject *filename, char* namebuf, size_t namelen, PyObject *
const char* filepath;
Py_ssize_t len;
PyObject* result;
_Py_identifier(open);
filebytes = PyUnicode_EncodeFSDefault(filename);
if (filebytes == NULL) {
@ -199,7 +200,7 @@ _Py_FindSourceFile(PyObject *filename, char* namebuf, size_t namelen, PyObject *
namebuf[len++] = SEP;
strcpy(namebuf+len, tail);
binary = PyObject_CallMethod(io, "open", "ss", namebuf, "rb");
binary = _PyObject_CallMethodId(io, &PyId_open, "ss", namebuf, "rb");
if (binary != NULL) {
result = binary;
goto finally;
@ -231,6 +232,9 @@ _Py_DisplaySourceLine(PyObject *f, PyObject *filename, int lineno, int indent)
char buf[MAXPATHLEN+1];
int kind;
void *data;
_Py_identifier(close);
_Py_identifier(open);
_Py_identifier(TextIOWrapper);
/* open the file */
if (filename == NULL)
@ -239,7 +243,7 @@ _Py_DisplaySourceLine(PyObject *f, PyObject *filename, int lineno, int indent)
io = PyImport_ImportModuleNoBlock("io");
if (io == NULL)
return -1;
binary = PyObject_CallMethod(io, "open", "Os", filename, "rb");
binary = _PyObject_CallMethodId(io, &PyId_open, "Os", filename, "rb");
if (binary == NULL) {
binary = _Py_FindSourceFile(filename, buf, sizeof(buf), io);
@ -254,7 +258,7 @@ _Py_DisplaySourceLine(PyObject *f, PyObject *filename, int lineno, int indent)
found_encoding = PyTokenizer_FindEncodingFilename(fd, filename);
encoding = (found_encoding != NULL) ? found_encoding : "utf-8";
lseek(fd, 0, 0); /* Reset position */
fob = PyObject_CallMethod(io, "TextIOWrapper", "Os", binary, encoding);
fob = _PyObject_CallMethodId(io, &PyId_TextIOWrapper, "Os", binary, encoding);
Py_DECREF(io);
Py_DECREF(binary);
PyMem_FREE(found_encoding);
@ -273,7 +277,7 @@ _Py_DisplaySourceLine(PyObject *f, PyObject *filename, int lineno, int indent)
break;
}
}
res = PyObject_CallMethod(fob, "close", "");
res = _PyObject_CallMethodId(fob, &PyId_close, "");
if (res)
Py_DECREF(res);
else