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

@ -7,6 +7,7 @@ extern "C" {
#ifdef PY_SSIZE_T_CLEAN #ifdef PY_SSIZE_T_CLEAN
#define PyObject_CallFunction _PyObject_CallFunction_SizeT #define PyObject_CallFunction _PyObject_CallFunction_SizeT
#define PyObject_CallMethod _PyObject_CallMethod_SizeT #define PyObject_CallMethod _PyObject_CallMethod_SizeT
#define _PyObject_CallMethodId _PyObject_CallMethodId_SizeT
#endif #endif
/* Abstract Object Interface (many thanks to Jim Fulton) */ /* Abstract Object Interface (many thanks to Jim Fulton) */
@ -307,11 +308,22 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
Python expression: o.method(args). Python expression: o.method(args).
*/ */
PyAPI_FUNC(PyObject *) _PyObject_CallMethodId(PyObject *o, _Py_Identifier *method,
char *format, ...);
/*
Like PyObject_CallMethod, but expect a _Py_Identifier* as the
method name.
*/
PyAPI_FUNC(PyObject *) _PyObject_CallFunction_SizeT(PyObject *callable, PyAPI_FUNC(PyObject *) _PyObject_CallFunction_SizeT(PyObject *callable,
char *format, ...); char *format, ...);
PyAPI_FUNC(PyObject *) _PyObject_CallMethod_SizeT(PyObject *o, PyAPI_FUNC(PyObject *) _PyObject_CallMethod_SizeT(PyObject *o,
char *name, char *name,
char *format, ...); char *format, ...);
PyAPI_FUNC(PyObject *) _PyObject_CallMethodId_SizeT(PyObject *o,
_Py_Identifier *name,
char *format, ...);
PyAPI_FUNC(PyObject *) PyObject_CallFunctionObjArgs(PyObject *callable, PyAPI_FUNC(PyObject *) PyObject_CallFunctionObjArgs(PyObject *callable,
...); ...);

View File

@ -454,6 +454,7 @@ PyAPI_FUNC(unsigned int) PyType_ClearCache(void);
PyAPI_FUNC(void) PyType_Modified(PyTypeObject *); PyAPI_FUNC(void) PyType_Modified(PyTypeObject *);
/* Generic operations on objects */ /* Generic operations on objects */
struct _Py_Identifier;
#ifndef Py_LIMITED_API #ifndef Py_LIMITED_API
PyAPI_FUNC(int) PyObject_Print(PyObject *, FILE *, int); PyAPI_FUNC(int) PyObject_Print(PyObject *, FILE *, int);
PyAPI_FUNC(void) _Py_BreakPoint(void); PyAPI_FUNC(void) _Py_BreakPoint(void);
@ -471,6 +472,9 @@ PyAPI_FUNC(int) PyObject_HasAttrString(PyObject *, const char *);
PyAPI_FUNC(PyObject *) PyObject_GetAttr(PyObject *, PyObject *); PyAPI_FUNC(PyObject *) PyObject_GetAttr(PyObject *, PyObject *);
PyAPI_FUNC(int) PyObject_SetAttr(PyObject *, PyObject *, PyObject *); PyAPI_FUNC(int) PyObject_SetAttr(PyObject *, PyObject *, PyObject *);
PyAPI_FUNC(int) PyObject_HasAttr(PyObject *, PyObject *); PyAPI_FUNC(int) PyObject_HasAttr(PyObject *, PyObject *);
PyAPI_FUNC(PyObject *) _PyObject_GetAttrId(PyObject *, struct _Py_Identifier *);
PyAPI_FUNC(int) _PyObject_SetAttrId(PyObject *, struct _Py_Identifier *, PyObject *);
PyAPI_FUNC(int) _PyObject_HasAttrId(PyObject *, struct _Py_Identifier *);
#ifndef Py_LIMITED_API #ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject **) _PyObject_GetDictPtr(PyObject *); PyAPI_FUNC(PyObject **) _PyObject_GetDictPtr(PyObject *);
#endif #endif

View File

@ -2024,6 +2024,40 @@ PyAPI_FUNC(int) _PyUnicode_CheckConsistency(
int check_content); int check_content);
#endif #endif
/********************* String Literals ****************************************/
/* This structure helps managing static strings. The basic usage goes like this:
Instead of doing
r = PyObject_CallMethod(o, "foo", "args", ...);
do
_Py_identifier(foo);
...
r = _PyObject_CallMethodId(o, &PyId_foo, "args", ...);
PyId_foo is a static variable, either on block level or file level. On first
usage, the string "foo" is interned, and the structures are linked. On interpreter
shutdown, all strings are released (through _PyUnicode_ClearStaticStrings).
Alternatively, _Py_static_string allows to choose the variable name.
_PyUnicode_FromId returns a new reference to the interned string.
_PyObject_{Get,Set,Has}AttrId are __getattr__ versions using _Py_Identifier*.
*/
typedef struct _Py_Identifier {
struct _Py_Identifier *next;
const char* string;
PyObject *object;
} _Py_Identifier;
#define _Py_static_string(varname, value) static _Py_Identifier varname = { 0, value, 0 };
#define _Py_identifier(varname) _Py_static_string(PyId_##varname, #varname)
/* Return an interned Unicode object for an Identifier; may fail if there is no memory.*/
PyAPI_FUNC(PyObject*) _PyUnicode_FromId(_Py_Identifier*);
/* Clear all static strings. */
PyAPI_FUNC(void) _PyUnicode_ClearStaticStrings(void);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -10,6 +10,8 @@ What's New in Python 3.3 Alpha 1?
Core and Builtins Core and Builtins
----------------- -----------------
- Add internal API for static strings (_Py_identifier et.al.).
- Issue #13063: the Windows error ERROR_NO_DATA (numbered 232 and described - Issue #13063: the Windows error ERROR_NO_DATA (numbered 232 and described
as "The pipe is being closed") is now mapped to POSIX errno EPIPE as "The pipe is being closed") is now mapped to POSIX errno EPIPE
(previously EINVAL). (previously EINVAL).

View File

