mirror of https://github.com/python/cpython
gh-122985: add SYMBOL_TO_SCOPE macro in symtable (#122986)
This commit is contained in:
parent
e03073ff20
commit
05fc4d758a
|
@ -171,6 +171,7 @@ extern PyObject* _Py_Mangle(PyObject *p, PyObject *name);
|
||||||
*/
|
*/
|
||||||
#define SCOPE_OFFSET 12
|
#define SCOPE_OFFSET 12
|
||||||
#define SCOPE_MASK (DEF_GLOBAL | DEF_LOCAL | DEF_PARAM | DEF_NONLOCAL)
|
#define SCOPE_MASK (DEF_GLOBAL | DEF_LOCAL | DEF_PARAM | DEF_NONLOCAL)
|
||||||
|
#define SYMBOL_TO_SCOPE(S) (((S) >> SCOPE_OFFSET) & SCOPE_MASK)
|
||||||
|
|
||||||
#define LOCAL 1
|
#define LOCAL 1
|
||||||
#define GLOBAL_EXPLICIT 2
|
#define GLOBAL_EXPLICIT 2
|
||||||
|
|
|
@ -491,7 +491,7 @@ each key.
|
||||||
static PyObject *
|
static PyObject *
|
||||||
dictbytype(PyObject *src, int scope_type, int flag, Py_ssize_t offset)
|
dictbytype(PyObject *src, int scope_type, int flag, Py_ssize_t offset)
|
||||||
{
|
{
|
||||||
Py_ssize_t i = offset, scope, num_keys, key_i;
|
Py_ssize_t i = offset, num_keys, key_i;
|
||||||
PyObject *k, *v, *dest = PyDict_New();
|
PyObject *k, *v, *dest = PyDict_New();
|
||||||
PyObject *sorted_keys;
|
PyObject *sorted_keys;
|
||||||
|
|
||||||
|
@ -533,10 +533,7 @@ dictbytype(PyObject *src, int scope_type, int flag, Py_ssize_t offset)
|
||||||
Py_DECREF(dest);
|
Py_DECREF(dest);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
/* XXX this should probably be a macro in symtable.h */
|
if (SYMBOL_TO_SCOPE(vi) == scope_type || vi & flag) {
|
||||||
scope = (vi >> SCOPE_OFFSET) & SCOPE_MASK;
|
|
||||||
|
|
||||||
if (scope == scope_type || vi & flag) {
|
|
||||||
PyObject *item = PyLong_FromSsize_t(i);
|
PyObject *item = PyLong_FromSsize_t(i);
|
||||||
if (item == NULL) {
|
if (item == NULL) {
|
||||||
Py_DECREF(sorted_keys);
|
Py_DECREF(sorted_keys);
|
||||||
|
@ -5393,7 +5390,7 @@ push_inlined_comprehension_state(struct compiler *c, location loc,
|
||||||
if (symbol == -1 && PyErr_Occurred()) {
|
if (symbol == -1 && PyErr_Occurred()) {
|
||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
long scope = (symbol >> SCOPE_OFFSET) & SCOPE_MASK;
|
long scope = SYMBOL_TO_SCOPE(symbol);
|
||||||
PyObject *outv = PyDict_GetItemWithError(SYMTABLE_ENTRY(c)->ste_symbols, k);
|
PyObject *outv = PyDict_GetItemWithError(SYMTABLE_ENTRY(c)->ste_symbols, k);
|
||||||
if (outv == NULL) {
|
if (outv == NULL) {
|
||||||
if (PyErr_Occurred()) {
|
if (PyErr_Occurred()) {
|
||||||
|
@ -5405,7 +5402,7 @@ push_inlined_comprehension_state(struct compiler *c, location loc,
|
||||||
if (outsymbol == -1 && PyErr_Occurred()) {
|
if (outsymbol == -1 && PyErr_Occurred()) {
|
||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
long outsc = (outsymbol >> SCOPE_OFFSET) & SCOPE_MASK;
|
long outsc = SYMBOL_TO_SCOPE(outsymbol);
|
||||||
// If a name has different scope inside than outside the comprehension,
|
// If a name has different scope inside than outside the comprehension,
|
||||||
// we need to temporarily handle it with the right scope while
|
// we need to temporarily handle it with the right scope while
|
||||||
// compiling the comprehension. If it's free in the comprehension
|
// compiling the comprehension. If it's free in the comprehension
|
||||||
|
|
|
@ -551,7 +551,7 @@ _PyST_GetScope(PySTEntryObject *ste, PyObject *name)
|
||||||
if (symbol < 0) {
|
if (symbol < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return (symbol >> SCOPE_OFFSET) & SCOPE_MASK;
|
return SYMBOL_TO_SCOPE(symbol);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -809,7 +809,7 @@ inline_comprehension(PySTEntryObject *ste, PySTEntryObject *comp,
|
||||||
assert(_PyUnicode_EqualToASCIIString(k, ".0"));
|
assert(_PyUnicode_EqualToASCIIString(k, ".0"));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
int scope = (comp_flags >> SCOPE_OFFSET) & SCOPE_MASK;
|
int scope = SYMBOL_TO_SCOPE(comp_flags);
|
||||||
int only_flags = comp_flags & ((1 << SCOPE_OFFSET) - 1);
|
int only_flags = comp_flags & ((1 << SCOPE_OFFSET) - 1);
|
||||||
if (scope == CELL || only_flags & DEF_COMP_CELL) {
|
if (scope == CELL || only_flags & DEF_COMP_CELL) {
|
||||||
if (PySet_Add(inlined_cells, k) < 0) {
|
if (PySet_Add(inlined_cells, k) < 0) {
|
||||||
|
|
Loading…
Reference in New Issue