Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-100321: Remove redundant variable newfree in function analyze_block #100327

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 9 additions & 18 deletions Python/symtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -729,15 +729,15 @@ update_symbols(PyObject *symbols, PyObject *scopes,
*/

static int
analyze_child_block(PySTEntryObject *entry, PyObject *bound, PyObject *free,
analyze_child_block(PySTEntryObject *entry, PyObject *bound,
PyObject *global, PyObject* child_free);

static int
analyze_block(PySTEntryObject *ste, PyObject *bound, PyObject *free,
PyObject *global)
{
PyObject *name, *v, *local = NULL, *scopes = NULL, *newbound = NULL;
PyObject *newglobal = NULL, *newfree = NULL, *allfree = NULL;
PyObject *newglobal = NULL, *allfree = NULL;
PyObject *temp;
int i, success = 0;
Py_ssize_t pos = 0;
Expand All @@ -763,9 +763,6 @@ analyze_block(PySTEntryObject *ste, PyObject *bound, PyObject *free,
newglobal = PySet_New(NULL);
if (!newglobal)
goto error;
newfree = PySet_New(NULL);
if (!newfree)
goto error;
newbound = PySet_New(NULL);
if (!newbound)
goto error;
Expand Down Expand Up @@ -839,30 +836,25 @@ analyze_block(PySTEntryObject *ste, PyObject *bound, PyObject *free,
PySTEntryObject* entry;
assert(c && PySTEntry_Check(c));
entry = (PySTEntryObject*)c;
if (!analyze_child_block(entry, newbound, newfree, newglobal,
if (!analyze_child_block(entry, newbound, newglobal,
allfree))
goto error;
/* Check if any children have free variables */
if (entry->ste_free || entry->ste_child_free)
ste->ste_child_free = 1;
}

temp = PyNumber_InPlaceOr(newfree, allfree);
if (!temp)
goto error;
Py_DECREF(temp);

/* Check if any local variables must be converted to cell variables */
if (ste->ste_type == FunctionBlock && !analyze_cells(scopes, newfree))
if (ste->ste_type == FunctionBlock && !analyze_cells(scopes, allfree))
goto error;
else if (ste->ste_type == ClassBlock && !drop_class_free(ste, newfree))
else if (ste->ste_type == ClassBlock && !drop_class_free(ste, allfree))
goto error;
/* Records the results of the analysis in the symbol table entry */
if (!update_symbols(ste->ste_symbols, scopes, bound, newfree,
if (!update_symbols(ste->ste_symbols, scopes, bound, allfree,
ste->ste_type == ClassBlock))
goto error;

temp = PyNumber_InPlaceOr(free, newfree);
temp = PyNumber_InPlaceOr(free, allfree);
if (!temp)
goto error;
Py_DECREF(temp);
Expand All @@ -872,15 +864,14 @@ analyze_block(PySTEntryObject *ste, PyObject *bound, PyObject *free,
Py_XDECREF(local);
Py_XDECREF(newbound);
Py_XDECREF(newglobal);
Py_XDECREF(newfree);
Py_XDECREF(allfree);
if (!success)
assert(PyErr_Occurred());
return success;
}

static int
analyze_child_block(PySTEntryObject *entry, PyObject *bound, PyObject *free,
analyze_child_block(PySTEntryObject *entry, PyObject *bound,
PyObject *global, PyObject* child_free)
{
PyObject *temp_bound = NULL, *temp_global = NULL, *temp_free = NULL;
Expand All @@ -896,7 +887,7 @@ analyze_child_block(PySTEntryObject *entry, PyObject *bound, PyObject *free,
temp_bound = PySet_New(bound);
if (!temp_bound)
goto error;
temp_free = PySet_New(free);
temp_free = PySet_New(NULL);
if (!temp_free)
goto error;
temp_global = PySet_New(global);
Expand Down