Salome HOME
Agressive Windows porting V9_8_0 V9_8_0a1 V9_8_0a2 V9_8_0b1 V9_8_0rc1 V9_9_0 V9_9_0a1 V9_9_0a2 V9_9_0b1 V9_9_0rc1 V9_9_0rc2 V9_9_1b1
authorAnthony Geay <anthony.geay@edf.fr>
Mon, 21 Jun 2021 19:39:33 +0000 (21:39 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Mon, 21 Jun 2021 19:39:33 +0000 (21:39 +0200)
src/CMakeLists.txt
src/Errors.hxx
src/PyFunction.hxx
src/PyPtr.hxx
src/Result.hxx
src/TypeConversions.hxx
src/py2cppExports.hxx [new file with mode: 0644]

index 9022030ead67839f011583320459ec4e3f3bb92f..38854a1fcd5cb3444bf72ae61b2a6e37bcef4d47 100644 (file)
@@ -36,6 +36,7 @@ SET(_py2cpp_sources
 )
 
 SET(_py2cpp_headers
+  py2cppExports.hxx
   TypeConversions.hxx
   PyFunction.hxx
   Errors.hxx
index a325820cd0f6a935be6555ce8e7bf50d6fc9de41..840076734abbc922a505e41b93af3752cebe139e 100644 (file)
@@ -19,6 +19,8 @@
 #ifndef PY2CPP_ERRORS_HXX
 #define PY2CPP_ERRORS_HXX
 
+#include "py2cppExports.hxx"
+
 #include <string>
 #include <exception>
 #include <Python.h>
@@ -31,12 +33,12 @@ namespace py2cpp
  * After the call of this function, the python error indicator is cleared.
  * see PyErr_Fetch.
  */
-std::string getLastPyError();
+PY2CPP_EXPORT std::string getLastPyError();
 
 /*!
  * ConversionCheck class gathers the errors within fromPy functions.
  */
-class ConversionCheck
+class PY2CPP_EXPORT ConversionCheck
 {
 public:
   ConversionCheck();
@@ -52,7 +54,7 @@ private:
   std::string _message;
 };
 
-class Exception:public std::exception
+class PY2CPP_EXPORT Exception:public std::exception
 {
 public:
   Exception(const std::string& message);
@@ -61,19 +63,19 @@ private:
   std::string _message;
 };
 
-class ConversionException:public Exception
+class PY2CPP_EXPORT ConversionException:public Exception
 {
 public:
   ConversionException(const std::string& message);
 };
 
-class ExecutionException:public Exception
+class PY2CPP_EXPORT ExecutionException:public Exception
 {
 public:
   ExecutionException(const std::string& message);
 };
 
-class AttributeException:public Exception
+class PY2CPP_EXPORT AttributeException:public Exception
 {
 public:
   AttributeException(const std::string& message);
index b110c24b801cc139af42cf567393b9e9db206542..39a6f128d1f4dceae10a99fb94e765b1c2d50607 100644 (file)
@@ -18,6 +18,8 @@
 //
 #ifndef PY2CPP_FUNCTIONCALLS_HXX
 #define PY2CPP_FUNCTIONCALLS_HXX
+
+#include "py2cppExports.hxx"
 #include <Python.h>
 #include <tuple>
 #include "TypeConversions.hxx"
@@ -25,7 +27,7 @@
 
 namespace py2cpp
 {
-class PyFunction : public PyPtr
+class PY2CPP_EXPORT PyFunction : public PyPtr
 {
 public:
   /*! Load a callable object from a python module.*/
index dad9babc8c6fc5629c166cc722df93f305a118cf..d118d3b7d2fc2a26c51e9762fd933eaad4f8b9a9 100644 (file)
 //
 #ifndef PY2CPP_PYPTR_HXX
 #define PY2CPP_PYPTR_HXX
+#include "py2cppExports.hxx"
 #include <Python.h>
 #include <memory>
 #include <string>
 
 namespace py2cpp
 {
-class PyPtrDeleter
+class PY2CPP_EXPORT PyPtrDeleter
 {
 public:
   void operator()(PyObject * po){Py_DECREF(po);}
@@ -32,7 +33,7 @@ public:
 
 typedef std::unique_ptr<PyObject, PyPtrDeleter> _PyPtr;
 
-class PyPtr: public _PyPtr
+class PY2CPP_EXPORT PyPtr: public _PyPtr
 {
 public:
   PyPtr();
@@ -49,7 +50,7 @@ public:
   std::string repr()const;
 };
 
-class AutoGIL
+class PY2CPP_EXPORT AutoGIL
 {
 public:
   AutoGIL():_gstate(PyGILState_Ensure()) { }
index 301d795f24595d3b328e8d8bd3c2792728e286bd..f2f9c6ffc28e3e8699952dc4afd8b936e119b42f 100644 (file)
@@ -18,6 +18,7 @@
 //
 #ifndef PY2CPP_RESULT_HXX
 #define PY2CPP_RESULT_HXX
+#include "py2cppExports.hxx"
 #include <Python.h>
 #include <tuple>
 #include "TypeConversions.hxx"
@@ -27,7 +28,7 @@ namespace py2cpp
 {
 
 template<class ...Ts>
-class Result;
+class PY2CPP_EXPORT Result;
 
 /*! class Result is used by pyResult function for syntax sugar purpose.
  * You can write this:
@@ -57,7 +58,7 @@ class Result;
  *     std::cerr << py2cpp::getLastPyError();
  **/
 template<>
-class Result<>
+class PY2CPP_EXPORT Result<>
 {
 public:
   void operator=(PyObject * po)
@@ -69,7 +70,7 @@ public:
 };
 
 template<class T>
-class Result<T>
+class PY2CPP_EXPORT Result<T>
 {
 public:
   Result() = delete;
@@ -91,7 +92,7 @@ private:
 };
 
 template<class ...Ts>
-class Result
+class PY2CPP_EXPORT Result
 {
 public:
   Result() = delete;
@@ -111,7 +112,7 @@ private:
 };
 
 template<class ...Ts>
-Result<Ts...> pyResult(Ts&... args)
+PY2CPP_EXPORT Result<Ts...> pyResult(Ts&... args)
 {
   return Result<Ts...>(args...);
 }
index 7e8dab22184d294fc6bc9739d345e24adc483eea..8575ce68d2228098a14b71d93b3fb3ea39458cad 100644 (file)
@@ -18,6 +18,7 @@
 //
 #ifndef PY2CPP_TYPECONVERSIONS_HXX
 #define PY2CPP_TYPECONVERSIONS_HXX
+#include "py2cppExports.hxx"
 #include <Python.h>
 
 #include <list>
@@ -34,59 +35,59 @@ namespace py2cpp
  * toPy functions return a new python object built from a c++ object.
  * The conversion is always possible and it does not throw exceptions.
  */
-PyObject * toPy(int);
-PyObject * toPy(unsigned int);
-PyObject * toPy(bool);
-PyObject * toPy(double);
-PyObject * toPy(const std::string&);
-PyObject * toPy(const char*);
-PyObject * toPy(PyObject *);
-PyObject * toPy(const PyPtr&);
+PY2CPP_EXPORT PyObject * toPy(int);
+PY2CPP_EXPORT PyObject * toPy(unsigned int);
+PY2CPP_EXPORT PyObject * toPy(bool);
+PY2CPP_EXPORT PyObject * toPy(double);
+PY2CPP_EXPORT PyObject * toPy(const std::string&);
+PY2CPP_EXPORT PyObject * toPy(const char*);
+PY2CPP_EXPORT PyObject * toPy(PyObject *);
+PY2CPP_EXPORT PyObject * toPy(const PyPtr&);
 template <class T>
-PyObject * toPy(const std::vector<T>& values);
+PY2CPP_EXPORT PyObject * toPy(const std::vector<T>& values);
 template <class T>
-PyObject * toPy(const std::list<T>& values);
+PY2CPP_EXPORT PyObject * toPy(const std::list<T>& values);
 template <class K, class V>
-PyObject * toPy(const std::map<K, V>& values);
+PY2CPP_EXPORT PyObject * toPy(const std::map<K, V>& values);
 template<class ...Ts>
-PyObject * toPy(const std::tuple<Ts...>& vars );
+PY2CPP_EXPORT PyObject * toPy(const std::tuple<Ts...>& vars );
 
 /*!
  * fromPy functions convert a python object to a c++ object.
  * If the convertion fails, the ConversionCheck object returned contains the
  * error message. No exception is thrown.
  */
-ConversionCheck fromPy( PyObject *, int&);
-ConversionCheck fromPy( PyObject *, unsigned int&);
-ConversionCheck fromPy( PyObject *, bool&);
-ConversionCheck fromPy( PyObject *, double&);
-ConversionCheck fromPy( PyObject *, std::string&);
-ConversionCheck fromPy( PyObject *, PyObject *&);
-ConversionCheck fromPy( PyObject *, PyPtr&);
+PY2CPP_EXPORT ConversionCheck fromPy( PyObject *, int&);
+PY2CPP_EXPORT ConversionCheck fromPy( PyObject *, unsigned int&);
+PY2CPP_EXPORT ConversionCheck fromPy( PyObject *, bool&);
+PY2CPP_EXPORT ConversionCheck fromPy( PyObject *, double&);
+PY2CPP_EXPORT ConversionCheck fromPy( PyObject *, std::string&);
+PY2CPP_EXPORT ConversionCheck fromPy( PyObject *, PyObject *&);
+PY2CPP_EXPORT ConversionCheck fromPy( PyObject *, PyPtr&);
 template<class ...Ts>
-ConversionCheck fromPy(PyObject * obj, std::tuple<Ts&...>& vars);
+PY2CPP_EXPORT ConversionCheck fromPy(PyObject * obj, std::tuple<Ts&...>& vars);
 template <class T>
-ConversionCheck fromPy( PyObject *obj, std::vector<T>& result);
+PY2CPP_EXPORT ConversionCheck fromPy( PyObject *obj, std::vector<T>& result);
 template <class T>
-ConversionCheck fromPy( PyObject *obj, std::list<T>& result);
+PY2CPP_EXPORT ConversionCheck fromPy( PyObject *obj, std::list<T>& result);
 template <class K, class V>
-ConversionCheck fromPy( PyObject *obj, std::map<K, V>& result);
+PY2CPP_EXPORT ConversionCheck fromPy( PyObject *obj, std::map<K, V>& result);
 
 /*! This templated version  of fromPy throws ConversionException if the
  * conversion fails.
  */
 template<class T>
-T fromPy( PyObject *po);
+PY2CPP_EXPORT T fromPy( PyObject *po);
 
 // These versions of fromPy and toPy use PyPtr instead of PyObject *
 template<class T>
-T fromPyPtr( const PyPtr& py);
+PY2CPP_EXPORT T fromPyPtr( const PyPtr& py);
 template<class T>
-ConversionCheck fromPyPtr( const PyPtr& py, T& var);
+PY2CPP_EXPORT ConversionCheck fromPyPtr( const PyPtr& py, T& var);
 template<class T>
-PyPtr toPyPtr(const T& v);
+PY2CPP_EXPORT PyPtr toPyPtr(const T& v);
 template<>
-PyPtr fromPy<PyPtr>( PyObject *po);
+PY2CPP_EXPORT PyPtr fromPy<PyPtr>( PyObject *po);
 
 ////////////////////////////////////////////////////////////////////////////////
 // Template implementations
@@ -109,7 +110,7 @@ addInPyTuple(PyObject * result, const std::tuple<Ts...>& vars )
 }
 
 template<class ...Ts>
-PyObject * toPy(const std::tuple<Ts...>& vars )
+PY2CPP_EXPORT PyObject * toPy(const std::tuple<Ts...>& vars )
 {
   PyObject * result = PyTuple_New(sizeof...(Ts));
   addInPyTuple<0, Ts... >(result, vars);
@@ -118,7 +119,7 @@ PyObject * toPy(const std::tuple<Ts...>& vars )
 
 // std containers
 template <class T>
-PyObject * toPy(const std::vector<T>& values)
+PY2CPP_EXPORT PyObject * toPy(const std::vector<T>& values)
 {
   PyObject * result = PyList_New(values.size());
   for(std::size_t i = 0; i < values.size(); ++i)
@@ -127,7 +128,7 @@ PyObject * toPy(const std::vector<T>& values)
 }
 
 template <class T>
-PyObject * toPy(const std::list<T>& values)
+PY2CPP_EXPORT PyObject * toPy(const std::list<T>& values)
 {
   PyObject * result = PyList_New(values.size());
   std::size_t i = 0;
@@ -140,7 +141,7 @@ PyObject * toPy(const std::list<T>& values)
 }
 
 template <class K, class V>
-PyObject * toPy(const std::map<K, V>& values)
+PY2CPP_EXPORT PyObject * toPy(const std::map<K, V>& values)
 {
   PyObject * result = PyDict_New();
   for(const auto& it: values)
@@ -173,7 +174,7 @@ getFromPyTuple(PyObject * tup, std::tuple<Ts&...>& vars )
 }
 
 template<class ...Ts>
-ConversionCheck fromPy(PyObject * obj, std::tuple<Ts&...>& vars)
+PY2CPP_EXPORT ConversionCheck fromPy(PyObject * obj, std::tuple<Ts&...>& vars)
 {
   ConversionCheck check;
   if(obj)
@@ -197,7 +198,7 @@ ConversionCheck fromPy(PyObject * obj, std::tuple<Ts&...>& vars)
 }
 
 template <class T>
-ConversionCheck fromPy( PyObject *obj, std::vector<T>& result)
+PY2CPP_EXPORT ConversionCheck fromPy( PyObject *obj, std::vector<T>& result)
 {
   ConversionCheck check;
   if(PyList_Check(obj))
@@ -226,7 +227,7 @@ ConversionCheck fromPy( PyObject *obj, std::vector<T>& result)
 }
 
 template <class T>
-ConversionCheck fromPy( PyObject *obj, std::list<T>& result)
+PY2CPP_EXPORT ConversionCheck fromPy( PyObject *obj, std::list<T>& result)
 {
   ConversionCheck check;
   if(PyList_Check(obj))
@@ -269,7 +270,7 @@ ConversionCheck fromPy( PyObject *obj, std::list<T>& result)
 }
 
 template <class K, class V>
-ConversionCheck fromPy( PyObject *obj, std::map<K, V>& result)
+PY2CPP_EXPORT ConversionCheck fromPy( PyObject *obj, std::map<K, V>& result)
 {
   ConversionCheck check;
   if(PyDict_Check(obj))
@@ -298,7 +299,7 @@ ConversionCheck fromPy( PyObject *obj, std::map<K, V>& result)
 
 // PyPtr
 template<class T>
-T fromPyPtr( const PyPtr& py)
+PY2CPP_EXPORT T fromPyPtr( const PyPtr& py)
 {
   T result;
   fromPy(py.get(), result);
@@ -306,19 +307,19 @@ T fromPyPtr( const PyPtr& py)
 }
 
 template<class T>
-ConversionCheck fromPyPtr( const PyPtr& py, T& var)
+PY2CPP_EXPORT ConversionCheck fromPyPtr( const PyPtr& py, T& var)
 {
   return fromPy(py.get(), var);
 }
 
 template<class T>
-PyPtr toPyPtr(const T& v)
+PY2CPP_EXPORT PY2CPP_EXPORT PyPtr toPyPtr(const T& v)
 {
   return PyPtr(toPy(v));
 }
 
 template<class T>
-T fromPy( PyObject *po)
+PY2CPP_EXPORT T fromPy( PyObject *po)
 {
   T result;
   ConversionCheck check;
diff --git a/src/py2cppExports.hxx b/src/py2cppExports.hxx
new file mode 100644 (file)
index 0000000..cc55549
--- /dev/null
@@ -0,0 +1,30 @@
+// Copyright (C) 2021 EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#pragma once
+
+#ifdef WIN32
+#  if defined(py2cpp_EXPORTS) || defined(py2cpp_EXPORTS)
+#    define PY2CPP_EXPORT __declspec( dllexport )
+#  else
+#    define PY2CPP_EXPORT __declspec( dllimport )
+#  endif
+#else
+#  define PY2CPP_EXPORT
+#endif