From 1430b89e396fe941e7dd5c02924e3b54b97de5a3 Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Fri, 1 Sep 2017 09:33:57 +0200 Subject: [PATCH] Update pybind11 to version 2.2.0 - Replace PYBIND11_PLUGIN with PYBIND11_MODULE - Fix warnings about symbol visibility by replacing 'namespace pybind11' with 'namespace PYBIND11_NAMESPACE' - Pybind sets the default visibility of its namespace to 'hidden' Thus, our export functions like ExportCSG(py::module &m) also are hidden by default. To work around that define DLL_HEADER '__attribute__ ((visibility ("default"))) on GNUC platforms. --- external_dependencies/pybind11 | 2 +- libsrc/csg/python_csg.cpp | 4 +--- libsrc/csg/vscsg.cpp | 4 +--- libsrc/general/ngpython.hpp | 3 ++- libsrc/geom2d/python_geom2d.cpp | 4 +--- libsrc/include/mydefs.hpp | 6 +++++- libsrc/include/nginterface.h | 6 +++++- libsrc/meshing/python_mesh.cpp | 4 +--- libsrc/occ/python_occ.cpp | 4 +--- libsrc/stlgeom/python_stl.cpp | 6 +----- libsrc/stlgeom/vsstl.cpp | 6 +----- ng/netgenpy.cpp | 4 +--- 12 files changed, 21 insertions(+), 32 deletions(-) diff --git a/external_dependencies/pybind11 b/external_dependencies/pybind11 index fe0cf8b7..2a5a5ec0 160000 --- a/external_dependencies/pybind11 +++ b/external_dependencies/pybind11 @@ -1 +1 @@ -Subproject commit fe0cf8b73b8e068c205e062c779eb694b194d6b4 +Subproject commit 2a5a5ec0a47c245fbf1bb1a8a90b4c3278e01693 diff --git a/libsrc/csg/python_csg.cpp b/libsrc/csg/python_csg.cpp index 41bb7376..c63d700d 100644 --- a/libsrc/csg/python_csg.cpp +++ b/libsrc/csg/python_csg.cpp @@ -619,10 +619,8 @@ DLL_HEADER void ExportCSG(py::module &m) ; } -PYBIND11_PLUGIN(libcsg) { - py::module m("csg", "pybind csg"); +PYBIND11_MODULE(libcsg, m) { ExportCSG(m); - return m.ptr(); } #endif diff --git a/libsrc/csg/vscsg.cpp b/libsrc/csg/vscsg.cpp index 8fab26bd..f28a49bc 100644 --- a/libsrc/csg/vscsg.cpp +++ b/libsrc/csg/vscsg.cpp @@ -527,10 +527,8 @@ DLL_HEADER void ExportCSGVis(py::module &m) }); } -PYBIND11_PLUGIN(libcsgvis) { - py::module m("csg", "pybind csg"); +PYBIND11_MODULE(libcsgvis, m) { ExportCSGVis(m); - return m.ptr(); } #endif diff --git a/libsrc/general/ngpython.hpp b/libsrc/general/ngpython.hpp index 7c2d98a5..e0980d85 100644 --- a/libsrc/general/ngpython.hpp +++ b/libsrc/general/ngpython.hpp @@ -6,7 +6,8 @@ namespace py = pybind11; #include #include -namespace pybind11 { + +namespace PYBIND11_NAMESPACE { template bool CheckCast( py::handle obj ) { try{ diff --git a/libsrc/geom2d/python_geom2d.cpp b/libsrc/geom2d/python_geom2d.cpp index 6dbca157..f67de52e 100644 --- a/libsrc/geom2d/python_geom2d.cpp +++ b/libsrc/geom2d/python_geom2d.cpp @@ -265,10 +265,8 @@ DLL_HEADER void ExportGeom2d(py::module &m) } -PYBIND11_PLUGIN(libgeom2d) { - py::module m("geom2d", "pybind geom2d"); +PYBIND11_MODULE(libgeom2d, m) { ExportGeom2d(m); - return m.ptr(); } #endif diff --git a/libsrc/include/mydefs.hpp b/libsrc/include/mydefs.hpp index 794e6521..694dc97c 100644 --- a/libsrc/include/mydefs.hpp +++ b/libsrc/include/mydefs.hpp @@ -21,7 +21,11 @@ #define DLL_HEADER __declspec(dllimport) #endif #else - #define DLL_HEADER + #if __GNUC__ >= 4 + #define DLL_HEADER __attribute__ ((visibility ("default"))) + #else + #define DLL_HEADER + #endif #endif diff --git a/libsrc/include/nginterface.h b/libsrc/include/nginterface.h index a76ebe1d..4bce5914 100644 --- a/libsrc/include/nginterface.h +++ b/libsrc/include/nginterface.h @@ -23,7 +23,11 @@ #define DLL_HEADER __declspec(dllimport) #endif #else - #define DLL_HEADER + #if __GNUC__ >= 4 + #define DLL_HEADER __attribute__ ((visibility ("default"))) + #else + #define DLL_HEADER + #endif #endif diff --git a/libsrc/meshing/python_mesh.cpp b/libsrc/meshing/python_mesh.cpp index 5db83ed1..8542c87e 100644 --- a/libsrc/meshing/python_mesh.cpp +++ b/libsrc/meshing/python_mesh.cpp @@ -816,10 +816,8 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m) })); } -PYBIND11_PLUGIN(libmesh) { - py::module m("mesh", "pybind mesh"); +PYBIND11_MODULE(libmesh, m) { ExportNetgenMeshing(m); - return m.ptr(); } #endif diff --git a/libsrc/occ/python_occ.cpp b/libsrc/occ/python_occ.cpp index 0cb2454a..186970b7 100644 --- a/libsrc/occ/python_occ.cpp +++ b/libsrc/occ/python_occ.cpp @@ -46,10 +46,8 @@ DLL_HEADER void ExportNgOCC(py::module &m) ; } -PYBIND11_PLUGIN(libNgOCC) { - py::module m("NgOCC", "pybind NgOCC"); +PYBIND11_MODULE(libNgOCC, m) { ExportNgOCC(m); - return m.ptr(); } #endif // OCCGEOMETRY diff --git a/libsrc/stlgeom/python_stl.cpp b/libsrc/stlgeom/python_stl.cpp index 1220f133..37d3e1fc 100644 --- a/libsrc/stlgeom/python_stl.cpp +++ b/libsrc/stlgeom/python_stl.cpp @@ -6,8 +6,6 @@ #ifdef WIN32 #define DLL_HEADER __declspec(dllexport) -#else - #define DLL_HEADER #endif using namespace netgen; @@ -47,10 +45,8 @@ DLL_HEADER void ExportSTL(py::module & m) ; } -PYBIND11_PLUGIN(libstl) { - py::module m("stl", "pybind stl"); +PYBIND11_MODULE(libstl, m) { ExportSTL(m); - return m.ptr(); } #endif diff --git a/libsrc/stlgeom/vsstl.cpp b/libsrc/stlgeom/vsstl.cpp index 6e550b0f..ca1f2cbf 100644 --- a/libsrc/stlgeom/vsstl.cpp +++ b/libsrc/stlgeom/vsstl.cpp @@ -1218,8 +1218,6 @@ void VisualSceneSTLMeshing :: MouseDblClick (int px, int py) #ifdef WIN32 #define DLL_HEADER __declspec(dllexport) -#else - #define DLL_HEADER #endif #include <../general/ngpython.hpp> @@ -1245,9 +1243,7 @@ DLL_HEADER void ExportSTLVis(py::module &m) }); } -PYBIND11_PLUGIN(libstlvis) { - py::module m("stlvis", "pybind stl vis"); +PYBIND11_MODULE(libstlvis, m) { ExportSTLVis(m); - return m.ptr(); } #endif diff --git a/ng/netgenpy.cpp b/ng/netgenpy.cpp index 6cbeba60..a4e7a8d1 100644 --- a/ng/netgenpy.cpp +++ b/ng/netgenpy.cpp @@ -21,9 +21,8 @@ void DLL_HEADER ExportSTLVis(py::module &m); void DLL_HEADER ExportNgOCC(py::module &m); #endif // OCCGEOMETRY -PYBIND11_PLUGIN(libngpy) +PYBIND11_MODULE(libngpy, ngpy) { - py::module ngpy("libngpy", "pybind netgen module"); py::module meshing = ngpy.def_submodule("_meshing", "pybind meshing module"); ExportNetgenMeshing(meshing); py::module csg = ngpy.def_submodule("_csg", "pybind csg module"); @@ -44,7 +43,6 @@ PYBIND11_PLUGIN(libngpy) py::module stlvis = ngpy.def_submodule("stlvis", "pybind stlvis module"); ExportSTLVis(stlvis); #endif // OPENGL - return ngpy.ptr(); } // Force linking libnglib to libnetgenpy