Add API for static strings, primarily good for identifiers.
Thanks to Konrad Schöbel and Jasper Schulz for helping with the mass-editing.
diff --git a/Python/traceback.c b/Python/traceback.c
index b66c96c..551f9d6 100644
--- a/Python/traceback.c
+++ b/Python/traceback.c
@@ -152,6 +152,7 @@
const char* filepath;
Py_ssize_t len;
PyObject* result;
+ _Py_identifier(open);
filebytes = PyUnicode_EncodeFSDefault(filename);
if (filebytes == NULL) {
@@ -199,7 +200,7 @@
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 @@
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 @@
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 @@
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 @@
break;
}
}
- res = PyObject_CallMethod(fob, "close", "");
+ res = _PyObject_CallMethodId(fob, &PyId_close, "");
if (res)
Py_DECREF(res);
else