Skip to content

Commit

Permalink
refactor: address review
Browse files Browse the repository at this point in the history
  • Loading branch information
henryiii committed Oct 26, 2021
1 parent b04f4cd commit 7f1fa8c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
13 changes: 6 additions & 7 deletions include/pybind11/detail/type_caster_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -469,19 +469,18 @@ PYBIND11_NOINLINE std::string error_string() {
errorString += "\n\nAt:\n";
while (frame) {
#if PY_VERSION_HEX >= 0x03090000
PyCodeObject *code = PyFrame_GetCode(frame);
PyCodeObject *f_code = PyFrame_GetCode(frame);
#else
PyCodeObject *code = frame->f_code;
PyCodeObject *f_code = frame->f_code;
Py_INCREF(f_code);
#endif
int lineno = PyFrame_GetLineNumber(frame);
errorString +=
" " + handle(code->co_filename).cast<std::string>() +
" " + handle(f_code->co_filename).cast<std::string>() +
"(" + std::to_string(lineno) + "): " +
handle(code->co_name).cast<std::string>() + "\n";
handle(f_code->co_name).cast<std::string>() + "\n";
frame = frame->f_back;
#if PY_VERSION_HEX >= 0x03090000
Py_DECREF(code);
#endif
Py_DECREF(f_code);
}
}
#endif
Expand Down
11 changes: 6 additions & 5 deletions include/pybind11/pybind11.h
Original file line number Diff line number Diff line change
Expand Up @@ -2339,21 +2339,22 @@ inline function get_type_override(const void *this_ptr, const type_info *this_ty
#if PY_VERSION_HEX >= 0x03090000
PyFrameObject *frame = PyThreadState_GetFrame(PyThreadState_Get());
if (frame != nullptr) {
PyCodeObject *code = PyFrame_GetCode(frame);
if ((std::string) str(code->co_name) == name && code->co_argcount > 0) {
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(code->co_varnames, 0)
locals, PyTuple_GET_ITEM(f_code->co_varnames, 0)
);
if (self_caller == self.ptr()) {
Py_DECREF(code);
Py_DECREF(f_code);
Py_DECREF(frame);
return function();
}
}
}
Py_DECREF(code);
Py_DECREF(f_code);
Py_DECREF(frame);
}
#else
Expand Down
21 changes: 12 additions & 9 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,13 @@ set(PYBIND11_EIGEN_REPO
"https://gitlab.com/libeigen/eigen.git"
CACHE STRING "Eigen repository to use for tests")
# Always use a hash for reconfigure speed and security reasons
set(PYBIND11_EIGEN_VERSION
"929bc0e191d0927b1735b9a1ddc0e8b77e3a25ec"
CACHE STRING "Eigen version to use for tests")
# Pretty print the version (keep in sync)
set(PYBIND11_EIGEN_VERSION_STRING
"3.4.0"
CACHE STRING "Eigen version string to use for tests")
# Include the version number for pretty printing (keep in sync)
set(PYBIND11_EIGEN_VERSION_AND_HASH
"3.4.0;929bc0e191d0927b1735b9a1ddc0e8b77e3a25ec"
CACHE STRING "Eigen version to use for tests, format: VERSION;HASH")

list(GET PYBIND11_EIGEN_VERSION_AND_HASH 0 PYBIND11_EIGEN_VERSION_STRING)
list(GET PYBIND11_EIGEN_VERSION_AND_HASH 1 PYBIND11_EIGEN_VERSION_HASH)

# Check if Eigen is available; if not, remove from PYBIND11_TEST_FILES (but
# keep it in PYBIND11_PYTEST_FILES, so that we get the "eigen is not installed"
Expand All @@ -200,11 +200,14 @@ if(PYBIND11_TEST_FILES_EIGEN_I GREATER -1)
FetchContent_Declare(
eigen
GIT_REPOSITORY "${PYBIND11_EIGEN_REPO}"
GIT_TAG "${PYBIND11_EIGEN_VERSION}")
GIT_TAG "${PYBIND11_EIGEN_VERSION_HASH}")

FetchContent_GetProperties(eigen)
if(NOT eigen_POPULATED)
message(STATUS "Downloading Eigen")
message(
STATUS
"Downloading Eigen ${PYBIND11_EIGEN_VERSION_STRING} (${PYBIND11_EIGEN_VERSION_HASH}) from ${PYBIND11_EIGEN_REPO}"
)
FetchContent_Populate(eigen)
endif()

Expand Down

0 comments on commit 7f1fa8c

Please sign in to comment.