upgrade PyCXX from v6.2.5 to v6.2.8

This commit is contained in:
wmayer 2016-08-10 11:55:23 +02:00
parent e25a5b7fca
commit 50ca24fd55
8 changed files with 142 additions and 118 deletions

View File

@ -91,7 +91,9 @@ static PyObject *ptr__Exc_NotImplementedError = NULL;
static PyObject *ptr__Exc_OSError = NULL;
static PyObject *ptr__Exc_OverflowError = NULL;
static PyObject *ptr__Exc_RuntimeError = 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;
@ -125,6 +127,7 @@ static PyTypeObject *ptr__Slice_Type = NULL;
static PyTypeObject *ptr__TraceBack_Type = NULL;
static PyTypeObject *ptr__Tuple_Type = NULL;
static PyTypeObject *ptr__Type_Type = NULL;
static PyTypeObject *ptr__Unicode_Type = NULL;
#if PY_MAJOR_VERSION == 2
static PyTypeObject *ptr__Int_Type = NULL;
static PyTypeObject *ptr__String_Type = NULL;
@ -264,7 +267,9 @@ bool InitialisePythonIndirectInterface()
ptr__Exc_OSError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_OSError" );
ptr__Exc_OverflowError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_OverflowError" );
ptr__Exc_RuntimeError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_RuntimeError" );
#if PY_MAJOR_VERSION == 2
ptr__Exc_StandardError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_StandardError" );
#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" );
@ -280,7 +285,11 @@ bool InitialisePythonIndirectInterface()
ptr__Exc_UnicodeError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_UnicodeError" );
ptr__PyNone = GetPyObject_As_PyObjectPointer( "_Py_NoneStruct" );
#if PY_MAJOR_VERSION == 2
ptr__PyFalse = GetPyObject_As_PyObjectPointer( "_Py_ZeroStruct" );
#else
ptr__PyFalse = GetPyObject_As_PyObjectPointer( "_Py_FalseStruct" );
#endif
ptr__PyTrue = GetPyObject_As_PyObjectPointer( "_Py_TrueStruct" );
ptr__CFunction_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyCFunction_Type" );
@ -343,7 +352,9 @@ PYCXX_EXPORT PyObject *_Exc_NotImplementedError() { return ptr__Exc_NotImplem
PYCXX_EXPORT PyObject *_Exc_OSError() { return ptr__Exc_OSError; }
PYCXX_EXPORT PyObject *_Exc_OverflowError() { return ptr__Exc_OverflowError; }
PYCXX_EXPORT PyObject *_Exc_RuntimeError() { return ptr__Exc_RuntimeError; }
#if PY_MAJOR_VERSION == 2
PYCXX_EXPORT PyObject *_Exc_StandardError() { return ptr__Exc_StandardError; }
#endif
PYCXX_EXPORT PyObject *_Exc_SyntaxError() { return ptr__Exc_SyntaxError; }
PYCXX_EXPORT PyObject *_Exc_SystemError() { return ptr__Exc_SystemError; }
PYCXX_EXPORT PyObject *_Exc_SystemExit() { return ptr__Exc_SystemExit; }

View File

@ -220,7 +220,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 );

View File

@ -49,6 +49,8 @@
#include <iterator>
#include <utility>
#include <typeinfo>
#include <algorithm>
namespace Py
{
@ -101,19 +103,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 +126,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 +177,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 +188,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 +231,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
{
@ -371,13 +377,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.");
throw AttributeError ("setAttr failed.");
}
void delAttr (const std::string& s)
{
if(PyObject_DelAttrString (p, const_cast<char*>(s.c_str())) == -1)
throw AttributeError ("delAttr failed.");
throw AttributeError ("delAttr failed.");
}
// PyObject_SetItem is too weird to be using from C++
@ -385,9 +391,9 @@ 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)
// failed to link on Windows?
throw KeyError("delItem failed.");
}
// Equality and comparison use PyObject_RichCompareBool
@ -2909,7 +2915,8 @@ namespace Py
// Queries
List keys () const
{
return List(PyMapping_Keys(ptr()), true);
static char keys[] = {'k', 'e', 'y', 's', 0};
return List(PyObject_CallMethod( ptr(), keys, NULL ), true );
}
List values () const
@ -3212,18 +3219,35 @@ namespace Py
// Call
Object apply(const Tuple& args) const
{
return asObject(PyObject_CallObject(ptr(), args.ptr()));
PyObject *result = PyObject_CallObject( ptr(), args.ptr() );
if( result == NULL )
{
throw Exception();
}
return asObject( result );
}
// Call with keywords
Object apply(const Tuple& args, const Dict& kw) const
{
return asObject( PyEval_CallObjectWithKeywords( ptr(), args.ptr(), kw.ptr() ) );
PyObject *result = PyEval_CallObjectWithKeywords( ptr(), args.ptr(), kw.ptr() );
if( result == NULL )
{
throw Exception();
}
return asObject( result );
}
Object apply(PyObject* pargs = 0) const
{
return apply (Tuple(pargs));
if( pargs == 0 )
{
return apply( Tuple() );
}
else
{
return apply( Tuple( pargs ) );
}
}
};

View File

@ -191,6 +191,7 @@ ExtensionModuleBase::ExtensionModuleBase( const char *name )
: m_module_name( name )
, m_full_module_name( __Py_PackageContext() != NULL ? std::string( __Py_PackageContext() ) : m_module_name )
, m_method_table()
, m_module( NULL )
{}
ExtensionModuleBase::~ExtensionModuleBase()
@ -222,7 +223,7 @@ public:
void ExtensionModuleBase::initialize( const char *module_doc )
{
PyObject *module_ptr = new ExtensionModuleBasePtr( this );
Py_InitModule4
m_module = Py_InitModule4
(
const_cast<char *>( m_module_name.c_str() ), // name
m_method_table.table(), // methods
@ -242,6 +243,11 @@ Py::Dict ExtensionModuleBase::moduleDictionary( void ) const
return module().getDict();
}
Object ExtensionModuleBase::moduleObject( void ) const
{
return Object( m_module );
}
//================================================================================
//
// Implementation of PythonType
@ -1787,27 +1793,27 @@ extern "C" PyObject *method_noargs_call_handler( PyObject *_self_and_name_tuple,
return 0;
}
#if 0
try
{
Tuple self_and_name_tuple( _self_and_name_tuple );
PyObject *self_in_cobject = self_and_name_tuple[0].ptr();
void *self_as_void = PyCObject_AsVoidPtr( self_in_cobject );
if( self_as_void == NULL )
return NULL;
ExtensionModuleBase *self = static_cast<ExtensionModuleBase *>( self_as_void );
String py_name( self_and_name_tuple[1] );
std::string name( py_name.as_std_string( NULL ) );
Object result( self->invoke_method_noargs( name ) );
return new_reference_to( result.ptr() );
}
catch( Exception & )
{
return 0;
try
{
Tuple self_and_name_tuple( _self_and_name_tuple );
PyObject *self_in_cobject = self_and_name_tuple[0].ptr();
void *self_as_void = PyCObject_AsVoidPtr( self_in_cobject );
if( self_as_void == NULL )
return NULL;
ExtensionModuleBase *self = static_cast<ExtensionModuleBase *>( self_as_void );
String py_name( self_and_name_tuple[1] );
std::string name( py_name.as_std_string( NULL ) );
Object result( self->invoke_method_noargs( name ) );
return new_reference_to( result.ptr() );
}
catch( Exception & )
{
return 0;
}
#else
return 0;

View File

@ -124,7 +124,7 @@ namespace Py
~ExtensionClassMethodsTable()
{
delete m_methods_table;
delete[] m_methods_table;
}
// check that all methods added are unique
@ -219,7 +219,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 );

View File

@ -50,6 +50,7 @@
#include <iterator>
#include <utility>
#include <typeinfo>
#include <algorithm>
namespace Py
{
@ -221,7 +222,9 @@ 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 );
}
@ -378,13 +381,17 @@ 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." );
{
throw AttributeError( "setAttr failed." );
}
}
void delAttr( const std::string &s )
{
if( PyObject_DelAttrString( p, const_cast<char*>( s.c_str() ) ) == -1 )
{
throw AttributeError( "delAttr failed." );
}
}
// PyObject_SetItem is too weird to be using from C++
@ -392,9 +399,11 @@ 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 )
{
// failed to link on Windows?
throw KeyError( "delItem failed." );
}
}
// Equality and comparison use PyObject_Compare
@ -413,7 +422,7 @@ namespace Py
{
}
virtual bool accepts( PyObject *pyob )
virtual bool accepts( PyObject *pyob ) const
{
return pyob == NULL;
}
@ -1408,14 +1417,18 @@ namespace Py
void verify_length( size_type required_size ) const
{
if( size() != required_size )
{
throw IndexError( "Unexpected SeqBase<T> length." );
}
}
void verify_length( size_type min_size, size_type max_size ) const
{
size_type n = size();
if( n < min_size || n > max_size )
{
throw IndexError( "Unexpected SeqBase<T> length." );
}
}
class PYCXX_EXPORT iterator
@ -1520,8 +1533,9 @@ namespace Py
int operator-( const iterator &other ) const
{
if( seq->ptr() != other.seq->ptr() )
{
throw RuntimeError( "SeqBase<T>::iterator comparison error" );
}
return count - other.count;
}
@ -1672,7 +1686,9 @@ namespace Py
int operator-( const const_iterator &other ) const
{
if( *seq != *other.seq )
{
throw RuntimeError( "SeqBase<T>::const_iterator::- error" );
}
return count - other.count;
}
@ -3122,7 +3138,9 @@ namespace Py
Callable &operator=( PyObject *rhsp )
{
if( ptr() != rhsp )
{
set( rhsp );
}
return *this;
}
@ -3135,18 +3153,35 @@ namespace Py
// Call
Object apply( const Tuple &args ) const
{
return asObject( PyObject_CallObject( ptr(), args.ptr() ) );
PyObject *result = PyObject_CallObject( ptr(), args.ptr() );
if( result == NULL )
{
throw Exception();
}
return asObject( result );
}
// Call with keywords
Object apply( const Tuple &args, const Dict &kw ) const
{
return asObject( PyEval_CallObjectWithKeywords( ptr(), args.ptr(), kw.ptr() ) );
PyObject *result = PyEval_CallObjectWithKeywords( ptr(), args.ptr(), kw.ptr() );
if( result == NULL )
{
throw Exception();
}
return asObject( result );
}
Object apply( PyObject *pargs = 0 ) const
{
return apply( Tuple( pargs ) );
if( pargs == 0 )
{
return apply( Tuple() );
}
else
{
return apply( Tuple( pargs ) );
}
}
};

View File

@ -205,6 +205,11 @@ Py::Dict ExtensionModuleBase::moduleDictionary( void ) const
return module().getDict();
}
Object ExtensionModuleBase::moduleObject( void ) const
{
return Object( m_module );
}
//================================================================================
//
// Implementation of PythonType
@ -1518,63 +1523,6 @@ extern "C" PyObject *method_noargs_call_handler( PyObject *_self_and_name_tuple,
}
}
#if 0
extern "C" PyObject *method_noargs_call_handler( PyObject *_self_and_name_tuple, PyObject * )
{
try
{
Tuple self_and_name_tuple( _self_and_name_tuple );
PyObject *self_in_cobject = self_and_name_tuple[0].ptr();
void *self_as_void = PyCObject_AsVoidPtr( self_in_cobject );
if( self_as_void == NULL )
return NULL;
ExtensionModuleBase *self = static_cast<ExtensionModuleBase *>( self_as_void );
Object result
(
self->invoke_method_noargs
(
PyCObject_AsVoidPtr( self_and_name_tuple[1].ptr() )
)
);
return new_reference_to( result.ptr() );
}
catch( Exception & )
{
return 0;
}
// #if 0
try
{
Tuple self_and_name_tuple( _self_and_name_tuple );
PyObject *self_in_cobject = self_and_name_tuple[0].ptr();
void *self_as_void = PyCObject_AsVoidPtr( self_in_cobject );
if( self_as_void == NULL )
return NULL;
ExtensionModuleBase *self = static_cast<ExtensionModuleBase *>( self_as_void );
String py_name( self_and_name_tuple[1] );
std::string name( py_name.as_std_string( NULL ) );
Object result( self->invoke_method_noargs( name ) );
return new_reference_to( result.ptr() );
}
catch( Exception & )
{
return 0;
}
// #else
return 0;
// #endif
}
#endif
extern "C" PyObject *method_varargs_call_handler( PyObject *_self_and_name_tuple, PyObject *_args )
{
try

View File

@ -40,7 +40,7 @@
#define PYCXX_VERSION_MAJOR 6
#define PYCXX_VERSION_MINOR 2
#define PYCXX_VERSION_PATCH 5
#define PYCXX_VERSION_PATCH 8
#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 )
#endif