Skip to content

Commit 195a1ec

Browse files
Pass tstate to _PyCode_SetUnboundVarCounts().
1 parent ddbe9bc commit 195a1ec

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

Include/internal/pycore_code.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,7 @@ PyAPI_FUNC(void) _PyCode_GetVarCounts(
607607
PyCodeObject *,
608608
_PyCode_var_counts_t *);
609609
PyAPI_FUNC(int) _PyCode_SetUnboundVarCounts(
610+
PyThreadState *,
610611
PyCodeObject *,
611612
_PyCode_var_counts_t *,
612613
PyObject *globalnames,

Modules/_testinternalcapi.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,7 @@ get_co_localskinds(PyObject *self, PyObject *arg)
10021002
static PyObject *
10031003
get_code_var_counts(PyObject *self, PyObject *_args, PyObject *_kwargs)
10041004
{
1005+
PyThreadState *tstate = _PyThreadState_GET();
10051006
PyObject *codearg;
10061007
PyObject *globalnames = NULL;
10071008
PyObject *attrnames = NULL;
@@ -1035,7 +1036,8 @@ get_code_var_counts(PyObject *self, PyObject *_args, PyObject *_kwargs)
10351036
_PyCode_var_counts_t counts = {0};
10361037
_PyCode_GetVarCounts(code, &counts);
10371038
if (_PyCode_SetUnboundVarCounts(
1038-
code, &counts, globalnames, attrnames, globalsns, builtinsns) < 0)
1039+
tstate, code, &counts, globalnames, attrnames,
1040+
globalsns, builtinsns) < 0)
10391041
{
10401042
return NULL;
10411043
}

Objects/codeobject.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,7 +1691,7 @@ PyCode_GetFreevars(PyCodeObject *code)
16911691

16921692

16931693
static int
1694-
identify_unbound_names(PyCodeObject *co,
1694+
identify_unbound_names(PyThreadState *tstate, PyCodeObject *co,
16951695
PyObject *globalnames, PyObject *attrnames,
16961696
PyObject *globalsns, PyObject *builtinsns,
16971697
struct co_unbound_counts *counts)
@@ -1715,7 +1715,7 @@ identify_unbound_names(PyCodeObject *co,
17151715
PyObject *name = PyTuple_GET_ITEM(co->co_names, inst.op.arg>>1);
17161716
if (counts != NULL) {
17171717
if (PySet_Contains(attrnames, name)) {
1718-
if (PyErr_Occurred()) {
1718+
if (_PyErr_Occurred(tstate)) {
17191719
return -1;
17201720
}
17211721
continue;
@@ -1731,7 +1731,7 @@ identify_unbound_names(PyCodeObject *co,
17311731
PyObject *name = PyTuple_GET_ITEM(co->co_names, inst.op.arg>>1);
17321732
if (counts != NULL) {
17331733
if (PySet_Contains(globalnames, name)) {
1734-
if (PyErr_Occurred()) {
1734+
if (_PyErr_Occurred(tstate)) {
17351735
return -1;
17361736
}
17371737
continue;
@@ -1740,14 +1740,14 @@ identify_unbound_names(PyCodeObject *co,
17401740
counts->globals.total += 1;
17411741
counts->globals.numunknown += 1;
17421742
if (globalsns != NULL && PyDict_Contains(globalsns, name)) {
1743-
if (PyErr_Occurred()) {
1743+
if (_PyErr_Occurred(tstate)) {
17441744
return -1;
17451745
}
17461746
counts->globals.numglobal += 1;
17471747
counts->globals.numunknown -= 1;
17481748
}
17491749
if (builtinsns != NULL && PyDict_Contains(builtinsns, name)) {
1750-
if (PyErr_Occurred()) {
1750+
if (_PyErr_Occurred(tstate)) {
17511751
return -1;
17521752
}
17531753
counts->globals.numbuiltin += 1;
@@ -1866,7 +1866,8 @@ _PyCode_GetVarCounts(PyCodeObject *co, _PyCode_var_counts_t *counts)
18661866
}
18671867

18681868
int
1869-
_PyCode_SetUnboundVarCounts(PyCodeObject *co, _PyCode_var_counts_t *counts,
1869+
_PyCode_SetUnboundVarCounts(PyThreadState *tstate,
1870+
PyCodeObject *co, _PyCode_var_counts_t *counts,
18701871
PyObject *globalnames, PyObject *attrnames,
18711872
PyObject *globalsns, PyObject *builtinsns)
18721873
{
@@ -1881,7 +1882,7 @@ _PyCode_SetUnboundVarCounts(PyCodeObject *co, _PyCode_var_counts_t *counts,
18811882
globalnames = globalnames_owned;
18821883
}
18831884
else if (!PySet_Check(globalnames)) {
1884-
PyErr_Format(PyExc_TypeError,
1885+
_PyErr_Format(tstate, PyExc_TypeError,
18851886
"expected a set for \"globalnames\", got %R", globalnames);
18861887
goto finally;
18871888
}
@@ -1893,14 +1894,15 @@ _PyCode_SetUnboundVarCounts(PyCodeObject *co, _PyCode_var_counts_t *counts,
18931894
attrnames = attrnames_owned;
18941895
}
18951896
else if (!PySet_Check(attrnames)) {
1896-
PyErr_Format(PyExc_TypeError,
1897+
_PyErr_Format(tstate, PyExc_TypeError,
18971898
"expected a set for \"attrnames\", got %R", attrnames);
18981899
goto finally;
18991900
}
19001901

19011902
struct co_unbound_counts unbound = {0};
19021903
if (identify_unbound_names(
1903-
co, globalnames, attrnames, globalsns, builtinsns, &unbound) < 0)
1904+
tstate, co, globalnames, attrnames, globalsns, builtinsns,
1905+
&unbound) < 0)
19041906
{
19051907
goto finally;
19061908
}

0 commit comments

Comments
 (0)