Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita8e93d3

Browse files
authored
gh-115756: make PyCode_GetFirstFree an unstable API (GH-115781)
1 parenta3cf0fa commita8e93d3

File tree

8 files changed

+23
-6
lines changed

8 files changed

+23
-6
lines changed

‎Doc/c-api/code.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,16 @@ bound into a function.
3434
3535
Return the number of free variables in a code object.
3636
37-
..c:function::intPyCode_GetFirstFree(PyCodeObject *co)
37+
..c:function::intPyUnstable_Code_GetFirstFree(PyCodeObject *co)
3838
3939
Return the position of the first free variable in a code object.
4040
41+
..versionchanged::3.13
42+
43+
Renamed from ``PyCode_GetFirstFree`` as part of:ref:`unstable-c-api`.
44+
The old name is deprecated, but will remain available until the
45+
signature changes again.
46+
4147
..c:function:: PyCodeObject*PyUnstable_Code_New(int argcount, int kwonlyargcount, int nlocals, int stacksize, int flags, PyObject *code, PyObject *consts, PyObject *names, PyObject *varnames, PyObject *freevars, PyObject *cellvars, PyObject *filename, PyObject *name, PyObject *qualname, int firstlineno, PyObject *linetable, PyObject *exceptiontable)
4248
4349
Return a new code object. If you need a dummy code object to create a frame,

‎Doc/whatsnew/3.13.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,6 +1471,10 @@ Changes in the Python API
14711471
than directories only. Users may add a trailing slash to match only
14721472
directories.
14731473

1474+
*:c:func:`!PyCode_GetFirstFree` is an ustable API now and has been renamed
1475+
to:c:func:`PyUnstable_Code_GetFirstFree`.
1476+
(Contributed by Bogdan Romanyuk in:gh:`115781`)
1477+
14741478

14751479
Build Changes
14761480
=============

‎Include/cpython/code.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,15 @@ static inline Py_ssize_t PyCode_GetNumFree(PyCodeObject *op) {
226226
returnop->co_nfreevars;
227227
}
228228

229-
staticinlineintPyCode_GetFirstFree(PyCodeObject*op) {
229+
staticinlineintPyUnstable_Code_GetFirstFree(PyCodeObject*op) {
230230
assert(PyCode_Check(op));
231231
returnop->co_nlocalsplus-op->co_nfreevars;
232232
}
233233

234+
Py_DEPRECATED(3.13)staticinlineintPyCode_GetFirstFree(PyCodeObject*op) {
235+
returnPyUnstable_Code_GetFirstFree(op);
236+
}
237+
234238
#define_PyCode_CODE(CO) _Py_RVALUE((_Py_CODEUNIT *)(CO)->co_code_adaptive)
235239
#define_PyCode_NBYTES(CO) (Py_SIZE(CO) * (Py_ssize_t)sizeof(_Py_CODEUNIT))
236240

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:c:func:`!PyCode_GetFirstFree` is an ustable API now and has been renamed to
2+
:c:func:`PyUnstable_Code_GetFirstFree`. (Contributed by Bogdan Romanyuk in
3+
:gh:`115781`)

‎Objects/frameobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1140,7 +1140,7 @@ frame_init_get_vars(_PyInterpreterFrame *frame)
11401140

11411141
/* Free vars have not been initialized -- Do that */
11421142
PyObject*closure= ((PyFunctionObject*)frame->f_funcobj)->func_closure;
1143-
intoffset=PyCode_GetFirstFree(co);
1143+
intoffset=PyUnstable_Code_GetFirstFree(co);
11441144
for (inti=0;i<co->co_nfreevars;++i) {
11451145
PyObject*o=PyTuple_GET_ITEM(closure,i);
11461146
frame->localsplus[offset+i]=Py_NewRef(o);

‎Objects/typeobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10884,7 +10884,7 @@ super_init_without_args(_PyInterpreterFrame *cframe, PyCodeObject *co,
1088410884

1088510885
// Look for __class__ in the free vars.
1088610886
PyTypeObject*type=NULL;
10887-
inti=PyCode_GetFirstFree(co);
10887+
inti=PyUnstable_Code_GetFirstFree(co);
1088810888
for (;i<co->co_nlocalsplus;i++) {
1088910889
assert((_PyLocals_GetKind(co->co_localspluskinds,i)&CO_FAST_FREE)!=0);
1089010890
PyObject*name=PyTuple_GET_ITEM(co->co_localsplusnames,i);

‎Python/ceval.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2903,7 +2903,7 @@ _PyEval_FormatExcUnbound(PyThreadState *tstate, PyCodeObject *co, int oparg)
29032903
if (_PyErr_Occurred(tstate))
29042904
return;
29052905
name=PyTuple_GET_ITEM(co->co_localsplusnames,oparg);
2906-
if (oparg<PyCode_GetFirstFree(co)) {
2906+
if (oparg<PyUnstable_Code_GetFirstFree(co)) {
29072907
_PyEval_FormatExcCheckArg(tstate,PyExc_UnboundLocalError,
29082908
UNBOUNDLOCAL_ERROR_MSG,name);
29092909
}else {

‎Python/compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1830,7 +1830,7 @@ compiler_make_closure(struct compiler *c, location loc,
18301830
PyCodeObject*co,Py_ssize_tflags)
18311831
{
18321832
if (co->co_nfreevars) {
1833-
inti=PyCode_GetFirstFree(co);
1833+
inti=PyUnstable_Code_GetFirstFree(co);
18341834
for (;i<co->co_nlocalsplus;++i) {
18351835
/* Bypass com_addop_varname because it will generate
18361836
LOAD_DEREF but LOAD_CLOSURE is needed.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp