mirror of
https://github.com/pybind/pybind11.git
synced 2026-06-08 15:29:45 +00:00
fix: improve support for Python 3.11-dev (#3368)
* ci: support Python 3.11-dev Also update 3.10 to final, better PyPy usage * fix: use PyFrame_GetCode on Python 3.9+ * ci: some bitiness of pypy not supported on win * chore: update CMake support to 3.22rc1 to quiet warning * fix: use dev version of py to fix Py 3.11 * tests: print proper Eigen version * ci: include pypy2, not sure why * ci: avoid running on Python 3.11 for now * ci: fix runs * ci: simpler PyPy usage, drop unmaintained scipy + pypy index * ci: only binary numpy, wait on pypy 3.8 * refactor: address review
This commit is contained in:
@@ -468,12 +468,19 @@ PYBIND11_NOINLINE std::string error_string() {
|
||||
PyFrameObject *frame = trace->tb_frame;
|
||||
errorString += "\n\nAt:\n";
|
||||
while (frame) {
|
||||
#if PY_VERSION_HEX >= 0x03090000
|
||||
PyCodeObject *f_code = PyFrame_GetCode(frame);
|
||||
#else
|
||||
PyCodeObject *f_code = frame->f_code;
|
||||
Py_INCREF(f_code);
|
||||
#endif
|
||||
int lineno = PyFrame_GetLineNumber(frame);
|
||||
errorString +=
|
||||
" " + handle(frame->f_code->co_filename).cast<std::string>() +
|
||||
" " + handle(f_code->co_filename).cast<std::string>() +
|
||||
"(" + std::to_string(lineno) + "): " +
|
||||
handle(frame->f_code->co_name).cast<std::string>() + "\n";
|
||||
handle(f_code->co_name).cast<std::string>() + "\n";
|
||||
frame = frame->f_back;
|
||||
Py_DECREF(f_code);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -2335,6 +2335,29 @@ inline function get_type_override(const void *this_ptr, const type_info *this_ty
|
||||
/* Don't call dispatch code if invoked from overridden function.
|
||||
Unfortunately this doesn't work on PyPy. */
|
||||
#if !defined(PYPY_VERSION)
|
||||
|
||||
#if PY_VERSION_HEX >= 0x03090000
|
||||
PyFrameObject *frame = PyThreadState_GetFrame(PyThreadState_Get());
|
||||
if (frame != nullptr) {
|
||||
PyCodeObject *f_code = PyFrame_GetCode(frame);
|
||||
// f_code is guaranteed to not be NULL
|
||||
if ((std::string) str(f_code->co_name) == name && f_code->co_argcount > 0) {
|
||||
PyObject* locals = PyEval_GetLocals();
|
||||
if (locals != nullptr) {
|
||||
PyObject *self_caller = dict_getitem(
|
||||
locals, PyTuple_GET_ITEM(f_code->co_varnames, 0)
|
||||
);
|
||||
if (self_caller == self.ptr()) {
|
||||
Py_DECREF(f_code);
|
||||
Py_DECREF(frame);
|
||||
return function();
|
||||
}
|
||||
}
|
||||
}
|
||||
Py_DECREF(f_code);
|
||||
Py_DECREF(frame);
|
||||
}
|
||||
#else
|
||||
PyFrameObject *frame = PyThreadState_Get()->frame;
|
||||
if (frame != nullptr && (std::string) str(frame->f_code->co_name) == name
|
||||
&& frame->f_code->co_argcount > 0) {
|
||||
@@ -2344,6 +2367,8 @@ inline function get_type_override(const void *this_ptr, const type_info *this_ty
|
||||
if (self_caller == self.ptr())
|
||||
return function();
|
||||
}
|
||||
#endif
|
||||
|
||||
#else
|
||||
/* PyPy currently doesn't provide a detailed cpyext emulation of
|
||||
frame objects, so we have to emulate this using Python. This
|
||||
|
||||
Reference in New Issue
Block a user