Skip to content

Commit e9ce7b0

Browse files
committed
golang: Fix XPyFrame_WhiteoutFastLocal for py3.14
Problem 1: golang/_golang.cpp: In function ‘void XPyFrame_WhiteoutFastLocal(PyFrameObject*, PyObject*)’: golang/_golang.cpp:1572:43: error: invalid use of incomplete type ‘_PyInterpreterFrame’ {aka ‘struct _PyInterpreterFrame’} 1572 | f->f_frame->localsplus; | ^~ In file included from /home/kirr/local/py3.14/include/python3.14/pyframe.h:19, from /home/kirr/local/py3.14/include/python3.14/Python.h:113, from golang/_golang.cpp:150: /home/kirr/local/py3.14/include/python3.14/cpython/pyframe.h:25:8: note: forward declaration of ‘_PyInterpreterFrame’ {aka ‘struct _PyInterpreterFrame’} 25 | struct _PyInterpreterFrame; | ^~~~~~~~~~~~~~~~~~~ -> include internal/pycore_interpframe.h like we already do with e.g. internal/pycore_frame.h . Problem 2: golang/_golang.cpp: In function ‘void XPyFrame_WhiteoutFastLocal(PyFrameObject*, PyObject*)’: golang/_golang.cpp:1575:45: error: cannot convert ‘_PyStackRef*’ to ‘PyObject**’ {aka ‘_object**’} in initialization 1575 | f->f_frame->localsplus; | ~~~~~~~~~~~~^~~~~~~~~~ | | | _PyStackRef* It turns out _PyInterpreterFrame.localsplus was changed from PyObject to _PyStackRef: python/cpython@22b0de2755ee2 python/cpython#118450 python/cpython#117139 -> Adjust the code to work with localsplus as _PyStackRef on py3.14+ . /reviewed-by @jerome /reviewed-on https://lab.nexedi.com/nexedi/pygolang/-/merge_requests/39
1 parent ffa1fb8 commit e9ce7b0

1 file changed

Lines changed: 25 additions & 4 deletions

File tree

‎golang/_golang.pyx‎

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# distutils: language = c++
77
# distutils: depends = libgolang.h os/signal.h unicode/utf8.h _golang_str.pyx _golang_str_pickle.pyx
88
#
9-
# Copyright (C) 2018-2025 Nexedi SA and Contributors.
9+
# Copyright (C) 2018-2026 Nexedi SA and Contributors.
1010
# Kirill Smelkov <kirr@nexedi.com>
1111
#
1212
# This program is free software: you can Use, Study, Modify and Redistribute
@@ -964,6 +964,9 @@ cdef extern from "frameobject.h":
964964
# endif
965965
# include "internal/pycore_frame.h"
966966
# include "internal/pycore_code.h"
967+
# if PY_VERSION_HEX >= 0x030E0000 // 3.14
968+
# include "internal/pycore_interpframe.h"
969+
# endif
967970
#endif
968971
969972
#if PY_VERSION_HEX < 0x030B0000 // 3.11
@@ -1020,11 +1023,16 @@ cdef extern from "frameobject.h":
10201023
static void XPyFrame_WhiteoutFastLocal(PyFrameObject* f, PyObject* name) {
10211024
if (!PyFrame_Check(f))
10221025
panic("XPyFrame_WhiteoutFastLocal: invoked on non-frame object");
1023-
PyObject** fastlocals =
1024-
#if PY_VERSION_HEX >= 0x030B0000 // 3.11
1026+
#if PY_VERSION_HEX >= 0x030E0000 // 3.14
1027+
_PyStackRef* fastlocals =
10251028
f->f_frame->localsplus;
10261029
#else
1030+
PyObject** fastlocals =
1031+
# if PY_VERSION_HEX >= 0x030B0000 // 3.11
1032+
f->f_frame->localsplus;
1033+
# else
10271034
f->f_localsplus;
1035+
# endif
10281036
#endif
10291037
10301038
PyCodeObject* f_code = PyFrame_GetCode(f);
@@ -1053,9 +1061,17 @@ cdef extern from "frameobject.h":
10531061
continue;
10541062
10551063
_PyLocals_Kind kind = _XPyCode_FastLocalKind(f_code, i);
1056-
PyObject* v = fastlocals[i];
1064+
PyObject* v = NULL;
10571065
PyObject* cell = NULL;
1066+
#if PY_VERSION_HEX < 0x030E0000 // 3.14
1067+
v = fastlocals[i];
1068+
#endif
10581069
if (kind & (CO_FAST_FREE | CO_FAST_CELL)) {
1070+
#if PY_VERSION_HEX >= 0x030E0000 // 3.14
1071+
_PyStackRef vstk = fastlocals[i];
1072+
if (!PyStackRef_IsNull(vstk))
1073+
v = PyStackRef_AsPyObjectBorrow(vstk);
1074+
#endif
10591075
if (v != NULL && PyCell_Check(v))
10601076
cell = v;
10611077
}
@@ -1064,7 +1080,12 @@ cdef extern from "frameobject.h":
10641080
PyCell_SET(cell, NULL);
10651081
}
10661082
else {
1083+
#if PY_VERSION_HEX >= 0x030E0000 // 3.14
1084+
PyStackRef_CLEAR(fastlocals[i]);
1085+
v = NULL;
1086+
#else
10671087
fastlocals[i] = NULL;
1088+
#endif
10681089
}
10691090
Py_XDECREF(v);
10701091

0 commit comments

Comments
 (0)