[Python-modules-commits] [pycxx] 01/08: Import pycxx_7.0.1.orig.tar.gz

Josué Ortega josue at moszumanska.debian.org
Sun Sep 25 19:06:13 UTC 2016


This is an automated email from the git hooks/post-receive script.

josue pushed a commit to branch master
in repository pycxx.

commit 5183a3c282af02f765f3b0a763df8aa9c3a2672c
Author: Josue Ortega <josue at debian.org>
Date:   Sun Sep 25 12:24:43 2016 -0600

    Import pycxx_7.0.1.orig.tar.gz
---
 CXX/Config.hxx                          |   6 +
 CXX/{Config.hxx => CxxDebug.hxx}        |   6 +-
 CXX/Python2/Exception.hxx               | 289 ++++--------
 CXX/Python2/ExtensionModule.hxx         |   6 +-
 CXX/Python2/ExtensionOldType.hxx        |   8 +-
 CXX/Python2/ExtensionType.hxx           |  51 ++-
 CXX/Python2/ExtensionTypeBase.hxx       |  10 +-
 CXX/Python2/Extensions.hxx              |   2 +-
 CXX/Python2/IndirectPythonInterface.hxx |  49 +-
 CXX/Python2/Objects.hxx                 | 369 ++++++++-------
 CXX/Python2/PythonType.hxx              | 104 ++++-
 CXX/Python2/cxx_standard_exceptions.hxx |  46 ++
 CXX/Python3/Exception.hxx               | 290 ++++--------
 CXX/Python3/ExtensionModule.hxx         |   6 +-
 CXX/Python3/ExtensionOldType.hxx        |   8 +-
 CXX/Python3/ExtensionType.hxx           |  51 ++-
 CXX/Python3/ExtensionTypeBase.hxx       |  11 +-
 CXX/Python3/Extensions.hxx              |   2 +-
 CXX/Python3/IndirectPythonInterface.hxx |  42 +-
 CXX/Python3/Objects.hxx                 | 243 ++++++----
 CXX/Python3/PythonType.hxx              |  92 +++-
 CXX/Python3/cxx_standard_exceptions.hxx |  68 +++
 CXX/Version.hxx                         |   6 +-
 Demo/Python2/example.cxx                |  30 +-
 Demo/Python2/range.cxx                  |  11 +-
 Demo/Python2/range.hxx                  |   8 +-
 Demo/Python2/simple.cxx                 |  49 +-
 Demo/Python2/test_simple.py             |  13 +-
 Demo/Python3/example.cxx                |  26 +-
 Demo/Python3/pycxx_iter.cxx             |   2 +-
 Demo/Python3/pycxx_iter.hxx             |   2 +-
 Demo/Python3/range.cxx                  |  22 +-
 Demo/Python3/range.hxx                  |  12 +-
 Demo/Python3/simple.cxx                 | 108 ++++-
 Demo/Python3/test_assert.hxx            |  19 +-
 Demo/Python3/test_simple.py             |  83 +++-
 Doc/Python2/PyCXX.html                  |  34 +-
 Doc/Python3/PyCXX.html                  | 187 ++++----
 Doc/Python3/make_contents.py            |  12 +-
 Lib/__init__.py                         |   4 +-
 PyCXX-Release-Notes.txt                 |  13 +
 README.html                             |  82 +++-
 README.txt                              |  13 +
 SourceForge/PyCXX-Python2.html          |   1 +
 SourceForge/PyCXX-Python3.html          |   1 +
 SourceForge/README.html                 |   1 +
 SourceForge/deploy.sh                   |   2 +-
 SourceForge/index.html                  | 118 +----
 SourceForge/style.css                   |   1 +
 Src/IndirectPythonInterface.cxx         | 134 ++----
 Src/Python2/cxx_exceptions.cxx          |  72 +++
 Src/Python2/cxx_extensions.cxx          | 772 ++++++++++++++++++++------------
 Src/Python3/cxx_exceptions.cxx          |  72 +++
 Src/Python3/cxx_extensions.cxx          | 620 +++++++++++++++----------
 Src/Python3/cxxsupport.cxx              |  20 +-
 Src/cxx_exceptions.cxx                  |   7 +
 build-all.cmd                           |  78 +++-
 build-all.sh                            |  19 +-
 how_to_release_pycxx.txt                |  12 +-
 make_src_kit.py                         |   2 +-
 setup.py                                |  16 +-
 setup_makefile.py                       |  32 +-
 tag_pycxx.py                            |  32 +-
 63 files changed, 2684 insertions(+), 1823 deletions(-)