@ -86,7 +86,9 @@ insort_right(PyObject *self, PyObject *args, PyObject *kw)
if (PyList_Insert(list, index, item) < 0) if (PyList_Insert(list, index, item) < 0)
return NULL; return NULL;
} else { } else {
result = PyObject_CallMethod(list, "insert", "nO", index, item); _Py_identifier(insert);
result = _PyObject_CallMethodId(list, &PyId_insert, "nO", index, item);
if (result == NULL) if (result == NULL)
return NULL; return NULL;
Py_DECREF(result); Py_DECREF(result);
@ -186,7 +188,9 @@ insort_left(PyObject *self, PyObject *args, PyObject *kw)
if (PyList_Insert(list, index, item) < 0) if (PyList_Insert(list, index, item) < 0)
return NULL; return NULL;
} else { } else {
result = PyObject_CallMethod(list, "insert", "iO", index, item); _Py_identifier(insert);
result = _PyObject_CallMethodId(list, &PyId_insert, "iO", index, item);
if (result == NULL) if (result == NULL)
return NULL; return NULL;
Py_DECREF(result); Py_DECREF(result);

View File

@ -1334,13 +1334,15 @@ defdict_reduce(defdictobject *dd)
PyObject *items; PyObject *items;
PyObject *iter; PyObject *iter;
PyObject *result; PyObject *result;
_Py_identifier(items);
if (dd->default_factory == NULL || dd->default_factory == Py_None) if (dd->default_factory == NULL || dd->default_factory == Py_None)
args = PyTuple_New(0); args = PyTuple_New(0);
else else
args = PyTuple_Pack(1, dd->default_factory); args = PyTuple_Pack(1, dd->default_factory);
if (args == NULL) if (args == NULL)
return NULL; return NULL;
items = PyObject_CallMethod((PyObject *)dd, "items", "()"); items = _PyObject_CallMethodId((PyObject *)dd, &PyId_items, "()");
if (items == NULL) { if (items == NULL) {
Py_DECREF(args); Py_DECREF(args);
return NULL; return NULL;

View File

@ -3679,8 +3679,10 @@ _build_result(PyObject *result, PyObject *callargs,
PyTuple_SET_ITEM(tup, index, v); PyTuple_SET_ITEM(tup, index, v);
index++; index++;
} else if (bit & outmask) { } else if (bit & outmask) {
_Py_identifier(__ctypes_from_outparam__);
v = PyTuple_GET_ITEM(callargs, i); v = PyTuple_GET_ITEM(callargs, i);
v = PyObject_CallMethod(v, "__ctypes_from_outparam__", NULL); v = _PyObject_CallMethodId(v, &PyId___ctypes_from_outparam__, NULL);
if (v == NULL || numretvals == 1) { if (v == NULL || numretvals == 1) {
Py_DECREF(callargs); Py_DECREF(callargs);
return v; return v;

View File

@ -1687,13 +1687,15 @@ unpickle(PyObject *self, PyObject *args)
PyObject *state; PyObject *state;
PyObject *result; PyObject *result;
PyObject *tmp; PyObject *tmp;
_Py_identifier(__new__);
_Py_identifier(__setstate__);
if (!PyArg_ParseTuple(args, "OO", &typ, &state)) if (!PyArg_ParseTuple(args, "OO", &typ, &state))
return NULL; return NULL;
result = PyObject_CallMethod(typ, "__new__", "O", typ); result = _PyObject_CallMethodId(typ, &PyId___new__, "O", typ);
if (result == NULL) if (result == NULL)
return NULL; return NULL;
tmp = PyObject_CallMethod(result, "__setstate__", "O", state); tmp = _PyObject_CallMethodId(result, &PyId___setstate__, "O", state);
if (tmp == NULL) { if (tmp == NULL) {
Py_DECREF(result); Py_DECREF(result);
return NULL; return NULL;

View File

@ -1418,10 +1418,12 @@ PyCursesWindow_PutWin(PyCursesWindowObject *self, PyObject *stream)
while (1) { while (1) {
char buf[BUFSIZ]; char buf[BUFSIZ];
Py_ssize_t n = fread(buf, 1, BUFSIZ, fp); Py_ssize_t n = fread(buf, 1, BUFSIZ, fp);
_Py_identifier(write);
if (n <= 0) if (n <= 0)
break; break;
Py_DECREF(res); Py_DECREF(res);
res = PyObject_CallMethod(stream, "write", "y#", buf, n); res = _PyObject_CallMethodId(stream, &PyId_write, "y#", buf, n);
if (res == NULL) if (res == NULL)
break; break;
} }
@ -1911,6 +1913,7 @@ PyCurses_GetWin(PyCursesWindowObject *self, PyObject *stream)
WINDOW *win; WINDOW *win;
PyCursesInitialised; PyCursesInitialised;
_Py_identifier(read);
strcpy(fn, "/tmp/py.curses.getwin.XXXXXX"); strcpy(fn, "/tmp/py.curses.getwin.XXXXXX");
fd = mkstemp(fn); fd = mkstemp(fn);
@ -1922,7 +1925,7 @@ PyCurses_GetWin(PyCursesWindowObject *self, PyObject *stream)
remove(fn); remove(fn);
return PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn); return PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn);
} }
data = PyObject_CallMethod(stream, "read", ""); data = _PyObject_CallMethodId(stream, &PyId_read, "");
if (data == NULL) { if (data == NULL) {
fclose(fp); fclose(fp);
remove(fn); remove(fn);

View File

@ -946,6 +946,7 @@ static PyObject *
call_tzname(PyObject *tzinfo, PyObject *tzinfoarg) call_tzname(PyObject *tzinfo, PyObject *tzinfoarg)
{ {
PyObject *result; PyObject *result;
_Py_identifier(tzname);
assert(tzinfo != NULL); assert(tzinfo != NULL);
assert(check_tzinfo_subclass(tzinfo) >= 0); assert(check_tzinfo_subclass(tzinfo) >= 0);
@ -954,7 +955,7 @@ call_tzname(PyObject *tzinfo, PyObject *tzinfoarg)
if (tzinfo == Py_None) if (tzinfo == Py_None)
Py_RETURN_NONE; Py_RETURN_NONE;
result = PyObject_CallMethod(tzinfo, "tzname", "O", tzinfoarg); result = _PyObject_CallMethodId(tzinfo, &PyId_tzname, "O", tzinfoarg);
if (result == NULL || result == Py_None) if (result == NULL || result == Py_None)
return result; return result;
@ -1078,6 +1079,8 @@ make_Zreplacement(PyObject *object, PyObject *tzinfoarg)
PyObject *temp; PyObject *temp;
PyObject *tzinfo = get_tzinfo_member(object); PyObject *tzinfo = get_tzinfo_member(object);
PyObject *Zreplacement = PyUnicode_FromStringAndSize(NULL, 0); PyObject *Zreplacement = PyUnicode_FromStringAndSize(NULL, 0);
_Py_identifier(replace);
if (Zreplacement == NULL) if (Zreplacement == NULL)
return NULL; return NULL;
if (tzinfo == Py_None || tzinfo == NULL) if (tzinfo == Py_None || tzinfo == NULL)
@ -1098,7 +1101,7 @@ make_Zreplacement(PyObject *object, PyObject *tzinfoarg)
* strftime doesn't treat them as format codes. * strftime doesn't treat them as format codes.
*/ */
Py_DECREF(Zreplacement); Py_DECREF(Zreplacement);
Zreplacement = PyObject_CallMethod(temp, "replace", "ss", "%", "%%"); Zreplacement = _PyObject_CallMethodId(temp, &PyId_replace, "ss", "%", "%%");
Py_DECREF(temp); Py_DECREF(temp);
if (Zreplacement == NULL) if (Zreplacement == NULL)
return NULL; return NULL;
@ -1281,12 +1284,15 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
{ {
PyObject *format; PyObject *format;
PyObject *time = PyImport_ImportModuleNoBlock("time"); PyObject *time = PyImport_ImportModuleNoBlock("time");
if (time == NULL) if (time == NULL)
goto Done; goto Done;
format = PyUnicode_FromString(PyBytes_AS_STRING(newfmt)); format = PyUnicode_FromString(PyBytes_AS_STRING(newfmt));
if (format != NULL) { if (format != NULL) {
result = PyObject_CallMethod(time, "strftime", "OO", _Py_identifier(strftime);
format, timetuple, NULL);
result = _PyObject_CallMethodId(time, &PyId_strftime, "OO",
format, timetuple, NULL);
Py_DECREF(format); Py_DECREF(format);
} }
Py_DECREF(time); Py_DECREF(time);
@ -1312,7 +1318,9 @@ time_time(void)
PyObject *time = PyImport_ImportModuleNoBlock("time"); PyObject *time = PyImport_ImportModuleNoBlock("time");
if (time != NULL) { if (time != NULL) {
result = PyObject_CallMethod(time, "time", "()"); _Py_identifier(time);
result = _PyObject_CallMethodId(time, &PyId_time, "()");
Py_DECREF(time); Py_DECREF(time);
} }
return result; return result;
@ -1329,13 +1337,15 @@ build_struct_time(int y, int m, int d, int hh, int mm, int ss, int dstflag)
time = PyImport_ImportModuleNoBlock("time"); time = PyImport_ImportModuleNoBlock("time");
if (time != NULL) { if (time != NULL) {
result = PyObject_CallMethod(time, "struct_time", _Py_identifier(struct_time);
"((iiiiiiiii))",
y, m, d, result = _PyObject_CallMethodId(time, &PyId_struct_time,
hh, mm, ss, "((iiiiiiiii))",
weekday(y, m, d), y, m, d,
days_before_month(y, m) + d, hh, mm, ss,
dstflag); weekday(y, m, d),
days_before_month(y, m) + d,
dstflag);
Py_DECREF(time); Py_DECREF(time);
} }
return result; return result;
@ -1568,11 +1578,12 @@ multiply_float_timedelta(PyObject *floatobj, PyDateTime_Delta *delta)
PyObject *result = NULL; PyObject *result = NULL;
PyObject *pyus_in = NULL, *temp, *pyus_out; PyObject *pyus_in = NULL, *temp, *pyus_out;
PyObject *ratio = NULL; PyObject *ratio = NULL;
_Py_identifier(as_integer_ratio);
pyus_in = delta_to_microseconds(delta); pyus_in = delta_to_microseconds(delta);
if (pyus_in == NULL) if (pyus_in == NULL)
return NULL; return NULL;
ratio = PyObject_CallMethod(floatobj, "as_integer_ratio", NULL); ratio = _PyObject_CallMethodId(floatobj, &PyId_as_integer_ratio, NULL);
if (ratio == NULL) if (ratio == NULL)
goto error; goto error;
temp = PyNumber_Multiply(pyus_in, PyTuple_GET_ITEM(ratio, 0)); temp = PyNumber_Multiply(pyus_in, PyTuple_GET_ITEM(ratio, 0));
@ -1666,11 +1677,12 @@ truedivide_timedelta_float(PyDateTime_Delta *delta, PyObject *f)
PyObject *result = NULL; PyObject *result = NULL;
PyObject *pyus_in = NULL, *temp, *pyus_out; PyObject *pyus_in = NULL, *temp, *pyus_out;
PyObject *ratio = NULL; PyObject *ratio = NULL;
_Py_identifier(as_integer_ratio);
pyus_in = delta_to_microseconds(delta); pyus_in = delta_to_microseconds(delta);
if (pyus_in == NULL) if (pyus_in == NULL)
return NULL; return NULL;
ratio = PyObject_CallMethod(f, "as_integer_ratio", NULL); ratio = _PyObject_CallMethodId(f, &PyId_as_integer_ratio, NULL);
if (ratio == NULL) if (ratio == NULL)
goto error; goto error;
temp = PyNumber_Multiply(pyus_in, PyTuple_GET_ITEM(ratio, 1)); temp = PyNumber_Multiply(pyus_in, PyTuple_GET_ITEM(ratio, 1));
@ -2461,6 +2473,7 @@ date_today(PyObject *cls, PyObject *dummy)
{ {
PyObject *time; PyObject *time;
PyObject *result; PyObject *result;
_Py_identifier(fromtimestamp);
time = time_time(); time = time_time();
if (time == NULL) if (time == NULL)
@ -2472,7 +2485,7 @@ date_today(PyObject *cls, PyObject *dummy)
* time.time() delivers; if someone were gonzo about optimization, * time.time() delivers; if someone were gonzo about optimization,
* date.today() could get away with plain C time(). * date.today() could get away with plain C time().
*/ */
result = PyObject_CallMethod(cls, "fromtimestamp", "O", time); result = _PyObject_CallMethodId(cls, &PyId_fromtimestamp, "O", time);
Py_DECREF(time); Py_DECREF(time);
return result; return result;
} }
@ -2613,7 +2626,9 @@ date_isoformat(PyDateTime_Date *self)
static PyObject * static PyObject *
date_str(PyDateTime_Date *self) date_str(PyDateTime_Date *self)
{ {
return PyObject_CallMethod((PyObject *)self, "isoformat", "()"); _Py_identifier(isoformat);
return _PyObject_CallMethodId((PyObject *)self, &PyId_isoformat, "()");
} }
@ -2632,13 +2647,14 @@ date_strftime(PyDateTime_Date *self, PyObject *args, PyObject *kw)
PyObject *result; PyObject *result;
PyObject *tuple; PyObject *tuple;
PyObject *format; PyObject *format;
_Py_identifier(timetuple);
static char *keywords[] = {"format", NULL}; static char *keywords[] = {"format", NULL};
if (! PyArg_ParseTupleAndKeywords(args, kw, "U:strftime", keywords, if (! PyArg_ParseTupleAndKeywords(args, kw, "U:strftime", keywords,
&format)) &format))
return NULL; return NULL;
tuple = PyObject_CallMethod((PyObject *)self, "timetuple", "()"); tuple = _PyObject_CallMethodId((PyObject *)self, &PyId_timetuple, "()");
if (tuple == NULL) if (tuple == NULL)
return NULL; return NULL;
result = wrap_strftime((PyObject *)self, format, tuple, result = wrap_strftime((PyObject *)self, format, tuple,
@ -2651,6 +2667,7 @@ static PyObject *
date_format(PyDateTime_Date *self, PyObject *args) date_format(PyDateTime_Date *self, PyObject *args)
{ {
PyObject *format; PyObject *format;
_Py_identifier(strftime);
if (!PyArg_ParseTuple(args, "U:__format__", &format)) if (!PyArg_ParseTuple(args, "U:__format__", &format))
return NULL; return NULL;
@ -2659,7 +2676,7 @@ date_format(PyDateTime_Date *self, PyObject *args)
if (PyUnicode_GetSize(format) == 0) if (PyUnicode_GetSize(format) == 0)
return PyObject_Str((PyObject *)self); return PyObject_Str((PyObject *)self);
return PyObject_CallMethod((PyObject *)self, "strftime", "O", format); return _PyObject_CallMethodId((PyObject *)self, &PyId_strftime, "O", format);
} }
/* ISO methods. */ /* ISO methods. */
@ -3573,7 +3590,9 @@ time_repr(PyDateTime_Time *self)
static PyObject * static PyObject *
time_str(PyDateTime_Time *self) time_str(PyDateTime_Time *self)
{ {
return PyObject_CallMethod((PyObject *)self, "isoformat", "()"); _Py_identifier(isoformat);
return _PyObject_CallMethodId((PyObject *)self, &PyId_isoformat, "()");
} }
static PyObject * static PyObject *
@ -4152,7 +4171,9 @@ datetime_now(PyObject *cls, PyObject *args, PyObject *kw)
if (self != NULL && tzinfo != Py_None) { if (self != NULL && tzinfo != Py_None) {
/* Convert UTC to tzinfo's zone. */ /* Convert UTC to tzinfo's zone. */
PyObject *temp = self; PyObject *temp = self;
self = PyObject_CallMethod(tzinfo, "fromutc", "O", self); _Py_identifier(fromutc);
self = _PyObject_CallMethodId(tzinfo, &PyId_fromutc, "O", self);
Py_DECREF(temp); Py_DECREF(temp);
} }
return self; return self;
@ -4189,7 +4210,9 @@ datetime_fromtimestamp(PyObject *cls, PyObject *args, PyObject *kw)
if (self != NULL && tzinfo != Py_None) { if (self != NULL && tzinfo != Py_None) {
/* Convert UTC to tzinfo's zone. */ /* Convert UTC to tzinfo's zone. */
PyObject *temp = self; PyObject *temp = self;
self = PyObject_CallMethod(tzinfo, "fromutc", "O", self); _Py_identifier(fromutc);
self = _PyObject_CallMethodId(tzinfo, &PyId_fromutc, "O", self);
Py_DECREF(temp); Py_DECREF(temp);
} }
return self; return self;
@ -4214,6 +4237,7 @@ datetime_strptime(PyObject *cls, PyObject *args)
{ {
static PyObject *module = NULL; static PyObject *module = NULL;
PyObject *string, *format; PyObject *string, *format;
_Py_identifier(_strptime_datetime);
if (!PyArg_ParseTuple(args, "UU:strptime", &string, &format)) if (!PyArg_ParseTuple(args, "UU:strptime", &string, &format))
return NULL; return NULL;
@ -4223,8 +4247,8 @@ datetime_strptime(PyObject *cls, PyObject *args)
if (module == NULL) if (module == NULL)
return NULL; return NULL;
} }
return PyObject_CallMethod(module, "_strptime_datetime", "OOO", return _PyObject_CallMethodId(module, &PyId__strptime_datetime, "OOO",
cls, string, format); cls, string, format);
} }
/* Return new datetime from date/datetime and time arguments. */ /* Return new datetime from date/datetime and time arguments. */
@ -4469,7 +4493,9 @@ datetime_repr(PyDateTime_DateTime *self)
static PyObject * static PyObject *
datetime_str(PyDateTime_DateTime *self) datetime_str(PyDateTime_DateTime *self)
{ {
return PyObject_CallMethod((PyObject *)self, "isoformat", "(s)", " "); _Py_identifier(isoformat);
return _PyObject_CallMethodId((PyObject *)self, &PyId_isoformat, "(s)", " ");
} }
static PyObject * static PyObject *
@ -4676,6 +4702,7 @@ datetime_astimezone(PyDateTime_DateTime *self, PyObject *args, PyObject *kw)
PyObject *offset; PyObject *offset;
PyObject *temp; PyObject *temp;
PyObject *tzinfo; PyObject *tzinfo;
_Py_identifier(fromutc);
static char *keywords[] = {"tz", NULL}; static char *keywords[] = {"tz", NULL};
if (! PyArg_ParseTupleAndKeywords(args, kw, "O!:astimezone", keywords, if (! PyArg_ParseTupleAndKeywords(args, kw, "O!:astimezone", keywords,
@ -4717,7 +4744,7 @@ datetime_astimezone(PyDateTime_DateTime *self, PyObject *args, PyObject *kw)
Py_DECREF(temp); Py_DECREF(temp);
temp = result; temp = result;
result = PyObject_CallMethod(tzinfo, "fromutc", "O", temp); result = _PyObject_CallMethodId(tzinfo, &PyId_fromutc, "O", temp);
Py_DECREF(temp); Py_DECREF(temp);
return result; return result;

View File

@ -790,16 +790,18 @@ static PyObject*
element_find(ElementObject* self, PyObject* args) element_find(ElementObject* self, PyObject* args)
{ {
int i; int i;
PyObject* tag; PyObject* tag;
PyObject* namespaces = Py_None; PyObject* namespaces = Py_None;
if (!PyArg_ParseTuple(args, "O|O:find", &tag, &namespaces)) if (!PyArg_ParseTuple(args, "O|O:find", &tag, &namespaces))
return NULL; return NULL;
if (checkpath(tag) || namespaces != Py_None) if (checkpath(tag) || namespaces != Py_None) {
return PyObject_CallMethod( _Py_identifier(find);
elementpath_obj, "find", "OOO", self, tag, namespaces return _PyObject_CallMethodId(
elementpath_obj, &PyId_find, "OOO", self, tag, namespaces
); );
}
if (!self->extra) if (!self->extra)
Py_RETURN_NONE; Py_RETURN_NONE;
@ -820,16 +822,17 @@ static PyObject*
element_findtext(ElementObject* self, PyObject* args) element_findtext(ElementObject* self, PyObject* args)
{ {
int i; int i;
PyObject* tag; PyObject* tag;
PyObject* default_value = Py_None; PyObject* default_value = Py_None;
PyObject* namespaces = Py_None; PyObject* namespaces = Py_None;
_Py_identifier(findtext);
if (!PyArg_ParseTuple(args, "O|OO:findtext", &tag, &default_value, &namespaces)) if (!PyArg_ParseTuple(args, "O|OO:findtext", &tag, &default_value, &namespaces))
return NULL; return NULL;
if (checkpath(tag) || namespaces != Py_None) if (checkpath(tag) || namespaces != Py_None)
return PyObject_CallMethod( return _PyObject_CallMethodId(
elementpath_obj, "findtext", "OOOO", self, tag, default_value, namespaces elementpath_obj, &PyId_findtext, "OOOO", self, tag, default_value, namespaces
); );
if (!self->extra) { if (!self->extra) {
@ -858,16 +861,18 @@ element_findall(ElementObject* self, PyObject* args)
{ {
int i; int i;
PyObject* out; PyObject* out;
PyObject* tag; PyObject* tag;
PyObject* namespaces = Py_None; PyObject* namespaces = Py_None;
if (!PyArg_ParseTuple(args, "O|O:findall", &tag, &namespaces)) if (!PyArg_ParseTuple(args, "O|O:findall", &tag, &namespaces))
return NULL; return NULL;
if (checkpath(tag) || namespaces != Py_None) if (checkpath(tag) || namespaces != Py_None) {
return PyObject_CallMethod( _Py_identifier(findall);
elementpath_obj, "findall", "OOO", self, tag, namespaces return _PyObject_CallMethodId(
elementpath_obj, &PyId_findall, "OOO", self, tag, namespaces
); );
}
out = PyList_New(0); out = PyList_New(0);
if (!out) if (!out)
@ -895,11 +900,13 @@ element_iterfind(ElementObject* self, PyObject* args)
{ {
PyObject* tag; PyObject* tag;
PyObject* namespaces = Py_None; PyObject* namespaces = Py_None;
_Py_identifier(iterfind);
if (!PyArg_ParseTuple(args, "O|O:iterfind", &tag, &namespaces)) if (!PyArg_ParseTuple(args, "O|O:iterfind", &tag, &namespaces))
return NULL; return NULL;
return PyObject_CallMethod( return _PyObject_CallMethodId(
elementpath_obj, "iterfind", "OOO", self, tag, namespaces elementpath_obj, &PyId_iterfind, "OOO", self, tag, namespaces
); );
} }

View File

@ -308,6 +308,9 @@ io_open(PyObject *self, PyObject *args, PyObject *kwds)
PyObject *raw, *modeobj = NULL, *buffer = NULL, *wrapper = NULL; PyObject *raw, *modeobj = NULL, *buffer = NULL, *wrapper = NULL;
_Py_identifier(isatty);
_Py_identifier(fileno);
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|sizzzi:open", kwlist, if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|sizzzi:open", kwlist,
&file, &mode, &buffering, &file, &mode, &buffering,
&encoding, &errors, &newline, &encoding, &errors, &newline,
@ -421,7 +424,7 @@ io_open(PyObject *self, PyObject *args, PyObject *kwds)
/* buffering */ /* buffering */
{ {
PyObject *res = PyObject_CallMethod(raw, "isatty", NULL); PyObject *res = _PyObject_CallMethodId(raw, &PyId_isatty, NULL);
if (res == NULL) if (res == NULL)
goto error; goto error;
isatty = PyLong_AsLong(res); isatty = PyLong_AsLong(res);
@ -443,7 +446,7 @@ io_open(PyObject *self, PyObject *args, PyObject *kwds)
{ {
struct stat st; struct stat st;
long fileno; long fileno;
PyObject *res = PyObject_CallMethod(raw, "fileno", NULL); PyObject *res = _PyObject_CallMethodId(raw, &PyId_fileno, NULL);
if (res == NULL) if (res == NULL)
goto error; goto error;

View File

@ -13,6 +13,18 @@
#include "pythread.h" #include "pythread.h"
#include "_iomodule.h" #include "_iomodule.h"
_Py_identifier(close);
_Py_identifier(_dealloc_warn);
_Py_identifier(flush);
_Py_identifier(isatty);
_Py_identifier(peek);
_Py_identifier(read);
_Py_identifier(read1);
_Py_identifier(readable);
_Py_identifier(readinto);
_Py_identifier(writable);
_Py_identifier(write);
/* /*
* BufferedIOBase class, inherits from IOBase. * BufferedIOBase class, inherits from IOBase.
*/ */
@ -38,12 +50,13 @@ bufferediobase_readinto(PyObject *self, PyObject *args)
Py_buffer buf; Py_buffer buf;
Py_ssize_t len; Py_ssize_t len;
PyObject *data; PyObject *data;
_Py_identifier(read);
if (!PyArg_ParseTuple(args, "w*:readinto", &buf)) { if (!PyArg_ParseTuple(args, "w*:readinto", &buf)) {
return NULL; return NULL;
} }
data = PyObject_CallMethod(self, "read", "n", buf.len); data = _PyObject_CallMethodId(self, &PyId_read, "n", buf.len);
if (data == NULL) if (data == NULL)
goto error; goto error;
@ -410,7 +423,7 @@ buffered_dealloc_warn(buffered *self, PyObject *source)
{ {
if (self->ok && self->raw) { if (self->ok && self->raw) {
PyObject *r; PyObject *r;
r = PyObject_CallMethod(self->raw, "_dealloc_warn", "O", source); r = _PyObject_CallMethodId(self->raw, &PyId__dealloc_warn, "O", source);
if (r) if (r)
Py_DECREF(r); Py_DECREF(r);
else else
@ -2216,13 +2229,13 @@ bufferedrwpair_dealloc(rwpair *self)
} }
static PyObject * static PyObject *
_forward_call(buffered *self, const char *name, PyObject *args) _forward_call(buffered *self, _Py_Identifier *name, PyObject *args)
{ {
PyObject *func = PyObject_GetAttrString((PyObject *)self, name); PyObject *func = _PyObject_GetAttrId((PyObject *)self, name);
PyObject *ret; PyObject *ret;
if (func == NULL) { if (func == NULL) {
PyErr_SetString(PyExc_AttributeError, name); PyErr_SetString(PyExc_AttributeError, name->string);
return NULL; return NULL;
} }
@ -2234,66 +2247,66 @@ _forward_call(buffered *self, const char *name, PyObject *args)
static PyObject * static PyObject *
bufferedrwpair_read(rwpair *self, PyObject *args) bufferedrwpair_read(rwpair *self, PyObject *args)
{ {
return _forward_call(self->reader, "read", args); return _forward_call(self->reader, &PyId_read, args);
} }
static PyObject * static PyObject *
bufferedrwpair_peek(rwpair *self, PyObject *args) bufferedrwpair_peek(rwpair *self, PyObject *args)
{ {
return _forward_call(self->reader, "peek", args); return _forward_call(self->reader, &PyId_peek, args);
} }
static PyObject * static PyObject *
bufferedrwpair_read1(rwpair *self, PyObject *args) bufferedrwpair_read1(rwpair *self, PyObject *args)
{ {
return _forward_call(self->reader, "read1", args); return _forward_call(self->reader, &PyId_read1, args);
} }
static PyObject * static PyObject *
bufferedrwpair_readinto(rwpair *self, PyObject *args) bufferedrwpair_readinto(rwpair *self, PyObject *args)
{ {
return _forward_call(self->reader, "readinto", args); return _forward_call(self->reader, &PyId_readinto, args);
} }
static PyObject * static PyObject *
bufferedrwpair_write(rwpair *self, PyObject *args) bufferedrwpair_write(rwpair *self, PyObject *args)
{ {
return _forward_call(self->writer, "write", args); return _forward_call(self->writer, &PyId_write, args);
} }
static PyObject * static PyObject *
bufferedrwpair_flush(rwpair *self, PyObject *args) bufferedrwpair_flush(rwpair *self, PyObject *args)
{ {
return _forward_call(self->writer, "flush", args); return _forward_call(self->writer, &PyId_flush, args);
} }
static PyObject * static PyObject *
bufferedrwpair_readable(rwpair *self, PyObject *args) bufferedrwpair_readable(rwpair *self, PyObject *args)
{ {
return _forward_call(self->reader, "readable", args); return _forward_call(self->reader, &PyId_readable, args);
} }
static PyObject * static PyObject *
bufferedrwpair_writable(rwpair *self, PyObject *args) bufferedrwpair_writable(rwpair *self, PyObject *args)
{ {
return _forward_call(self->writer, "writable", args); return _forward_call(self->writer, &PyId_writable, args);
} }
static PyObject * static PyObject *
bufferedrwpair_close(rwpair *self, PyObject *args) bufferedrwpair_close(rwpair *self, PyObject *args)
{ {
PyObject *ret = _forward_call(self->writer, "close", args); PyObject *ret = _forward_call(self->writer, &PyId_close, args);
if (ret == NULL) if (ret == NULL)
return NULL; return NULL;
Py_DECREF(ret); Py_DECREF(ret);
return _forward_call(self->reader, "close", args); return _forward_call(self->reader, &PyId_close, args);
} }
static PyObject * static PyObject *
bufferedrwpair_isatty(rwpair *self, PyObject *args) bufferedrwpair_isatty(rwpair *self, PyObject *args)
{ {
PyObject *ret = _forward_call(self->writer, "isatty", args); PyObject *ret = _forward_call(self->writer, &PyId_isatty, args);
if (ret != Py_False) { if (ret != Py_False) {
/* either True or exception */ /* either True or exception */
@ -2301,7 +2314,7 @@ bufferedrwpair_isatty(rwpair *self, PyObject *args)
} }
Py_DECREF(ret); Py_DECREF(ret);
return _forward_call(self->reader, "isatty", args); return _forward_call(self->reader, &PyId_isatty, args);
} }
static PyObject * static PyObject *

View File

@ -128,6 +128,7 @@ internal_close(fileio *self)
static PyObject * static PyObject *
fileio_close(fileio *self) fileio_close(fileio *self)
{ {
_Py_identifier(close);
if (!self->closefd) { if (!self->closefd) {
self->fd = -1; self->fd = -1;
Py_RETURN_NONE; Py_RETURN_NONE;
@ -143,8 +144,8 @@ fileio_close(fileio *self)
if (errno < 0) if (errno < 0)
return NULL; return NULL;
return PyObject_CallMethod((PyObject*)&PyRawIOBase_Type, return _PyObject_CallMethodId((PyObject*)&PyRawIOBase_Type,
"close", "O", self); &PyId_close, "O", self);
} }
static PyObject * static PyObject *

View File

@ -97,7 +97,9 @@ PyDoc_STRVAR(iobase_tell_doc,
static PyObject * static PyObject *
iobase_tell(PyObject *self, PyObject *args) iobase_tell(PyObject *self, PyObject *args)
{ {
return PyObject_CallMethod(self, "seek", "ii", 0, 1); _Py_identifier(seek);
return _PyObject_CallMethodId(self, &PyId_seek, "ii", 0, 1);
} }
PyDoc_STRVAR(iobase_truncate_doc, PyDoc_STRVAR(iobase_truncate_doc,
@ -464,6 +466,7 @@ iobase_readline(PyObject *self, PyObject *args)
int has_peek = 0; int has_peek = 0;
PyObject *buffer, *result; PyObject *buffer, *result;
Py_ssize_t old_size = -1; Py_ssize_t old_size = -1;
_Py_identifier(read);
if (!PyArg_ParseTuple(args, "|O&:readline", &_PyIO_ConvertSsize_t, &limit)) { if (!PyArg_ParseTuple(args, "|O&:readline", &_PyIO_ConvertSsize_t, &limit)) {
return NULL; return NULL;
@ -481,7 +484,9 @@ iobase_readline(PyObject *self, PyObject *args)
PyObject *b; PyObject *b;
if (has_peek) { if (has_peek) {
PyObject *readahead = PyObject_CallMethod(self, "peek", "i", 1); _Py_identifier(peek);
PyObject *readahead = _PyObject_CallMethodId(self, &PyId_peek, "i", 1);
if (readahead == NULL) if (readahead == NULL)
goto fail; goto fail;
if (!PyBytes_Check(readahead)) { if (!PyBytes_Check(readahead)) {
@ -515,7 +520,7 @@ iobase_readline(PyObject *self, PyObject *args)
Py_DECREF(readahead); Py_DECREF(readahead);
} }
b = PyObject_CallMethod(self, "read", "n", nreadahead); b = _PyObject_CallMethodId(self, &PyId_read, "n", nreadahead);
if (b == NULL) if (b == NULL)
goto fail; goto fail;
if (!PyBytes_Check(b)) { if (!PyBytes_Check(b)) {
@ -601,7 +606,9 @@ iobase_readlines(PyObject *self, PyObject *args)
/* XXX special-casing this made sense in the Python version in order /* XXX special-casing this made sense in the Python version in order
to remove the bytecode interpretation overhead, but it could to remove the bytecode interpretation overhead, but it could
probably be removed here. */ probably be removed here. */
PyObject *ret = PyObject_CallMethod(result, "extend", "O", self); _Py_identifier(extend);
PyObject *ret = _PyObject_CallMethodId(result, &PyId_extend, "O", self);
if (ret == NULL) { if (ret == NULL) {
Py_DECREF(result); Py_DECREF(result);
return NULL; return NULL;
@ -781,8 +788,11 @@ rawiobase_read(PyObject *self, PyObject *args)
return NULL; return NULL;
} }
if (n < 0) if (n < 0) {
return PyObject_CallMethod(self, "readall", NULL); _Py_identifier(readall);
return _PyObject_CallMethodId(self, &PyId_readall, NULL);
}
/* TODO: allocate a bytes object directly instead and manually construct /* TODO: allocate a bytes object directly instead and manually construct
a writable memoryview pointing to it. */ a writable memoryview pointing to it. */
@ -823,8 +833,9 @@ rawiobase_readall(PyObject *self, PyObject *args)
return NULL; return NULL;
while (1) { while (1) {
PyObject *data = PyObject_CallMethod(self, "read", _Py_identifier(read);
"i", DEFAULT_BUFFER_SIZE); PyObject *data = _PyObject_CallMethodId(self, &PyId_read,
"i", DEFAULT_BUFFER_SIZE);
if (!data) { if (!data) {
Py_DECREF(chunks); Py_DECREF(chunks);
return NULL; return NULL;

View File

@ -11,6 +11,24 @@
#include "structmember.h" #include "structmember.h"
#include "_iomodule.h" #include "_iomodule.h"
_Py_identifier(close);
_Py_identifier(_dealloc_warn);
_Py_identifier(decode);
_Py_identifier(device_encoding);
_Py_identifier(fileno);
_Py_identifier(flush);
_Py_identifier(getpreferredencoding);
_Py_identifier(isatty);
_Py_identifier(read);
_Py_identifier(readable);
_Py_identifier(replace);
_Py_identifier(reset);
_Py_identifier(seek);
_Py_identifier(seekable);
_Py_identifier(setstate);
_Py_identifier(tell);
_Py_identifier(writable);
/* TextIOBase */ /* TextIOBase */
PyDoc_STRVAR(textiobase_doc, PyDoc_STRVAR(textiobase_doc,
@ -501,8 +519,8 @@ incrementalnewlinedecoder_setstate(nldecoder_object *self, PyObject *state)
flag >>= 1; flag >>= 1;
if (self->decoder != Py_None) if (self->decoder != Py_None)
return PyObject_CallMethod(self->decoder, return _PyObject_CallMethodId(self->decoder,
"setstate", "((OK))", buffer, flag); &PyId_setstate, "((OK))", buffer, flag);
else else
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -842,7 +860,7 @@ textiowrapper_init(textio *self, PyObject *args, PyObject *kwds)
if (encoding == NULL) { if (encoding == NULL) {
/* Try os.device_encoding(fileno) */ /* Try os.device_encoding(fileno) */
PyObject *fileno; PyObject *fileno;
fileno = PyObject_CallMethod(buffer, "fileno", NULL); fileno = _PyObject_CallMethodId(buffer, &PyId_fileno, NULL);
/* Ignore only AttributeError and UnsupportedOperation */ /* Ignore only AttributeError and UnsupportedOperation */
if (fileno == NULL) { if (fileno == NULL) {
if (PyErr_ExceptionMatches(PyExc_AttributeError) || if (PyErr_ExceptionMatches(PyExc_AttributeError) ||
@ -854,9 +872,9 @@ textiowrapper_init(textio *self, PyObject *args, PyObject *kwds)
} }
} }
else { else {
self->encoding = PyObject_CallMethod(state->os_module, self->encoding = _PyObject_CallMethodId(state->os_module,
"device_encoding", &PyId_device_encoding,
"N", fileno); "N", fileno);
if (self->encoding == NULL) if (self->encoding == NULL)
goto error; goto error;
else if (!PyUnicode_Check(self->encoding)) else if (!PyUnicode_Check(self->encoding))
@ -873,8 +891,8 @@ textiowrapper_init(textio *self, PyObject *args, PyObject *kwds)
} }
else { else {
use_locale: use_locale:
self->encoding = PyObject_CallMethod( self->encoding = _PyObject_CallMethodId(
state->locale_module, "getpreferredencoding", NULL); state->locale_module, &PyId_getpreferredencoding, NULL);
if (self->encoding == NULL) { if (self->encoding == NULL) {
catch_ImportError: catch_ImportError:
/* /*
@ -939,7 +957,7 @@ textiowrapper_init(textio *self, PyObject *args, PyObject *kwds)
#endif #endif
/* Build the decoder object */ /* Build the decoder object */
res = PyObject_CallMethod(buffer, "readable", NULL); res = _PyObject_CallMethodId(buffer, &PyId_readable, NULL);
if (res == NULL) if (res == NULL)
goto error; goto error;
r = PyObject_IsTrue(res); r = PyObject_IsTrue(res);
@ -964,7 +982,7 @@ textiowrapper_init(textio *self, PyObject *args, PyObject *kwds)
} }
/* Build the encoder object */ /* Build the encoder object */
res = PyObject_CallMethod(buffer, "writable", NULL); res = _PyObject_CallMethodId(buffer, &PyId_writable, NULL);
if (res == NULL) if (res == NULL)
goto error; goto error;
r = PyObject_IsTrue(res); r = PyObject_IsTrue(res);
@ -1022,7 +1040,7 @@ textiowrapper_init(textio *self, PyObject *args, PyObject *kwds)
Py_DECREF(raw); Py_DECREF(raw);
} }
res = PyObject_CallMethod(buffer, "seekable", NULL); res = _PyObject_CallMethodId(buffer, &PyId_seekable, NULL);
if (res == NULL) if (res == NULL)
goto error; goto error;
self->seekable = self->telling = PyObject_IsTrue(res); self->seekable = self->telling = PyObject_IsTrue(res);
@ -1255,8 +1273,8 @@ textiowrapper_write(textio *self, PyObject *args)
haslf = 1; haslf = 1;
if (haslf && self->writetranslate && self->writenl != NULL) { if (haslf && self->writetranslate && self->writenl != NULL) {
PyObject *newtext = PyObject_CallMethod( PyObject *newtext = _PyObject_CallMethodId(
text, "replace", "ss", "\n", self->writenl); text, &PyId_replace, "ss", "\n", self->writenl);
Py_DECREF(text); Py_DECREF(text);
if (newtext == NULL) if (newtext == NULL)
return NULL; return NULL;
@ -1311,7 +1329,7 @@ textiowrapper_write(textio *self, PyObject *args)
Py_CLEAR(self->snapshot); Py_CLEAR(self->snapshot);
if (self->decoder) { if (self->decoder) {
ret = PyObject_CallMethod(self->decoder, "reset", NULL); ret = _PyObject_CallMethodId(self->decoder, &PyId_reset, NULL);
if (ret == NULL) if (ret == NULL)
return NULL; return NULL;
Py_DECREF(ret); Py_DECREF(ret);
@ -1490,7 +1508,7 @@ textiowrapper_read(textio *self, PyObject *args)
if (n < 0) { if (n < 0) {
/* Read everything */ /* Read everything */
PyObject *bytes = PyObject_CallMethod(self->buffer, "read", NULL); PyObject *bytes = _PyObject_CallMethodId(self->buffer, &PyId_read, NULL);
PyObject *decoded; PyObject *decoded;
if (bytes == NULL) if (bytes == NULL)
goto fail; goto fail;
@ -1940,8 +1958,8 @@ _textiowrapper_decoder_setstate(textio *self, cookie_type *cookie)
if (cookie->start_pos == 0 && cookie->dec_flags == 0) if (cookie->start_pos == 0 && cookie->dec_flags == 0)
res = PyObject_CallMethodObjArgs(self->decoder, _PyIO_str_reset, NULL); res = PyObject_CallMethodObjArgs(self->decoder, _PyIO_str_reset, NULL);
else else
res = PyObject_CallMethod(self->decoder, "setstate", res = _PyObject_CallMethodId(self->decoder, &PyId_setstate,
"((yi))", "", cookie->dec_flags); "((yi))", "", cookie->dec_flags);
if (res == NULL) if (res == NULL)
return -1; return -1;
Py_DECREF(res); Py_DECREF(res);
@ -2005,13 +2023,12 @@ textiowrapper_seek(textio *self, PyObject *args)
* sync the underlying buffer with the current position. * sync the underlying buffer with the current position.
*/ */
Py_DECREF(cookieObj); Py_DECREF(cookieObj);
cookieObj = PyObject_CallMethod((PyObject *)self, "tell", NULL); cookieObj = _PyObject_CallMethodId((PyObject *)self, &PyId_tell, NULL);
if (cookieObj == NULL) if (cookieObj == NULL)
goto fail; goto fail;
} }
else if (whence == 2) { else if (whence == 2) {
/* seek relative to end of file */ /* seek relative to end of file */
cmp = PyObject_RichCompareBool(cookieObj, _PyIO_zero, Py_EQ); cmp = PyObject_RichCompareBool(cookieObj, _PyIO_zero, Py_EQ);
if (cmp < 0) if (cmp < 0)
goto fail; goto fail;
@ -2021,7 +2038,7 @@ textiowrapper_seek(textio *self, PyObject *args)
goto fail; goto fail;
} }
res = PyObject_CallMethod((PyObject *)self, "flush", NULL); res = _PyObject_CallMethodId((PyObject *)self, &PyId_flush, NULL);
if (res == NULL) if (res == NULL)
goto fail; goto fail;
Py_DECREF(res); Py_DECREF(res);
@ -2029,13 +2046,13 @@ textiowrapper_seek(textio *self, PyObject *args)
textiowrapper_set_decoded_chars(self, NULL); textiowrapper_set_decoded_chars(self, NULL);
Py_CLEAR(self->snapshot); Py_CLEAR(self->snapshot);
if (self->decoder) { if (self->decoder) {
res = PyObject_CallMethod(self->decoder, "reset", NULL); res = _PyObject_CallMethodId(self->decoder, &PyId_reset, NULL);
if (res == NULL) if (res == NULL)
goto fail; goto fail;
Py_DECREF(res); Py_DECREF(res);
} }
res = PyObject_CallMethod(self->buffer, "seek", "ii", 0, 2); res = _PyObject_CallMethodId(self->buffer, &PyId_seek, "ii", 0, 2);
Py_XDECREF(cookieObj); Py_XDECREF(cookieObj);
return res; return res;
} }
@ -2088,8 +2105,8 @@ textiowrapper_seek(textio *self, PyObject *args)
if (cookie.chars_to_skip) { if (cookie.chars_to_skip) {
/* Just like _read_chunk, feed the decoder and save a snapshot. */ /* Just like _read_chunk, feed the decoder and save a snapshot. */
PyObject *input_chunk = PyObject_CallMethod( PyObject *input_chunk = _PyObject_CallMethodId(
self->buffer, "read", "i", cookie.bytes_to_feed); self->buffer, &PyId_read, "i", cookie.bytes_to_feed);
PyObject *decoded; PyObject *decoded;
if (input_chunk == NULL) if (input_chunk == NULL)
@ -2103,8 +2120,8 @@ textiowrapper_seek(textio *self, PyObject *args)
goto fail; goto fail;
} }
decoded = PyObject_CallMethod(self->decoder, "decode", decoded = _PyObject_CallMethodId(self->decoder, &PyId_decode,
"Oi", input_chunk, (int)cookie.need_eof); "Oi", input_chunk, (int)cookie.need_eof);
if (decoded == NULL) if (decoded == NULL)
goto fail; goto fail;
@ -2170,12 +2187,12 @@ textiowrapper_tell(textio *self, PyObject *args)
if (_textiowrapper_writeflush(self) < 0) if (_textiowrapper_writeflush(self) < 0)
return NULL; return NULL;
res = PyObject_CallMethod((PyObject *)self, "flush", NULL); res = _PyObject_CallMethodId((PyObject *)self, &PyId_flush, NULL);
if (res == NULL) if (res == NULL)
goto fail; goto fail;
Py_DECREF(res); Py_DECREF(res);
posobj = PyObject_CallMethod(self->buffer, "tell", NULL); posobj = _PyObject_CallMethodId(self->buffer, &PyId_tell, NULL);
if (posobj == NULL) if (posobj == NULL)
goto fail; goto fail;
@ -2229,8 +2246,8 @@ textiowrapper_tell(textio *self, PyObject *args)
/* TODO: replace assert with exception */ /* TODO: replace assert with exception */
#define DECODER_DECODE(start, len, res) do { \ #define DECODER_DECODE(start, len, res) do { \
PyObject *_decoded = PyObject_CallMethod( \ PyObject *_decoded = _PyObject_CallMethodId( \
self->decoder, "decode", "y#", start, len); \ self->decoder, &PyId_decode, "y#", start, len); \
if (_decoded == NULL) \ if (_decoded == NULL) \
goto fail; \ goto fail; \
assert (PyUnicode_Check(_decoded)); \ assert (PyUnicode_Check(_decoded)); \
@ -2312,8 +2329,8 @@ textiowrapper_tell(textio *self, PyObject *args)
} }
if (input == input_end) { if (input == input_end) {
/* We didn't get enough decoded data; signal EOF to get more. */ /* We didn't get enough decoded data; signal EOF to get more. */
PyObject *decoded = PyObject_CallMethod( PyObject *decoded = _PyObject_CallMethodId(
self->decoder, "decode", "yi", "", /* final = */ 1); self->decoder, &PyId_decode, "yi", "", /* final = */ 1);
if (decoded == NULL) if (decoded == NULL)
goto fail; goto fail;
assert (PyUnicode_Check(decoded)); assert (PyUnicode_Check(decoded));
@ -2329,7 +2346,7 @@ textiowrapper_tell(textio *self, PyObject *args)
} }
finally: finally:
res = PyObject_CallMethod(self->decoder, "setstate", "(O)", saved_state); res = _PyObject_CallMethodId(self->decoder, &PyId_setstate, "(O)", saved_state);
Py_DECREF(saved_state); Py_DECREF(saved_state);
if (res == NULL) if (res == NULL)
return NULL; return NULL;
@ -2344,7 +2361,7 @@ fail:
PyObject *type, *value, *traceback; PyObject *type, *value, *traceback;
PyErr_Fetch(&type, &value, &traceback); PyErr_Fetch(&type, &value, &traceback);
res = PyObject_CallMethod(self->decoder, "setstate", "(O)", saved_state); res = _PyObject_CallMethodId(self->decoder, &PyId_setstate, "(O)", saved_state);
Py_DECREF(saved_state); Py_DECREF(saved_state);
if (res == NULL) if (res == NULL)
return NULL; return NULL;
@ -2432,35 +2449,35 @@ static PyObject *
textiowrapper_fileno(textio *self, PyObject *args) textiowrapper_fileno(textio *self, PyObject *args)
{ {
CHECK_INITIALIZED(self); CHECK_INITIALIZED(self);
return PyObject_CallMethod(self->buffer, "fileno", NULL); return _PyObject_CallMethodId(self->buffer, &PyId_fileno, NULL);
} }
static PyObject * static PyObject *
textiowrapper_seekable(textio *self, PyObject *args) textiowrapper_seekable(textio *self, PyObject *args)
{ {
CHECK_INITIALIZED(self); CHECK_INITIALIZED(self);
return PyObject_CallMethod(self->buffer, "seekable", NULL); return _PyObject_CallMethodId(self->buffer, &PyId_seekable, NULL);
} }
static PyObject * static PyObject *
textiowrapper_readable(textio *self, PyObject *args) textiowrapper_readable(textio *self, PyObject *args)
{ {
CHECK_INITIALIZED(self); CHECK_INITIALIZED(self);
return PyObject_CallMethod(self->buffer, "readable", NULL); return _PyObject_CallMethodId(self->buffer, &PyId_readable, NULL);
} }
static PyObject * static PyObject *
textiowrapper_writable(textio *self, PyObject *args) textiowrapper_writable(textio *self, PyObject *args)
{ {
CHECK_INITIALIZED(self); CHECK_INITIALIZED(self);
return PyObject_CallMethod(self->buffer, "writable", NULL); return _PyObject_CallMethodId(self->buffer, &PyId_writable, NULL);
} }
static PyObject * static PyObject *
textiowrapper_isatty(textio *self, PyObject *args) textiowrapper_isatty(textio *self, PyObject *args)
{ {
CHECK_INITIALIZED(self); CHECK_INITIALIZED(self);
return PyObject_CallMethod(self->buffer, "isatty", NULL); return _PyObject_CallMethodId(self->buffer, &PyId_isatty, NULL);
} }
static PyObject * static PyObject *
@ -2479,7 +2496,7 @@ textiowrapper_flush(textio *self, PyObject *args)
self->telling = self->seekable; self->telling = self->seekable;
if (_textiowrapper_writeflush(self) < 0) if (_textiowrapper_writeflush(self) < 0)
return NULL; return NULL;
return PyObject_CallMethod(self->buffer, "flush", NULL); return _PyObject_CallMethodId(self->buffer, &PyId_flush, NULL);
} }
static PyObject * static PyObject *
@ -2502,20 +2519,20 @@ textiowrapper_close(textio *self, PyObject *args)
} }
else { else {
if (self->deallocating) { if (self->deallocating) {
res = PyObject_CallMethod(self->buffer, "_dealloc_warn", "O", self); res = _PyObject_CallMethodId(self->buffer, &PyId__dealloc_warn, "O", self);
if (res) if (res)
Py_DECREF(res); Py_DECREF(res);
else else
PyErr_Clear(); PyErr_Clear();
} }
res = PyObject_CallMethod((PyObject *)self, "flush", NULL); res = _PyObject_CallMethodId((PyObject *)self, &PyId_flush, NULL);
if (res == NULL) { if (res == NULL) {
return NULL; return NULL;
} }
else else
Py_DECREF(res); Py_DECREF(res);
return PyObject_CallMethod(self->buffer, "close", NULL); return _PyObject_CallMethodId(self->buffer, &PyId_close, NULL);
} }
} }

View File

@ -2488,7 +2488,9 @@ save_dict(PicklerObject *self, PyObject *obj)
status = batch_dict_exact(self, obj); status = batch_dict_exact(self, obj);
Py_LeaveRecursiveCall(); Py_LeaveRecursiveCall();
} else { } else {
items = PyObject_CallMethod(obj, "items", "()"); _Py_identifier(items);
items = _PyObject_CallMethodId(obj, &PyId_items, "()");
if (items == NULL) if (items == NULL)
goto error; goto error;
iter = PyObject_GetIter(items); iter = PyObject_GetIter(items);
@ -3774,8 +3776,10 @@ static PyTypeObject Pickler_Type = {
static PyObject * static PyObject *
find_class(UnpicklerObject *self, PyObject *module_name, PyObject *global_name) find_class(UnpicklerObject *self, PyObject *module_name, PyObject *global_name)
{ {
return PyObject_CallMethod((PyObject *)self, "find_class", "OO", _Py_identifier(find_class);
module_name, global_name);
return _PyObject_CallMethodId((PyObject *)self, &PyId_find_class, "OO",
module_name, global_name);
} }
static Py_ssize_t static Py_ssize_t
@ -4388,7 +4392,9 @@ instantiate(PyObject *cls, PyObject *args)
result = PyObject_CallObject(cls, args); result = PyObject_CallObject(cls, args);
} }
else { else {
result = PyObject_CallMethod(cls, "__new__", "O", cls); _Py_identifier(__new__);
result = _PyObject_CallMethodId(cls, &PyId___new__, "O", cls);
} }
return result; return result;
} }

View File

@ -18,7 +18,9 @@ static long max_fd;
static int _enable_gc(PyObject *gc_module) static int _enable_gc(PyObject *gc_module)
{ {
PyObject *result; PyObject *result;
result = PyObject_CallMethod(gc_module, "enable", NULL); _Py_identifier(enable);
result = _PyObject_CallMethodId(gc_module, &PyId_enable, NULL);
if (result == NULL) if (result == NULL)
return 1; return 1;
Py_DECREF(result); Py_DECREF(result);
@ -249,10 +251,13 @@ subprocess_fork_exec(PyObject* self, PyObject *args)
/* We need to call gc.disable() when we'll be calling preexec_fn */ /* We need to call gc.disable() when we'll be calling preexec_fn */
if (preexec_fn != Py_None) { if (preexec_fn != Py_None) {
PyObject *result; PyObject *result;
_Py_identifier(isenabled);
_Py_identifier(disable);
gc_module = PyImport_ImportModule("gc"); gc_module = PyImport_ImportModule("gc");
if (gc_module == NULL) if (gc_module == NULL)
return NULL; return NULL;
result = PyObject_CallMethod(gc_module, "isenabled", NULL); result = _PyObject_CallMethodId(gc_module, &PyId_isenabled, NULL);
if (result == NULL) { if (result == NULL) {
Py_DECREF(gc_module); Py_DECREF(gc_module);
return NULL; return NULL;
@ -263,7 +268,7 @@ subprocess_fork_exec(PyObject* self, PyObject *args)
Py_DECREF(gc_module); Py_DECREF(gc_module);
return NULL; return NULL;
} }
result = PyObject_CallMethod(gc_module, "disable", NULL); result = _PyObject_CallMethodId(gc_module, &PyId_disable, NULL);
if (result == NULL) { if (result == NULL) {
Py_DECREF(gc_module); Py_DECREF(gc_module);
return NULL; return NULL;

View File

@ -675,6 +675,7 @@ void _pysqlite_final_callback(sqlite3_context* context)
{ {
PyObject* function_result = NULL; PyObject* function_result = NULL;
PyObject** aggregate_instance; PyObject** aggregate_instance;
_Py_identifier(finalize);
#ifdef WITH_THREAD #ifdef WITH_THREAD
PyGILState_STATE threadstate; PyGILState_STATE threadstate;
@ -690,7 +691,7 @@ void _pysqlite_final_callback(sqlite3_context* context)
goto error; goto error;
} }
function_result = PyObject_CallMethod(*aggregate_instance, "finalize", ""); function_result = _PyObject_CallMethodId(*aggregate_instance, &PyId_finalize, "");
if (!function_result) { if (!function_result) {
if (_enable_callback_tracebacks) { if (_enable_callback_tracebacks) {
PyErr_Print(); PyErr_Print();
@ -1230,8 +1231,9 @@ PyObject* pysqlite_connection_execute(pysqlite_Connection* self, PyObject* args,
PyObject* cursor = 0; PyObject* cursor = 0;
PyObject* result = 0; PyObject* result = 0;
PyObject* method = 0; PyObject* method = 0;
_Py_identifier(cursor);
cursor = PyObject_CallMethod((PyObject*)self, "cursor", ""); cursor = _PyObject_CallMethodId((PyObject*)self, &PyId_cursor, "");
if (!cursor) { if (!cursor) {
goto error; goto error;
} }
@ -1259,8 +1261,9 @@ PyObject* pysqlite_connection_executemany(pysqlite_Connection* self, PyObject* a
PyObject* cursor = 0; PyObject* cursor = 0;
PyObject* result = 0; PyObject* result = 0;
PyObject* method = 0; PyObject* method = 0;
_Py_identifier(cursor);
cursor = PyObject_CallMethod((PyObject*)self, "cursor", ""); cursor = _PyObject_CallMethodId((PyObject*)self, &PyId_cursor, "");
if (!cursor) { if (!cursor) {
goto error; goto error;
} }
@ -1288,8 +1291,9 @@ PyObject* pysqlite_connection_executescript(pysqlite_Connection* self, PyObject*
PyObject* cursor = 0; PyObject* cursor = 0;
PyObject* result = 0; PyObject* result = 0;
PyObject* method = 0; PyObject* method = 0;
_Py_identifier(cursor);
cursor = PyObject_CallMethod((PyObject*)self, "cursor", ""); cursor = _PyObject_CallMethodId((PyObject*)self, &PyId_cursor, "");
if (!cursor) { if (!cursor) {
goto error; goto error;
} }
@ -1437,6 +1441,7 @@ pysqlite_connection_create_collation(pysqlite_Connection* self, PyObject* args)
PyObject* name; PyObject* name;
PyObject* retval; PyObject* retval;
Py_ssize_t i, len; Py_ssize_t i, len;
_Py_identifier(upper);
char *uppercase_name_str; char *uppercase_name_str;
int rc; int rc;
unsigned int kind; unsigned int kind;
@ -1450,7 +1455,7 @@ pysqlite_connection_create_collation(pysqlite_Connection* self, PyObject* args)
goto finally; goto finally;
} }
uppercase_name = PyObject_CallMethod(name, "upper", ""); uppercase_name = _PyObject_CallMethodId(name, &PyId_upper, "");
if (!uppercase_name) { if (!uppercase_name) {
goto finally; goto finally;
} }

View File

@ -150,8 +150,9 @@ PyObject* _pysqlite_get_converter(PyObject* key)
{ {
PyObject* upcase_key; PyObject* upcase_key;
PyObject* retval; PyObject* retval;
_Py_identifier(upper);
upcase_key = PyObject_CallMethod(key, "upper", ""); upcase_key = _PyObject_CallMethodId(key, &PyId_upper, "");
if (!upcase_key) { if (!upcase_key) {
return NULL; return NULL;
} }

View File

@ -95,7 +95,9 @@ pysqlite_microprotocols_adapt(PyObject *obj, PyObject *proto, PyObject *alt)
/* try to have the protocol adapt this object*/ /* try to have the protocol adapt this object*/
if (PyObject_HasAttrString(proto, "__adapt__")) { if (PyObject_HasAttrString(proto, "__adapt__")) {
PyObject *adapted = PyObject_CallMethod(proto, "__adapt__", "O", obj); _Py_identifier(__adapt__);
PyObject *adapted = _PyObject_CallMethodId(proto, &PyId___adapt__, "O", obj);
if (adapted) { if (adapted) {
if (adapted != Py_None) { if (adapted != Py_None) {
return adapted; return adapted;
@ -110,7 +112,9 @@ pysqlite_microprotocols_adapt(PyObject *obj, PyObject *proto, PyObject *alt)
/* and finally try to have the object adapt itself */ /* and finally try to have the object adapt itself */
if (PyObject_HasAttrString(obj, "__conform__")) { if (PyObject_HasAttrString(obj, "__conform__")) {
PyObject *adapted = PyObject_CallMethod(obj, "__conform__","O", proto); _Py_identifier(__conform__);
PyObject *adapted = _PyObject_CallMethodId(obj, &PyId___conform__,"O", proto);
if (adapted) { if (adapted) {
if (adapted != Py_None) { if (adapted != Py_None) {
return adapted; return adapted;

View File

@ -179,13 +179,14 @@ static PyObject* module_register_converter(PyObject* self, PyObject* args)
PyObject* name = NULL; PyObject* name = NULL;
PyObject* callable; PyObject* callable;
PyObject* retval = NULL; PyObject* retval = NULL;
_Py_identifier(upper);
if (!PyArg_ParseTuple(args, "UO", &orig_name, &callable)) { if (!PyArg_ParseTuple(args, "UO", &orig_name, &callable)) {
return NULL; return NULL;
} }
/* convert the name to upper case */ /* convert the name to upper case */
name = PyObject_CallMethod(orig_name, "upper", ""); name = _PyObject_CallMethodId(orig_name, &PyId_upper, "");
if (!name) { if (!name) {
goto error; goto error;
} }

View File

@ -1253,6 +1253,7 @@ array_fromfile(arrayobject *self, PyObject *args)
PyObject *f, *b, *res; PyObject *f, *b, *res;
Py_ssize_t itemsize = self->ob_descr->itemsize; Py_ssize_t itemsize = self->ob_descr->itemsize;
Py_ssize_t n, nbytes; Py_ssize_t n, nbytes;
_Py_identifier(read);
int not_enough_bytes; int not_enough_bytes;
if (!PyArg_ParseTuple(args, "On:fromfile", &f, &n)) if (!PyArg_ParseTuple(args, "On:fromfile", &f, &n))
@ -1264,7 +1265,7 @@ array_fromfile(arrayobject *self, PyObject *args)
return NULL; return NULL;
} }
b = PyObject_CallMethod(f, "read", "n", nbytes); b = _PyObject_CallMethodId(f, &PyId_read, "n", nbytes);
if (b == NULL) if (b == NULL)
return NULL; return NULL;
@ -1321,12 +1322,14 @@ array_tofile(arrayobject *self, PyObject *f)
char* ptr = self->ob_item + i*BLOCKSIZE; char* ptr = self->ob_item + i*BLOCKSIZE;
Py_ssize_t size = BLOCKSIZE; Py_ssize_t size = BLOCKSIZE;
PyObject *bytes, *res; PyObject *bytes, *res;
_Py_identifier(write);
if (i*BLOCKSIZE + size > nbytes) if (i*BLOCKSIZE + size > nbytes)
size = nbytes - i*BLOCKSIZE; size = nbytes - i*BLOCKSIZE;
bytes = PyBytes_FromStringAndSize(ptr, size); bytes = PyBytes_FromStringAndSize(ptr, size);
if (bytes == NULL) if (bytes == NULL)
return NULL; return NULL;
res = PyObject_CallMethod(f, "write", "O", bytes); res = _PyObject_CallMethodId(f, &PyId_write, "O", bytes);
Py_DECREF(bytes); Py_DECREF(bytes);
if (res == NULL) if (res == NULL)
return NULL; return NULL;

View File

@ -1579,12 +1579,13 @@ mbstreamwriter_iwrite(MultibyteStreamWriterObject *self,
PyObject *unistr) PyObject *unistr)
{ {
PyObject *str, *wr; PyObject *str, *wr;
_Py_identifier(write);
str = encoder_encode_stateful(STATEFUL_ECTX(self), unistr, 0); str = encoder_encode_stateful(STATEFUL_ECTX(self), unistr, 0);
if (str == NULL) if (str == NULL)
return -1; return -1;
wr = PyObject_CallMethod(self->stream, "write", "O", str); wr = _PyObject_CallMethodId(self->stream, &PyId_write, "O", str);
Py_DECREF(str); Py_DECREF(str);
if (wr == NULL) if (wr == NULL)
return -1; return -1;
@ -1650,7 +1651,9 @@ mbstreamwriter_reset(MultibyteStreamWriterObject *self)
assert(PyBytes_Check(pwrt)); assert(PyBytes_Check(pwrt));
if (PyBytes_Size(pwrt) > 0) { if (PyBytes_Size(pwrt) > 0) {
PyObject *wr; PyObject *wr;
wr = PyObject_CallMethod(self->stream, "write", "O", pwrt); _Py_identifier(write);
wr = _PyObject_CallMethodId(self->stream, &PyId_write, "O", pwrt);
if (wr == NULL) { if (wr == NULL) {
Py_DECREF(pwrt); Py_DECREF(pwrt);
return NULL; return NULL;

View File

@ -146,6 +146,8 @@ static PyObject*
faulthandler_get_fileno(PyObject *file, int *p_fd) faulthandler_get_fileno(PyObject *file, int *p_fd)
{ {
PyObject *result; PyObject *result;
_Py_identifier(fileno);
_Py_identifier(flush);
long fd_long; long fd_long;
int fd; int fd;
@ -157,7 +159,7 @@ faulthandler_get_fileno(PyObject *file, int *p_fd)
} }
} }
result = PyObject_CallMethod(file, "fileno", ""); result = _PyObject_CallMethodId(file, &PyId_fileno, "");
if (result == NULL) if (result == NULL)
return NULL; return NULL;
@ -175,7 +177,7 @@ faulthandler_get_fileno(PyObject *file, int *p_fd)
return NULL; return NULL;
} }
result = PyObject_CallMethod(file, "flush", ""); result = _PyObject_CallMethodId(file, &PyId_flush, "");
if (result != NULL) if (result != NULL)
Py_DECREF(result); Py_DECREF(result);
else { else {
@ -1197,6 +1199,7 @@ static int
faulthandler_env_options(void) faulthandler_env_options(void)
{ {
PyObject *xoptions, *key, *module, *res; PyObject *xoptions, *key, *module, *res;
_Py_identifier(enable);
if (!Py_GETENV("PYTHONFAULTHANDLER")) { if (!Py_GETENV("PYTHONFAULTHANDLER")) {
int has_key; int has_key;
@ -1219,7 +1222,7 @@ faulthandler_env_options(void)
if (module == NULL) { if (module == NULL) {
return -1; return -1;
} }
res = PyObject_CallMethod(module, "enable", ""); res = _PyObject_CallMethodId(module, &PyId_enable, "");
Py_DECREF(module); Py_DECREF(module);
if (res == NULL) if (res == NULL)
return -1; return -1;

View File

@ -769,7 +769,9 @@ get_time(void)
{ {
double result = 0; double result = 0;
if (tmod != NULL) { if (tmod != NULL) {
PyObject *f = PyObject_CallMethod(tmod, "time", NULL); _Py_identifier(time);
PyObject *f = _PyObject_CallMethodId(tmod, &PyId_time, NULL);
if (f == NULL) { if (f == NULL) {
PyErr_Clear(); PyErr_Clear();
} }

View File

@ -654,7 +654,9 @@ tee(PyObject *self, PyObject *args)
copyable = it; copyable = it;
PyTuple_SET_ITEM(result, 0, copyable); PyTuple_SET_ITEM(result, 0, copyable);
for (i=1 ; i<n ; i++) { for (i=1 ; i<n ; i++) {
copyable = PyObject_CallMethod(copyable, "__copy__", NULL); _Py_identifier(__copy__);
copyable = _PyObject_CallMethodId(copyable, &PyId___copy__, NULL);
if (copyable == NULL) { if (copyable == NULL) {
Py_DECREF(result); Py_DECREF(result);
return NULL; return NULL;

View File

@ -702,7 +702,9 @@ mmap__enter__method(mmap_object *self, PyObject *args)
static PyObject * static PyObject *
mmap__exit__method(PyObject *self, PyObject *args) mmap__exit__method(PyObject *self, PyObject *args)
{ {
return PyObject_CallMethod(self, "close", NULL); _Py_identifier(close);
return _PyObject_CallMethodId(self, &PyId_close, NULL);
} }
static struct PyMethodDef mmap_object_methods[] = { static struct PyMethodDef mmap_object_methods[] = {

View File

@ -534,7 +534,9 @@ oss_self(PyObject *self, PyObject *unused)
static PyObject * static PyObject *
oss_exit(PyObject *self, PyObject *unused) oss_exit(PyObject *self, PyObject *unused)
{ {
PyObject *ret = PyObject_CallMethod(self, "close", NULL); _Py_identifier(close);
PyObject *ret = _PyObject_CallMethodId(self, &PyId_close, NULL);
if (!ret) if (!ret)
return NULL; return NULL;
Py_DECREF(ret); Py_DECREF(ret);

View File

@ -4821,7 +4821,9 @@ socket_getaddrinfo(PyObject *self, PyObject *args, PyObject* kwargs)
if (hobj == Py_None) { if (hobj == Py_None) {
hptr = NULL; hptr = NULL;
} else if (PyUnicode_Check(hobj)) { } else if (PyUnicode_Check(hobj)) {
idna = PyObject_CallMethod(hobj, "encode", "s", "idna"); _Py_identifier(encode);
idna = _PyObject_CallMethodId(hobj, &PyId_encode, "s", "idna");
if (!idna) if (!idna)
return NULL; return NULL;
assert(PyBytes_Check(idna)); assert(PyBytes_Check(idna));

View File

@ -535,11 +535,12 @@ time_strptime(PyObject *self, PyObject *args)
{ {
PyObject *strptime_module = PyImport_ImportModuleNoBlock("_strptime"); PyObject *strptime_module = PyImport_ImportModuleNoBlock("_strptime");
PyObject *strptime_result; PyObject *strptime_result;
_Py_identifier(_strptime_time);
if (!strptime_module) if (!strptime_module)
return NULL; return NULL;
strptime_result = PyObject_CallMethod(strptime_module, strptime_result = _PyObject_CallMethodId(strptime_module,
"_strptime_time", "O", args); &PyId__strptime_time, "O", args);
Py_DECREF(strptime_module); Py_DECREF(strptime_module);
return strptime_result; return strptime_result;
} }

View File

@ -2082,10 +2082,11 @@ PyMapping_Keys(PyObject *o)
{ {
PyObject *keys; PyObject *keys;
PyObject *fast; PyObject *fast;
_Py_identifier(keys);
if (PyDict_CheckExact(o)) if (PyDict_CheckExact(o))
return PyDict_Keys(o); return PyDict_Keys(o);
keys = PyObject_CallMethod(o, "keys", NULL); keys = _PyObject_CallMethodId(o, &PyId_keys, NULL);
if (keys == NULL) if (keys == NULL)
return NULL; return NULL;
fast = PySequence_Fast(keys, "o.keys() are not iterable"); fast = PySequence_Fast(keys, "o.keys() are not iterable");
@ -2098,10 +2099,11 @@ PyMapping_Items(PyObject *o)
{ {
PyObject *items; PyObject *items;
PyObject *fast; PyObject *fast;
_Py_identifier(items);
if (PyDict_CheckExact(o)) if (PyDict_CheckExact(o))
return PyDict_Items(o); return PyDict_Items(o);
items = PyObject_CallMethod(o, "items", NULL); items = _PyObject_CallMethodId(o, &PyId_items, NULL);
if (items == NULL) if (items == NULL)
return NULL; return NULL;
fast = PySequence_Fast(items, "o.items() are not iterable"); fast = PySequence_Fast(items, "o.items() are not iterable");
@ -2114,10 +2116,11 @@ PyMapping_Values(PyObject *o)
{ {
PyObject *values; PyObject *values;
PyObject *fast; PyObject *fast;
_Py_identifier(values);
if (PyDict_CheckExact(o)) if (PyDict_CheckExact(o))
return PyDict_Values(o); return PyDict_Values(o);
values = PyObject_CallMethod(o, "values", NULL); values = _PyObject_CallMethodId(o, &PyId_values, NULL);
if (values == NULL) if (values == NULL)
return NULL; return NULL;
fast = PySequence_Fast(values, "o.values() are not iterable"); fast = PySequence_Fast(values, "o.values() are not iterable");
@ -2223,11 +2226,39 @@ _PyObject_CallFunction_SizeT(PyObject *callable, char *format, ...)
return call_function_tail(callable, args); return call_function_tail(callable, args);
} }
static PyObject*
callmethod(PyObject* func, char *format, va_list va, int is_size_t)
{
PyObject *retval = NULL;
PyObject *args;
if (!PyCallable_Check(func)) {
type_error("attribute of type '%.200s' is not callable", func);
goto exit;
}
if (format && *format) {
if (is_size_t)
args = _Py_VaBuildValue_SizeT(format, va);
else
args = Py_VaBuildValue(format, va);
}
else
args = PyTuple_New(0);
retval = call_function_tail(func, args);
exit:
/* args gets consumed in call_function_tail */
Py_XDECREF(func);
return retval;
}
PyObject * PyObject *
PyObject_CallMethod(PyObject *o, char *name, char *format, ...) PyObject_CallMethod(PyObject *o, char *name, char *format, ...)
{ {
va_list va; va_list va;
PyObject *args;
PyObject *func = NULL; PyObject *func = NULL;
PyObject *retval = NULL; PyObject *retval = NULL;
@ -2240,25 +2271,31 @@ PyObject_CallMethod(PyObject *o, char *name, char *format, ...)
return 0; return 0;
} }
if (!PyCallable_Check(func)) { va_start(va, format);
type_error("attribute of type '%.200s' is not callable", func); retval = callmethod(func, format, va, 0);
goto exit; va_end(va);
return retval;
}
PyObject *
_PyObject_CallMethodId(PyObject *o, _Py_Identifier *name, char *format, ...)
{
va_list va;
PyObject *func = NULL;
PyObject *retval = NULL;
if (o == NULL || name == NULL)
return null_error();
func = _PyObject_GetAttrId(o, name);
if (func == NULL) {
PyErr_SetString(PyExc_AttributeError, name->string);
return 0;
} }
if (format && *format) { va_start(va, format);
va_start(va, format); retval = callmethod(func, format, va, 0);
args = Py_VaBuildValue(format, va); va_end(va);
va_end(va);
}
else
args = PyTuple_New(0);
retval = call_function_tail(func, args);
exit:
/* args gets consumed in call_function_tail */
Py_XDECREF(func);
return retval; return retval;
} }
@ -2266,9 +2303,8 @@ PyObject *
_PyObject_CallMethod_SizeT(PyObject *o, char *name, char *format, ...) _PyObject_CallMethod_SizeT(PyObject *o, char *name, char *format, ...)
{ {
va_list va; va_list va;
PyObject *args;
PyObject *func = NULL; PyObject *func = NULL;
PyObject *retval = NULL; PyObject *retval;
if (o == NULL || name == NULL) if (o == NULL || name == NULL)
return null_error(); return null_error();
@ -2278,29 +2314,32 @@ _PyObject_CallMethod_SizeT(PyObject *o, char *name, char *format, ...)
PyErr_SetString(PyExc_AttributeError, name); PyErr_SetString(PyExc_AttributeError, name);
return 0; return 0;
} }
va_start(va, format);
if (!PyCallable_Check(func)) { retval = callmethod(func, format, va, 1);
type_error("attribute of type '%.200s' is not callable", func); va_end(va);
goto exit;
}
if (format && *format) {
va_start(va, format);
args = _Py_VaBuildValue_SizeT(format, va);
va_end(va);
}
else
args = PyTuple_New(0);
retval = call_function_tail(func, args);
exit:
/* args gets consumed in call_function_tail */
Py_XDECREF(func);
return retval; return retval;
} }
PyObject *
_PyObject_CallMethodId_SizeT(PyObject *o, _Py_Identifier *name, char *format, ...)
{
va_list va;
PyObject *func = NULL;
PyObject *retval;
if (o == NULL || name == NULL)
return null_error();
func = _PyObject_GetAttrId(o, name);
if (func == NULL) {
PyErr_SetString(PyExc_AttributeError, name->string);
return NULL;
}
va_start(va, format);
retval = callmethod(func, format, va, 1);
va_end(va);
return retval;
}
static PyObject * static PyObject *
objargs_mktuple(va_list va) objargs_mktuple(va_list va)

View File

@ -703,34 +703,39 @@ static PyObject *
proxy_get(proxyobject *pp, PyObject *args) proxy_get(proxyobject *pp, PyObject *args)
{ {
PyObject *key, *def = Py_None; PyObject *key, *def = Py_None;
_Py_identifier(get);
if (!PyArg_UnpackTuple(args, "get", 1, 2, &key, &def)) if (!PyArg_UnpackTuple(args, "get", 1, 2, &key, &def))
return NULL; return NULL;
return PyObject_CallMethod(pp->dict, "get", "(OO)", key, def); return _PyObject_CallMethodId(pp->dict, &PyId_get, "(OO)", key, def);
} }
static PyObject * static PyObject *
proxy_keys(proxyobject *pp) proxy_keys(proxyobject *pp)
{ {
return PyObject_CallMethod(pp->dict, "keys", NULL); _Py_identifier(keys);
return _PyObject_CallMethodId(pp->dict, &PyId_keys, NULL);
} }
static PyObject * static PyObject *
proxy_values(proxyobject *pp) proxy_values(proxyobject *pp)
{ {
return PyObject_CallMethod(pp->dict, "values", NULL); _Py_identifier(values);
return _PyObject_CallMethodId(pp->dict, &PyId_values, NULL);
} }
static PyObject * static PyObject *
proxy_items(proxyobject *pp) proxy_items(proxyobject *pp)
{ {
return PyObject_CallMethod(pp->dict, "items", NULL); _Py_identifier(items);
return _PyObject_CallMethodId(pp->dict, &PyId_items, NULL);
} }
static PyObject * static PyObject *
proxy_copy(proxyobject *pp) proxy_copy(proxyobject *pp)
{ {
return PyObject_CallMethod(pp->dict, "copy", NULL); _Py_identifier(copy);
return _PyObject_CallMethodId(pp->dict, &PyId_copy, NULL);
} }
static PyMethodDef proxy_methods[] = { static PyMethodDef proxy_methods[] = {

View File

@ -2707,10 +2707,12 @@ dictviews_sub(PyObject* self, PyObject *other)
{ {
PyObject *result = PySet_New(self); PyObject *result = PySet_New(self);
PyObject *tmp; PyObject *tmp;
_Py_identifier(difference_update);
if (result == NULL) if (result == NULL)
return NULL; return NULL;
tmp = PyObject_CallMethod(result, "difference_update", "O", other); tmp = _PyObject_CallMethodId(result, &PyId_difference_update, "O", other);
if (tmp == NULL) { if (tmp == NULL) {
Py_DECREF(result); Py_DECREF(result);
return NULL; return NULL;
@ -2725,10 +2727,12 @@ dictviews_and(PyObject* self, PyObject *other)
{ {
PyObject *result = PySet_New(self); PyObject *result = PySet_New(self);
PyObject *tmp; PyObject *tmp;
_Py_identifier(intersection_update);
if (result == NULL) if (result == NULL)
return NULL; return NULL;
tmp = PyObject_CallMethod(result, "intersection_update", "O", other); tmp = _PyObject_CallMethodId(result, &PyId_intersection_update, "O", other);
if (tmp == NULL) { if (tmp == NULL) {
Py_DECREF(result); Py_DECREF(result);
return NULL; return NULL;
@ -2761,10 +2765,12 @@ dictviews_xor(PyObject* self, PyObject *other)
{ {
PyObject *result = PySet_New(self); PyObject *result = PySet_New(self);
PyObject *tmp; PyObject *tmp;
_Py_identifier(symmetric_difference_update);
if (result == NULL) if (result == NULL)
return NULL; return NULL;
tmp = PyObject_CallMethod(result, "symmetric_difference_update", "O", tmp = _PyObject_CallMethodId(result, &PyId_symmetric_difference_update, "O",
other); other);
if (tmp == NULL) { if (tmp == NULL) {
Py_DECREF(result); Py_DECREF(result);

View File

@ -30,11 +30,12 @@ PyFile_FromFd(int fd, char *name, char *mode, int buffering, char *encoding,
char *errors, char *newline, int closefd) char *errors, char *newline, int closefd)
{ {
PyObject *io, *stream; PyObject *io, *stream;
_Py_identifier(open);
io = PyImport_ImportModule("io"); io = PyImport_ImportModule("io");
if (io == NULL) if (io == NULL)
return NULL; return NULL;
stream = PyObject_CallMethod(io, "open", "isisssi", fd, mode, stream = _PyObject_CallMethodId(io, &PyId_open, "isisssi", fd, mode,
buffering, encoding, errors, buffering, encoding, errors,
newline, closefd); newline, closefd);
Py_DECREF(io); Py_DECREF(io);

View File

@ -810,6 +810,42 @@ PyObject_SetAttrString(PyObject *v, const char *name, PyObject *w)
return res; return res;
} }
PyObject *
_PyObject_GetAttrId(PyObject *v, _Py_Identifier *name)
{
PyObject *result;
PyObject *oname = _PyUnicode_FromId(name);
if (!oname)
return NULL;
result = PyObject_GetAttr(v, oname);
Py_DECREF(oname);
return result;
}
int
_PyObject_HasAttrId(PyObject *v, _Py_Identifier *name)
{
int result;
PyObject *oname = _PyUnicode_FromId(name);
if (!oname)
return -1;
result = PyObject_HasAttr(v, oname);
Py_DECREF(oname);
return result;
}
int
_PyObject_SetAttrId(PyObject *v, _Py_Identifier *name, PyObject *w)
{
int result;
PyObject *oname = _PyUnicode_FromId(name);
if (!oname)
return -1;
result = PyObject_SetAttr(v, oname, w);
Py_DECREF(oname);
return result;
}
PyObject * PyObject *
PyObject_GetAttr(PyObject *v, PyObject *name) PyObject_GetAttr(PyObject *v, PyObject *name)
{ {

View File

@ -2897,6 +2897,7 @@ object_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
PyObject *sorted; PyObject *sorted;
PyObject *sorted_methods = NULL; PyObject *sorted_methods = NULL;
PyObject *joined = NULL; PyObject *joined = NULL;
_Py_identifier(join);
/* Compute ", ".join(sorted(type.__abstractmethods__)) /* Compute ", ".join(sorted(type.__abstractmethods__))
into joined. */ into joined. */
@ -2919,7 +2920,7 @@ object_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
if (comma == NULL) if (comma == NULL)
goto error; goto error;
} }
joined = PyObject_CallMethod(comma, "join", joined = _PyObject_CallMethodId(comma, &PyId_join,
"O", sorted_methods); "O", sorted_methods);
if (joined == NULL) if (joined == NULL)
goto error; goto error;
@ -3184,6 +3185,7 @@ slotnames(PyObject *cls)
PyObject *copyreg; PyObject *copyreg;
PyObject *slotnames; PyObject *slotnames;
static PyObject *str_slotnames; static PyObject *str_slotnames;
_Py_identifier(_slotnames);
if (str_slotnames == NULL) { if (str_slotnames == NULL) {
str_slotnames = PyUnicode_InternFromString("__slotnames__"); str_slotnames = PyUnicode_InternFromString("__slotnames__");
@ -3202,7 +3204,7 @@ slotnames(PyObject *cls)
if (copyreg == NULL) if (copyreg == NULL)
return NULL; return NULL;
slotnames = PyObject_CallMethod(copyreg, "_slotnames", "O", cls); slotnames = _PyObject_CallMethodId(copyreg, &PyId__slotnames, "O", cls);
Py_DECREF(copyreg); Py_DECREF(copyreg);
if (slotnames != NULL && if (slotnames != NULL &&
slotnames != Py_None && slotnames != Py_None &&
@ -3323,7 +3325,8 @@ reduce_2(PyObject *obj)
Py_INCREF(dictitems); Py_INCREF(dictitems);
} }
else { else {
PyObject *items = PyObject_CallMethod(obj, "items", ""); _Py_identifier(items);
PyObject *items = _PyObject_CallMethodId(obj, &PyId_items, "");
if (items == NULL) if (items == NULL)
goto end; goto end;
dictitems = PyObject_GetIter(items); dictitems = PyObject_GetIter(items);

View File

@ -201,6 +201,9 @@ static PyObject *interned;
/* The empty Unicode object is shared to improve performance. */ /* The empty Unicode object is shared to improve performance. */
static PyObject *unicode_empty; static PyObject *unicode_empty;
/* List of static strings. */
static _Py_Identifier *static_strings;
/* Single character Unicode strings in the Latin-1 range are being /* Single character Unicode strings in the Latin-1 range are being
shared as well. */ shared as well. */
static PyObject *unicode_latin1[256]; static PyObject *unicode_latin1[256];
@ -1609,6 +1612,33 @@ PyUnicode_FromString(const char *u)
return PyUnicode_FromStringAndSize(u, size); return PyUnicode_FromStringAndSize(u, size);
} }
PyObject *
_PyUnicode_FromId(_Py_Identifier *id)
{
if (!id->object) {
id->object = PyUnicode_FromString(id->string);
if (!id->object)
return NULL;
PyUnicode_InternInPlace(&id->object);
assert(!id->next);
id->next = static_strings;
static_strings = id;
}
Py_INCREF(id->object);
return id->object;
}
void
_PyUnicode_ClearStaticStrings()
{
_Py_Identifier *i;
for (i = static_strings; i; i = i->next) {
Py_DECREF(i->object);
i->object = NULL;
i->next = NULL;
}
}
static PyObject* static PyObject*
unicode_fromascii(const unsigned char* s, Py_ssize_t size) unicode_fromascii(const unsigned char* s, Py_ssize_t size)
{ {
@ -13523,6 +13553,7 @@ _PyUnicode_Fini(void)
unicode_latin1[i] = NULL; unicode_latin1[i] = NULL;
} }
} }
_PyUnicode_ClearStaticStrings();
(void)PyUnicode_ClearFreeList(); (void)PyUnicode_ClearFreeList();
} }

View File

@ -440,8 +440,9 @@ proxy_checkref(PyWeakReference *proxy)
#define WRAP_METHOD(method, special) \ #define WRAP_METHOD(method, special) \
static PyObject * \ static PyObject * \
method(PyObject *proxy) { \ method(PyObject *proxy) { \
_Py_identifier(special); \
UNWRAP(proxy); \ UNWRAP(proxy); \
return PyObject_CallMethod(proxy, special, ""); \ return _PyObject_CallMethodId(proxy, &PyId_##special, ""); \
} }
@ -584,7 +585,7 @@ proxy_iternext(PyWeakReference *proxy)
} }
WRAP_METHOD(proxy_bytes, "__bytes__") WRAP_METHOD(proxy_bytes, __bytes__)
static PyMethodDef proxy_methods[] = { static PyMethodDef proxy_methods[] = {

View File

@ -122,7 +122,9 @@ static FNFCIGETTEMPFILE(cb_gettempfile)
static FNFCISTATUS(cb_status) static FNFCISTATUS(cb_status)
{ {
if (pv) { if (pv) {
PyObject *result = PyObject_CallMethod(pv, "status", "iii", typeStatus, cb1, cb2); _Py_identifier(status);
PyObject *result = _PyObject_CallMethodId(pv, &PyId_status, "iii", typeStatus, cb1, cb2);
if (result == NULL) if (result == NULL)
return -1; return -1;
Py_DECREF(result); Py_DECREF(result);
@ -133,7 +135,9 @@ static FNFCISTATUS(cb_status)
static FNFCIGETNEXTCABINET(cb_getnextcabinet) static FNFCIGETNEXTCABINET(cb_getnextcabinet)
{ {
if (pv) { if (pv) {
PyObject *result = PyObject_CallMethod(pv, "getnextcabinet", "i", pccab->iCab); _Py_identifier(getnextcabinet);
PyObject *result = _PyObject_CallMethodId(pv, &PyId_getnextcabinet, "i", pccab->iCab);
if (result == NULL) if (result == NULL)
return -1; return -1;
if (!PyBytes_Check(result)) { if (!PyBytes_Check(result)) {

View File

@ -462,6 +462,7 @@ static int
fp_setreadl(struct tok_state *tok, const char* enc) fp_setreadl(struct tok_state *tok, const char* enc)
{ {
PyObject *readline = NULL, *stream = NULL, *io = NULL; PyObject *readline = NULL, *stream = NULL, *io = NULL;
_Py_identifier(open);
int fd; int fd;
io = PyImport_ImportModuleNoBlock("io"); io = PyImport_ImportModuleNoBlock("io");
@ -474,7 +475,7 @@ fp_setreadl(struct tok_state *tok, const char* enc)
goto cleanup; goto cleanup;
} }
stream = PyObject_CallMethod(io, "open", "isisOOO", stream = _PyObject_CallMethodId(io, &PyId_open, "isisOOO",
fd, "r", -1, enc, Py_None, Py_None, Py_False); fd, "r", -1, enc, Py_None, Py_None, Py_False);
if (stream == NULL) if (stream == NULL)
goto cleanup; goto cleanup;

View File

@ -18,11 +18,12 @@ static int
check_matched(PyObject *obj, PyObject *arg) check_matched(PyObject *obj, PyObject *arg)
{ {
PyObject *result; PyObject *result;
_Py_identifier(match);
int rc; int rc;
if (obj == Py_None) if (obj == Py_None)
return 1; return 1;
result = PyObject_CallMethod(obj, "match", "O", arg); result = _PyObject_CallMethodId(obj, &PyId_match, "O", arg);
if (result == NULL) if (result == NULL)
return -1; return -1;

View File

@ -527,6 +527,7 @@ static PyObject *parsestrplus(struct compiling *, const node *n,
static identifier static identifier
new_identifier(const char* n, PyArena *arena) new_identifier(const char* n, PyArena *arena)
{ {
_Py_identifier(normalize);
PyObject* id = PyUnicode_DecodeUTF8(n, strlen(n), NULL); PyObject* id = PyUnicode_DecodeUTF8(n, strlen(n), NULL);
if (!id || PyUnicode_READY(id) == -1) if (!id || PyUnicode_READY(id) == -1)
return NULL; return NULL;
@ -537,7 +538,7 @@ new_identifier(const char* n, PyArena *arena)
PyObject *id2; PyObject *id2;
if (!m) if (!m)
return NULL; return NULL;
id2 = PyObject_CallMethod(m, "normalize", "sO", "NFKC", id); id2 = _PyObject_CallMethodId(m, &PyId_normalize, "sO", "NFKC", id);
Py_DECREF(m); Py_DECREF(m);
if (!id2) if (!id2)
return NULL; return NULL;

View File

@ -32,6 +32,9 @@ const char *Py_FileSystemDefaultEncoding = NULL; /* set by initfsencoding() */
int Py_HasFileSystemDefaultEncoding = 0; int Py_HasFileSystemDefaultEncoding = 0;
#endif #endif
_Py_identifier(fileno);
_Py_identifier(flush);
static PyObject * static PyObject *
builtin___build_class__(PyObject *self, PyObject *args, PyObject *kwds) builtin___build_class__(PyObject *self, PyObject *args, PyObject *kwds)
{ {
@ -1567,7 +1570,7 @@ builtin_input(PyObject *self, PyObject *args)
} }
/* First of all, flush stderr */ /* First of all, flush stderr */
tmp = PyObject_CallMethod(ferr, "flush", ""); tmp = _PyObject_CallMethodId(ferr, &PyId_flush, "");
if (tmp == NULL) if (tmp == NULL)
PyErr_Clear(); PyErr_Clear();
else else
@ -1576,7 +1579,7 @@ builtin_input(PyObject *self, PyObject *args)
/* We should only use (GNU) readline if Python's sys.stdin and /* We should only use (GNU) readline if Python's sys.stdin and
sys.stdout are the same as C's stdin and stdout, because we sys.stdout are the same as C's stdin and stdout, because we
need to pass it those. */ need to pass it those. */
tmp = PyObject_CallMethod(fin, "fileno", ""); tmp = _PyObject_CallMethodId(fin, &PyId_fileno, "");
if (tmp == NULL) { if (tmp == NULL) {
PyErr_Clear(); PyErr_Clear();
tty = 0; tty = 0;
@ -1589,7 +1592,7 @@ builtin_input(PyObject *self, PyObject *args)
tty = fd == fileno(stdin) && isatty(fd); tty = fd == fileno(stdin) && isatty(fd);
} }
if (tty) { if (tty) {
tmp = PyObject_CallMethod(fout, "fileno", ""); tmp = _PyObject_CallMethodId(fout, &PyId_fileno, "");
if (tmp == NULL) if (tmp == NULL)
PyErr_Clear(); PyErr_Clear();
else { else {
@ -1621,7 +1624,7 @@ builtin_input(PyObject *self, PyObject *args)
Py_DECREF(stdin_encoding); Py_DECREF(stdin_encoding);
return NULL; return NULL;
} }
tmp = PyObject_CallMethod(fout, "flush", ""); tmp = _PyObject_CallMethodId(fout, &PyId_flush, "");
if (tmp == NULL) if (tmp == NULL)
PyErr_Clear(); PyErr_Clear();
else else
@ -1703,7 +1706,7 @@ builtin_input(PyObject *self, PyObject *args)
if (PyFile_WriteObject(promptarg, fout, Py_PRINT_RAW) != 0) if (PyFile_WriteObject(promptarg, fout, Py_PRINT_RAW) != 0)
return NULL; return NULL;
} }
tmp = PyObject_CallMethod(fout, "flush", ""); tmp = _PyObject_CallMethodId(fout, &PyId_flush, "");
if (tmp == NULL) if (tmp == NULL)
PyErr_Clear(); PyErr_Clear();
else else

View File

@ -372,6 +372,7 @@ PyEval_ReleaseThread(PyThreadState *tstate)
void void
PyEval_ReInitThreads(void) PyEval_ReInitThreads(void)
{ {
_Py_identifier(_after_fork);
PyObject *threading, *result; PyObject *threading, *result;
PyThreadState *tstate = PyThreadState_GET(); PyThreadState *tstate = PyThreadState_GET();
@ -392,7 +393,7 @@ PyEval_ReInitThreads(void)
PyErr_Clear(); PyErr_Clear();
return; return;
} }
result = PyObject_CallMethod(threading, "_after_fork", NULL); result = _PyObject_CallMethodId(threading, &PyId__after_fork, NULL);
if (result == NULL) if (result == NULL)
PyErr_WriteUnraisable(threading); PyErr_WriteUnraisable(threading);
else else

View File

@ -1801,6 +1801,7 @@ find_module_path(PyObject *fullname, PyObject *name, PyObject *path,
/* sys.path_hooks import hook */ /* sys.path_hooks import hook */
if (p_loader != NULL) { if (p_loader != NULL) {
_Py_identifier(find_module);
PyObject *importer; PyObject *importer;
importer = get_path_importer(path_importer_cache, importer = get_path_importer(path_importer_cache,
@ -1811,8 +1812,8 @@ find_module_path(PyObject *fullname, PyObject *name, PyObject *path,
/* Note: importer is a borrowed reference */ /* Note: importer is a borrowed reference */
if (importer != Py_None) { if (importer != Py_None) {
PyObject *loader; PyObject *loader;
loader = PyObject_CallMethod(importer, loader = _PyObject_CallMethodId(importer,
"find_module", "O", fullname); &PyId_find_module, "O", fullname);
if (loader == NULL) if (loader == NULL)
return -1; /* error */ return -1; /* error */
if (loader != Py_None) { if (loader != Py_None) {
@ -2030,6 +2031,7 @@ find_module(PyObject *fullname, PyObject *name, PyObject *search_path_list,
/* sys.meta_path import hook */ /* sys.meta_path import hook */
if (p_loader != NULL) { if (p_loader != NULL) {
_Py_identifier(find_module);
PyObject *meta_path; PyObject *meta_path;
meta_path = PySys_GetObject("meta_path"); meta_path = PySys_GetObject("meta_path");
@ -2044,7 +2046,7 @@ find_module(PyObject *fullname, PyObject *name, PyObject *search_path_list,
for (i = 0; i < npath; i++) { for (i = 0; i < npath; i++) {
PyObject *loader; PyObject *loader;
PyObject *hook = PyList_GetItem(meta_path, i); PyObject *hook = PyList_GetItem(meta_path, i);
loader = PyObject_CallMethod(hook, "find_module", loader = _PyObject_CallMethodId(hook, &PyId_find_module,
"OO", fullname, "OO", fullname,
search_path_list != NULL ? search_path_list != NULL ?
search_path_list : Py_None); search_path_list : Py_None);
@ -2454,12 +2456,13 @@ load_module(PyObject *name, FILE *fp, PyObject *pathname, int type, PyObject *lo
break; break;
case IMP_HOOK: { case IMP_HOOK: {
_Py_identifier(load_module);
if (loader == NULL) { if (loader == NULL) {
PyErr_SetString(PyExc_ImportError, PyErr_SetString(PyExc_ImportError,
"import hook without loader"); "import hook without loader");
return NULL; return NULL;
} }
m = PyObject_CallMethod(loader, "load_module", "O", name); m = _PyObject_CallMethodId(loader, &PyId_load_module, "O", name);
break; break;
} }

View File

@ -480,7 +480,9 @@ r_string(char *s, int n, RFILE *p)
} }
} }
else { else {
PyObject *data = PyObject_CallMethod(p->readable, "read", "i", n); _Py_identifier(read);
PyObject *data = _PyObject_CallMethodId(p->readable, &PyId_read, "i", n);
read = 0; read = 0;
if (data != NULL) { if (data != NULL) {
if (!PyBytes_Check(data)) { if (!PyBytes_Check(data)) {
@ -1290,12 +1292,14 @@ marshal_dump(PyObject *self, PyObject *args)
int version = Py_MARSHAL_VERSION; int version = Py_MARSHAL_VERSION;
PyObject *s; PyObject *s;
PyObject *res; PyObject *res;
_Py_identifier(write);
if (!PyArg_ParseTuple(args, "OO|i:dump", &x, &f, &version)) if (!PyArg_ParseTuple(args, "OO|i:dump", &x, &f, &version))
return NULL; return NULL;
s = PyMarshal_WriteObjectToString(x, version); s = PyMarshal_WriteObjectToString(x, version);
if (s == NULL) if (s == NULL)
return NULL; return NULL;
res = PyObject_CallMethod(f, "write", "O", s); res = _PyObject_CallMethodId(f, &PyId_write, "O", s);
Py_DECREF(s); Py_DECREF(s);
return res; return res;
} }
@ -1317,6 +1321,7 @@ static PyObject *
marshal_load(PyObject *self, PyObject *f) marshal_load(PyObject *self, PyObject *f)
{ {
PyObject *data, *result; PyObject *data, *result;
_Py_identifier(read);
RFILE rf; RFILE rf;
/* /*
@ -1324,7 +1329,7 @@ marshal_load(PyObject *self, PyObject *f)
* This is to ensure that the object passed in at least * This is to ensure that the object passed in at least
* has a read method which returns bytes. * has a read method which returns bytes.
*/ */
data = PyObject_CallMethod(f, "read", "i", 0); data = _PyObject_CallMethodId(f, &PyId_read, "i", 0);
if (data == NULL) if (data == NULL)
return NULL; return NULL;
if (!PyBytes_Check(data)) { if (!PyBytes_Check(data)) {

View File

@ -352,9 +352,10 @@ flush_std_files(void)
PyObject *fout = PySys_GetObject("stdout"); PyObject *fout = PySys_GetObject("stdout");
PyObject *ferr = PySys_GetObject("stderr"); PyObject *ferr = PySys_GetObject("stderr");
PyObject *tmp; PyObject *tmp;
_Py_identifier(flush);
if (fout != NULL && fout != Py_None) { if (fout != NULL && fout != Py_None) {
tmp = PyObject_CallMethod(fout, "flush", ""); tmp = _PyObject_CallMethodId(fout, &PyId_flush, "");
if (tmp == NULL) if (tmp == NULL)
PyErr_WriteUnraisable(fout); PyErr_WriteUnraisable(fout);
else else
@ -362,7 +363,7 @@ flush_std_files(void)
} }
if (ferr != NULL && ferr != Py_None) { if (ferr != NULL && ferr != Py_None) {
tmp = PyObject_CallMethod(ferr, "flush", ""); tmp = _PyObject_CallMethodId(ferr, &PyId_flush, "");
if (tmp == NULL) if (tmp == NULL)
PyErr_Clear(); PyErr_Clear();
else else
@ -805,6 +806,9 @@ create_stdio(PyObject* io,
const char* newline; const char* newline;
PyObject *line_buffering; PyObject *line_buffering;
int buffering, isatty; int buffering, isatty;
_Py_identifier(open);
_Py_identifier(isatty);
_Py_identifier(TextIOWrapper);
/* stdin is always opened in buffered mode, first because it shouldn't /* stdin is always opened in buffered mode, first because it shouldn't
make a difference in common use cases, second because TextIOWrapper make a difference in common use cases, second because TextIOWrapper
@ -819,9 +823,9 @@ create_stdio(PyObject* io,
mode = "wb"; mode = "wb";
else else
mode = "rb"; mode = "rb";
buf = PyObject_CallMethod(io, "open", "isiOOOi", buf = _PyObject_CallMethodId(io, &PyId_open, "isiOOOi",
fd, mode, buffering, fd, mode, buffering,
Py_None, Py_None, Py_None, 0); Py_None, Py_None, Py_None, 0);
if (buf == NULL) if (buf == NULL)
goto error; goto error;
@ -838,7 +842,7 @@ create_stdio(PyObject* io,
text = PyUnicode_FromString(name); text = PyUnicode_FromString(name);
if (text == NULL || PyObject_SetAttrString(raw, "name", text) < 0) if (text == NULL || PyObject_SetAttrString(raw, "name", text) < 0)
goto error; goto error;
res = PyObject_CallMethod(raw, "isatty", ""); res = _PyObject_CallMethodId(raw, &PyId_isatty, "");
if (res == NULL) if (res == NULL)
goto error; goto error;
isatty = PyObject_IsTrue(res); isatty = PyObject_IsTrue(res);
@ -861,9 +865,9 @@ create_stdio(PyObject* io,
} }
#endif #endif
stream = PyObject_CallMethod(io, "TextIOWrapper", "OsssO", stream = _PyObject_CallMethodId(io, &PyId_TextIOWrapper, "OsssO",
buf, encoding, errors, buf, encoding, errors,
newline, line_buffering); newline, line_buffering);
Py_CLEAR(buf); Py_CLEAR(buf);
if (stream == NULL) if (stream == NULL)
goto error; goto error;
@ -1759,13 +1763,14 @@ flush_io(void)
{ {
PyObject *f, *r; PyObject *f, *r;
PyObject *type, *value, *traceback; PyObject *type, *value, *traceback;
_Py_identifier(flush);
/* Save the current exception */ /* Save the current exception */
PyErr_Fetch(&type, &value, &traceback); PyErr_Fetch(&type, &value, &traceback);
f = PySys_GetObject("stderr"); f = PySys_GetObject("stderr");
if (f != NULL) { if (f != NULL) {
r = PyObject_CallMethod(f, "flush", ""); r = _PyObject_CallMethodId(f, &PyId_flush, "");
if (r) if (r)
Py_DECREF(r); Py_DECREF(r);
else else
@ -1773,7 +1778,7 @@ flush_io(void)
} }
f = PySys_GetObject("stdout"); f = PySys_GetObject("stdout");
if (f != NULL) { if (f != NULL) {
r = PyObject_CallMethod(f, "flush", ""); r = _PyObject_CallMethodId(f, &PyId_flush, "");
if (r) if (r)
Py_DECREF(r); Py_DECREF(r);
else else
@ -2205,6 +2210,7 @@ static void
wait_for_thread_shutdown(void) wait_for_thread_shutdown(void)
{ {
#ifdef WITH_THREAD #ifdef WITH_THREAD
_Py_identifier(_shutdown);
PyObject *result; PyObject *result;
PyThreadState *tstate = PyThreadState_GET(); PyThreadState *tstate = PyThreadState_GET();
PyObject *threading = PyMapping_GetItemString(tstate->interp->modules, PyObject *threading = PyMapping_GetItemString(tstate->interp->modules,
@ -2214,7 +2220,7 @@ wait_for_thread_shutdown(void)
PyErr_Clear(); PyErr_Clear();
return; return;
} }
result = PyObject_CallMethod(threading, "_shutdown", ""); result = _PyObject_CallMethodId(threading, &PyId__shutdown, "");
if (result == NULL) { if (result == NULL) {
PyErr_WriteUnraisable(threading); PyErr_WriteUnraisable(threading);
} }

View File

@ -99,7 +99,8 @@ sys_displayhook_unencodable(PyObject *outf, PyObject *o)
buffer = PyObject_GetAttrString(outf, "buffer"); buffer = PyObject_GetAttrString(outf, "buffer");
if (buffer) { if (buffer) {
result = PyObject_CallMethod(buffer, "write", "(O)", encoded); _Py_identifier(write);
result = _PyObject_CallMethodId(buffer, &PyId_write, "(O)", encoded);
Py_DECREF(buffer); Py_DECREF(buffer);
Py_DECREF(encoded); Py_DECREF(encoded);
if (result == NULL) if (result == NULL)

View File

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