Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion example/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[build-system]
requires = [
"scikit-build-core",
"swig<4.4.0",
"swig",
"pybind11",
]
# Use a custom in-tree backend to inject local dependencies.
Expand Down
10 changes: 7 additions & 3 deletions include/swigbind11/swigbind11.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@ inline auto extract_swig_object(py::handle obj, std::string_view type_name) {

// obj is a proxy object generated by SWIG, we need to extract the underlying SWIG object
auto swig_obj = obj.attr("this");
const auto type = py::str(py::type::of(swig_obj)).cast<std::string>();
if (type != "<class 'SwigPyObject'>") {
throw py::cast_error{"expected SWIG-wrapped object, got: " + type};
const std::string type_str = py::str(py::type::of(swig_obj)).cast<std::string>();

// look for "SwigPyObject" in name
// type_str = <class 'SwigPyObject'> (SWIG < 4.4.0)
// type_str = <class 'swig_runtime_data5.SwigPyObject'> (SWIG >= 4.4.0)
if (type_str.find("SwigPyObject") == std::string::npos) {
throw py::cast_error{"expected SWIG-wrapped object, got: " + type_str};
}

return swig_obj;
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[build-system]
requires = ["scikit-build-core",
"swig<4.4.0",
"swig",
"setuptools-scm"
]
build-backend = "scikit_build_core.build"
Expand Down