diff --git a/CXX/Config.hxx b/CXX/Config.hxx
index 536e7c8..951d22c 100644
--- a/CXX/Config.hxx
+++ b/CXX/Config.hxx
@@ -36,6 +36,12 @@
 //-----------------------------------------------------------------------------
 #include "CXX/WrapPython.h"
 
+#if defined( PYCXX_6_2_COMPATIBILITY )
+    typedef int PyCxx_ssize_t;
+#else
+    typedef Py_ssize_t PyCxx_ssize_t;
+#endif
+
 #if PY_MAJOR_VERSION == 2
 #include "CXX/Python2/Config.hxx"
 #else
diff --git a/CXX/Config.hxx b/CXX/CxxDebug.hxx
similarity index 95%
copy from CXX/Config.hxx
copy to CXX/CxxDebug.hxx
index 536e7c8..508395f 100644
--- a/CXX/Config.hxx
+++ b/CXX/CxxDebug.hxx
@@ -34,10 +34,8 @@
 // DAMAGE.
 //
 //-----------------------------------------------------------------------------
-#include "CXX/WrapPython.h"
-
 #if PY_MAJOR_VERSION == 2
-#include "CXX/Python2/Config.hxx"
+#include "CXX/Python2/CxxDebug.hxx"
 #else
-#include "CXX/Python3/Config.hxx"
+#include "CXX/Python3/CxxDebug.hxx"
 #endif
diff --git a/CXX/Python2/Exception.hxx b/CXX/Python2/Exception.hxx
index 3acc0ae..84b7e8c 100644
--- a/CXX/Python2/Exception.hxx
+++ b/CXX/Python2/Exception.hxx
@@ -40,8 +40,9 @@
 
 #include "CXX/WrapPython.h"
 #include "CXX/Version.hxx"
-#include "CXX/Config.hxx"
-#include "CXX/IndirectPythonInterface.hxx"
+#include "CXX/Python2/Config.hxx"
+#include "CXX/Python2/CxxDebug.hxx"
+#include "CXX/Python2/IndirectPythonInterface.hxx"
 
 #include <string>
 #include <iostream>
@@ -53,206 +54,112 @@ namespace Py
 
     class Object;
 
-    class Exception
+    class BaseException
     {
     public:
-        Exception( ExtensionExceptionType &exception, const std::string& reason );
-        Exception( ExtensionExceptionType &exception, Object &reason );
+        BaseException( ExtensionExceptionType &exception, const std::string &reason );
+        BaseException( ExtensionExceptionType &exception, Object &reason );
+        BaseException( PyObject *exception, Object &reason );
+        BaseException( PyObject *exception, const std::string &reason );
+        explicit BaseException();
 
-        explicit Exception ()
-        {}
-        
-        Exception (const std::string& reason)
-        {
-            PyErr_SetString (Py::_Exc_RuntimeError(), reason.c_str());
-        }
-        
-        Exception (PyObject* exception, const std::string& reason)
-        {
-            PyErr_SetString (exception, reason.c_str());
-        }
-        
-        Exception (PyObject* exception, Object &reason);        
+        void clear(); // clear the error
 
-        void clear() // clear the error
-        // technically but not philosophically const
-        {
-            PyErr_Clear();
-        }
+        // is the exception this specific exception 'exc'
+        bool matches( ExtensionExceptionType &exc );
     };
-    
-    
-    // Abstract
-    class StandardError: public Exception
+
+#if defined( PYCXX_6_2_COMPATIBILITY )
+    class Exception : public BaseException
     {
-    protected: 
-        explicit StandardError()
+    public:
+        Exception( ExtensionExceptionType &exception, const std::string &reason )
+        : BaseException( exception, reason )
         {}
-    };
-    
-    class LookupError: public StandardError
-    {
-    protected: 
-        explicit LookupError()
+
+        Exception( ExtensionExceptionType &exception, Object &reason )
+        : BaseException( exception, reason )
         {}
-    };
-    
-    class ArithmeticError: public StandardError
-    {
-    protected: 
-        explicit ArithmeticError()
+
+        Exception( PyObject *exception, const std::string &reason )
+        : BaseException( exception, reason )
         {}
-    };
-    
-    class EnvironmentError: public StandardError
-    {
-    protected: 
-        explicit EnvironmentError()
+
+        explicit Exception()
+        : BaseException()
         {}
     };
