mirror of
https://github.com/python/cpython.git
synced 2025-08-26 19:55:24 +00:00
bpo-29878: Add global instances of int for 0 and 1. (#852)
This commit is contained in:
parent
e6911a44f6
commit
ba85d69a3e
18 changed files with 105 additions and 249 deletions
|
@ -287,20 +287,15 @@ static int
|
|||
update_registry(PyObject *registry, PyObject *text, PyObject *category,
|
||||
int add_zero)
|
||||
{
|
||||
PyObject *altkey, *zero = NULL;
|
||||
PyObject *altkey;
|
||||
int rc;
|
||||
|
||||
if (add_zero) {
|
||||
zero = PyLong_FromLong(0);
|
||||
if (zero == NULL)
|
||||
return -1;
|
||||
altkey = PyTuple_Pack(3, text, category, zero);
|
||||
}
|
||||
if (add_zero)
|
||||
altkey = PyTuple_Pack(3, text, category, _PyLong_Zero);
|
||||
else
|
||||
altkey = PyTuple_Pack(2, text, category);
|
||||
|
||||
rc = already_warned(registry, altkey, 1);
|
||||
Py_XDECREF(zero);
|
||||
Py_XDECREF(altkey);
|
||||
return rc;
|
||||
}
|
||||
|
@ -1130,7 +1125,6 @@ create_filter(PyObject *category, const char *action)
|
|||
static PyObject *default_str = NULL;
|
||||
static PyObject *always_str = NULL;
|
||||
PyObject *action_obj = NULL;
|
||||
PyObject *lineno, *result;
|
||||
|
||||
if (!strcmp(action, "ignore")) {
|
||||
if (ignore_str == NULL) {
|
||||
|
@ -1169,12 +1163,7 @@ create_filter(PyObject *category, const char *action)
|
|||
}
|
||||
|
||||
/* This assumes the line number is zero for now. */
|
||||
lineno = PyLong_FromLong(0);
|
||||
if (lineno == NULL)
|
||||
return NULL;
|
||||
result = PyTuple_Pack(5, action_obj, Py_None, category, Py_None, lineno);
|
||||
Py_DECREF(lineno);
|
||||
return result;
|
||||
return PyTuple_Pack(5, action_obj, Py_None, category, Py_None, _PyLong_Zero);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
|
|
|
@ -561,7 +561,7 @@ compiler_enter_scope(struct compiler *c, identifier name,
|
|||
if (u->u_ste->ste_needs_class_closure) {
|
||||
/* Cook up an implicit __class__ cell. */
|
||||
_Py_IDENTIFIER(__class__);
|
||||
PyObject *tuple, *name, *zero;
|
||||
PyObject *tuple, *name;
|
||||
int res;
|
||||
assert(u->u_scope_type == COMPILER_SCOPE_CLASS);
|
||||
assert(PyDict_GET_SIZE(u->u_cellvars) == 0);
|
||||
|
@ -575,15 +575,8 @@ compiler_enter_scope(struct compiler *c, identifier name,
|
|||
compiler_unit_free(u);
|
||||
return 0;
|
||||
}
|
||||
zero = PyLong_FromLong(0);
|
||||
if (!zero) {
|
||||
Py_DECREF(tuple);
|
||||
compiler_unit_free(u);
|
||||
return 0;
|
||||
}
|
||||
res = PyDict_SetItem(u->u_cellvars, tuple, zero);
|
||||
res = PyDict_SetItem(u->u_cellvars, tuple, _PyLong_Zero);
|
||||
Py_DECREF(tuple);
|
||||
Py_DECREF(zero);
|
||||
if (res < 0) {
|
||||
compiler_unit_free(u);
|
||||
return 0;
|
||||
|
@ -2596,14 +2589,8 @@ compiler_import(struct compiler *c, stmt_ty s)
|
|||
for (i = 0; i < n; i++) {
|
||||
alias_ty alias = (alias_ty)asdl_seq_GET(s->v.Import.names, i);
|
||||
int r;
|
||||
PyObject *level;
|
||||
|
||||
level = PyLong_FromLong(0);
|
||||
if (level == NULL)
|
||||
return 0;
|
||||
|
||||
ADDOP_O(c, LOAD_CONST, level, consts);
|
||||
Py_DECREF(level);
|
||||
ADDOP_O(c, LOAD_CONST, _PyLong_Zero, consts);
|
||||
ADDOP_O(c, LOAD_CONST, Py_None, consts);
|
||||
ADDOP_NAME(c, IMPORT_NAME, alias->name, names);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue