PyCXX: update to version 7.0.0

This commit is contained in:
wmayer
2022-08-01 16:39:26 +02:00
parent 04615798ab
commit a2f509087e
16 changed files with 758 additions and 486 deletions

View File

@@ -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

41
src/CXX/CxxDebug.hxx Normal file
View File

@@ -0,0 +1,41 @@
//-----------------------------------------------------------------------------
//
// Copyright (c) 1998 - 2007, The Regents of the University of California
// Produced at the Lawrence Livermore National Laboratory
// All rights reserved.
//
// This file is part of PyCXX. For details,see http://cxx.sourceforge.net/. The
// full copyright notice is contained in the file COPYRIGHT located at the root
// of the PyCXX distribution.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// - Redistributions of source code must retain the above copyright notice,
// this list of conditions and the disclaimer below.
// - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the disclaimer (as noted below) in the
// documentation and/or materials provided with the distribution.
// - Neither the name of the UC/LLNL nor the names of its contributors may be
// used to endorse or promote products derived from this software without
// specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OF THE UNIVERSITY OF
// CALIFORNIA, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
//
//-----------------------------------------------------------------------------
#if PY_MAJOR_VERSION == 2
#include "CXX/Python2/CxxDebug.hxx"
#else
#include "CXX/Python3/CxxDebug.hxx"
#endif

View File

@@ -72,46 +72,17 @@ PYCXX_EXPORT bool _Bytes_Check( PyObject *op ) { return op->ob_type == _By
static HMODULE python_dll;
static PyObject *ptr__Exc_ArithmeticError = NULL;
static PyObject *ptr__Exc_AssertionError = NULL;
static PyObject *ptr__Exc_AttributeError = NULL;
static PyObject *ptr__Exc_EnvironmentError = NULL;
static PyObject *ptr__Exc_EOFError = NULL;
static PyObject *ptr__Exc_Exception = NULL;
static PyObject *ptr__Exc_FloatingPointError = NULL;
static PyObject *ptr__Exc_ImportError = NULL;
static PyObject *ptr__Exc_IndexError = NULL;
static PyObject *ptr__Exc_IOError = NULL;
static PyObject *ptr__Exc_KeyboardInterrupt = NULL;
static PyObject *ptr__Exc_KeyError = NULL;
static PyObject *ptr__Exc_LookupError = NULL;
static PyObject *ptr__Exc_MemoryError = NULL;
static PyObject *ptr__Exc_NameError = NULL;
static PyObject *ptr__Exc_NotImplementedError = NULL;
static PyObject *ptr__Exc_OSError = NULL;
static PyObject *ptr__Exc_OverflowError = NULL;
static PyObject *ptr__Exc_RuntimeError = NULL;
#define PYCXX_STANDARD_EXCEPTION( eclass, bclass ) \
static PyObject *ptr_Exc_##eclass = NULL;
#if PY_MAJOR_VERSION == 2
static PyObject *ptr__Exc_StandardError = NULL;
#endif
static PyObject *ptr__Exc_SyntaxError = NULL;
static PyObject *ptr__Exc_SystemError = NULL;
static PyObject *ptr__Exc_SystemExit = NULL;
static PyObject *ptr__Exc_TypeError = NULL;
static PyObject *ptr__Exc_ValueError = NULL;
static PyObject *ptr__Exc_ZeroDivisionError = NULL;
#ifdef MS_WINDOWS
static PyObject *ptr__Exc_WindowsError = NULL;
#include "CXX/Python2/cxx_standard_exceptions.hxx"
#else
#include "CXX/Python3/cxx_standard_exceptions.hxx"
#endif
static PyObject *ptr__Exc_IndentationError = NULL;
static PyObject *ptr__Exc_TabError = NULL;
static PyObject *ptr__Exc_UnboundLocalError = NULL;
static PyObject *ptr__Exc_UnicodeError = NULL;
static PyObject *ptr__PyNone = NULL;
static PyObject *ptr__PyFalse = NULL;
static PyObject *ptr__PyTrue = NULL;
#undef PYCXX_STANDARD_EXCEPTION
static PyTypeObject *ptr__CFunction_Type = NULL;
static PyTypeObject *ptr__Complex_Type = NULL;
static PyTypeObject *ptr__Dict_Type = NULL;
@@ -248,41 +219,17 @@ bool InitialisePythonIndirectInterface()
ptr_Py_VerboseFlag = GetInt_as_IntPointer( "Py_VerboseFlag" );
ptr__Py_PackageContext = GetCharPointer_as_CharPointerPointer( "_Py_PackageContext" );
ptr__Exc_ArithmeticError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_ArithmeticError" );
ptr__Exc_AssertionError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_AssertionError" );
ptr__Exc_AttributeError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_AttributeError" );
ptr__Exc_EnvironmentError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_EnvironmentError" );
ptr__Exc_EOFError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_EOFError" );
ptr__Exc_Exception = GetPyObjectPointer_As_PyObjectPointer( "PyExc_Exception" );
ptr__Exc_FloatingPointError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_FloatingPointError" );
ptr__Exc_ImportError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_ImportError" );
ptr__Exc_IndexError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_IndexError" );
ptr__Exc_IOError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_IOError" );
ptr__Exc_KeyboardInterrupt = GetPyObjectPointer_As_PyObjectPointer( "PyExc_KeyboardInterrupt" );
ptr__Exc_KeyError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_KeyError" );
ptr__Exc_LookupError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_LookupError" );
ptr__Exc_MemoryError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_MemoryError" );
ptr__Exc_NameError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_NameError" );
ptr__Exc_NotImplementedError= GetPyObjectPointer_As_PyObjectPointer( "PyExc_NotImplementedError" );
ptr__Exc_OSError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_OSError" );
ptr__Exc_OverflowError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_OverflowError" );
ptr__Exc_RuntimeError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_RuntimeError" );
#define PYCXX_STANDARD_EXCEPTION( eclass, bclass )
ptr_Exc_#eclass = GetPyTypeObject_As_PyTypeObjectPointer( "PyExc_" #eclass );
#if PY_MAJOR_VERSION == 2
ptr__Exc_StandardError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_StandardError" );
#include "CXX/Python2/cxx_standard_exceptions.hxx"
#else
#include "CXX/Python3/cxx_standard_exceptions.hxx"
#endif
ptr__Exc_SyntaxError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_SyntaxError" );
ptr__Exc_SystemError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_SystemError" );
ptr__Exc_SystemExit = GetPyObjectPointer_As_PyObjectPointer( "PyExc_SystemExit" );
ptr__Exc_TypeError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_TypeError" );
ptr__Exc_ValueError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_ValueError" );
#ifdef MS_WINDOWS
ptr__Exc_WindowsError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_WindowsError" );
#endif
ptr__Exc_ZeroDivisionError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_ZeroDivisionError" );
ptr__Exc_IndentationError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_IndentationError" );
ptr__Exc_TabError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_TabError" );
ptr__Exc_UnboundLocalError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_UnboundLocalError" );
ptr__Exc_UnicodeError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_UnicodeError" );
#undef PYCXX_STANDARD_EXCEPTION
ptr__PyNone = GetPyObject_As_PyObjectPointer( "_Py_NoneStruct" );
# if PY_MAJOR_VERSION == 2
@@ -469,43 +416,16 @@ void _XDECREF( PyObject *op )
//
// Wrap variables as function calls
//
#define PYCXX_STANDARD_EXCEPTION( eclass, bclass ) \
PYCXX_EXPORT PyObject *_Exc_##eclass() { return ::PyExc_##eclass; }
PYCXX_EXPORT PyObject *_Exc_ArithmeticError() { return ::PyExc_ArithmeticError; }
PYCXX_EXPORT PyObject *_Exc_AssertionError() { return ::PyExc_AssertionError; }
PYCXX_EXPORT PyObject *_Exc_AttributeError() { return ::PyExc_AttributeError; }
PYCXX_EXPORT PyObject *_Exc_EnvironmentError() { return ::PyExc_EnvironmentError; }
PYCXX_EXPORT PyObject *_Exc_EOFError() { return ::PyExc_EOFError; }
PYCXX_EXPORT PyObject *_Exc_Exception() { return ::PyExc_Exception; }
PYCXX_EXPORT PyObject *_Exc_FloatingPointError() { return ::PyExc_FloatingPointError; }
PYCXX_EXPORT PyObject *_Exc_ImportError() { return ::PyExc_ImportError; }
PYCXX_EXPORT PyObject *_Exc_IndexError() { return ::PyExc_IndexError; }
PYCXX_EXPORT PyObject *_Exc_IOError() { return ::PyExc_IOError; }
PYCXX_EXPORT PyObject *_Exc_KeyboardInterrupt() { return ::PyExc_KeyboardInterrupt; }
PYCXX_EXPORT PyObject *_Exc_KeyError() { return ::PyExc_KeyError; }
PYCXX_EXPORT PyObject *_Exc_LookupError() { return ::PyExc_LookupError; }
PYCXX_EXPORT PyObject *_Exc_MemoryError() { return ::PyExc_MemoryError; }
PYCXX_EXPORT PyObject *_Exc_NameError() { return ::PyExc_NameError; }
PYCXX_EXPORT PyObject *_Exc_NotImplementedError() { return ::PyExc_NotImplementedError; }
PYCXX_EXPORT PyObject *_Exc_OSError() { return ::PyExc_OSError; }
PYCXX_EXPORT PyObject *_Exc_OverflowError() { return ::PyExc_OverflowError; }
PYCXX_EXPORT PyObject *_Exc_RuntimeError() { return ::PyExc_RuntimeError; }
PYCXX_EXPORT PyObject *_Exc_SyntaxError() { return ::PyExc_SyntaxError; }
PYCXX_EXPORT PyObject *_Exc_SystemError() { return ::PyExc_SystemError; }
PYCXX_EXPORT PyObject *_Exc_SystemExit() { return ::PyExc_SystemExit; }
PYCXX_EXPORT PyObject *_Exc_TypeError() { return ::PyExc_TypeError; }
PYCXX_EXPORT PyObject *_Exc_ValueError() { return ::PyExc_ValueError; }
PYCXX_EXPORT PyObject *_Exc_ZeroDivisionError() { return ::PyExc_ZeroDivisionError; }
PYCXX_EXPORT PyObject *_Exc_IndentationError() { return ::PyExc_IndentationError; }
PYCXX_EXPORT PyObject *_Exc_TabError() { return ::PyExc_TabError; }
PYCXX_EXPORT PyObject *_Exc_UnboundLocalError() { return ::PyExc_UnboundLocalError; }
PYCXX_EXPORT PyObject *_Exc_UnicodeError() { return ::PyExc_UnicodeError; }
#ifdef MS_WINDOWS
PYCXX_EXPORT PyObject *_Exc_WindowsError() { return ::PyExc_WindowsError; }
#if PY_MAJOR_VERSION == 2
#include "CXX/Python2/cxx_standard_exceptions.hxx"
#else
#include "CXX/Python3/cxx_standard_exceptions.hxx"
#endif
#undef PYCXX_STANDARD_EXCEPTION
//
// wrap items in Object.h

View File

@@ -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 );

View File

@@ -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;
}

View File

@@ -54,33 +54,16 @@ namespace Py
class Object;
class PYCXX_EXPORT Exception
class PYCXX_EXPORT 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 ()
{}
// This overloaded constructor will be removed in future PyCXX versions
//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
// technically but not philosophically const
{
PyErr_Clear();
}
void clear(); // clear the error
// is the exception this specific exception 'exc'
bool matches( ExtensionExceptionType &exc );
@@ -90,13 +73,27 @@ namespace Py
typedef void (*throw_exception_func_t)( void );
void addPythonException( ExtensionExceptionType &py_exc_type, throw_exception_func_t throw_func );
// Abstract
class PYCXX_EXPORT StandardError: public Exception
#if defined( PYCXX_6_2_COMPATIBILITY )
class PYCXX_EXPORT Exception : public BaseException
{
protected:
explicit StandardError()
public:
Exception( ExtensionExceptionType &exception, const std::string &reason )
: BaseException( exception, reason )
{}
Exception( ExtensionExceptionType &exception, Object &reason )
: BaseException( exception, reason )
{}
Exception( PyObject *exception, const std::string &reason )
: BaseException( exception, reason )
{}
explicit Exception()
: BaseException()
{}
};
#endif
#define PYCXX_STANDARD_EXCEPTION( eclass, bclass ) \
class PYCXX_EXPORT eclass : public bclass \
@@ -114,6 +111,56 @@ namespace Py
#include <CXX/Python3/cxx_standard_exceptions.hxx>
#undef PYCXX_STANDARD_EXCEPTION
#define PYCXX_USER_EXCEPTION_STR_ARG( uclass ) \
class PYCXX_EXPORT 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 PYCXX_EXPORT 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
#endif

View File

@@ -270,7 +270,7 @@ namespace Py
return new_reference_to( result.ptr() );
}
catch( Exception & )
catch( BaseException & )
{
return 0;
}
@@ -307,7 +307,7 @@ namespace Py
return new_reference_to( result.ptr() );
}
catch( Exception & )
catch( BaseException & )
{
return 0;
}
@@ -335,7 +335,7 @@ namespace Py
return new_reference_to( result.ptr() );
}
catch( Exception & )
catch( BaseException & )
{
return 0;
}

View File

@@ -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; \
} \
@@ -119,6 +119,13 @@ 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()
@@ -247,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;
}
@@ -263,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;
}
@@ -293,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 );
@@ -313,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 )

View File

@@ -89,14 +89,20 @@ 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 int sequence_ass_item( 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 & );

View File

@@ -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)();

View File

@@ -49,40 +49,12 @@ bool InitialisePythonIndirectInterface();
// Wrap Exception variables as function calls
//
PYCXX_EXPORT PyObject * _Exc_Exception();
PYCXX_EXPORT PyObject * _Exc_StandardError();
PYCXX_EXPORT PyObject * _Exc_ArithmeticError();
PYCXX_EXPORT PyObject * _Exc_LookupError();
PYCXX_EXPORT PyObject * _Exc_AssertionError();
PYCXX_EXPORT PyObject * _Exc_AttributeError();
PYCXX_EXPORT PyObject * _Exc_EOFError();
PYCXX_EXPORT PyObject * _Exc_FloatingPointError();
PYCXX_EXPORT PyObject * _Exc_EnvironmentError();
PYCXX_EXPORT PyObject * _Exc_IOError();
PYCXX_EXPORT PyObject * _Exc_OSError();
PYCXX_EXPORT PyObject * _Exc_ImportError();
PYCXX_EXPORT PyObject * _Exc_IndexError();
PYCXX_EXPORT PyObject * _Exc_KeyError();
PYCXX_EXPORT PyObject * _Exc_KeyboardInterrupt();
PYCXX_EXPORT PyObject * _Exc_MemoryError();
PYCXX_EXPORT PyObject * _Exc_NameError();
PYCXX_EXPORT PyObject * _Exc_OverflowError();
PYCXX_EXPORT PyObject * _Exc_RuntimeError();
PYCXX_EXPORT PyObject * _Exc_NotImplementedError();
PYCXX_EXPORT PyObject * _Exc_SyntaxError();
PYCXX_EXPORT PyObject * _Exc_SystemError();
PYCXX_EXPORT PyObject * _Exc_SystemExit();
PYCXX_EXPORT PyObject * _Exc_TypeError();
PYCXX_EXPORT PyObject * _Exc_ValueError();
PYCXX_EXPORT PyObject * _Exc_ZeroDivisionError();
#ifdef MS_WINDOWS
PYCXX_EXPORT PyObject * _Exc_WindowsError();
#endif
#define PYCXX_STANDARD_EXCEPTION( eclass, bclass ) \
PYCXX_EXPORT PyObject * _Exc_##eclass();
PYCXX_EXPORT PyObject * _Exc_IndentationError();
PYCXX_EXPORT PyObject * _Exc_TabError();
PYCXX_EXPORT PyObject * _Exc_UnboundLocalError();
PYCXX_EXPORT PyObject * _Exc_UnicodeError();
#include "CXX/Python3/cxx_standard_exceptions.hxx"
#undef PYCXX_STANDARD_EXCEPTION
//
// Wrap Object variables as function calls

View File