-    
-    // Concrete
-    
-    class TypeError: public StandardError
-    {
-    public:
-        TypeError (const std::string& reason)
-            : StandardError()
-        {
-            PyErr_SetString (Py::_Exc_TypeError(),reason.c_str());
-        }
-    };
-    
-    class IndexError: public LookupError
-    {
-    public:
-        IndexError (const std::string& reason)
-            : LookupError()
-        {
-            PyErr_SetString (Py::_Exc_IndexError(), reason.c_str());
-        }
-    };
-    
-    class AttributeError: public StandardError
-    {
-    public:
-        AttributeError (const std::string& reason)
-            : StandardError()
-        {
-            PyErr_SetString (Py::_Exc_AttributeError(), reason.c_str());
-        }        
-    };
-    
-    class NameError: public StandardError
-    {
-    public:
-        NameError (const std::string& reason)
-            : StandardError()
-        {
-            PyErr_SetString (Py::_Exc_NameError(), reason.c_str());
-        }
-    };
-    
-    class RuntimeError: public StandardError
-    {
-    public:
-        RuntimeError (const std::string& reason)
-            : StandardError()
-        {
-            PyErr_SetString (Py::_Exc_RuntimeError(), reason.c_str());
-        }
-    };
-    
-    class NotImplementedError: public StandardError
-    {
-    public:
-        NotImplementedError (const std::string& reason)
-            : StandardError()
-        {
-            PyErr_SetString (Py::_Exc_NotImplementedError(), reason.c_str());
-        }
-    };
-    
-    class SystemError: public StandardError
-    {
-    public:
-        SystemError (const std::string& reason)
-            : StandardError()
-        {
-            PyErr_SetString (Py::_Exc_SystemError(),reason.c_str());
-        }
-    };
-    
-    class KeyError: public LookupError
-    {
-    public:
-        KeyError (const std::string& reason)
-            : LookupError()
-        {
-            PyErr_SetString (Py::_Exc_KeyError(),reason.c_str());
-        }
-    };
-    
-    
-    class ValueError: public StandardError
-    {
-    public:
-        ValueError (const std::string& reason)
-            : StandardError()
-        {
-            PyErr_SetString (Py::_Exc_ValueError(), reason.c_str());
-        }
-    };
-    
-    class OverflowError: public ArithmeticError
-    {
-    public:
-        OverflowError (const std::string& reason)
-            : ArithmeticError()
-        {
-            PyErr_SetString (Py::_Exc_OverflowError(), reason.c_str());
-        }        
-    };
-    
-    class ZeroDivisionError: public ArithmeticError
-    {
-    public:
-        ZeroDivisionError (const std::string& reason)
-            : ArithmeticError() 
-        {
-            PyErr_SetString (Py::_Exc_ZeroDivisionError(), reason.c_str());
-        }
-    };
-    
-    class FloatingPointError: public ArithmeticError
-    {
-    public:
-        FloatingPointError (const std::string& reason)
-            : ArithmeticError() 
-        {
-            PyErr_SetString (Py::_Exc_FloatingPointError(), reason.c_str());
-        }
-    };
-    
-    class MemoryError: public StandardError
-    {
-    public:
-        MemoryError (const std::string& reason)
-            : StandardError()
-        {
-            PyErr_SetString (Py::_Exc_MemoryError(), reason.c_str());
-        }    
-    };
-    
-    class SystemExit: public StandardError
-    {
-    public:
-        SystemExit (const std::string& reason)
-            : StandardError() 
-        {
-            PyErr_SetString (Py::_Exc_SystemExit(),reason.c_str());
-        }
-    };
+#endif
+
+    // for user defined exceptions to be made know to pycxx
+    typedef void (*throw_exception_func_t)( void );
+    void addPythonException( ExtensionExceptionType &py_exc_type, throw_exception_func_t throw_func );
+
+#define PYCXX_STANDARD_EXCEPTION( eclass, bclass ) \
+    class eclass : public bclass \
+    { \
+    public: \
+        eclass() {} \
+        eclass( const char *reason ) { PyErr_SetString( _Exc_##eclass(), reason ); } \
+        eclass( const std::string &reason ) { PyErr_SetString( _Exc_##eclass(), reason.c_str() ); } \
+        ~eclass() {} \
+        \
+        static void throwFunc() { throw eclass(); } \
+        static PyObject *exceptionType() { return _Exc_##eclass(); } \
+    }; \
+
+#include <CXX/Python2/cxx_standard_exceptions.hxx>
+
+#undef PYCXX_STANDARD_EXCEPTION
+
+#define PYCXX_USER_EXCEPTION_STR_ARG( uclass ) \
+class uclass : public Py::BaseException \
+{ \
+public: \
+    uclass( const std::string &reason ) \
+    : Py::BaseException( m_error, reason ) \
+    { } \
+    ~uclass() {} \
+    static void init( Py::ExtensionModuleBase &module ) \
+    { \
+        m_error.init( module, #uclass ); \
+        Py::addPythonException( m_error, throwFunc ); \
+        Py::Dict d( module.moduleDictionary() ); \
+        d[#uclass] = m_error; \
+    } \
+private: \
+    uclass() : Py::BaseException() {} \
+    static void throwFunc() \
+    { \
+        throw uclass(); \
+    } \
+    static Py::ExtensionExceptionType m_error; \
+}; \
+Py::ExtensionExceptionType uclass::m_error;
+
+#define PYCXX_USER_EXCEPTION_NO_ARG( uclass ) \
+class uclass : public Py::BaseException \
+{ \
+public: \
+    uclass() \
+    : Py::BaseException() \
+    { } \
+    ~uclass() {} \
+    static void init( Py::ExtensionModuleBase &module ) \
+    { \
+        m_error.init( module, #uclass ); \
+        Py::addPythonException( m_error, throwFunc ); \
+        Py::Dict d( module.moduleDictionary() ); \
+        d[#uclass] = m_error; \
+    } \
+private: \
+    static void throwFunc() \
+    { \
+        throw uclass(); \
+    } \
+    static Py::ExtensionExceptionType m_error; \
+}; \
+Py::ExtensionExceptionType uclass::m_error;
 
 }// Py
 
diff --git a/CXX/Python2/ExtensionModule.hxx b/CXX/Python2/ExtensionModule.hxx
index 3eb436d..5f59dc0 100644
--- a/CXX/Python2/ExtensionModule.hxx
+++ b/CXX/Python2/ExtensionModule.hxx
@@ -139,10 +139,12 @@ namespace Py
                 args[0] = Object( self, true );
                 args[1] = Object( PyCObject_FromVoidPtr( method_def, do_not_dealloc ), true );
 
-                PyObject *func = PyCFunction_New
+                assert( m_module != NULL );
+                PyObject *func = PyCFunction_NewEx
                                     (
                                     &method_def->ext_meth_def,
-                                    new_reference_to( args )
+                                    new_reference_to( args ),
+                                    m_module
                                     );
 
                 method_def->py_method = Object( func, true );
diff --git a/CXX/Python2/ExtensionOldType.hxx b/CXX/Python2/ExtensionOldType.hxx
index cfd2fbe..570e31f 100644
--- a/CXX/Python2/ExtensionOldType.hxx
+++ b/CXX/Python2/ExtensionOldType.hxx
@@ -180,7 +180,7 @@ namespace Py
             self[0] = Object( this );
             self[1] = Object( PyCObject_FromVoidPtr( method_def, do_not_dealloc ), true );
 
-            PyObject *func = PyCFunction_New( &method_def->ext_meth_def, self.ptr() );
+            PyObject *func = PyCFunction_NewEx( &method_def->ext_meth_def, self.ptr(), NULL );
 
             return Object(func, true);
         }
@@ -256,7 +256,7 @@ namespace Py
 
                 return new_reference_to( result.ptr() );
             }
-            catch( Exception & )
+            catch( BaseException & )
             {
                 return 0;
             }
@@ -293,7 +293,7 @@ namespace Py
 
                 return new_reference_to( result.ptr() );
             }
-            catch( Exception & )
+            catch( BaseException & )
             {
                 return 0;
             }
@@ -322,7 +322,7 @@ namespace Py
 
                 return new_reference_to( result.ptr() );
             }
-            catch( Exception & )
+            catch( BaseException & )
             {
                 return 0;
             }
diff --git a/CXX/Python2/ExtensionType.hxx b/CXX/Python2/ExtensionType.hxx
index 4128960..7145bd0 100644
--- a/CXX/Python2/ExtensionType.hxx
+++ b/CXX/Python2/ExtensionType.hxx
@@ -52,7 +52,7 @@
             Py::Object r( (self->NAME)() ); \
             return Py::new_reference_to( r.ptr() ); \
         } \
-        catch( Py::Exception & ) \
+        catch( Py::BaseException & ) \
         { \
             return 0; \
         } \
@@ -68,7 +68,7 @@
             Py::Object r( (self->NAME)( a ) ); \
             return Py::new_reference_to( r.ptr() ); \
         } \
-        catch( Py::Exception & ) \
+        catch( Py::BaseException & ) \
         { \
             return 0; \
         } \
@@ -87,7 +87,7 @@
             Py::Object r( (self->NAME)( a, k ) ); \
             return Py::new_reference_to( r.ptr() ); \
         } \
-        catch( Py::Exception & ) \
+        catch( Py::BaseException & ) \
         { \
             return 0; \
         } \
@@ -112,7 +112,6 @@ namespace Py
         PythonExtensionBase *m_pycxx_object;
     };
 
