Skip to content

Commit ef987c1

Browse files
authored
Merge pull request #216 from fredroy/fix_pybind_2_8_1
Fix for pybind version >= 2.8.1
2 parents 1c66fc5 + 290ed24 commit ef987c1

File tree

7 files changed

+20
-13
lines changed

7 files changed

+20
-13
lines changed

Plugin/src/SofaPython3/PythonFactory.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ using sofa::core::objectmodel::Event;
5757

5858
#include <sofa/defaulttype/DataTypeInfo.h>
5959

60-
/// Bind the python's attribute error
61-
namespace pybind11 { PYBIND11_RUNTIME_EXCEPTION(attribute_error, PyExc_AttributeError) }
60+
SOFAPYTHON3_BIND_ATTRIBUTE_ERROR()
61+
6262
/// Makes an alias for the pybind11 namespace to increase readability.
6363
namespace py { using namespace pybind11; }
6464

Plugin/src/SofaPython3/config.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,12 @@
3737
#define SOFAPYTHON3_API PYBIND11_EXPORT
3838
#else
3939
#define SOFAPYTHON3_API SOFA_IMPORT_DYNAMIC_LIBRARY
40-
#endif
40+
#endif
41+
42+
// pybind11 already bind the attributeError starting from 2.8.1 version.
43+
// so if the version is >= 2.8.1, macro does nothing, otherwise bind attribute_error
44+
#if not(PYBIND11_VERSION_MAJOR >= 2 && PYBIND11_VERSION_MINOR >= 8 && PYBIND11_VERSION_PATCH >= 1)
45+
#define SOFAPYTHON3_BIND_ATTRIBUTE_ERROR() namespace pybind11 { PYBIND11_RUNTIME_EXCEPTION(attribute_error, PyExc_AttributeError) }
46+
#else
47+
#define SOFAPYTHON3_BIND_ATTRIBUTE_ERROR()
48+
#endif // not(PYBIND11_VERSION >= 2.8.1)

bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_Base.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ using sofa::simulation::Node;
4343

4444
#include <SofaPython3/DataHelper.h>
4545

46-
/// Bind the python's attribute error
47-
namespace pybind11 { PYBIND11_RUNTIME_EXCEPTION(attribute_error, PyExc_AttributeError) }
46+
SOFAPYTHON3_BIND_ATTRIBUTE_ERROR()
4847

4948
/// Makes an alias for the pybind11 namespace to increase readability.
5049
namespace py { using namespace pybind11; }

bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_BaseData.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
#include <SofaPython3/DataHelper.h>
3434
#include <SofaPython3/PythonFactory.h>
3535

36-
/// Bind the python's attribute error
37-
namespace pybind11 { PYBIND11_RUNTIME_EXCEPTION(attribute_error, PyExc_AttributeError) }
36+
SOFAPYTHON3_BIND_ATTRIBUTE_ERROR()
37+
3838
/// Makes an alias for the pybind11 namespace to increase readability.
3939
namespace py { using namespace pybind11; }
4040

bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_Controller.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
#include <SofaPython3/PythonFactory.h>
2929
#include <SofaPython3/PythonEnvironment.h>
3030

31-
/// Bind the python's attribute error
32-
namespace pybind11 { PYBIND11_RUNTIME_EXCEPTION(attribute_error, PyExc_AttributeError) }
31+
SOFAPYTHON3_BIND_ATTRIBUTE_ERROR()
32+
3333
/// Makes an alias for the pybind11 namespace to increase readability.
3434
namespace py { using namespace pybind11; }
3535

bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_DataEngine.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ using sofapython3::PythonEnvironment;
2727

2828
#include <pybind11/pybind11.h>
2929

30-
/// Bind the python's attribute error
31-
namespace pybind11 { PYBIND11_RUNTIME_EXCEPTION(attribute_error, PyExc_AttributeError) }
30+
SOFAPYTHON3_BIND_ATTRIBUTE_ERROR()
31+
3232
/// Makes an alias for the pybind11 namespace to increase readability.
3333
namespace py { using namespace pybind11; }
3434

bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_Prefab.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ using sofa::simulation::VisualInitVisitor;
3636
using sofa::simulation::Simulation;
3737

3838

39-
/// Bind the python's attribute error
40-
namespace pybind11 { PYBIND11_RUNTIME_EXCEPTION(attribute_error, PyExc_AttributeError) }
39+
SOFAPYTHON3_BIND_ATTRIBUTE_ERROR()
40+
4141
/// Makes an alias for the pybind11 namespace to increase readability.
4242
namespace py { using namespace pybind11; }
4343
/// To bring in the `_a` literal

0 commit comments

Comments
 (0)