Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
make PyCode_GetFirstFree an unstable API
  • Loading branch information
wrongnull committed Feb 21, 2024
commit cf33af72173a6dcc6c947afa387e3819a2ff270c
2 changes: 1 addition & 1 deletion Include/cpython/code.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ static inline Py_ssize_t PyCode_GetNumFree(PyCodeObject *op) {
return op->co_nfreevars;
}

static inline int PyCode_GetFirstFree(PyCodeObject *op) {
static inline int PyUnstable_Code_GetFirstFree(PyCodeObject *op) {
assert(PyCode_Check(op));
return op->co_nlocalsplus - op->co_nfreevars;
}
Expand Down
2 changes: 1 addition & 1 deletion Objects/frameobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,7 @@ frame_init_get_vars(_PyInterpreterFrame *frame)

/* Free vars have not been initialized -- Do that */
PyObject *closure = ((PyFunctionObject *)frame->f_funcobj)->func_closure;
int offset = PyCode_GetFirstFree(co);
int offset = PyUnstable_Code_GetFirstFree(co);
for (int i = 0; i < co->co_nfreevars; ++i) {
PyObject *o = PyTuple_GET_ITEM(closure, i);
frame->localsplus[offset + i] = Py_NewRef(o);
Expand Down
2 changes: 1 addition & 1 deletion Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -10814,7 +10814,7 @@ super_init_without_args(_PyInterpreterFrame *cframe, PyCodeObject *co,

// Look for __class__ in the free vars.
PyTypeObject *type = NULL;
int i = PyCode_GetFirstFree(co);
int i = PyUnstable_Code_GetFirstFree(co);
for (; i < co->co_nlocalsplus; i++) {
assert((_PyLocals_GetKind(co->co_localspluskinds, i) & CO_FAST_FREE) != 0);
PyObject *name = PyTuple_GET_ITEM(co->co_localsplusnames, i);
Expand Down
2 changes: 1 addition & 1 deletion Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -2892,7 +2892,7 @@ _PyEval_FormatExcUnbound(PyThreadState *tstate, PyCodeObject *co, int oparg)
if (_PyErr_Occurred(tstate))
return;
name = PyTuple_GET_ITEM(co->co_localsplusnames, oparg);
if (oparg < PyCode_GetFirstFree(co)) {
if (oparg < PyUnstable_Code_GetFirstFree(co)) {
_PyEval_FormatExcCheckArg(tstate, PyExc_UnboundLocalError,
UNBOUNDLOCAL_ERROR_MSG, name);
} else {
Expand Down
2 changes: 1 addition & 1 deletion Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1831,7 +1831,7 @@ compiler_make_closure(struct compiler *c, location loc,
PyCodeObject *co, Py_ssize_t flags)
{
if (co->co_nfreevars) {
int i = PyCode_GetFirstFree(co);
int i = PyUnstable_Code_GetFirstFree(co);
for (; i < co->co_nlocalsplus; ++i) {
/* Bypass com_addop_varname because it will generate
LOAD_DEREF but LOAD_CLOSURE is needed.
Expand Down