From 433bf1947f22258bcbed1f70f0d7e75531cba2a8 Mon Sep 17 00:00:00 2001 From: looooo Date: Mon, 22 May 2017 11:57:43 +0200 Subject: [PATCH] py3: CXX: remaining diff: win: exernalize missing CXX-functions define PYCXX_PYTHON_2TO3 --- src/CXX/Python3/Config.hxx | 29 +++++++++------- src/CXX/Python3/ExtensionType.hxx | 2 +- src/CXX/Python3/IndirectPythonInterface.hxx | 4 +-- src/CXX/Python3/Objects.hxx | 38 ++++++++++----------- src/CXX/Python3/cxx_extensions.cxx | 6 ++-- 5 files changed, 43 insertions(+), 36 deletions(-) diff --git a/src/CXX/Python3/Config.hxx b/src/CXX/Python3/Config.hxx index 4772606445..a181b42d9a 100644 --- a/src/CXX/Python3/Config.hxx +++ b/src/CXX/Python3/Config.hxx @@ -106,20 +106,20 @@ # define EXPLICIT_CLASS # define TEMPLATE_TYPENAME class #endif - -// export macro + +// export macro #if defined( _MSC_VER ) -# pragma warning( disable : 4251 ) -#endif +# pragma warning( disable : 4251 ) +#endif #if defined( _MSC_VER ) || defined( __MINGW32__ ) -# ifdef PYCXX_DLL -# define PYCXX_EXPORT __declspec(dllexport) -# else -# define PYCXX_EXPORT __declspec(dllimport) -# endif -#else -# define PYCXX_EXPORT -#endif +# ifdef PYCXX_DLL +# define PYCXX_EXPORT __declspec(dllexport) +# else +# define PYCXX_EXPORT __declspec(dllimport) +# endif +#else +# define PYCXX_EXPORT +#endif // before 3.2 Py_hash_t was missing #ifndef PY_MAJOR_VERSION @@ -128,4 +128,9 @@ #if PY_MINOR_VERSION < 2 typedef long int Py_hash_t; #endif + +#ifndef PYCXX_PYTHON_2TO3 +#define PYCXX_PYTHON_2TO3 +#endif + #endif // __PyCXX_config_hh__ diff --git a/src/CXX/Python3/ExtensionType.hxx b/src/CXX/Python3/ExtensionType.hxx index 90829e21c6..f8cff78ea5 100644 --- a/src/CXX/Python3/ExtensionType.hxx +++ b/src/CXX/Python3/ExtensionType.hxx @@ -104,7 +104,7 @@ namespace Py { - extern PythonExtensionBase *getPythonExtensionBase( PyObject *self ); + PYCXX_EXPORT extern PythonExtensionBase *getPythonExtensionBase( PyObject *self ); struct PythonClassInstance { PyObject_HEAD diff --git a/src/CXX/Python3/IndirectPythonInterface.hxx b/src/CXX/Python3/IndirectPythonInterface.hxx index 5ffaf43a83..a4c0cf424c 100644 --- a/src/CXX/Python3/IndirectPythonInterface.hxx +++ b/src/CXX/Python3/IndirectPythonInterface.hxx @@ -175,8 +175,8 @@ PYCXX_EXPORT int &_Py_TabcheckFlag(); PYCXX_EXPORT int &_Py_VerboseFlag(); PYCXX_EXPORT int &_Py_UnicodeFlag(); -void _XINCREF( PyObject *op ); -void _XDECREF( PyObject *op ); +PYCXX_EXPORT void _XINCREF( PyObject *op ); +PYCXX_EXPORT void _XDECREF( PyObject *op ); PYCXX_EXPORT char *__Py_PackageContext(); }; diff --git a/src/CXX/Python3/Objects.hxx b/src/CXX/Python3/Objects.hxx index 21cd891705..d2390a4274 100644 --- a/src/CXX/Python3/Objects.hxx +++ b/src/CXX/Python3/Objects.hxx @@ -239,7 +239,7 @@ namespace Py // // Can pyob be used in this object's constructor? - virtual bool accepts( PyObject *pyob ) const + virtual bool accepts( PyObject * /* pyob */ ) const { // allow any object or NULL return true; @@ -429,12 +429,12 @@ namespace Py }; //------------------------------------------------------------ - bool operator==( const Object &o1, const Object &o2 ); - bool operator!=( const Object &o1, const Object &o2 ); - bool operator>=( const Object &o1, const Object &o2 ); - bool operator<=( const Object &o1, const Object &o2 ); - bool operator<( const Object &o1, const Object &o2 ); - bool operator>( const Object &o1, const Object &o2 ); + PYCXX_EXPORT bool operator==( const Object &o1, const Object &o2 ); + PYCXX_EXPORT bool operator!=( const Object &o1, const Object &o2 ); + PYCXX_EXPORT bool operator>=( const Object &o1, const Object &o2 ); + PYCXX_EXPORT bool operator<=( const Object &o1, const Object &o2 ); + PYCXX_EXPORT bool operator<( const Object &o1, const Object &o2 ); + PYCXX_EXPORT bool operator>( const Object &o1, const Object &o2 ); //------------------------------------------------------------ @@ -480,7 +480,7 @@ namespace Py // TMM: 31May'01 - Added the #ifndef so I can exlude iostreams. #ifndef CXX_NO_IOSTREAMS - std::ostream &operator<<( std::ostream &os, const Object &ob ); + PYCXX_EXPORT std::ostream &operator<<( std::ostream &os, const Object &ob ); #endif // Class Type @@ -1285,7 +1285,7 @@ namespace Py // ...the base class for all sequence types template - class PYCXX_EXPORT SeqBase: public Object + class SeqBase: public Object { public: // STL definitions @@ -2179,7 +2179,7 @@ namespace Py } // New tuple of a given size - explicit Tuple( int size = 0 ) + explicit Tuple( sequence_index_type size = 0 ) { set( PyTuple_New( size ), true ); validate(); @@ -2237,7 +2237,7 @@ namespace Py { public: TupleN() - : Tuple( 0 ) + : Tuple( (sequence_index_type)0 ) { } @@ -2362,7 +2362,7 @@ namespace Py validate(); } // Creation at a fixed size - List( int size = 0 ) + List( sequence_index_type size = 0 ) { set( PyList_New( size ), true ); validate(); @@ -2379,7 +2379,7 @@ namespace Py List( const Sequence &s ) : Sequence() { - int n =( int )s.length(); + sequence_index_type n =( int )s.length(); set( PyList_New( n ), true ); validate(); for( sequence_index_type i=0; i < n; i++ ) @@ -2648,7 +2648,7 @@ namespace Py #endif template - class PYCXX_EXPORT MapBase: public Object + class MapBase: public Object { protected: explicit MapBase() @@ -3059,10 +3059,10 @@ namespace Py template bool operator==( const EXPLICIT_TYPENAME MapBase::const_iterator &left, const EXPLICIT_TYPENAME MapBase::const_iterator &right ); template bool operator!=( const EXPLICIT_TYPENAME MapBase::const_iterator &left, const EXPLICIT_TYPENAME MapBase::const_iterator &right ); - extern bool operator==( const Mapping::iterator &left, const Mapping::iterator &right ); - extern bool operator!=( const Mapping::iterator &left, const Mapping::iterator &right ); - extern bool operator==( const Mapping::const_iterator &left, const Mapping::const_iterator &right ); - extern bool operator!=( const Mapping::const_iterator &left, const Mapping::const_iterator &right ); + PYCXX_EXPORT extern bool operator==( const Mapping::iterator &left, const Mapping::iterator &right ); + PYCXX_EXPORT extern bool operator!=( const Mapping::iterator &left, const Mapping::iterator &right ); + PYCXX_EXPORT extern bool operator==( const Mapping::const_iterator &left, const Mapping::const_iterator &right ); + PYCXX_EXPORT extern bool operator!=( const Mapping::const_iterator &left, const Mapping::const_iterator &right ); // ================================================== @@ -3233,7 +3233,7 @@ namespace Py inline Object Object::callMemberFunction( const std::string &function_name ) const { Callable target( getAttr( function_name ) ); - Tuple args( 0 ); + Tuple args( (sequence_index_type)0 ); return target.apply( args ); } diff --git a/src/CXX/Python3/cxx_extensions.cxx b/src/CXX/Python3/cxx_extensions.cxx index 22f804274c..a75e200361 100644 --- a/src/CXX/Python3/cxx_extensions.cxx +++ b/src/CXX/Python3/cxx_extensions.cxx @@ -222,7 +222,9 @@ extern "C" // All the following functions redirect the call from Python // onto the matching virtual function in PythonExtensionBase // +#ifdef PYCXX_PYTHON_2TO3 static int print_handler( PyObject *, FILE *, int ); +#endif static PyObject *getattr_handler( PyObject *, char * ); static int setattr_handler( PyObject *, char *, PyObject * ); static PyObject *getattro_handler( PyObject *, PyObject * ); @@ -1221,7 +1223,7 @@ Py::Object PythonExtensionBase::callOnSelf( const std::string &fn_name, return self().callMemberFunction( fn_name, args ); } -void PythonExtensionBase::reinit( Tuple &args, Dict &kwds ) +void PythonExtensionBase::reinit( Tuple & /* args */, Dict & /* kwds */) { throw RuntimeError( "Must not call __init__ twice on this class" ); } @@ -1479,7 +1481,7 @@ Py::Object PythonExtensionBase::number_power( const Py::Object &, const Py::Obje // Buffer -int PythonExtensionBase::buffer_get( Py_buffer *buf, int flags ) +int PythonExtensionBase::buffer_get( Py_buffer * /* buf */, int /* flags */ ) { missing_method( buffer_get ); return -1;