Browse Source

fix reference count bug in type caster

python
Jørgen Lien Sellæg 7 years ago committed by Jørgen Sverre Lien Sellæg
parent
commit
c3b4f21735
  1. 2
      CMakeLists.txt
  2. 11
      src/python_type_casters.h

2
CMakeLists.txt

@ -18,7 +18,7 @@ include(CPack)
set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD 14)
add_compile_options(-pthread -Wall -Wextra -Wno-unused-parameter -Wno-deprecated-declarations) add_compile_options(-pthread -Wall -Wextra -Wno-unused-parameter -Wno-deprecated-declarations -fvisibility=hidden)
add_definitions(-DJUCI_VERSION="${JUCI_VERSION}") add_definitions(-DJUCI_VERSION="${JUCI_VERSION}")
if(CMAKE_BUILD_TYPE STREQUAL "") if(CMAKE_BUILD_TYPE STREQUAL "")
add_compile_options(-O3) add_compile_options(-O3)

11
src/python_type_casters.h

@ -9,12 +9,19 @@ namespace pybind11 {
public: public:
PYBIND11_TYPE_CASTER(boost::filesystem::path, _("str")); PYBIND11_TYPE_CASTER(boost::filesystem::path, _("str"));
bool load(handle src, bool) { bool load(handle src, bool) {
value = std::string(pybind11::str(src)); if (!src) {
return false;
}
try {
value = std::string(py::str(src));
} catch(...) {
return false;
}
return !PyErr_Occurred(); return !PyErr_Occurred();
} }
static handle cast(boost::filesystem::path src, return_value_policy, handle) { static handle cast(boost::filesystem::path src, return_value_policy, handle) {
return pybind11::str(src.string()); return pybind11::str(src.string()).release();
} }
}; };
} // namespace detail } // namespace detail

Loading…
Cancel
Save