Upgraded PyCXX to version 6.2.5
This commit is contained in:
@@ -114,19 +114,5 @@
|
||||
#if PY_MAJOR_VERSION < 2 || (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 5)
|
||||
typedef int Py_ssize_t;
|
||||
#endif
|
||||
|
||||
// export macro
|
||||
#if defined( _MSC_VER )
|
||||
# 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
|
||||
|
||||
#endif // __PyCXX_config_hh__
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace Py
|
||||
|
||||
class Object;
|
||||
|
||||
class PYCXX_EXPORT Exception
|
||||
class Exception
|
||||
{
|
||||
public:
|
||||
Exception( ExtensionExceptionType &exception, const std::string& reason );
|
||||
@@ -83,28 +83,28 @@ namespace Py
|
||||
|
||||
|
||||
// Abstract
|
||||
class PYCXX_EXPORT StandardError: public Exception
|
||||
class StandardError: public Exception
|
||||
{
|
||||
protected:
|
||||
explicit StandardError()
|
||||
{}
|
||||
};
|
||||
|
||||
class PYCXX_EXPORT LookupError: public StandardError
|
||||
class LookupError: public StandardError
|
||||
{
|
||||
protected:
|
||||
explicit LookupError()
|
||||
{}
|
||||
};
|
||||
|
||||
class PYCXX_EXPORT ArithmeticError: public StandardError
|
||||
class ArithmeticError: public StandardError
|
||||
{
|
||||
protected:
|
||||
explicit ArithmeticError()
|
||||
{}
|
||||
};
|
||||
|
||||
class PYCXX_EXPORT EnvironmentError: public StandardError
|
||||
class EnvironmentError: public StandardError
|
||||
{
|
||||
protected:
|
||||
explicit EnvironmentError()
|
||||
@@ -113,7 +113,7 @@ namespace Py
|
||||
|
||||
// Concrete
|
||||
|
||||
class PYCXX_EXPORT TypeError: public StandardError
|
||||
class TypeError: public StandardError
|
||||
{
|
||||
public:
|
||||
TypeError (const std::string& reason)
|
||||
@@ -123,7 +123,7 @@ namespace Py
|
||||
}
|
||||
};
|
||||
|
||||
class PYCXX_EXPORT IndexError: public LookupError
|
||||
class IndexError: public LookupError
|
||||
{
|
||||
public:
|
||||
IndexError (const std::string& reason)
|
||||
@@ -133,7 +133,7 @@ namespace Py
|
||||
}
|
||||
};
|
||||
|
||||
class PYCXX_EXPORT AttributeError: public StandardError
|
||||
class AttributeError: public StandardError
|
||||
{
|
||||
public:
|
||||
AttributeError (const std::string& reason)
|
||||
@@ -143,7 +143,7 @@ namespace Py
|
||||
}
|
||||
};
|
||||
|
||||
class PYCXX_EXPORT NameError: public StandardError
|
||||
class NameError: public StandardError
|
||||
{
|
||||
public:
|
||||
NameError (const std::string& reason)
|
||||
@@ -153,7 +153,7 @@ namespace Py
|
||||
}
|
||||
};
|
||||
|
||||
class PYCXX_EXPORT RuntimeError: public StandardError
|
||||
class RuntimeError: public StandardError
|
||||
{
|
||||
public:
|
||||
RuntimeError (const std::string& reason)
|
||||
@@ -163,7 +163,17 @@ namespace Py
|
||||
}
|
||||
};
|
||||
|
||||
class PYCXX_EXPORT SystemError: public StandardError
|
||||
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)
|
||||
@@ -173,7 +183,7 @@ namespace Py
|
||||
}
|
||||
};
|
||||
|
||||
class PYCXX_EXPORT KeyError: public LookupError
|
||||
class KeyError: public LookupError
|
||||
{
|
||||
public:
|
||||
KeyError (const std::string& reason)
|
||||
@@ -184,7 +194,7 @@ namespace Py
|
||||
};
|
||||
|
||||
|
||||
class PYCXX_EXPORT ValueError: public StandardError
|
||||
class ValueError: public StandardError
|
||||
{
|
||||
public:
|
||||
ValueError (const std::string& reason)
|
||||
@@ -194,7 +204,7 @@ namespace Py
|
||||
}
|
||||
};
|
||||
|
||||
class PYCXX_EXPORT OverflowError: public ArithmeticError
|
||||
class OverflowError: public ArithmeticError
|
||||
{
|
||||
public:
|
||||
OverflowError (const std::string& reason)
|
||||
@@ -204,7 +214,7 @@ namespace Py
|
||||
}
|
||||
};
|
||||
|
||||
class PYCXX_EXPORT ZeroDivisionError: public ArithmeticError
|
||||
class ZeroDivisionError: public ArithmeticError
|
||||
{
|
||||
public:
|
||||
ZeroDivisionError (const std::string& reason)
|
||||
@@ -214,7 +224,7 @@ namespace Py
|
||||
}
|
||||
};
|
||||
|
||||
class PYCXX_EXPORT FloatingPointError: public ArithmeticError
|
||||
class FloatingPointError: public ArithmeticError
|
||||
{
|
||||
public:
|
||||
FloatingPointError (const std::string& reason)
|
||||
@@ -224,7 +234,7 @@ namespace Py
|
||||
}
|
||||
};
|
||||
|
||||
class PYCXX_EXPORT MemoryError: public StandardError
|
||||
class MemoryError: public StandardError
|
||||
{
|
||||
public:
|
||||
MemoryError (const std::string& reason)
|
||||
@@ -234,7 +244,7 @@ namespace Py
|
||||
}
|
||||
};
|
||||
|
||||
class PYCXX_EXPORT SystemExit: public StandardError
|
||||
class SystemExit: public StandardError
|
||||
{
|
||||
public:
|
||||
SystemExit (const std::string& reason)
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
|
||||
namespace Py
|
||||
{
|
||||
class PYCXX_EXPORT ExtensionModuleBase
|
||||
class ExtensionModuleBase
|
||||
{
|
||||
public:
|
||||
ExtensionModuleBase( const char *name );
|
||||
@@ -66,9 +66,6 @@ namespace Py
|
||||
const std::string m_module_name;
|
||||
const std::string m_full_module_name;
|
||||
MethodTable m_method_table;
|
||||
#if PY3
|
||||
PyModuleDef m_module_def;
|
||||
#endif
|
||||
PyObject *m_module;
|
||||
|
||||
private:
|
||||
@@ -80,11 +77,11 @@ namespace Py
|
||||
};
|
||||
|
||||
// Note: Python calls noargs as varargs buts args==NULL
|
||||
extern "C" PYCXX_EXPORT PyObject *method_noargs_call_handler( PyObject *_self_and_name_tuple, PyObject * );
|
||||
extern "C" PYCXX_EXPORT PyObject *method_varargs_call_handler( PyObject *_self_and_name_tuple, PyObject *_args );
|
||||
extern "C" PYCXX_EXPORT PyObject *method_keyword_call_handler( PyObject *_self_and_name_tuple, PyObject *_args, PyObject *_keywords );
|
||||
extern "C" PyObject *method_noargs_call_handler( PyObject *_self_and_name_tuple, PyObject * );
|
||||
extern "C" PyObject *method_varargs_call_handler( PyObject *_self_and_name_tuple, PyObject *_args );
|
||||
extern "C" PyObject *method_keyword_call_handler( PyObject *_self_and_name_tuple, PyObject *_args, PyObject *_keywords );
|
||||
|
||||
extern "C" PYCXX_EXPORT void do_not_dealloc( void * );
|
||||
extern "C" void do_not_dealloc( void * );
|
||||
|
||||
template<TEMPLATE_TYPENAME T>
|
||||
class ExtensionModule : public ExtensionModuleBase
|
||||
@@ -139,8 +136,8 @@ namespace Py
|
||||
static PyObject *self = PyCObject_FromVoidPtr( this, do_not_dealloc );
|
||||
|
||||
Tuple args( 2 );
|
||||
args[0] = Object( self );
|
||||
args[1] = Object( PyCObject_FromVoidPtr( method_def, do_not_dealloc ) );
|
||||
args[0] = Object( self, true );
|
||||
args[1] = Object( PyCObject_FromVoidPtr( method_def, do_not_dealloc ), true );
|
||||
|
||||
PyObject *func = PyCFunction_New
|
||||
(
|
||||
|
||||
@@ -178,7 +178,7 @@ namespace Py
|
||||
Tuple self( 2 );
|
||||
|
||||
self[0] = Object( this );
|
||||
self[1] = Object( PyCObject_FromVoidPtr( method_def, do_not_dealloc ) );
|
||||
self[1] = Object( PyCObject_FromVoidPtr( method_def, do_not_dealloc ), true );
|
||||
|
||||
PyObject *func = PyCFunction_New( &method_def->ext_meth_def, self.ptr() );
|
||||
|
||||
|
||||
@@ -113,7 +113,7 @@ namespace Py
|
||||
};
|
||||
|
||||
|
||||
class PYCXX_EXPORT ExtensionClassMethodsTable
|
||||
class ExtensionClassMethodsTable
|
||||
{
|
||||
public:
|
||||
ExtensionClassMethodsTable()
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace Py
|
||||
|
||||
// This special deallocator does a delete on the pointer.
|
||||
|
||||
class PYCXX_EXPORT PythonExtensionBase : public PyObject
|
||||
class PythonExtensionBase : public PyObject
|
||||
{
|
||||
public:
|
||||
PythonExtensionBase();
|
||||
@@ -70,9 +70,7 @@ namespace Py
|
||||
virtual void reinit( Tuple &args, Dict &kwds );
|
||||
|
||||
// object basics
|
||||
#if defined( PYCXX_PYTHON_2TO3 ) || !defined( PY3 )
|
||||
virtual int print( FILE *, int );
|
||||
#endif
|
||||
virtual Object getattr( const char * );
|
||||
virtual int setattr( const char *, const Object & );
|
||||
virtual Object getattro( const String & );
|
||||
|
||||
@@ -63,7 +63,7 @@ namespace Py
|
||||
class ExtensionModuleBase;
|
||||
|
||||
// Make an Exception Type for use in raising custom exceptions
|
||||
class PYCXX_EXPORT ExtensionExceptionType : public Object
|
||||
class ExtensionExceptionType : public Object
|
||||
{
|
||||
public:
|
||||
ExtensionExceptionType();
|
||||
@@ -74,7 +74,7 @@ namespace Py
|
||||
void init( ExtensionModuleBase &module, const std::string &name );
|
||||
};
|
||||
|
||||
class PYCXX_EXPORT MethodTable
|
||||
class MethodTable
|
||||
{
|
||||
public:
|
||||
MethodTable();
|
||||
|
||||
@@ -1,597 +0,0 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "CXX/IndirectPythonInterface.hxx"
|
||||
|
||||
namespace Py
|
||||
{
|
||||
bool _Buffer_Check( PyObject *op ) { return (op)->ob_type == _Buffer_Type(); }
|
||||
bool _CFunction_Check( PyObject *op ) { return (op)->ob_type == _CFunction_Type(); }
|
||||
bool _Class_Check( PyObject *op ) { return (op)->ob_type == _Class_Type(); }
|
||||
bool _CObject_Check( PyObject *op ) { return (op)->ob_type == _CObject_Type(); }
|
||||
bool _Complex_Check( PyObject *op ) { return (op)->ob_type == _Complex_Type(); }
|
||||
bool _Dict_Check( PyObject *op ) { return (op)->ob_type == _Dict_Type(); }
|
||||
bool _File_Check( PyObject *op ) { return (op)->ob_type == _File_Type(); }
|
||||
bool _Float_Check( PyObject *op ) { return (op)->ob_type == _Float_Type(); }
|
||||
bool _Function_Check( PyObject *op ) { return (op)->ob_type == _Function_Type(); }
|
||||
bool _Instance_Check( PyObject *op ) { return (op)->ob_type == _Instance_Type(); }
|
||||
bool _Boolean_Check( PyObject *op ) { return (op)->ob_type == _Bool_Type(); }
|
||||
bool _Int_Check( PyObject *op ) { return (op)->ob_type == _Int_Type(); }
|
||||
bool _List_Check( PyObject *o ) { return o->ob_type == _List_Type(); }
|
||||
bool _Long_Check( PyObject *op ) { return (op)->ob_type == _Long_Type(); }
|
||||
bool _Method_Check( PyObject *op ) { return (op)->ob_type == _Method_Type(); }
|
||||
bool _Module_Check( PyObject *op ) { return (op)->ob_type == _Module_Type(); }
|
||||
bool _Range_Check( PyObject *op ) { return (op)->ob_type == _Range_Type(); }
|
||||
bool _Slice_Check( PyObject *op ) { return (op)->ob_type == _Slice_Type(); }
|
||||
bool _String_Check( PyObject *o ) { return o->ob_type == _String_Type(); }
|
||||
bool _TraceBack_Check( PyObject *v ) { return (v)->ob_type == _TraceBack_Type(); }
|
||||
bool _Tuple_Check( PyObject *op ) { return (op)->ob_type == _Tuple_Type(); }
|
||||
bool _Type_Check( PyObject *op ) { return (op)->ob_type == _Type_Type(); }
|
||||
|
||||
#if PY_MAJOR_VERSION >= 2
|
||||
bool _Unicode_Check( PyObject *op ) { return (op)->ob_type == _Unicode_Type(); }
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if defined(PY_WIN32_DELAYLOAD_PYTHON_DLL)
|
||||
|
||||
#if defined(MS_WINDOWS)
|
||||
#include <windows.h>
|
||||
|
||||
|
||||
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_MemoryErrorInst = 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;
|
||||
static PyObject *ptr__Exc_StandardError = NULL;
|
||||
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;
|
||||
#endif
|
||||
|
||||
#if PY_MAJOR_VERSION >= 2
|
||||
static PyObject *ptr__Exc_IndentationError = NULL;
|
||||
static PyObject *ptr__Exc_TabError = NULL;
|
||||
static PyObject *ptr__Exc_UnboundLocalError = NULL;
|
||||
static PyObject *ptr__Exc_UnicodeError = NULL;
|
||||
#endif
|
||||
|
||||
static PyObject *ptr__PyNone = NULL;
|
||||
|
||||
static PyObject *ptr__PyFalse = NULL;
|
||||
static PyObject *ptr__PyTrue = NULL;
|
||||
|
||||
static PyTypeObject *ptr__Buffer_Type = NULL;
|
||||
static PyTypeObject *ptr__CFunction_Type = NULL;
|
||||
static PyTypeObject *ptr__Class_Type = NULL;
|
||||
static PyTypeObject *ptr__CObject_Type = NULL;
|
||||
static PyTypeObject *ptr__Complex_Type = NULL;
|
||||
static PyTypeObject *ptr__Dict_Type = NULL;
|
||||
static PyTypeObject *ptr__File_Type = NULL;
|
||||
static PyTypeObject *ptr__Float_Type = NULL;
|
||||
static PyTypeObject *ptr__Function_Type = NULL;
|
||||
static PyTypeObject *ptr__Instance_Type = NULL;
|
||||
static PyTypeObject *ptr__Int_Type = NULL;
|
||||
static PyTypeObject *ptr__List_Type = NULL;
|
||||
static PyTypeObject *ptr__Long_Type = NULL;
|
||||
static PyTypeObject *ptr__Method_Type = NULL;
|
||||
static PyTypeObject *ptr__Module_Type = NULL;
|
||||
static PyTypeObject *ptr__Range_Type = NULL;
|
||||
static PyTypeObject *ptr__Slice_Type = NULL;
|
||||
static PyTypeObject *ptr__String_Type = NULL;
|
||||
static PyTypeObject *ptr__TraceBack_Type = NULL;
|
||||
static PyTypeObject *ptr__Tuple_Type = NULL;
|
||||
static PyTypeObject *ptr__Type_Type = NULL;
|
||||
|
||||
#if PY_MAJOR_VERSION >= 2
|
||||
static PyTypeObject *ptr__Unicode_Type = NULL;
|
||||
#endif
|
||||
|
||||
static int *ptr_Py_DebugFlag = NULL;
|
||||
static int *ptr_Py_InteractiveFlag = NULL;
|
||||
static int *ptr_Py_OptimizeFlag = NULL;
|
||||
static int *ptr_Py_NoSiteFlag = NULL;
|
||||
static int *ptr_Py_TabcheckFlag = NULL;
|
||||
static int *ptr_Py_VerboseFlag = NULL;
|
||||
|
||||
#if PY_MAJOR_VERSION >= 2
|
||||
static int *ptr_Py_UnicodeFlag = NULL;
|
||||
#endif
|
||||
|
||||
static char **ptr__Py_PackageContext = NULL;
|
||||
|
||||
#ifdef Py_REF_DEBUG
|
||||
int *ptr_Py_RefTotal;
|
||||
#endif
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
class GetAddressException
|
||||
{
|
||||
public:
|
||||
GetAddressException( const char *_name )
|
||||
: name( _name )
|
||||
{}
|
||||
virtual ~GetAddressException() {}
|
||||
const char *name;
|
||||
};
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
static PyObject *GetPyObjectPointer_As_PyObjectPointer( const char *name )
|
||||
{
|
||||
FARPROC addr = GetProcAddress( python_dll, name );
|
||||
if( addr == NULL )
|
||||
throw GetAddressException( name );
|
||||
|
||||
return *(PyObject **)addr;
|
||||
}
|
||||
|
||||
static PyObject *GetPyObject_As_PyObjectPointer( const char *name )
|
||||
{
|
||||
FARPROC addr = GetProcAddress( python_dll, name );
|
||||
if( addr == NULL )
|
||||
throw GetAddressException( name );
|
||||
|
||||
return (PyObject *)addr;
|
||||
}
|
||||
|
||||
static PyTypeObject *GetPyTypeObjectPointer_As_PyTypeObjectPointer( const char *name )
|
||||
{
|
||||
FARPROC addr = GetProcAddress( python_dll, name );
|
||||
if( addr == NULL )
|
||||
throw GetAddressException( name );
|
||||
|
||||
return *(PyTypeObject **)addr;
|
||||
}
|
||||
|
||||
static PyTypeObject *GetPyTypeObject_As_PyTypeObjectPointer( const char *name )
|
||||
{
|
||||
FARPROC addr = GetProcAddress( python_dll, name );
|
||||
if( addr == NULL )
|
||||
throw GetAddressException( name );
|
||||
|
||||
return (PyTypeObject *)addr;
|
||||
}
|
||||
|
||||
static int *GetInt_as_IntPointer( const char *name )
|
||||
{
|
||||
FARPROC addr = GetProcAddress( python_dll, name );
|
||||
if( addr == NULL )
|
||||
throw GetAddressException( name );
|
||||
|
||||
return (int *)addr;
|
||||
}
|
||||
|
||||
static char **GetCharPointer_as_CharPointerPointer( const char *name )
|
||||
{
|
||||
FARPROC addr = GetProcAddress( python_dll, name );
|
||||
if( addr == NULL )
|
||||
throw GetAddressException( name );
|
||||
|
||||
return (char **)addr;
|
||||
}
|
||||
|
||||
|
||||
#ifdef _DEBUG
|
||||
static const char python_dll_name_format[] = "PYTHON%1.1d%1.1d_D.DLL";
|
||||
#else
|
||||
static const char python_dll_name_format[] = "PYTHON%1.1d%1.1d.DLL";
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
bool InitialisePythonIndirectInterface()
|
||||
{
|
||||
char python_dll_name[sizeof(python_dll_name_format)];
|
||||
|
||||
sprintf( python_dll_name, python_dll_name_format, PY_MAJOR_VERSION, PY_MINOR_VERSION );
|
||||
|
||||
python_dll = LoadLibrary( python_dll_name );
|
||||
if( python_dll == NULL )
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
#ifdef Py_REF_DEBUG
|
||||
ptr_Py_RefTotal = GetInt_as_IntPointer( "_Py_RefTotal" );
|
||||
#endif
|
||||
ptr_Py_DebugFlag = GetInt_as_IntPointer( "Py_DebugFlag" );
|
||||
ptr_Py_InteractiveFlag = GetInt_as_IntPointer( "Py_InteractiveFlag" );
|
||||
ptr_Py_OptimizeFlag = GetInt_as_IntPointer( "Py_OptimizeFlag" );
|
||||
ptr_Py_NoSiteFlag = GetInt_as_IntPointer( "Py_NoSiteFlag" );
|
||||
ptr_Py_TabcheckFlag = GetInt_as_IntPointer( "Py_TabcheckFlag" );
|
||||
ptr_Py_VerboseFlag = GetInt_as_IntPointer( "Py_VerboseFlag" );
|
||||
#if PY_MAJOR_VERSION >= 2
|
||||
ptr_Py_UnicodeFlag = GetInt_as_IntPointer( "Py_UnicodeFlag" );
|
||||
#endif
|
||||
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_MemoryErrorInst = GetPyObjectPointer_As_PyObjectPointer( "PyExc_MemoryErrorInst" );
|
||||
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" );
|
||||
ptr__Exc_StandardError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_StandardError" );
|
||||
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" );
|
||||
|
||||
#if PY_MAJOR_VERSION >= 2
|
||||
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" );
|
||||
#endif
|
||||
ptr__PyNone = GetPyObject_As_PyObjectPointer( "_Py_NoneStruct" );
|
||||
|
||||
ptr__PyFalse = GetPyObject_As_PyObjectPointer( "_Py_ZeroStruct" );
|
||||
ptr__PyTrue = GetPyObject_As_PyObjectPointer( "_Py_TrueStruct" );
|
||||
|
||||
ptr__Buffer_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyBuffer_Type" );
|
||||
ptr__CFunction_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyCFunction_Type" );
|
||||
ptr__Class_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyClass_Type" );
|
||||
ptr__CObject_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyCObject_Type" );
|
||||
ptr__Complex_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyComplex_Type" );
|
||||
ptr__Dict_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyDict_Type" );
|
||||
ptr__File_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyFile_Type" );
|
||||
ptr__Float_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyFloat_Type" );
|
||||
ptr__Function_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyFunction_Type" );
|
||||
ptr__Instance_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyInstance_Type" );
|
||||
ptr__Int_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyInt_Type" );
|
||||
ptr__List_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyList_Type" );
|
||||
ptr__Long_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyLong_Type" );
|
||||
ptr__Method_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyMethod_Type" );
|
||||
ptr__Module_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyModule_Type" );
|
||||
ptr__Range_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyRange_Type" );
|
||||
ptr__Slice_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PySlice_Type" );
|
||||
ptr__String_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyString_Type" );
|
||||
ptr__TraceBack_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyTraceBack_Type" );
|
||||
ptr__Tuple_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyTuple_Type" );
|
||||
ptr__Type_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyType_Type" );
|
||||
|
||||
#if PY_MAJOR_VERSION >= 2
|
||||
ptr__Unicode_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyUnicode_Type" );
|
||||
#endif
|
||||
}
|
||||
catch( GetAddressException &e )
|
||||
{
|
||||
OutputDebugString( python_dll_name );
|
||||
OutputDebugString( " does not contain symbol ");
|
||||
OutputDebugString( e.name );
|
||||
OutputDebugString( "\n" );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
// Wrap variables as function calls
|
||||
//
|
||||
PyObject * _Exc_ArithmeticError(){ return ptr__Exc_ArithmeticError; }
|
||||
PyObject * _Exc_AssertionError(){ return ptr__Exc_AssertionError; }
|
||||
PyObject * _Exc_AttributeError(){ return ptr__Exc_AttributeError; }
|
||||
PyObject * _Exc_EnvironmentError(){ return ptr__Exc_EnvironmentError; }
|
||||
PyObject * _Exc_EOFError() { return ptr__Exc_EOFError; }
|
||||
PyObject * _Exc_Exception() { return ptr__Exc_Exception; }
|
||||
PyObject * _Exc_FloatingPointError(){ return ptr__Exc_FloatingPointError; }
|
||||
PyObject * _Exc_ImportError() { return ptr__Exc_ImportError; }
|
||||
PyObject * _Exc_IndexError() { return ptr__Exc_IndexError; }
|
||||
PyObject * _Exc_IOError() { return ptr__Exc_IOError; }
|
||||
PyObject * _Exc_KeyboardInterrupt(){ return ptr__Exc_KeyboardInterrupt; }
|
||||
PyObject * _Exc_KeyError() { return ptr__Exc_KeyError; }
|
||||
PyObject * _Exc_LookupError() { return ptr__Exc_LookupError; }
|
||||
PyObject * _Exc_MemoryError() { return ptr__Exc_MemoryError; }
|
||||
PyObject * _Exc_MemoryErrorInst(){ return ptr__Exc_MemoryErrorInst; }
|
||||
PyObject * _Exc_NameError() { return ptr__Exc_NameError; }
|
||||
PyObject * _Exc_NotImplementedError(){ return ptr__Exc_NotImplementedError; }
|
||||
PyObject * _Exc_OSError() { return ptr__Exc_OSError; }
|
||||
PyObject * _Exc_OverflowError() { return ptr__Exc_OverflowError; }
|
||||
PyObject * _Exc_RuntimeError() { return ptr__Exc_RuntimeError; }
|
||||
PyObject * _Exc_StandardError() { return ptr__Exc_StandardError; }
|
||||
PyObject * _Exc_SyntaxError() { return ptr__Exc_SyntaxError; }
|
||||
PyObject * _Exc_SystemError() { return ptr__Exc_SystemError; }
|
||||
PyObject * _Exc_SystemExit() { return ptr__Exc_SystemExit; }
|
||||
PyObject * _Exc_TypeError() { return ptr__Exc_TypeError; }
|
||||
PyObject * _Exc_ValueError() { return ptr__Exc_ValueError; }
|
||||
#ifdef MS_WINDOWS
|
||||
PyObject * _Exc_WindowsError() { return ptr__Exc_WindowsError; }
|
||||
#endif
|
||||
PyObject * _Exc_ZeroDivisionError(){ return ptr__Exc_ZeroDivisionError; }
|
||||
|
||||
#if PY_MAJOR_VERSION >= 2
|
||||
PyObject * _Exc_IndentationError(){ return ptr__Exc_IndentationError; }
|
||||
PyObject * _Exc_TabError() { return ptr__Exc_TabError; }
|
||||
PyObject * _Exc_UnboundLocalError(){ return ptr__Exc_UnboundLocalError; }
|
||||
PyObject * _Exc_UnicodeError() { return ptr__Exc_UnicodeError; }
|
||||
#endif
|
||||
|
||||
//
|
||||
// wrap items in Object.h
|
||||
//
|
||||
PyObject * _None() { return ptr__PyNone; }
|
||||
|
||||
PyObject * _False() { return ptr__PyFalse; }
|
||||
PyObject * _True() { return ptr__PyTrue; }
|
||||
|
||||
PyTypeObject * _Buffer_Type() { return ptr__Buffer_Type; }
|
||||
PyTypeObject * _CFunction_Type(){ return ptr__CFunction_Type; }
|
||||
PyTypeObject * _Class_Type() { return ptr__Class_Type; }
|
||||
PyTypeObject * _CObject_Type() { return ptr__CObject_Type; }
|
||||
PyTypeObject * _Complex_Type() { return ptr__Complex_Type; }
|
||||
PyTypeObject * _Dict_Type() { return ptr__Dict_Type; }
|
||||
PyTypeObject * _File_Type() { return ptr__File_Type; }
|
||||
PyTypeObject * _Float_Type() { return ptr__Float_Type; }
|
||||
PyTypeObject * _Function_Type() { return ptr__Function_Type; }
|
||||
PyTypeObject * _Instance_Type() { return ptr__Instance_Type; }
|
||||
PyTypeObject * _Bool_Type() { return ptr__Bool_Type; }
|
||||
PyTypeObject * _Int_Type() { return ptr__Int_Type; }
|
||||
PyTypeObject * _List_Type() { return ptr__List_Type; }
|
||||
PyTypeObject * _Long_Type() { return ptr__Long_Type; }
|
||||
PyTypeObject * _Method_Type() { return ptr__Method_Type; }
|
||||
PyTypeObject * _Module_Type() { return ptr__Module_Type; }
|
||||
PyTypeObject * _Range_Type() { return ptr__Range_Type; }
|
||||
PyTypeObject * _Slice_Type() { return ptr__Slice_Type; }
|
||||
PyTypeObject * _String_Type() { return ptr__String_Type; }
|
||||
PyTypeObject * _TraceBack_Type(){ return ptr__TraceBack_Type; }
|
||||
PyTypeObject * _Tuple_Type() { return ptr__Tuple_Type; }
|
||||
PyTypeObject * _Type_Type() { return ptr__Type_Type; }
|
||||
|
||||
#if PY_MAJOR_VERSION >= 2
|
||||
PyTypeObject * _Unicode_Type() { return ptr__Unicode_Type; }
|
||||
#endif
|
||||
|
||||
char *__Py_PackageContext() { return *ptr__Py_PackageContext; }
|
||||
|
||||
|
||||
//
|
||||
// wrap the Python Flag variables
|
||||
//
|
||||
int &_Py_DebugFlag() { return *ptr_Py_DebugFlag; }
|
||||
int &_Py_InteractiveFlag() { return *ptr_Py_InteractiveFlag; }
|
||||
int &_Py_OptimizeFlag() { return *ptr_Py_OptimizeFlag; }
|
||||
int &_Py_NoSiteFlag() { return *ptr_Py_NoSiteFlag; }
|
||||
int &_Py_TabcheckFlag() { return *ptr_Py_TabcheckFlag; }
|
||||
int &_Py_VerboseFlag() { return *ptr_Py_VerboseFlag; }
|
||||
#if PY_MAJOR_VERSION >= 2
|
||||
int &_Py_UnicodeFlag() { return *ptr_Py_UnicodeFlag; }
|
||||
#endif
|
||||
|
||||
void _XINCREF( PyObject *op )
|
||||
{
|
||||
// This function must match the contents of Py_XINCREF(op)
|
||||
if( op == NULL )
|
||||
return;
|
||||
|
||||
#ifdef Py_REF_DEBUG
|
||||
(*ptr_Py_RefTotal)++;
|
||||
#endif
|
||||
(op)->ob_refcnt++;
|
||||
|
||||
}
|
||||
|
||||
void _XDECREF( PyObject *op )
|
||||
{
|
||||
// This function must match the contents of Py_XDECREF(op);
|
||||
if( op == NULL )
|
||||
return;
|
||||
|
||||
#ifdef Py_REF_DEBUG
|
||||
(*ptr_Py_RefTotal)--;
|
||||
#endif
|
||||
|
||||
if (--(op)->ob_refcnt == 0)
|
||||
_Py_Dealloc((PyObject *)(op));
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
#error "Can only delay load under Win32"
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
//
|
||||
// Duplicated these declarations from rangeobject.h which is missing the
|
||||
// extern "C". This has been reported as a bug upto and include 2.1
|
||||
//
|
||||
extern "C" DL_IMPORT(PyTypeObject) PyRange_Type;
|
||||
extern "C" DL_IMPORT(PyObject *) PyRange_New(long, long, long, int);
|
||||
|
||||
|
||||
//================================================================================
|
||||
//
|
||||
// Map onto Macros
|
||||
//
|
||||
//================================================================================
|
||||
|
||||
//
|
||||
// Wrap variables as function calls
|
||||
//
|
||||
|
||||
PyObject * _Exc_ArithmeticError() { return ::PyExc_ArithmeticError; }
|
||||
PyObject * _Exc_AssertionError() { return ::PyExc_AssertionError; }
|
||||
PyObject * _Exc_AttributeError() { return ::PyExc_AttributeError; }
|
||||
PyObject * _Exc_EnvironmentError() { return ::PyExc_EnvironmentError; }
|
||||
PyObject * _Exc_EOFError() { return ::PyExc_EOFError; }
|
||||
PyObject * _Exc_Exception() { return ::PyExc_Exception; }
|
||||
PyObject * _Exc_FloatingPointError() { return ::PyExc_FloatingPointError; }
|
||||
PyObject * _Exc_ImportError() { return ::PyExc_ImportError; }
|
||||
PyObject * _Exc_IndexError() { return ::PyExc_IndexError; }
|
||||
PyObject * _Exc_IOError() { return ::PyExc_IOError; }
|
||||
PyObject * _Exc_KeyboardInterrupt() { return ::PyExc_KeyboardInterrupt; }
|
||||
PyObject * _Exc_KeyError() { return ::PyExc_KeyError; }
|
||||
PyObject * _Exc_LookupError() { return ::PyExc_LookupError; }
|
||||
PyObject * _Exc_MemoryError() { return ::PyExc_MemoryError; }
|
||||
PyObject * _Exc_MemoryErrorInst() { return ::PyExc_MemoryErrorInst; }
|
||||
PyObject * _Exc_NameError() { return ::PyExc_NameError; }
|
||||
PyObject * _Exc_NotImplementedError() { return ::PyExc_NotImplementedError; }
|
||||
PyObject * _Exc_OSError() { return ::PyExc_OSError; }
|
||||
PyObject * _Exc_OverflowError() { return ::PyExc_OverflowError; }
|
||||
PyObject * _Exc_RuntimeError() { return ::PyExc_RuntimeError; }
|
||||
PyObject * _Exc_StandardError() { return ::PyExc_StandardError; }
|
||||
PyObject * _Exc_SyntaxError() { return ::PyExc_SyntaxError; }
|
||||
PyObject * _Exc_SystemError() { return ::PyExc_SystemError; }
|
||||
PyObject * _Exc_SystemExit() { return ::PyExc_SystemExit; }
|
||||
PyObject * _Exc_TypeError() { return ::PyExc_TypeError; }
|
||||
PyObject * _Exc_ValueError() { return ::PyExc_ValueError; }
|
||||
PyObject * _Exc_ZeroDivisionError() { return ::PyExc_ZeroDivisionError; }
|
||||
|
||||
#ifdef MS_WINDOWS
|
||||
PyObject * _Exc_WindowsError() { return ::PyExc_WindowsError; }
|
||||
#endif
|
||||
|
||||
|
||||
#if PY_MAJOR_VERSION >= 2
|
||||
PyObject * _Exc_IndentationError() { return ::PyExc_IndentationError; }
|
||||
PyObject * _Exc_TabError() { return ::PyExc_TabError; }
|
||||
PyObject * _Exc_UnboundLocalError() { return ::PyExc_UnboundLocalError; }
|
||||
PyObject * _Exc_UnicodeError() { return ::PyExc_UnicodeError; }
|
||||
#endif
|
||||
|
||||
|
||||
//
|
||||
// wrap items in Object.h
|
||||
//
|
||||
PyObject * _None() { return &::_Py_NoneStruct; }
|
||||
|
||||
PyObject * _False() { return Py_False; }
|
||||
PyObject * _True() { return Py_True; }
|
||||
|
||||
PyTypeObject * _Buffer_Type() { return &PyBuffer_Type; }
|
||||
PyTypeObject * _CFunction_Type() { return &PyCFunction_Type; }
|
||||
PyTypeObject * _Class_Type() { return &PyClass_Type; }
|
||||
PyTypeObject * _CObject_Type() { return &PyCObject_Type; }
|
||||
PyTypeObject * _Complex_Type() { return &PyComplex_Type; }
|
||||
PyTypeObject * _Dict_Type() { return &PyDict_Type; }
|
||||
PyTypeObject * _File_Type() { return &PyFile_Type; }
|
||||
PyTypeObject * _Float_Type() { return &PyFloat_Type; }
|
||||
PyTypeObject * _Function_Type() { return &PyFunction_Type; }
|
||||
PyTypeObject * _Instance_Type() { return &PyInstance_Type; }
|
||||
PyTypeObject * _Bool_Type() { return &PyBool_Type; }
|
||||
PyTypeObject * _Int_Type() { return &PyInt_Type; }
|
||||
PyTypeObject * _List_Type() { return &PyList_Type; }
|
||||
PyTypeObject * _Long_Type() { return &PyLong_Type; }
|
||||
PyTypeObject * _Method_Type() { return &PyMethod_Type; }
|
||||
PyTypeObject * _Module_Type() { return &PyModule_Type; }
|
||||
PyTypeObject * _Range_Type() { return &PyRange_Type; }
|
||||
PyTypeObject * _Slice_Type() { return &PySlice_Type; }
|
||||
PyTypeObject * _String_Type() { return &PyString_Type; }
|
||||
PyTypeObject * _TraceBack_Type() { return &PyTraceBack_Type; }
|
||||
PyTypeObject * _Tuple_Type() { return &PyTuple_Type; }
|
||||
PyTypeObject * _Type_Type() { return &PyType_Type; }
|
||||
|
||||
#if PY_MAJOR_VERSION >= 2
|
||||
PyTypeObject * _Unicode_Type() { return &PyUnicode_Type; }
|
||||
#endif
|
||||
|
||||
//
|
||||
// wrap flags
|
||||
//
|
||||
int &_Py_DebugFlag() { return Py_DebugFlag; }
|
||||
int &_Py_InteractiveFlag(){ return Py_InteractiveFlag; }
|
||||
int &_Py_OptimizeFlag() { return Py_OptimizeFlag; }
|
||||
int &_Py_NoSiteFlag() { return Py_NoSiteFlag; }
|
||||
int &_Py_TabcheckFlag() { return Py_TabcheckFlag; }
|
||||
int &_Py_VerboseFlag() { return Py_VerboseFlag; }
|
||||
#if PY_MAJOR_VERSION >= 2
|
||||
int &_Py_UnicodeFlag() { return Py_UnicodeFlag; }
|
||||
#endif
|
||||
char *__Py_PackageContext(){ return _Py_PackageContext; }
|
||||
|
||||
//
|
||||
// Needed to keep the abstactions for delayload interface
|
||||
//
|
||||
void _XINCREF( PyObject *op )
|
||||
{
|
||||
Py_XINCREF(op);
|
||||
}
|
||||
|
||||
void _XDECREF( PyObject *op )
|
||||
{
|
||||
Py_XDECREF(op);
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
@@ -39,7 +39,6 @@
|
||||
#define __CXX_INDIRECT_PYTHON_INTERFACE__HXX__
|
||||
|
||||
#include "CXX/WrapPython.h"
|
||||
#include "CXX/Config.hxx"
|
||||
|
||||
namespace Py
|
||||
{
|
||||
@@ -48,152 +47,152 @@ 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();
|
||||
PyObject * _Exc_Exception();
|
||||
PyObject * _Exc_StandardError();
|
||||
PyObject * _Exc_ArithmeticError();
|
||||
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();
|
||||
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
|
||||
PYCXX_EXPORT PyObject * _Exc_WindowsError();
|
||||
PyObject * _Exc_WindowsError();
|
||||
#endif
|
||||
|
||||
PYCXX_EXPORT PyObject * _Exc_MemoryErrorInst();
|
||||
PyObject * _Exc_MemoryErrorInst();
|
||||
|
||||
#if PY_MAJOR_VERSION >= 2
|
||||
PYCXX_EXPORT PyObject * _Exc_IndentationError();
|
||||
PYCXX_EXPORT PyObject * _Exc_TabError();
|
||||
PYCXX_EXPORT PyObject * _Exc_UnboundLocalError();
|
||||
PYCXX_EXPORT PyObject * _Exc_UnicodeError();
|
||||
PyObject * _Exc_IndentationError();
|
||||
PyObject * _Exc_TabError();
|
||||
PyObject * _Exc_UnboundLocalError();
|
||||
PyObject * _Exc_UnicodeError();
|
||||
#endif
|
||||
|
||||
//
|
||||
// Wrap Object variables as function calls
|
||||
//
|
||||
PYCXX_EXPORT PyObject * _None();
|
||||
PyObject * _None();
|
||||
|
||||
PYCXX_EXPORT PyObject * _False();
|
||||
PYCXX_EXPORT PyObject * _True();
|
||||
PyObject * _False();
|
||||
PyObject * _True();
|
||||
|
||||
//
|
||||
// Wrap Type variables as function calls
|
||||
//
|
||||
PYCXX_EXPORT PyTypeObject * _List_Type();
|
||||
PYCXX_EXPORT bool _List_Check( PyObject *o );
|
||||
PyTypeObject * _List_Type();
|
||||
bool _List_Check( PyObject *o );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Buffer_Type();
|
||||
PYCXX_EXPORT bool _Buffer_Check( PyObject *op );
|
||||
PyTypeObject * _Buffer_Type();
|
||||
bool _Buffer_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Class_Type();
|
||||
PYCXX_EXPORT bool _Class_Check( PyObject *op );
|
||||
PyTypeObject * _Class_Type();
|
||||
bool _Class_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Instance_Type();
|
||||
PYCXX_EXPORT bool _Instance_Check( PyObject *op );
|
||||
PyTypeObject * _Instance_Type();
|
||||
bool _Instance_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Method_Type();
|
||||
PYCXX_EXPORT bool _Method_Check( PyObject *op );
|
||||
PyTypeObject * _Method_Type();
|
||||
bool _Method_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _CObject_Type();
|
||||
PYCXX_EXPORT bool _CObject_Check( PyObject *op );
|
||||
PyTypeObject * _CObject_Type();
|
||||
bool _CObject_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Complex_Type();
|
||||
PYCXX_EXPORT bool _Complex_Check( PyObject *op );
|
||||
PyTypeObject * _Complex_Type();
|
||||
bool _Complex_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Dict_Type();
|
||||
PYCXX_EXPORT bool _Dict_Check( PyObject *op );
|
||||
PyTypeObject * _Dict_Type();
|
||||
bool _Dict_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _File_Type();
|
||||
PYCXX_EXPORT bool _File_Check( PyObject *op );
|
||||
PyTypeObject * _File_Type();
|
||||
bool _File_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Float_Type();
|
||||
PYCXX_EXPORT bool _Float_Check( PyObject *op );
|
||||
PyTypeObject * _Float_Type();
|
||||
bool _Float_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Frame_Type();
|
||||
PYCXX_EXPORT bool _Frame_Check( PyObject *op );
|
||||
PyTypeObject * _Frame_Type();
|
||||
bool _Frame_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Function_Type();
|
||||
PYCXX_EXPORT bool _Function_Check( PyObject *op );
|
||||
PyTypeObject * _Function_Type();
|
||||
bool _Function_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Bool_Type();
|
||||
PYCXX_EXPORT bool _Boolean_Check( PyObject *op );
|
||||
PyTypeObject * _Bool_Type();
|
||||
bool _Boolean_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Int_Type();
|
||||
PYCXX_EXPORT bool _Int_Check( PyObject *op );
|
||||
PyTypeObject * _Int_Type();
|
||||
bool _Int_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _List_Type();
|
||||
PYCXX_EXPORT bool _List_Check( PyObject *op );
|
||||
PyTypeObject * _List_Type();
|
||||
bool _List_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Long_Type();
|
||||
PYCXX_EXPORT bool _Long_Check( PyObject *op );
|
||||
PyTypeObject * _Long_Type();
|
||||
bool _Long_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _CFunction_Type();
|
||||
PYCXX_EXPORT bool _CFunction_Check( PyObject *op );
|
||||
PyTypeObject * _CFunction_Type();
|
||||
bool _CFunction_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Module_Type();
|
||||
PYCXX_EXPORT bool _Module_Check( PyObject *op );
|
||||
PyTypeObject * _Module_Type();
|
||||
bool _Module_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Type_Type();
|
||||
PYCXX_EXPORT bool _Type_Check( PyObject *op );
|
||||
PyTypeObject * _Type_Type();
|
||||
bool _Type_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Range_Type();
|
||||
PYCXX_EXPORT bool _Range_Check( PyObject *op );
|
||||
PyTypeObject * _Range_Type();
|
||||
bool _Range_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Slice_Type();
|
||||
PYCXX_EXPORT bool _Slice_Check( PyObject *op );
|
||||
PyTypeObject * _Slice_Type();
|
||||
bool _Slice_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _String_Type();
|
||||
PYCXX_EXPORT bool _String_Check( PyObject *op );
|
||||
PyTypeObject * _String_Type();
|
||||
bool _String_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Unicode_Type();
|
||||
PYCXX_EXPORT bool _Unicode_Check( PyObject *op );
|
||||
PyTypeObject * _Unicode_Type();
|
||||
bool _Unicode_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _TraceBack_Type();
|
||||
PYCXX_EXPORT bool _TraceBack_Check( PyObject *v );
|
||||
PyTypeObject * _TraceBack_Type();
|
||||
bool _TraceBack_Check( PyObject *v );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Tuple_Type();
|
||||
PYCXX_EXPORT bool _Tuple_Check( PyObject *op );
|
||||
PyTypeObject * _Tuple_Type();
|
||||
bool _Tuple_Check( PyObject *op );
|
||||
|
||||
#if PY_MAJOR_VERSION >= 2
|
||||
PYCXX_EXPORT PyTypeObject * _Unicode_Type();
|
||||
PYCXX_EXPORT bool _Unicode_Check( PyObject *op );
|
||||
PyTypeObject * _Unicode_Type();
|
||||
bool _Unicode_Check( PyObject *op );
|
||||
#endif
|
||||
|
||||
PYCXX_EXPORT int &_Py_DebugFlag();
|
||||
PYCXX_EXPORT int &_Py_InteractiveFlag();
|
||||
PYCXX_EXPORT int &_Py_OptimizeFlag();
|
||||
PYCXX_EXPORT int &_Py_NoSiteFlag();
|
||||
PYCXX_EXPORT int &_Py_TabcheckFlag();
|
||||
PYCXX_EXPORT int &_Py_VerboseFlag();
|
||||
int &_Py_DebugFlag();
|
||||
int &_Py_InteractiveFlag();
|
||||
int &_Py_OptimizeFlag();
|
||||
int &_Py_NoSiteFlag();
|
||||
int &_Py_TabcheckFlag();
|
||||
int &_Py_VerboseFlag();
|
||||
|
||||
#if PY_MAJOR_VERSION >= 2
|
||||
PYCXX_EXPORT int &_Py_UnicodeFlag();
|
||||
int &_Py_UnicodeFlag();
|
||||
#endif
|
||||
|
||||
PYCXX_EXPORT void _XINCREF( PyObject *op );
|
||||
PYCXX_EXPORT void _XDECREF( PyObject *op );
|
||||
void _XINCREF( PyObject *op );
|
||||
void _XDECREF( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT char *__Py_PackageContext();
|
||||
char *__Py_PackageContext();
|
||||
}
|
||||
|
||||
#endif // __CXX_INDIRECT_PYTHON_INTERFACE__HXX__
|
||||
|
||||
@@ -52,7 +52,7 @@
|
||||
|
||||
namespace Py
|
||||
{
|
||||
typedef size_t sequence_index_type; // type of an index into a sequence
|
||||
typedef int sequence_index_type; // type of an index into a sequence
|
||||
|
||||
// Forward declarations
|
||||
class Object;
|
||||
@@ -141,7 +141,7 @@ namespace Py
|
||||
// which you can use in accepts when writing a wrapper class.
|
||||
// See Demo/range.h and Demo/range.cxx for an example.
|
||||
|
||||
class PYCXX_EXPORT Object
|
||||
class Object
|
||||
{
|
||||
private:
|
||||
// the pointer to the Python object
|
||||
@@ -469,11 +469,11 @@ namespace Py
|
||||
|
||||
// TMM: 31May'01 - Added the #ifndef so I can exlude iostreams.
|
||||
#ifndef CXX_NO_IOSTREAMS
|
||||
PYCXX_EXPORT std::ostream& operator<< (std::ostream& os, const Object& ob);
|
||||
std::ostream& operator<< (std::ostream& os, const Object& ob);
|
||||
#endif
|
||||
|
||||
// Class Type
|
||||
class PYCXX_EXPORT Type: public Object
|
||||
class Type: public Object
|
||||
{
|
||||
public:
|
||||
explicit Type (PyObject* pyob, bool owned = false): Object(pyob, owned)
|
||||
@@ -519,7 +519,7 @@ namespace Py
|
||||
|
||||
// ===============================================
|
||||
// class boolean
|
||||
class PYCXX_EXPORT Boolean: public Object
|
||||
class Boolean: public Object
|
||||
{
|
||||
public:
|
||||
// Constructor
|
||||
@@ -582,7 +582,7 @@ namespace Py
|
||||
|
||||
// ===============================================
|
||||
// class Int
|
||||
class PYCXX_EXPORT Int: public Object
|
||||
class Int: public Object
|
||||
{
|
||||
public:
|
||||
// Constructor
|
||||
@@ -695,7 +695,7 @@ namespace Py
|
||||
|
||||
// ===============================================
|
||||
// class Long
|
||||
class PYCXX_EXPORT Long: public Object
|
||||
class Long: public Object
|
||||
{
|
||||
public:
|
||||
// Constructor
|
||||
@@ -798,7 +798,7 @@ namespace Py
|
||||
#ifdef HAVE_LONG_LONG
|
||||
// ===============================================
|
||||
// class LongLong
|
||||
class PYCXX_EXPORT LongLong: public Object
|
||||
class LongLong: public Object
|
||||
{
|
||||
public:
|
||||
// Constructor
|
||||
@@ -927,7 +927,7 @@ namespace Py
|
||||
// ===============================================
|
||||
// class Float
|
||||
//
|
||||
class PYCXX_EXPORT Float: public Object
|
||||
class Float: public Object
|
||||
{
|
||||
public:
|
||||
// Constructor
|
||||
@@ -1004,7 +1004,7 @@ namespace Py
|
||||
|
||||
// ===============================================
|
||||
// class Complex
|
||||
class PYCXX_EXPORT Complex: public Object
|
||||
class Complex: public Object
|
||||
{
|
||||
public:
|
||||
// Constructor
|
||||
@@ -1115,7 +1115,7 @@ namespace Py
|
||||
{
|
||||
protected:
|
||||
SeqBase<T>& s; // the sequence
|
||||
size_t offset; // item number
|
||||
int offset; // item number
|
||||
T the_item; // lvalue
|
||||
public:
|
||||
|
||||
@@ -1130,7 +1130,7 @@ namespace Py
|
||||
// TMM: added this seqref ctor for use with STL algorithms
|
||||
seqref (Object& obj)
|
||||
: s(dynamic_cast< SeqBase<T>&>(obj))
|
||||
, offset( 0 )
|
||||
, offset( NULL )
|
||||
, the_item(s.getItem(offset))
|
||||
{}
|
||||
~seqref()
|
||||
@@ -1449,7 +1449,7 @@ namespace Py
|
||||
protected:
|
||||
friend class SeqBase<T>;
|
||||
SeqBase<T>* seq;
|
||||
size_type count;
|
||||
int count;
|
||||
|
||||
public:
|
||||
~iterator ()
|
||||
@@ -1460,7 +1460,7 @@ namespace Py
|
||||
, count( 0 )
|
||||
{}
|
||||
|
||||
iterator (SeqBase<T>* s, size_type where)
|
||||
iterator (SeqBase<T>* s, int where)
|
||||
: seq( s )
|
||||
, count( where )
|
||||
{}
|
||||
@@ -1587,7 +1587,7 @@ namespace Py
|
||||
sequence_index_type count;
|
||||
|
||||
private:
|
||||
const_iterator (const SeqBase<T>* s, size_type where)
|
||||
const_iterator (const SeqBase<T>* s, int where)
|
||||
: seq( s )
|
||||
, count( where )
|
||||
{}
|
||||
@@ -1724,19 +1724,19 @@ namespace Py
|
||||
template <TEMPLATE_TYPENAME T> bool operator<=(const EXPLICIT_TYPENAME SeqBase<T>::const_iterator& left, const EXPLICIT_TYPENAME SeqBase<T>::const_iterator& right);
|
||||
template <TEMPLATE_TYPENAME T> bool operator>=(const EXPLICIT_TYPENAME SeqBase<T>::const_iterator& left, const EXPLICIT_TYPENAME SeqBase<T>::const_iterator& right);
|
||||
|
||||
PYCXX_EXPORT extern bool operator==(const Sequence::iterator& left, const Sequence::iterator& right);
|
||||
PYCXX_EXPORT extern bool operator!=(const Sequence::iterator& left, const Sequence::iterator& right);
|
||||
PYCXX_EXPORT extern bool operator< (const Sequence::iterator& left, const Sequence::iterator& right);
|
||||
PYCXX_EXPORT extern bool operator> (const Sequence::iterator& left, const Sequence::iterator& right);
|
||||
PYCXX_EXPORT extern bool operator<=(const Sequence::iterator& left, const Sequence::iterator& right);
|
||||
PYCXX_EXPORT extern bool operator>=(const Sequence::iterator& left, const Sequence::iterator& right);
|
||||
extern bool operator==(const Sequence::iterator& left, const Sequence::iterator& right);
|
||||
extern bool operator!=(const Sequence::iterator& left, const Sequence::iterator& right);
|
||||
extern bool operator< (const Sequence::iterator& left, const Sequence::iterator& right);
|
||||
extern bool operator> (const Sequence::iterator& left, const Sequence::iterator& right);
|
||||
extern bool operator<=(const Sequence::iterator& left, const Sequence::iterator& right);
|
||||
extern bool operator>=(const Sequence::iterator& left, const Sequence::iterator& right);
|
||||
|
||||
PYCXX_EXPORT extern bool operator==(const Sequence::const_iterator& left, const Sequence::const_iterator& right);
|
||||
PYCXX_EXPORT extern bool operator!=(const Sequence::const_iterator& left, const Sequence::const_iterator& right);
|
||||
PYCXX_EXPORT extern bool operator< (const Sequence::const_iterator& left, const Sequence::const_iterator& right);
|
||||
PYCXX_EXPORT extern bool operator> (const Sequence::const_iterator& left, const Sequence::const_iterator& right);
|
||||
PYCXX_EXPORT extern bool operator<=(const Sequence::const_iterator& left, const Sequence::const_iterator& right);
|
||||
PYCXX_EXPORT extern bool operator>=(const Sequence::const_iterator& left, const Sequence::const_iterator& right);
|
||||
extern bool operator==(const Sequence::const_iterator& left, const Sequence::const_iterator& right);
|
||||
extern bool operator!=(const Sequence::const_iterator& left, const Sequence::const_iterator& right);
|
||||
extern bool operator< (const Sequence::const_iterator& left, const Sequence::const_iterator& right);
|
||||
extern bool operator> (const Sequence::const_iterator& left, const Sequence::const_iterator& right);
|
||||
extern bool operator<=(const Sequence::const_iterator& left, const Sequence::const_iterator& right);
|
||||
extern bool operator>=(const Sequence::const_iterator& left, const Sequence::const_iterator& right);
|
||||
|
||||
// ==================================================
|
||||
// class Char
|
||||
@@ -1746,7 +1746,7 @@ namespace Py
|
||||
typedef std::basic_string<Py_UNICODE> unicodestring;
|
||||
extern Py_UNICODE unicode_null_string[1];
|
||||
|
||||
class PYCXX_EXPORT Char: public Object
|
||||
class Char: public Object
|
||||
{
|
||||
public:
|
||||
explicit Char (PyObject *pyob, bool owned = false): Object(pyob, owned)
|
||||
@@ -1833,7 +1833,7 @@ namespace Py
|
||||
// String and Bytes compatible with Python3 version in 6.0.0 PyCXX
|
||||
class Bytes;
|
||||
|
||||
class PYCXX_EXPORT String: public SeqBase<Char>
|
||||
class String: public SeqBase<Char>
|
||||
{
|
||||
public:
|
||||
virtual size_type capacity() const
|
||||
@@ -1889,13 +1889,6 @@ namespace Py
|
||||
validate();
|
||||
}
|
||||
|
||||
String( const std::string &v, std::string::size_type vsize )
|
||||
: SeqBase<Char>(PyString_FromStringAndSize( const_cast<char*>(v.data()),
|
||||
static_cast<int>( vsize ) ), true)
|
||||
{
|
||||
validate();
|
||||
}
|
||||
|
||||
String( const char *v, int vsize )
|
||||
: SeqBase<Char>(PyString_FromStringAndSize( const_cast<char*>(v), vsize ), true )
|
||||
{
|
||||
@@ -1989,7 +1982,7 @@ namespace Py
|
||||
}
|
||||
}
|
||||
};
|
||||
class PYCXX_EXPORT Bytes: public SeqBase<Char>
|
||||
class Bytes: public SeqBase<Char>
|
||||
{
|
||||
public:
|
||||
virtual size_type capacity() const
|
||||
@@ -2019,12 +2012,6 @@ namespace Py
|
||||
validate();
|
||||
}
|
||||
|
||||
Bytes( const std::string& v, std::string::size_type vsize )
|
||||
: SeqBase<Char>(PyString_FromStringAndSize( const_cast<char*>(v.data()), static_cast<int>( vsize ) ), true)
|
||||
{
|
||||
validate();
|
||||
}
|
||||
|
||||
Bytes( const char *v, int vsize )
|
||||
: SeqBase<Char>(PyString_FromStringAndSize( const_cast<char*>(v), vsize ), true )
|
||||
{
|
||||
@@ -2072,7 +2059,7 @@ namespace Py
|
||||
|
||||
String decode( const char *encoding, const char *error="strict" )
|
||||
{
|
||||
return Object( PyString_AsDecodedObject( ptr(), encoding, error ) );
|
||||
return Object( PyString_AsDecodedObject( ptr(), encoding, error ), true );
|
||||
}
|
||||
|
||||
// Queries
|
||||
@@ -2121,7 +2108,7 @@ namespace Py
|
||||
|
||||
#else
|
||||
// original PyCXX 5.4.x version of String
|
||||
class PYCXX_EXPORT String: public SeqBase<Char>
|
||||
class String: public SeqBase<Char>
|
||||
{
|
||||
public:
|
||||
virtual size_type capacity() const
|
||||
@@ -2170,13 +2157,6 @@ namespace Py
|
||||
validate();
|
||||
}
|
||||
|
||||
String( const std::string& v, std::string::size_type vsize )
|
||||
: SeqBase<Char>(PyString_FromStringAndSize( const_cast<char*>(v.data()),
|
||||
static_cast<int>( vsize ) ), true)
|
||||
{
|
||||
validate();
|
||||
}
|
||||
|
||||
String( const char *v, int vsize )
|
||||
: SeqBase<Char>(PyString_FromStringAndSize( const_cast<char*>(v), vsize ), true )
|
||||
{
|
||||
@@ -2228,17 +2208,17 @@ namespace Py
|
||||
{
|
||||
if( isUnicode() )
|
||||
{
|
||||
return String( PyUnicode_AsEncodedString( ptr(), encoding, error ) );
|
||||
return String( PyUnicode_AsEncodedString( ptr(), encoding, error ), true );
|
||||
}
|
||||
else
|
||||
{
|
||||
return String( PyString_AsEncodedObject( ptr(), encoding, error ) );
|
||||
return String( PyString_AsEncodedObject( ptr(), encoding, error ), true );
|
||||
}
|
||||
}
|
||||
|
||||
String decode( const char *encoding, const char *error="strict" )
|
||||
{
|
||||
return Object( PyString_AsDecodedObject( ptr(), encoding, error ) );
|
||||
return Object( PyString_AsDecodedObject( ptr(), encoding, error ), true );
|
||||
}
|
||||
|
||||
// Queries
|
||||
@@ -2290,7 +2270,7 @@ namespace Py
|
||||
|
||||
// ==================================================
|
||||
// class Tuple
|
||||
class PYCXX_EXPORT Tuple: public Sequence
|
||||
class Tuple: public Sequence
|
||||
{
|
||||
public:
|
||||
virtual void setItem (sequence_index_type offset, const Object&ob)
|
||||
@@ -2314,7 +2294,7 @@ namespace Py
|
||||
}
|
||||
|
||||
// New tuple of a given size
|
||||
explicit Tuple (sequence_index_type size = 0)
|
||||
explicit Tuple (int size = 0)
|
||||
{
|
||||
set(PyTuple_New (size), true);
|
||||
validate ();
|
||||
@@ -2368,11 +2348,11 @@ namespace Py
|
||||
|
||||
};
|
||||
|
||||
class PYCXX_EXPORT TupleN: public Tuple
|
||||
class TupleN: public Tuple
|
||||
{
|
||||
public:
|
||||
TupleN()
|
||||
: Tuple( (sequence_index_type)0 )
|
||||
: Tuple( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
@@ -2483,7 +2463,7 @@ namespace Py
|
||||
// ==================================================
|
||||
// class List
|
||||
|
||||
class PYCXX_EXPORT List: public Sequence
|
||||
class List: public Sequence
|
||||
{
|
||||
public:
|
||||
// Constructor
|
||||
@@ -2496,7 +2476,7 @@ namespace Py
|
||||
validate();
|
||||
}
|
||||
// Creation at a fixed size
|
||||
List (sequence_index_type size = 0)
|
||||
List (int size = 0)
|
||||
{
|
||||
set(PyList_New (size), true);
|
||||
validate();
|
||||
@@ -2512,7 +2492,7 @@ namespace Py
|
||||
// List from a sequence
|
||||
List (const Sequence& s): Sequence()
|
||||
{
|
||||
sequence_index_type n = s.length();
|
||||
int n = (int)s.length();
|
||||
set(PyList_New (n), true);
|
||||
validate();
|
||||
for (sequence_index_type i=0; i < n; i++)
|
||||
@@ -2858,7 +2838,7 @@ namespace Py
|
||||
return mapref<T>(*this, key);
|
||||
}
|
||||
|
||||
size_type length () const
|
||||
int length () const
|
||||
{
|
||||
return PyMapping_Length (ptr());
|
||||
}
|
||||
@@ -2956,7 +2936,7 @@ namespace Py
|
||||
//
|
||||
MapBase<T>* map;
|
||||
List keys; // for iterating over the map
|
||||
size_type pos; // index into the keys
|
||||
int pos; // index into the keys
|
||||
|
||||
private:
|
||||
iterator( MapBase<T>* m, List k, int p )
|
||||
@@ -3059,7 +3039,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
|
||||
int pos; // index into the keys
|
||||
|
||||
private:
|
||||
const_iterator( const MapBase<T>* m, List k, int p )
|
||||
@@ -3148,15 +3128,15 @@ namespace Py
|
||||
template <TEMPLATE_TYPENAME T> bool operator==(const EXPLICIT_TYPENAME MapBase<T>::const_iterator& left, const EXPLICIT_TYPENAME MapBase<T>::const_iterator& right);
|
||||
template <TEMPLATE_TYPENAME T> bool operator!=(const EXPLICIT_TYPENAME MapBase<T>::const_iterator& left, const EXPLICIT_TYPENAME MapBase<T>::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);
|
||||
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);
|
||||
|
||||
|
||||
// ==================================================
|
||||
// class Dict
|
||||
class PYCXX_EXPORT Dict: public Mapping
|
||||
class Dict: public Mapping
|
||||
{
|
||||
public:
|
||||
// Constructor
|
||||
@@ -3194,7 +3174,7 @@ namespace Py
|
||||
}
|
||||
};
|
||||
|
||||
class PYCXX_EXPORT Callable: public Object
|
||||
class Callable: public Object
|
||||
{
|
||||
public:
|
||||
// Constructor
|
||||
@@ -3247,7 +3227,7 @@ namespace Py
|
||||
}
|
||||
};
|
||||
|
||||
class PYCXX_EXPORT Module: public Object
|
||||
class Module: public Object
|
||||
{
|
||||
public:
|
||||
explicit Module (PyObject* pyob, bool owned = false): Object (pyob, owned)
|
||||
@@ -3292,7 +3272,7 @@ namespace Py
|
||||
inline Object Object::callMemberFunction( const std::string &function_name ) const
|
||||
{
|
||||
Callable target( getAttr( function_name ) );
|
||||
Tuple args( (sequence_index_type)0 );
|
||||
Tuple args( 0 );
|
||||
return target.apply( args );
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
|
||||
namespace Py
|
||||
{
|
||||
class PYCXX_EXPORT PythonType
|
||||
class PythonType
|
||||
{
|
||||
public:
|
||||
// if you define one sequence method you must define
|
||||
@@ -57,17 +57,15 @@ namespace Py
|
||||
PythonType &doc( const char *d );
|
||||
|
||||
PythonType &supportClass( void );
|
||||
#if !defined( PY3 )
|
||||
PythonType &dealloc( void (*f)( PyObject* ) );
|
||||
#endif
|
||||
#if defined( PYCXX_PYTHON_2TO3 ) || !defined( PY3 )
|
||||
#if defined( PYCXX_PYTHON_2TO3 )
|
||||
PythonType &supportPrint( void );
|
||||
#endif
|
||||
PythonType &supportGetattr( void );
|
||||
PythonType &supportSetattr( void );
|
||||
PythonType &supportGetattro( void );
|
||||
PythonType &supportSetattro( void );
|
||||
#if defined( PYCXX_PYTHON_2TO3 ) || !defined( PY3 )
|
||||
#if defined( PYCXX_PYTHON_2TO3 )
|
||||
PythonType &supportCompare( void );
|
||||
#endif
|
||||
PythonType &supportRichCompare( void );
|
||||
|
||||
@@ -254,12 +254,16 @@ extern "C"
|
||||
// All the following functions redirect the call from Python
|
||||
// onto the matching virtual function in PythonExtensionBase
|
||||
//
|
||||
#if defined( 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 * );
|
||||
static int setattro_handler( PyObject *, PyObject *, PyObject * );
|
||||
#if defined( PYCXX_PYTHON_2TO3 )
|
||||
static int compare_handler( PyObject *, PyObject * );
|
||||
#endif
|
||||
static PyObject *rich_compare_handler( PyObject *, PyObject *, int );
|
||||
static PyObject *repr_handler( PyObject * );
|
||||
static PyObject *str_handler( PyObject * );
|
||||
@@ -290,9 +294,7 @@ extern "C"
|
||||
static PyObject *number_invert_handler( PyObject * );
|
||||
static PyObject *number_int_handler( PyObject * );
|
||||
static PyObject *number_float_handler( PyObject * );
|
||||
#if !defined( PY3 )
|
||||
static PyObject *number_long_handler( PyObject * );
|
||||
#endif
|
||||
static PyObject *number_oct_handler( PyObject * );
|
||||
static PyObject *number_hex_handler( PyObject * );
|
||||
static PyObject *number_add_handler( PyObject *, PyObject * );
|
||||
@@ -335,13 +337,9 @@ PythonType &PythonType::supportSequenceType()
|
||||
sequence_table->sq_concat = sequence_concat_handler;
|
||||
sequence_table->sq_repeat = sequence_repeat_handler;
|
||||
sequence_table->sq_item = sequence_item_handler;
|
||||
#if !defined( PY3 )
|
||||
sequence_table->sq_slice = sequence_slice_handler;
|
||||
#endif
|
||||
sequence_table->sq_ass_item = sequence_ass_item_handler; // BAS setup seperately?
|
||||
#if !defined( PY3 )
|
||||
sequence_table->sq_ass_slice = sequence_ass_slice_handler; // BAS setup seperately?
|
||||
#endif
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
@@ -370,36 +368,26 @@ PythonType &PythonType::supportNumberType()
|
||||
number_table->nb_add = number_add_handler;
|
||||
number_table->nb_subtract = number_subtract_handler;
|
||||
number_table->nb_multiply = number_multiply_handler;
|
||||
#if !defined( PY3 )
|
||||
number_table->nb_divide = number_divide_handler;
|
||||
#endif
|
||||
number_table->nb_remainder = number_remainder_handler;
|
||||
number_table->nb_divmod = number_divmod_handler;
|
||||
number_table->nb_power = number_power_handler;
|
||||
number_table->nb_negative = number_negative_handler;
|
||||
number_table->nb_positive = number_positive_handler;
|
||||
number_table->nb_absolute = number_absolute_handler;
|
||||
#if !defined( PY3 )
|
||||
number_table->nb_nonzero = number_nonzero_handler;
|
||||
#endif
|
||||
number_table->nb_invert = number_invert_handler;
|
||||
number_table->nb_lshift = number_lshift_handler;
|
||||
number_table->nb_rshift = number_rshift_handler;
|
||||
number_table->nb_and = number_and_handler;
|
||||
number_table->nb_xor = number_xor_handler;
|
||||
number_table->nb_or = number_or_handler;
|
||||
#if !defined( PY3 )
|
||||
number_table->nb_coerce = 0;
|
||||
#endif
|
||||
number_table->nb_int = number_int_handler;
|
||||
#if !defined( PY3 )
|
||||
number_table->nb_long = number_long_handler;
|
||||
#endif
|
||||
number_table->nb_float = number_float_handler;
|
||||
#if !defined( PY3 )
|
||||
number_table->nb_oct = number_oct_handler;
|
||||
number_table->nb_hex = number_hex_handler;
|
||||
#endif
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
@@ -411,11 +399,9 @@ PythonType &PythonType::supportBufferType()
|
||||
buffer_table = new PyBufferProcs;
|
||||
memset( buffer_table, 0, sizeof( PyBufferProcs ) ); // ensure new fields are 0
|
||||
table->tp_as_buffer = buffer_table;
|
||||
#if !defined( PY3 )
|
||||
buffer_table->bf_getreadbuffer = buffer_getreadbuffer_handler;
|
||||
buffer_table->bf_getwritebuffer = buffer_getwritebuffer_handler;
|
||||
buffer_table->bf_getsegcount = buffer_getsegcount_handler;
|
||||
#endif
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
@@ -434,10 +420,9 @@ PythonType::PythonType( size_t basic_size, int itemsize, const char *default_nam
|
||||
|
||||
memset( table, 0, sizeof( PyTypeObject ) ); // ensure new fields are 0
|
||||
*reinterpret_cast<PyObject *>( table ) = py_object_initializer;
|
||||
#if !defined( PY3 )
|
||||
table->ob_type = _Type_Type();
|
||||
table->ob_size = 0;
|
||||
#endif
|
||||
|
||||
table->tp_name = const_cast<char *>( default_name );
|
||||
table->tp_basicsize = basic_size;
|
||||
table->tp_itemsize = itemsize;
|
||||
@@ -575,11 +560,13 @@ PythonType &PythonType::dealloc( void( *f )( PyObject * ))
|
||||
return *this;
|
||||
}
|
||||
|
||||
#if defined( PYCXX_PYTHON_2TO3 )
|
||||
PythonType &PythonType::supportPrint()
|
||||
{
|
||||
table->tp_print = print_handler;
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
|
||||
PythonType &PythonType::supportGetattr()
|
||||
{
|
||||
@@ -605,11 +592,13 @@ PythonType &PythonType::supportSetattro()
|
||||
return *this;
|
||||
}
|
||||
|
||||
#if defined( PYCXX_PYTHON_2TO3 )
|
||||
PythonType &PythonType::supportCompare()
|
||||
{
|
||||
table->tp_compare = compare_handler;
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if PY_MAJOR_VERSION > 2 || (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION >= 1)
|
||||
PythonType &PythonType::supportRichCompare()
|
||||
@@ -669,6 +658,7 @@ PythonExtensionBase *getPythonExtensionBase( PyObject *self )
|
||||
}
|
||||
|
||||
|
||||
#if defined( PYCXX_PYTHON_2TO3 )
|
||||
extern "C" int print_handler( PyObject *self, FILE *fp, int flags )
|
||||
{
|
||||
try
|
||||
@@ -681,6 +671,7 @@ extern "C" int print_handler( PyObject *self, FILE *fp, int flags )
|
||||
return -1; // indicate error
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
extern "C" PyObject *getattr_handler( PyObject *self, char *name )
|
||||
{
|
||||
@@ -734,6 +725,7 @@ extern "C" int setattro_handler( PyObject *self, PyObject *name, PyObject *value
|
||||
}
|
||||
}
|
||||
|
||||
#if defined( PYCXX_PYTHON_2TO3 )
|
||||
extern "C" int compare_handler( PyObject *self, PyObject *other )
|
||||
{
|
||||
try
|
||||
@@ -746,6 +738,7 @@ extern "C" int compare_handler( PyObject *self, PyObject *other )
|
||||
return -1; // indicate error
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if PY_MAJOR_VERSION > 2 || (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION >= 1)
|
||||
extern "C" PyObject *rich_compare_handler( PyObject *self, PyObject *other, int op )
|
||||
@@ -1766,61 +1759,6 @@ extern "C" PyObject *method_keyword_call_handler( PyObject *_self_and_name_tuple
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
extern "C" PyObject *method_varargs_call_handler( PyObject *_self_and_name_tuple, PyObject *_args )
|
||||
{
|
||||
try
|
||||
|
||||
Reference in New Issue
Block a user