@@ -375,7 +375,7 @@ namespace Py
{
if( PyObject_SetAttrString( p, const_cast<char*>( s.c_str() ), *value ) == -1 )
{
throw AttributeError( "setAttr failed." );
ifPyErrorThrowCxxException();
}
}
@@ -383,7 +383,7 @@ namespace Py
{
if( PyObject_DelAttrString( p, const_cast<char*>( s.c_str() ) ) == -1 )
{
throw AttributeError( "delAttr failed." );
ifPyErrorThrowCxxException();
}
}
@@ -394,8 +394,7 @@ namespace Py
{
if( PyObject_DelItem( p, *key ) == -1 )
{
// failed to link on Windows?
throw KeyError( "delItem failed." );
ifPyErrorThrowCxxException();
}
}
// Equality and comparison use PyObject_Compare
@@ -1378,7 +1377,7 @@ namespace Py
{
if( PySequence_SetItem( ptr(), i, *ob ) == -1 )
{
throw Exception();
ifPyErrorThrowCxxException();
}
}
@@ -1442,7 +1441,7 @@ namespace Py
protected:
friend class SeqBase<T>;
SeqBase<T> *seq;
size_type count;
sequence_index_type count;
public:
~iterator()
@@ -1453,7 +1452,7 @@ namespace Py
, count( 0 )
{}
iterator( SeqBase<T> *s, size_type where )
iterator( SeqBase<T> *s, Py_ssize_t where )
: seq( s )
, count( where )
{}
@@ -1513,29 +1512,29 @@ namespace Py
return *this;
}
iterator operator+( int n ) const
iterator operator+( sequence_index_type n ) const
{
return iterator( seq, count + n );
}
iterator operator-( int n ) const
iterator operator-( sequence_index_type n ) const
{
return iterator( seq, count - n );
}
iterator &operator+=( int n )
iterator &operator+=( sequence_index_type n )
{
count = count + n;
return *this;
}
iterator &operator-=( int n )
iterator &operator-=( sequence_index_type n )
{
count = count - n;
return *this;
}
int operator-( const iterator &other ) const
sequence_index_type operator-( const iterator &other ) const
{
if( seq->ptr() != other.seq->ptr() )
{
@@ -1612,7 +1611,7 @@ namespace Py
, count( 0 )
{}
const_iterator( const SeqBase<T> *s, size_type where )
const_iterator( const SeqBase<T> *s, sequence_index_type where )
: seq( s )
, count( where )
{}
@@ -1642,7 +1641,7 @@ namespace Py
return *this;
}
const_iterator operator+( int n ) const
const_iterator operator+( sequence_index_type n ) const
{
return const_iterator( seq, count + n );
}
@@ -1677,18 +1676,18 @@ namespace Py
return count >= other.count;
}
const_iterator operator-( int n )
const_iterator operator-( sequence_index_type n )
{
return const_iterator( seq, count - n );
}
const_iterator &operator+=( int n )
const_iterator &operator+=( sequence_index_type n )
{
count = count + n;
return *this;
}
const_iterator &operator-=( int n )
const_iterator &operator-=( sequence_index_type n )
{
count = count - n;
return *this;
@@ -1789,6 +1788,7 @@ namespace Py
virtual bool accepts( PyObject *pyob ) const
{
return pyob != NULL
// QQQ _Unicode_Check for a Byte???
&& Py::_Unicode_Check( pyob )
&& PySequence_Length( pyob ) == 1;
}
@@ -2176,7 +2176,7 @@ namespace Py
// note PyTuple_SetItem is a thief...
if( PyTuple_SetItem( ptr(), offset, new_reference_to( ob ) ) == -1 )
{
throw Exception();
ifPyErrorThrowCxxException();
}
}
@@ -2202,7 +2202,7 @@ namespace Py
{
if( PyTuple_SetItem( ptr(), i, new_reference_to( Py::_None() ) ) == -1 )
{
throw Exception();
ifPyErrorThrowCxxException();
}
}
}
@@ -2218,7 +2218,7 @@ namespace Py
{
if( PyTuple_SetItem( ptr(), i, new_reference_to( s[i] ) ) == -1 )
{
throw Exception();
ifPyErrorThrowCxxException();
}
}
}
@@ -2385,7 +2385,7 @@ namespace Py
{
if( PyList_SetItem( ptr(), i, new_reference_to( Py::_None() ) ) == -1 )
{
throw Exception();
ifPyErrorThrowCxxException();
}
}
}
@@ -2401,7 +2401,7 @@ namespace Py
{
if( PyList_SetItem( ptr(), i, new_reference_to( s[i] ) ) == -1 )
{
throw Exception();
ifPyErrorThrowCxxException();
}
}
}
@@ -2439,7 +2439,7 @@ namespace Py
{
if( PyList_SetSlice( ptr(), i, j, *v ) == -1 )
{
throw Exception();
ifPyErrorThrowCxxException();
}
}
@@ -2447,7 +2447,7 @@ namespace Py
{
if( PyList_Append( ptr(), *ob ) == -1 )
{
throw Exception();
ifPyErrorThrowCxxException();
}
}
@@ -2460,7 +2460,7 @@ namespace Py
{
if( PyList_Insert( ptr(), i, *ob ) == -1 )
{
throw Exception();
ifPyErrorThrowCxxException();
}
}
@@ -2468,7 +2468,7 @@ namespace Py
{
if( PyList_Sort( ptr() ) == -1 )
{
throw Exception();
ifPyErrorThrowCxxException();
}
}
@@ -2476,7 +2476,7 @@ namespace Py
{
if( PyList_Reverse( ptr() ) == -1 )
{
throw Exception();
ifPyErrorThrowCxxException();
}
}
};
@@ -2674,7 +2674,7 @@ namespace Py
// If you assume that Python mapping is a hash_map...
// hash_map::value_type is not assignable, but
//( *it ).second = data must be a valid expression
typedef Py_ssize_t size_type;
typedef PyCxx_ssize_t size_type;
typedef Object key_type;
typedef mapref<T> data_type;
typedef std::pair< const T, T > value_type;
@@ -2726,7 +2726,7 @@ namespace Py
}
}
virtual size_type size() const
virtual Py_ssize_t size() const
{
return PyMapping_Length( ptr() );
}
@@ -2757,7 +2757,7 @@ namespace Py
return mapref<T>( *this, key );
}
size_type length() const
Py_ssize_t length() const
{
return PyMapping_Length( ptr() );
}
@@ -2786,7 +2786,7 @@ namespace Py
{
if( PyMapping_SetItemString( ptr(), const_cast<char*>( s ), *ob ) == -1 )
{
throw Exception();
ifPyErrorThrowCxxException();
}
}
@@ -2794,7 +2794,7 @@ namespace Py
{
if( PyMapping_SetItemString( ptr(), const_cast<char*>( s.c_str() ), *ob ) == -1 )
{
throw Exception();
ifPyErrorThrowCxxException();
}
}
@@ -2802,7 +2802,7 @@ namespace Py
{
if( PyObject_SetItem( ptr(), s.ptr(), ob.ptr() ) == -1 )
{
throw Exception();
ifPyErrorThrowCxxException();
}
}
@@ -2810,7 +2810,7 @@ namespace Py
{
if( PyMapping_DelItemString( ptr(), const_cast<char*>( s.c_str() ) ) == -1 )
{
throw Exception();
ifPyErrorThrowCxxException();
}
}
@@ -2818,7 +2818,7 @@ namespace Py
{
if( PyMapping_DelItem( ptr(), *s ) == -1 )
{
throw Exception();
ifPyErrorThrowCxxException();
}
}
@@ -2853,7 +2853,7 @@ namespace Py
//
MapBase<T> *map;
List keys; // for iterating over the map
size_type pos; // index into the keys
sequence_index_type pos; // index into the keys
public:
~iterator()
@@ -2970,7 +2970,7 @@ namespace Py
friend class MapBase<T>;
const MapBase<T> *map;
List keys; // for iterating over the map
size_type pos; // index into the keys
Py_ssize_t pos; // index into the keys
public:
~const_iterator()
@@ -2982,7 +2982,7 @@ namespace Py
, pos()
{}
const_iterator( const MapBase<T> *m, List k, size_type p )
const_iterator( const MapBase<T> *m, List k, Py_ssize_t p )
: map( m )
, keys( k )
, pos( p )
@@ -3449,7 +3449,7 @@ namespace Py
//------------------------------------------------------------
// type
inline Object type( const Exception &) // return the type of the error
inline Object type( const BaseException & ) // return the type of the error
{
PyObject *ptype, *pvalue, *ptrace;
PyErr_Fetch( &ptype, &pvalue, &ptrace );
@@ -3460,7 +3460,7 @@ namespace Py
return result;
}
inline Object value( const Exception &) // return the value of the error
inline Object value( const BaseException & ) // return the value of the error
{
PyObject *ptype, *pvalue, *ptrace;
PyErr_Fetch( &ptype, &pvalue, &ptrace );
@@ -3471,7 +3471,7 @@ namespace Py
return result;
}
inline Object trace( const Exception &) // return the traceback of the error
inline Object trace( const BaseException & ) // return the traceback of the error
{
PyObject *ptype, *pvalue, *ptrace;
PyErr_Fetch( &ptype, &pvalue, &ptrace );

View File

@@ -72,12 +72,94 @@ namespace Py
PythonType &supportStr( void );
PythonType &supportHash( void );
PythonType &supportCall( void );
PythonType &supportIter( void );
PythonType &supportSequenceType( void );
PythonType &supportMappingType( void );
PythonType &supportNumberType( void );
PythonType &supportBufferType( void );
#define B( n ) (1<<(n))
enum {
support_iter_iter = B(0),
support_iter_iternext = B(1)
};
PythonType &supportIter( int methods_to_support=
support_iter_iter |
support_iter_iternext );
enum {
support_sequence_length = B(0),
support_sequence_repeat = B(1),
support_sequence_item = B(2),
support_sequence_slice = B(3),
support_sequence_concat = B(4),
support_sequence_ass_item = B(5),
support_sequence_ass_slice = B(6),
support_sequence_inplace_concat = B(7),
support_sequence_inplace_repeat = B(8),
support_sequence_contains = B(9)
};
PythonType &supportSequenceType( int methods_to_support=
support_sequence_length |
support_sequence_repeat |
support_sequence_item |
support_sequence_slice |
support_sequence_concat
);
enum {
support_mapping_length = B(0),
support_mapping_subscript = B(1),
support_mapping_ass_subscript = B(2)
};
PythonType &supportMappingType( int methods_to_support=
support_mapping_length |
support_mapping_subscript
);
enum {
support_number_add = B(0),
support_number_subtract = B(1),
support_number_multiply = B(2),
support_number_remainder = B(3),
support_number_divmod = B(4),
support_number_power = B(5),
support_number_negative = B(6),
support_number_positive = B(7),
support_number_absolute = B(8),
support_number_invert = B(9),
support_number_lshift = B(10),
support_number_rshift = B(11),
support_number_and = B(12),
support_number_xor = B(13),
support_number_or = B(14),
support_number_int = B(15),
support_number_float= B(16)
};
PythonType &supportNumberType( int methods_to_support=
support_number_add |
support_number_subtract |
support_number_multiply |
support_number_remainder |
support_number_divmod |
support_number_power |
support_number_negative |
support_number_positive |
support_number_absolute |
support_number_invert |
support_number_lshift |
support_number_rshift |
support_number_and |
support_number_xor |
support_number_or |
support_number_int |
support_number_float
);
enum {
support_buffer_getbuffer = B(0),
support_buffer_releasebuffer = B(1)
};
PythonType &supportBufferType( int methods_to_support=
support_buffer_getbuffer |
support_buffer_releasebuffer
);
#undef B
PythonType &set_tp_dealloc( void (*tp_dealloc)( PyObject * ) );
PythonType &set_tp_init( int (*tp_init)( PyObject *self, PyObject *args, PyObject *kwds ) );

File diff suppressed because it is too large Load Diff

View File

@@ -2,20 +2,67 @@
#pragma error( "define PYCXX_STANDARD_EXCEPTION before including" )
#endif
PYCXX_STANDARD_EXCEPTION( LookupError, StandardError )
PYCXX_STANDARD_EXCEPTION( ArithmeticError, StandardError )
PYCXX_STANDARD_EXCEPTION( EnvironmentError, StandardError )
PYCXX_STANDARD_EXCEPTION( TypeError, StandardError )
PYCXX_STANDARD_EXCEPTION( IndexError, LookupError )
PYCXX_STANDARD_EXCEPTION( AttributeError, StandardError )
PYCXX_STANDARD_EXCEPTION( NameError, StandardError )
PYCXX_STANDARD_EXCEPTION( RuntimeError, StandardError )
PYCXX_STANDARD_EXCEPTION( NotImplementedError, StandardError )
PYCXX_STANDARD_EXCEPTION( SystemError, StandardError )
PYCXX_STANDARD_EXCEPTION( KeyError, LookupError )
PYCXX_STANDARD_EXCEPTION( ValueError, StandardError )
PYCXX_STANDARD_EXCEPTION( OverflowError, ArithmeticError )
PYCXX_STANDARD_EXCEPTION( ZeroDivisionError, ArithmeticError )
PYCXX_STANDARD_EXCEPTION( FloatingPointError, ArithmeticError )
PYCXX_STANDARD_EXCEPTION( MemoryError, StandardError )
PYCXX_STANDARD_EXCEPTION( SystemExit, StandardError )
// taken for python3.5 documentation
// EnvironmentError and IOError are not used in Python3
//PYCXX_STANDARD_EXCEPTION( EnvironmentError, QQQ )
//PYCXX_STANDARD_EXCEPTION( IOError, QQQ )
// 5.4 Exception hierarchy
PYCXX_STANDARD_EXCEPTION( SystemExit, BaseException )
PYCXX_STANDARD_EXCEPTION( KeyboardInterrupt, BaseException )
PYCXX_STANDARD_EXCEPTION( GeneratorExit, BaseException )
#if !defined( PYCXX_6_2_COMPATIBILITY )
PYCXX_STANDARD_EXCEPTION( Exception, BaseException )
#endif
PYCXX_STANDARD_EXCEPTION( StopIteration, Exception )
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 5
PYCXX_STANDARD_EXCEPTION( StopAsyncIteration, Exception )
#endif
PYCXX_STANDARD_EXCEPTION( ArithmeticError, Exception )
PYCXX_STANDARD_EXCEPTION( FloatingPointError, ArithmeticError )
PYCXX_STANDARD_EXCEPTION( OverflowError, ArithmeticError )
PYCXX_STANDARD_EXCEPTION( ZeroDivisionError, ArithmeticError )
PYCXX_STANDARD_EXCEPTION( AssertionError, Exception )
PYCXX_STANDARD_EXCEPTION( AttributeError, Exception )
PYCXX_STANDARD_EXCEPTION( BufferError, Exception )
PYCXX_STANDARD_EXCEPTION( EOFError, Exception )
PYCXX_STANDARD_EXCEPTION( ImportError, Exception )
PYCXX_STANDARD_EXCEPTION( LookupError, Exception )
PYCXX_STANDARD_EXCEPTION( IndexError, LookupError )
PYCXX_STANDARD_EXCEPTION( KeyError, LookupError )
PYCXX_STANDARD_EXCEPTION( MemoryError, Exception )
PYCXX_STANDARD_EXCEPTION( NameError, Exception )
PYCXX_STANDARD_EXCEPTION( UnboundLocalError, NameError )
PYCXX_STANDARD_EXCEPTION( OSError, Exception )
PYCXX_STANDARD_EXCEPTION( BlockingIOError, OSError )
PYCXX_STANDARD_EXCEPTION( ChildProcessError,OSError )
PYCXX_STANDARD_EXCEPTION( ConnectionError, OSError )
PYCXX_STANDARD_EXCEPTION( BrokenPipeError, ConnectionError )
PYCXX_STANDARD_EXCEPTION( ConnectionAbortedError, ConnectionError )
PYCXX_STANDARD_EXCEPTION( ConnectionRefusedError, ConnectionError )
PYCXX_STANDARD_EXCEPTION( ConnectionResetError, ConnectionError )
PYCXX_STANDARD_EXCEPTION( FileExistsError, OSError )
PYCXX_STANDARD_EXCEPTION( FileNotFoundError, OSError )
PYCXX_STANDARD_EXCEPTION( InterruptedError, OSError )
PYCXX_STANDARD_EXCEPTION( IsADirectoryError, OSError )
PYCXX_STANDARD_EXCEPTION( NotADirectoryError, OSError )
PYCXX_STANDARD_EXCEPTION( PermissionError, OSError )
PYCXX_STANDARD_EXCEPTION( ProcessLookupError, OSError )
PYCXX_STANDARD_EXCEPTION( TimeoutError, OSError )
PYCXX_STANDARD_EXCEPTION( ReferenceError, Exception )
PYCXX_STANDARD_EXCEPTION( RuntimeError, Exception )
PYCXX_STANDARD_EXCEPTION( NotImplementedError, RuntimeError )
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 5
PYCXX_STANDARD_EXCEPTION( RecursionError, RuntimeError )
#endif
PYCXX_STANDARD_EXCEPTION( SyntaxError, Exception )
PYCXX_STANDARD_EXCEPTION( IndentationError, SyntaxError )
PYCXX_STANDARD_EXCEPTION( TabError, IndentationError )
PYCXX_STANDARD_EXCEPTION( SystemError, Exception )
PYCXX_STANDARD_EXCEPTION( TypeError, Exception )
PYCXX_STANDARD_EXCEPTION( ValueError, Exception )
PYCXX_STANDARD_EXCEPTION( UnicodeError, ValueError )
PYCXX_STANDARD_EXCEPTION( UnicodeDecodeError, UnicodeError )
PYCXX_STANDARD_EXCEPTION( UnicodeEncodeError, UnicodeError )
PYCXX_STANDARD_EXCEPTION( UnicodeTranslateError,UnicodeError )

View File

@@ -38,8 +38,8 @@
#ifndef __PyCXX_version_hxx__
#define __PyCXX_version_hxx__
#define PYCXX_VERSION_MAJOR 6
#define PYCXX_VERSION_MINOR 3
#define PYCXX_VERSION_MAJOR 7
#define PYCXX_VERSION_MINOR 0
#define PYCXX_VERSION_PATCH 0
#define PYCXX_MAKEVERSION( major, minor, patch ) ((major<<16)|(minor<<8)|(patch))
#define PYCXX_VERSION PYCXX_MAKEVERSION( PYCXX_VERSION_MAJOR, PYCXX_VERSION_MINOR, PYCXX_VERSION_PATCH )