-
     class ExtensionClassMethodsTable
     {
     public:
@@ -121,11 +120,18 @@ namespace Py
         , m_methods_used( 0 )
         , m_methods_size( METHOD_TABLE_SIZE_INCREMENT )
         {
+            // add the sentinel marking the table end
+            PyMethodDef *p = &m_methods_table[ 0 ];
+
+            p->ml_name = NULL;
+            p->ml_meth = NULL;
+            p->ml_flags = 0;
+            p->ml_doc = NULL;
         }
 
         ~ExtensionClassMethodsTable()
         {
-            delete m_methods_table;
+            delete[] m_methods_table;
         }
 
         // check that all methods added are unique
@@ -188,7 +194,7 @@ namespace Py
     : public PythonExtensionBase
     {
     protected:
-        explicit PythonClass( PythonClassInstance *self, Tuple &args, Dict &kwds )
+        explicit PythonClass( PythonClassInstance *self, Tuple &/*args*/, Dict &/*kwds*/ )
         : PythonExtensionBase()
         , m_class_instance( self )
         {
@@ -220,7 +226,7 @@ namespace Py
 #else
                 const char *default_name = "unknown";
 #endif
-                p = new PythonType( sizeof( T ), 0, default_name );
+                p = new PythonType( sizeof( PythonClassInstance ), 0, default_name );
                 p->set_tp_new( extension_object_new );
                 p->set_tp_init( extension_object_init );
                 p->set_tp_dealloc( extension_object_deallocator );
@@ -235,7 +241,7 @@ namespace Py
             return *p;
         }
 
-        static PyObject *extension_object_new( PyTypeObject *subtype, PyObject *args, PyObject *kwds )
+        static PyObject *extension_object_new( PyTypeObject *subtype, PyObject * /*args*/, PyObject * /*kwds*/ )
         {
 #ifdef PYCXX_DEBUG
             std::cout << "extension_object_new()" << std::endl;
@@ -248,7 +254,7 @@ namespace Py
 
             PyObject *self = reinterpret_cast<PyObject *>( o );
 #ifdef PYCXX_DEBUG
-            std::cout << "extension_object_new() => self=0x" << std::hex << reinterpret_cast< unsigned int >( self ) << std::dec << std::endl;
+            std::cout << "extension_object_new() => self=0x" << std::hex << reinterpret_cast< unsigned long >( self ) << std::dec << std::endl;
 #endif
             return self;
         }
@@ -264,26 +270,26 @@ namespace Py
 
                 PythonClassInstance *self = reinterpret_cast<PythonClassInstance *>( _self );
 #ifdef PYCXX_DEBUG
-                std::cout << "extension_object_init( self=0x" << std::hex << reinterpret_cast< unsigned int >( self ) << std::dec << " )" << std::endl;
-                std::cout << "    self->m_pycxx_object=0x" << std::hex << reinterpret_cast< unsigned int >( self->m_pycxx_object ) << std::dec << std::endl;
+                std::cout << "extension_object_init( self=0x" << std::hex << reinterpret_cast< unsigned long >( self ) << std::dec << " )" << std::endl;
+                std::cout << "    self->m_pycxx_object=0x" << std::hex << reinterpret_cast< unsigned long >( self->m_pycxx_object ) << std::dec << std::endl;
 #endif
 
                 if( self->m_pycxx_object == NULL )
                 {
                     self->m_pycxx_object = new T( self, args, kwds );
 #ifdef PYCXX_DEBUG
-                    std::cout << "    self->m_pycxx_object=0x" << std::hex << reinterpret_cast< unsigned int >( self->m_pycxx_object ) << std::dec << std::endl;
+                    std::cout << "    self->m_pycxx_object=0x" << std::hex << reinterpret_cast< unsigned long >( self->m_pycxx_object ) << std::dec << std::endl;
 #endif
                 }
                 else
                 {
 #ifdef PYCXX_DEBUG
-                    std::cout << "    reinit - self->m_pycxx_object=0x" << std::hex << reinterpret_cast< unsigned int >( self->m_pycxx_object ) << std::dec << std::endl;
+                    std::cout << "    reinit - self->m_pycxx_object=0x" << std::hex << reinterpret_cast< unsigned long >( self->m_pycxx_object ) << std::dec << std::endl;
 #endif
                     self->m_pycxx_object->reinit( args, kwds );
                 }
             }
-            catch( Exception & )
+            catch( BaseException & )
             {
                 return -1;
             }
@@ -294,8 +300,8 @@ namespace Py
         {
             PythonClassInstance *self = reinterpret_cast< PythonClassInstance * >( _self );
 #ifdef PYCXX_DEBUG
-            std::cout << "extension_object_deallocator( self=0x" << std::hex << reinterpret_cast< unsigned int >( self ) << std::dec << " )" << std::endl;
-            std::cout << "    self->m_pycxx_object=0x" << std::hex << reinterpret_cast< unsigned int >( self->m_pycxx_object ) << std::dec << std::endl;
+            std::cout << "extension_object_deallocator( self=0x" << std::hex << reinterpret_cast< unsigned long >( self ) << std::dec << " )" << std::endl;
+            std::cout << "    self->m_pycxx_object=0x" << std::hex << reinterpret_cast< unsigned long >( self->m_pycxx_object ) << std::dec << std::endl;
 #endif
             delete self->m_pycxx_object;
             _self->ob_type->tp_free( _self );
@@ -314,8 +320,17 @@ namespace Py
 
         static bool check( PyObject *p )
         {
-            // is p like me?
-            return p->ob_type == type_object();
+            // is p a me or a derived me
+            switch( PyObject_IsInstance( p, reinterpret_cast<PyObject *>( type_object() ) ) )
+            {
+                default:
+                case -1:
+                    throw Exception();
+                case 0:
+                    return false;
+                case 1:
+                    return true;
+            }            
         }
 
         static bool check( const Object &ob )
diff --git a/CXX/Python2/ExtensionTypeBase.hxx b/CXX/Python2/ExtensionTypeBase.hxx
index 1dfe424..237ae78 100644
--- a/CXX/Python2/ExtensionTypeBase.hxx
+++ b/CXX/Python2/ExtensionTypeBase.hxx
@@ -87,16 +87,22 @@ namespace Py
         virtual PyObject *iternext();
 
         // Sequence methods
-        virtual int sequence_length();
+        virtual PyCxx_ssize_t sequence_length();
         virtual Object sequence_concat( const Object & );
         virtual Object sequence_repeat( Py_ssize_t );
         virtual Object sequence_item( Py_ssize_t );
         virtual Object sequence_slice( Py_ssize_t, Py_ssize_t );
+
         virtual int sequence_ass_item( Py_ssize_t, const Object & );
         virtual int sequence_ass_slice( Py_ssize_t, Py_ssize_t, const Object & );
 
+        virtual Object sequence_inplace_concat( const Object & );
+        virtual Object sequence_inplace_repeat( Py_ssize_t );
+
+        virtual int sequence_contains( const Object & );
+
         // Mapping
-        virtual int mapping_length();
+        virtual PyCxx_ssize_t mapping_length();
         virtual Object mapping_subscript( const Object & );
         virtual int mapping_ass_subscript( const Object &, const Object & );
 
diff --git a/CXX/Python2/Extensions.hxx b/CXX/Python2/Extensions.hxx
index c4324b3..1b0f8f3 100644
--- a/CXX/Python2/Extensions.hxx
+++ b/CXX/Python2/Extensions.hxx
@@ -104,7 +104,7 @@ namespace Py
     extern "C" typedef PyObject *(*method_keyword_call_handler_t)( PyObject *_self, PyObject *_args, PyObject *_dict );
 
     template<class T>
-    class MethodDefExt : public PyMethodDef
+    class MethodDefExt
     {
     public:
         typedef Object (T::*method_noargs_function_t)();
diff --git a/CXX/Python2/IndirectPythonInterface.hxx b/CXX/Python2/IndirectPythonInterface.hxx
index a29a394..e2ee725 100644
--- a/CXX/Python2/IndirectPythonInterface.hxx
+++ b/CXX/Python2/IndirectPythonInterface.hxx
@@ -47,45 +47,13 @@ bool InitialisePythonIndirectInterface();
 //
 //    Wrap Exception variables as function calls
 //
-PyObject * _Exc_Exception();
-PyObject * _Exc_StandardError();
-PyObject * _Exc_ArithmeticError();
-PyObject * _Exc_LookupError();
-
-PyObject * _Exc_AssertionError();
-PyObject * _Exc_AttributeError();
-PyObject * _Exc_EOFError();
-PyObject * _Exc_FloatingPointError();
-PyObject * _Exc_EnvironmentError();
-PyObject * _Exc_IOError();
-PyObject * _Exc_OSError();
-PyObject * _Exc_ImportError();
-PyObject * _Exc_IndexError();
-PyObject * _Exc_KeyError();
-PyObject * _Exc_KeyboardInterrupt();
-PyObject * _Exc_MemoryError();
-PyObject * _Exc_NameError();
-PyObject * _Exc_OverflowError();
-PyObject * _Exc_RuntimeError();
-PyObject * _Exc_NotImplementedError();
-PyObject * _Exc_SyntaxError();
-PyObject * _Exc_SystemError();
-PyObject * _Exc_SystemExit();
-PyObject * _Exc_TypeError();
-PyObject * _Exc_ValueError();
-PyObject * _Exc_ZeroDivisionError();
-#ifdef MS_WINDOWS
-PyObject * _Exc_WindowsError();
-#endif
+PyObject * _Exc_BaseException();
 
-PyObject * _Exc_MemoryErrorInst();
+#define PYCXX_STANDARD_EXCEPTION( eclass, bclass ) \
+    PyObject * _Exc_##eclass();
 
-#if PY_MAJOR_VERSION >= 2
-PyObject * _Exc_IndentationError();
-PyObject * _Exc_TabError();
-PyObject * _Exc_UnboundLocalError();
-PyObject * _Exc_UnicodeError();
-#endif
+#include "CXX/Python2/cxx_standard_exceptions.hxx"
+#undef PYCXX_STANDARD_EXCEPTION
 
 //
 //    Wrap Object variables as function calls
@@ -164,9 +132,6 @@ bool _Slice_Check( PyObject *op );
 PyTypeObject * _String_Type();
 bool _String_Check( PyObject *op );
 
-PyTypeObject * _Unicode_Type();
-bool _Unicode_Check( PyObject *op );
-
 PyTypeObject * _TraceBack_Type();
 bool _TraceBack_Check( PyObject *v );
 
@@ -185,10 +150,6 @@ int &_Py_NoSiteFlag();
 int &_Py_TabcheckFlag();
 int &_Py_VerboseFlag();
 
-#if PY_MAJOR_VERSION >= 2
-int &_Py_UnicodeFlag();
-#endif
-
 void _XINCREF( PyObject *op );
 void _XDECREF( PyObject *op );
 
diff --git a/CXX/Python2/Objects.hxx b/CXX/Python2/Objects.hxx
index 0cd1524..1fc8216 100644
--- a/CXX/Python2/Objects.hxx
+++ b/CXX/Python2/Objects.hxx
@@ -49,10 +49,14 @@
 #include <iterator>
 #include <utility>
 #include <typeinfo>
+#include <algorithm>
+
 
 namespace Py
 {
-    typedef int sequence_index_type;    // type of an index into a sequence
+    void ifPyErrorThrowCxxException();
+
+    typedef PyCxx_ssize_t sequence_index_type;    // type of an index into a sequence
 
     // Forward declarations
     class Object;
@@ -101,19 +105,20 @@ namespace Py
     //
     /*
     explicit MyType (PyObject *pyob): Object(pyob) {
-    validate();
-}
+        validate();
+    }
 
     MyType(const Object& other): Object(other.ptr()) {
-    validate();
-}
+        validate();
+    }
     */
 
     // Alernate version for the constructor to allow for construction from owned pointers:
     /*
-    explicit MyType (PyObject *pyob): Object(pyob) {
-    validate();
-}
+    explicit MyType (PyObject *pyob)
+    : Object(pyob) {
+        validate();
+    }
     */
 
     // You may wish to add other constructors; see the classes below for examples.
@@ -123,14 +128,14 @@ namespace Py
     // (4) Each class needs at least these two assignment operators:
     /*
     MyType& operator= (const Object& rhs) {
-    return (*this = *rhs);
-}
+        return (*this = *rhs);
+    }
 
     Mytype& operator= (PyObject* rhsp) {
-    if(ptr() == rhsp) return *this;
-    set(rhsp);
-    return *this;
-}
+        if(ptr() == rhsp) return *this;
+        set(rhsp);
+        return *this;
+    }
     */
     // Note on accepts: constructors call the base class
     // version of a virtual when calling the base class constructor,
@@ -174,7 +179,8 @@ namespace Py
 
     public:
         // Constructor acquires new ownership of pointer unless explicitly told not to.
-        explicit Object (PyObject* pyob=Py::_None(), bool owned = false): p (pyob)
+        explicit Object (PyObject* pyob=Py::_None(), bool owned = false)
+        : p(pyob)
         {
             if(!owned)
             {
@@ -184,7 +190,8 @@ namespace Py
         }
 
         // Copy constructor acquires new ownership of pointer
-        Object (const Object& ob): p(ob.p)
+        Object (const Object& ob)
+        : p(ob.p)
         {
             Py::_XINCREF (p);
             validate();
@@ -226,9 +233,10 @@ namespace Py
         {
             // not allowed to commit suicide, however
             if(reference_count() == 1)
-            throw RuntimeError("Object::decrement_reference_count error.");
+                throw RuntimeError("Object::decrement_reference_count error.");
             Py::_XDECREF(p);
         }
+
         // Would like to call this pointer() but messes up STL in SeqBase<T>
         PyObject* ptr () const
         {
@@ -240,9 +248,10 @@ namespace Py
         //
 
         // Can pyob be used in this object's constructor?
-        virtual bool accepts (PyObject *pyob) const
+        virtual bool accepts (PyObject *) const
         {
-            return (pyob != 0);
+            // allow any object or NULL
+            return true;
         }
 
         Py_ssize_t reference_count () const
@@ -270,9 +279,9 @@ namespace Py
             return Object (PyObject_GetAttrString (p, const_cast<char*>(s.c_str())), true);
         }
 
-        Object callMemberFunction( const std::string &function_name ) const;
-        Object callMemberFunction( const std::string &function_name, const Tuple &args ) const;
-        Object callMemberFunction( const std::string &function_name, const Tuple &args, const Dict &kw ) const;
+        Object callMemberFunction( const std::string& function_name ) const;
+        Object callMemberFunction( const std::string& function_name, const Tuple &args ) const;
+        Object callMemberFunction( const std::string& function_name, const Tuple &args, const Dict &kw ) const;
 
         Object getItem (const Object& key) const
         {
@@ -284,12 +293,12 @@ namespace Py
             return PyObject_Hash (p);
         }
 
-        //
-        // int print (FILE* fp, int flags=Py_Print_RAW)
-        //{
-        //    return PyObject_Print (p, fp, flags);
-        //}
-        //
+        // convert to bool
+        bool as_bool() const
+        {
+            return PyObject_IsTrue( ptr() ) != 0;
+        }
+
         bool is(PyObject *pother) const
         {  // identity test
             return p == pother;
@@ -300,6 +309,11 @@ namespace Py
             return p == other.p;
         }
 
+        bool isNull() const
+        {
+            return p == NULL;
+        }
+
         bool isNone() const
         {
             return p == _None();
@@ -371,13 +385,13 @@ namespace Py
         void setAttr (const std::string& s, const Object& value)
         {
             if(PyObject_SetAttrString (p, const_cast<char*>(s.c_str()), *value) == -1)
-            throw AttributeError ("getAttr failed.");
+                ifPyErrorThrowCxxException();
         }
 
         void delAttr (const std::string& s)
         {
             if(PyObject_DelAttrString (p, const_cast<char*>(s.c_str())) == -1)
-            throw AttributeError ("delAttr failed.");
+                ifPyErrorThrowCxxException();
         }
 
         // PyObject_SetItem is too weird to be using from C++
@@ -385,9 +399,8 @@ namespace Py
 
         void delItem (const Object& key)
         {
-            //if(PyObject_DelItem(p, *key) == -1)
-            // failed to link on Windows?
-            throw KeyError("delItem failed.");
+            if(PyObject_DelItem(p, *key) == -1)
+                ifPyErrorThrowCxxException();
         }
 
         // Equality and comparison use PyObject_RichCompareBool
@@ -395,43 +408,42 @@ namespace Py
         bool operator==(const Object& o2) const
         {
             int k = PyObject_RichCompareBool (p, *o2, Py_EQ);
-            if (PyErr_Occurred()) throw Exception();
+            ifPyErrorThrowCxxException();
             return k != 0;
         }
 
         bool operator!=(const Object& o2) const
         {
             int k = PyObject_RichCompareBool (p, *o2, Py_NE);
-            if (PyErr_Occurred()) throw Exception();
+            ifPyErrorThrowCxxException();
             return k != 0;
-
         }
 
         bool operator>=(const Object& o2) const
         {
             int k = PyObject_RichCompareBool (p, *o2, Py_GE);
-            if (PyErr_Occurred()) throw Exception();
+            ifPyErrorThrowCxxException();
             return k != 0;
         }
 
         bool operator<=(const Object& o2) const
         {
             int k = PyObject_RichCompareBool (p, *o2, Py_LE);
-            if (PyErr_Occurred()) throw Exception();
+            ifPyErrorThrowCxxException();
             return k != 0;
         }
 
         bool operator<(const Object& o2) const
         {
             int k = PyObject_RichCompareBool (p, *o2, Py_LT);
-            if (PyErr_Occurred()) throw Exception();
+            ifPyErrorThrowCxxException();
             return k != 0;
         }
 
         bool operator>(const Object& o2) const
         {
             int k = PyObject_RichCompareBool (p, *o2, Py_GT);
-            if (PyErr_Occurred()) throw Exception();
+            ifPyErrorThrowCxxException();
             return k != 0;
         }
     };
@@ -1115,23 +1127,23 @@ namespace Py
     {
     protected:
... 8027 lines suppressed ...

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/pycxx.git



More information about the Python-modules-commits mailing list