// The data structure & init here are inspired by Tools/build/deepfreeze.py.
// All field names generated by ASCII_STR() have a common prefix,
-// to help avoid collisions with keywords, etc.
+// to help avoid collisions with keywords, macros, etc.
#define STRUCT_FOR_ASCII_STR(LITERAL) \
struct { \
uint8_t _data[sizeof(LITERAL)]; \
}
#define STRUCT_FOR_STR(NAME, LITERAL) \
- STRUCT_FOR_ASCII_STR(LITERAL) _ ## NAME;
+ STRUCT_FOR_ASCII_STR(LITERAL) _py_ ## NAME;
#define STRUCT_FOR_ID(NAME) \
- STRUCT_FOR_ASCII_STR(#NAME) _ ## NAME;
+ STRUCT_FOR_ASCII_STR(#NAME) _py_ ## NAME;
// XXX Order by frequency of use?
STRUCT_FOR_ID(_showwarnmsg)
STRUCT_FOR_ID(_shutdown)
STRUCT_FOR_ID(_slotnames)
+ STRUCT_FOR_ID(_strptime_datetime)
STRUCT_FOR_ID(_swappedbytes_)
STRUCT_FOR_ID(_type_)
STRUCT_FOR_ID(_uninitialized_submodules)
STRUCT_FOR_ID(argdefs)
STRUCT_FOR_ID(arguments)
STRUCT_FOR_ID(argv)
+ STRUCT_FOR_ID(as_integer_ratio)
STRUCT_FOR_ID(attribute)
STRUCT_FOR_ID(authorizer_callback)
STRUCT_FOR_ID(b)
STRUCT_FOR_ID(frequency)
STRUCT_FOR_ID(from_param)
STRUCT_FOR_ID(fromlist)
+ STRUCT_FOR_ID(fromtimestamp)
+ STRUCT_FOR_ID(fromutc)
STRUCT_FOR_ID(fset)
STRUCT_FOR_ID(func)
STRUCT_FOR_ID(future)
STRUCT_FOR_ID(intersection)
STRUCT_FOR_ID(isatty)
STRUCT_FOR_ID(isinstance)
+ STRUCT_FOR_ID(isoformat)
STRUCT_FOR_ID(isolation_level)
STRUCT_FOR_ID(istext)
STRUCT_FOR_ID(item)
STRUCT_FOR_ID(step)
STRUCT_FOR_ID(store_name)
STRUCT_FOR_ID(strategy)
+ STRUCT_FOR_ID(strftime)
STRUCT_FOR_ID(strict)
STRUCT_FOR_ID(strict_mode)
STRUCT_FOR_ID(string)
STRUCT_FOR_ID(throw)
STRUCT_FOR_ID(timeout)
STRUCT_FOR_ID(times)
+ STRUCT_FOR_ID(timetuple)
STRUCT_FOR_ID(top)
STRUCT_FOR_ID(trace_callback)
STRUCT_FOR_ID(traceback)
STRUCT_FOR_ID(txt)
STRUCT_FOR_ID(type)
STRUCT_FOR_ID(tz)
+ STRUCT_FOR_ID(tzname)
STRUCT_FOR_ID(uid)
STRUCT_FOR_ID(unlink)
STRUCT_FOR_ID(unraisablehook)
#define _Py_ID(NAME) \
- (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
+ (_Py_SINGLETON(strings.identifiers._py_ ## NAME._ascii.ob_base))
#define _Py_STR(NAME) \
- (_Py_SINGLETON(strings.literals._ ## NAME._ascii.ob_base))
+ (_Py_SINGLETON(strings.literals._py_ ## NAME._ascii.ob_base))
/* _Py_DECLARE_STR() should precede all uses of _Py_STR() in a function.
._data = (LITERAL) \
}
#define INIT_STR(NAME, LITERAL) \
- ._ ## NAME = _PyASCIIObject_INIT(LITERAL)
+ ._py_ ## NAME = _PyASCIIObject_INIT(LITERAL)
#define INIT_ID(NAME) \
- ._ ## NAME = _PyASCIIObject_INIT(#NAME)
+ ._py_ ## NAME = _PyASCIIObject_INIT(#NAME)
#define _PyUnicode_LATIN1_INIT(LITERAL, UTF8) \
{ \
._latin1 = { \
INIT_ID(_showwarnmsg), \
INIT_ID(_shutdown), \
INIT_ID(_slotnames), \
+ INIT_ID(_strptime_datetime), \
INIT_ID(_swappedbytes_), \
INIT_ID(_type_), \
INIT_ID(_uninitialized_submodules), \
INIT_ID(argdefs), \
INIT_ID(arguments), \
INIT_ID(argv), \
+ INIT_ID(as_integer_ratio), \
INIT_ID(attribute), \
INIT_ID(authorizer_callback), \
INIT_ID(b), \
INIT_ID(frequency), \
INIT_ID(from_param), \
INIT_ID(fromlist), \
+ INIT_ID(fromtimestamp), \
+ INIT_ID(fromutc), \
INIT_ID(fset), \
INIT_ID(func), \
INIT_ID(future), \
INIT_ID(intersection), \
INIT_ID(isatty), \
INIT_ID(isinstance), \
+ INIT_ID(isoformat), \
INIT_ID(isolation_level), \
INIT_ID(istext), \
INIT_ID(item), \
INIT_ID(step), \
INIT_ID(store_name), \
INIT_ID(strategy), \
+ INIT_ID(strftime), \
INIT_ID(strict), \
INIT_ID(strict_mode), \
INIT_ID(string), \
INIT_ID(throw), \
INIT_ID(timeout), \
INIT_ID(times), \
+ INIT_ID(timetuple), \
INIT_ID(top), \
INIT_ID(trace_callback), \
INIT_ID(traceback), \
INIT_ID(txt), \
INIT_ID(type), \
INIT_ID(tz), \
+ INIT_ID(tzname), \
INIT_ID(uid), \
INIT_ID(unlink), \
INIT_ID(unraisablehook), \
PyUnicode_InternInPlace(&string);
string = &_Py_ID(_slotnames);
PyUnicode_InternInPlace(&string);
+ string = &_Py_ID(_strptime_datetime);
+ PyUnicode_InternInPlace(&string);
string = &_Py_ID(_swappedbytes_);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(_type_);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(argv);
PyUnicode_InternInPlace(&string);
+ string = &_Py_ID(as_integer_ratio);
+ PyUnicode_InternInPlace(&string);
string = &_Py_ID(attribute);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(authorizer_callback);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(fromlist);
PyUnicode_InternInPlace(&string);
+ string = &_Py_ID(fromtimestamp);
+ PyUnicode_InternInPlace(&string);
+ string = &_Py_ID(fromutc);
+ PyUnicode_InternInPlace(&string);
string = &_Py_ID(fset);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(func);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(isinstance);
PyUnicode_InternInPlace(&string);
+ string = &_Py_ID(isoformat);
+ PyUnicode_InternInPlace(&string);
string = &_Py_ID(isolation_level);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(istext);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(strategy);
PyUnicode_InternInPlace(&string);
+ string = &_Py_ID(strftime);
+ PyUnicode_InternInPlace(&string);
string = &_Py_ID(strict);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(strict_mode);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(times);
PyUnicode_InternInPlace(&string);
+ string = &_Py_ID(timetuple);
+ PyUnicode_InternInPlace(&string);
string = &_Py_ID(top);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(trace_callback);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(tz);
PyUnicode_InternInPlace(&string);
+ string = &_Py_ID(tzname);
+ PyUnicode_InternInPlace(&string);
string = &_Py_ID(uid);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(unlink);
_PyObject_Dump((PyObject *)&_Py_ID(_slotnames));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
};
+ if (Py_REFCNT((PyObject *)&_Py_ID(_strptime_datetime)) < _PyObject_IMMORTAL_REFCNT) {
+ _PyObject_Dump((PyObject *)&_Py_ID(_strptime_datetime));
+ Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
+ };
if (Py_REFCNT((PyObject *)&_Py_ID(_swappedbytes_)) < _PyObject_IMMORTAL_REFCNT) {
_PyObject_Dump((PyObject *)&_Py_ID(_swappedbytes_));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
_PyObject_Dump((PyObject *)&_Py_ID(argv));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
};
+ if (Py_REFCNT((PyObject *)&_Py_ID(as_integer_ratio)) < _PyObject_IMMORTAL_REFCNT) {
+ _PyObject_Dump((PyObject *)&_Py_ID(as_integer_ratio));
+ Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
+ };
if (Py_REFCNT((PyObject *)&_Py_ID(attribute)) < _PyObject_IMMORTAL_REFCNT) {
_PyObject_Dump((PyObject *)&_Py_ID(attribute));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
_PyObject_Dump((PyObject *)&_Py_ID(fromlist));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
};
+ if (Py_REFCNT((PyObject *)&_Py_ID(fromtimestamp)) < _PyObject_IMMORTAL_REFCNT) {
+ _PyObject_Dump((PyObject *)&_Py_ID(fromtimestamp));
+ Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
+ };
+ if (Py_REFCNT((PyObject *)&_Py_ID(fromutc)) < _PyObject_IMMORTAL_REFCNT) {
+ _PyObject_Dump((PyObject *)&_Py_ID(fromutc));
+ Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
+ };
if (Py_REFCNT((PyObject *)&_Py_ID(fset)) < _PyObject_IMMORTAL_REFCNT) {
_PyObject_Dump((PyObject *)&_Py_ID(fset));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
_PyObject_Dump((PyObject *)&_Py_ID(isinstance));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
};
+ if (Py_REFCNT((PyObject *)&_Py_ID(isoformat)) < _PyObject_IMMORTAL_REFCNT) {
+ _PyObject_Dump((PyObject *)&_Py_ID(isoformat));
+ Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
+ };
if (Py_REFCNT((PyObject *)&_Py_ID(isolation_level)) < _PyObject_IMMORTAL_REFCNT) {
_PyObject_Dump((PyObject *)&_Py_ID(isolation_level));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
_PyObject_Dump((PyObject *)&_Py_ID(strategy));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
};
+ if (Py_REFCNT((PyObject *)&_Py_ID(strftime)) < _PyObject_IMMORTAL_REFCNT) {
+ _PyObject_Dump((PyObject *)&_Py_ID(strftime));
+ Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
+ };
if (Py_REFCNT((PyObject *)&_Py_ID(strict)) < _PyObject_IMMORTAL_REFCNT) {
_PyObject_Dump((PyObject *)&_Py_ID(strict));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
_PyObject_Dump((PyObject *)&_Py_ID(times));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
};
+ if (Py_REFCNT((PyObject *)&_Py_ID(timetuple)) < _PyObject_IMMORTAL_REFCNT) {
+ _PyObject_Dump((PyObject *)&_Py_ID(timetuple));
+ Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
+ };
if (Py_REFCNT((PyObject *)&_Py_ID(top)) < _PyObject_IMMORTAL_REFCNT) {
_PyObject_Dump((PyObject *)&_Py_ID(top));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
_PyObject_Dump((PyObject *)&_Py_ID(tz));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
};
+ if (Py_REFCNT((PyObject *)&_Py_ID(tzname)) < _PyObject_IMMORTAL_REFCNT) {
+ _PyObject_Dump((PyObject *)&_Py_ID(tzname));
+ Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
+ };
if (Py_REFCNT((PyObject *)&_Py_ID(uid)) < _PyObject_IMMORTAL_REFCNT) {
_PyObject_Dump((PyObject *)&_Py_ID(uid));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
#ifndef Py_BUILD_CORE_BUILTIN
# define Py_BUILD_CORE_MODULE 1
#endif
-#define NEEDS_PY_IDENTIFIER
#include "Python.h"
#include "pycore_long.h" // _PyLong_GetOne()
static int check_tzinfo_subclass(PyObject *p);
-_Py_IDENTIFIER(as_integer_ratio);
-_Py_IDENTIFIER(fromutc);
-_Py_IDENTIFIER(isoformat);
-_Py_IDENTIFIER(strftime);
/* ---------------------------------------------------------------------------
* Math utilities.
call_tzname(PyObject *tzinfo, PyObject *tzinfoarg)
{
PyObject *result;
- _Py_IDENTIFIER(tzname);
-
assert(tzinfo != NULL);
assert(check_tzinfo_subclass(tzinfo) >= 0);
assert(tzinfoarg != NULL);
if (tzinfo == Py_None)
Py_RETURN_NONE;
- result = _PyObject_CallMethodIdOneArg(tzinfo, &PyId_tzname, tzinfoarg);
+ result = PyObject_CallMethodOneArg(tzinfo, &_Py_ID(tzname), tzinfoarg);
if (result == NULL || result == Py_None)
return result;
if (tzinfo == Py_None || tzinfo == NULL) {
return PyBytes_FromStringAndSize(NULL, 0);
}
-
+
assert(tzinfoarg != NULL);
if (format_utcoffset(buf,
sizeof(buf),
tzinfo,
tzinfoarg) < 0)
return NULL;
-
+
return PyBytes_FromStringAndSize(buf, strlen(buf));
}
PyObject *temp;
PyObject *tzinfo = get_tzinfo_member(object);
PyObject *Zreplacement = PyUnicode_FromStringAndSize(NULL, 0);
- _Py_IDENTIFIER(replace);
if (Zreplacement == NULL)
return NULL;
* strftime doesn't treat them as format codes.
*/
Py_DECREF(Zreplacement);
- Zreplacement = _PyObject_CallMethodId(temp, &PyId_replace, "ss", "%", "%%");
+ Zreplacement = PyObject_CallMethod(temp, "replace", "ss", "%", "%%");
Py_DECREF(temp);
if (Zreplacement == NULL)
return NULL;
PyObject *ratio;
assert(floatobj && PyFloat_Check(floatobj));
- ratio = _PyObject_CallMethodIdNoArgs(floatobj, &PyId_as_integer_ratio);
+ ratio = PyObject_CallMethodNoArgs(floatobj, &_Py_ID(as_integer_ratio));
if (ratio == NULL) {
return NULL;
}
{
PyObject *time;
PyObject *result;
- _Py_IDENTIFIER(fromtimestamp);
-
time = time_time();
if (time == NULL)
return NULL;
* time.time() delivers; if someone were gonzo about optimization,
* date.today() could get away with plain C time().
*/
- result = _PyObject_CallMethodIdOneArg(cls, &PyId_fromtimestamp, time);
+ result = PyObject_CallMethodOneArg(cls, &_Py_ID(fromtimestamp), time);
Py_DECREF(time);
return result;
}
static PyObject *
date_str(PyDateTime_Date *self)
{
- return _PyObject_CallMethodIdNoArgs((PyObject *)self, &PyId_isoformat);
+ return PyObject_CallMethodNoArgs((PyObject *)self, &_Py_ID(isoformat));
}
PyObject *result;
PyObject *tuple;
PyObject *format;
- _Py_IDENTIFIER(timetuple);
static char *keywords[] = {"format", NULL};
if (! PyArg_ParseTupleAndKeywords(args, kw, "U:strftime", keywords,
&format))
return NULL;
- tuple = _PyObject_CallMethodIdNoArgs((PyObject *)self, &PyId_timetuple);
+ tuple = PyObject_CallMethodNoArgs((PyObject *)self, &_Py_ID(timetuple));
if (tuple == NULL)
return NULL;
result = wrap_strftime((PyObject *)self, format, tuple,
if (PyUnicode_GetLength(format) == 0)
return PyObject_Str((PyObject *)self);
- return _PyObject_CallMethodIdOneArg((PyObject *)self, &PyId_strftime,
+ return PyObject_CallMethodOneArg((PyObject *)self, &_Py_ID(strftime),
format);
}
{
PyObject *args, *state;
PyObject *getinitargs;
- _Py_IDENTIFIER(__getinitargs__);
- if (_PyObject_LookupAttrId(self, &PyId___getinitargs__, &getinitargs) < 0) {
+ if (_PyObject_LookupAttr(self, &_Py_ID(__getinitargs__), &getinitargs) < 0) {
return NULL;
}
if (getinitargs != NULL) {
static PyObject *
time_str(PyDateTime_Time *self)
{
- return _PyObject_CallMethodIdNoArgs((PyObject *)self, &PyId_isoformat);
+ return PyObject_CallMethodNoArgs((PyObject *)self, &_Py_ID(isoformat));
}
static PyObject *
tz);
if (self != NULL && tz != Py_None) {
/* Convert UTC to tzinfo's zone. */
- self = _PyObject_CallMethodId(tz, &PyId_fromutc, "N", self);
+ PyObject *res = PyObject_CallMethodOneArg(tz, &_Py_ID(fromutc), self);
+ Py_DECREF(self);
+ return res;
}
return self;
}
tzinfo);
if (self != NULL && tzinfo != Py_None) {
/* Convert UTC to tzinfo's zone. */
- self = _PyObject_CallMethodId(tzinfo, &PyId_fromutc, "N", self);
+ PyObject *res = PyObject_CallMethodOneArg(tzinfo, &_Py_ID(fromutc), self);
+ Py_DECREF(self);
+ return res;
}
return self;
}
{
static PyObject *module = NULL;
PyObject *string, *format;
- _Py_IDENTIFIER(_strptime_datetime);
if (!PyArg_ParseTuple(args, "UU:strptime", &string, &format))
return NULL;
if (module == NULL)
return NULL;
}
- return _PyObject_CallMethodIdObjArgs(module, &PyId__strptime_datetime,
+ return PyObject_CallMethodObjArgs(module, &_Py_ID(_strptime_datetime),
cls, string, format, NULL);
}
static PyObject *
datetime_str(PyDateTime_DateTime *self)
{
- return _PyObject_CallMethodId((PyObject *)self, &PyId_isoformat, "s", " ");
+ PyObject *space = PyUnicode_FromString(" ");
+ if (space == NULL) {
+ return NULL;
+ }
+ PyObject *res = PyObject_CallMethodOneArg((PyObject *)self,
+ &_Py_ID(isoformat), space);
+ Py_DECREF(space);
+ return res;
}
static PyObject *
temp = (PyObject *)result;
result = (PyDateTime_DateTime *)
- _PyObject_CallMethodIdOneArg(tzinfo, &PyId_fromutc, temp);
+ PyObject_CallMethodOneArg(tzinfo, &_Py_ID(fromutc), temp);
Py_DECREF(temp);
return result;
#undef Py_BUILD_CORE_MODULE
#undef Py_BUILD_CORE_BUILTIN
-#define NEEDS_PY_IDENTIFIER
/* Always enable assertions */
#undef NDEBUG
static void
slot_tp_del(PyObject *self)
{
- _Py_IDENTIFIER(__tp_del__);
PyObject *del, *res;
PyObject *error_type, *error_value, *error_traceback;
/* Save the current exception, if any. */
PyErr_Fetch(&error_type, &error_value, &error_traceback);
+ PyObject *tp_del = PyUnicode_InternFromString("__tp_del__");
+ if (tp_del == NULL) {
+ PyErr_WriteUnraisable(NULL);
+ PyErr_Restore(error_type, error_value, error_traceback);
+ return;
+ }
/* Execute __del__ method, if any. */
- del = _PyObject_LookupSpecialId(self, &PyId___tp_del__);
+ del = _PyType_Lookup(Py_TYPE(self), tp_del);
if (del != NULL) {
- res = PyObject_CallNoArgs(del);
+ res = PyObject_CallOneArg(del, self);
if (res == NULL)
PyErr_WriteUnraisable(del);
else
Py_DECREF(res);
- Py_DECREF(del);
}
/* Restore the saved exception. */
static PyObject *
raise_SIGINT_then_send_None(PyObject *self, PyObject *args)
{
- _Py_IDENTIFIER(send);
PyGenObject *gen;
if (!PyArg_ParseTuple(args, "O!", &PyGen_Type, &gen))
because we check for signals before every bytecode operation.
*/
raise(SIGINT);
- return _PyObject_CallMethodIdOneArg((PyObject *)gen, &PyId_send, Py_None);
+ return PyObject_CallMethod((PyObject *)gen, "send", "O", Py_None);
}
#ifndef Py_BUILD_CORE_BUILTIN
# define Py_BUILD_CORE_MODULE 1
#endif
-#define NEEDS_PY_IDENTIFIER
#define PY_SSIZE_T_CLEAN
#include "Python.h"
static PyObject *
oss_exit(PyObject *self, PyObject *unused)
{
- _Py_IDENTIFIER(close);
-
- PyObject *ret = _PyObject_CallMethodIdNoArgs(self, &PyId_close);
+ PyObject *ret = PyObject_CallMethod(self, "close", NULL);
if (!ret)
return NULL;
Py_DECREF(ret);
static FNFCISTATUS(cb_status)
{
if (pv) {
- _Py_IDENTIFIER(status);
-
- PyObject *result = _PyObject_CallMethodId(pv, &PyId_status, "iii", typeStatus, cb1, cb2);
+ PyObject *result = PyObject_CallMethod(pv, "status", "iii", typeStatus, cb1, cb2);
if (result == NULL)
return -1;
Py_DECREF(result);
static FNFCIGETNEXTCABINET(cb_getnextcabinet)
{
if (pv) {
- _Py_IDENTIFIER(getnextcabinet);
-
- PyObject *result = _PyObject_CallMethodId(pv, &PyId_getnextcabinet, "i", pccab->iCab);
+ PyObject *result = PyObject_CallMethod(pv, "getnextcabinet", "i", pccab->iCab);
if (result == NULL)
return -1;
if (!PyBytes_Check(result)) {