Core: Move PyCXX library to src/3rdParty.
This commit is contained in:
56
src/3rdParty/PyCXX/CXX/COPYRIGHT
vendored
Normal file
56
src/3rdParty/PyCXX/CXX/COPYRIGHT
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
|
||||
Copyright (c) 1998 - 2007
|
||||
The Regents of the University of California
|
||||
Produced at the Lawrence Livermore National Laboratory
|
||||
Written by Geoff Furnish, Paul F. Dubois, Barry A. Scott
|
||||
UCRL-CODE-227018
|
||||
All rights reserved.
|
||||
|
||||
This file is part of PyCXX. For details, see http://cxx.sourceforge.net.
|
||||
|
||||
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.
|
||||
|
||||
Additional BSD Notice
|
||||
|
||||
1. This notice is required to be provided under our contract with the U.S.
|
||||
Department of Energy (DOE). This work was produced at the University of
|
||||
California, Lawrence Livermore National Laboratory under Contract No.
|
||||
W-7405-ENG-48 with the DOE.
|
||||
|
||||
2. Neither the United States Government nor the University of California
|
||||
nor any of their employees, makes any warranty, express or implied, or
|
||||
assumes any liability or responsibility for the accuracy, completeness,
|
||||
or usefulness of any information, apparatus, product, or process disclosed,
|
||||
or represents that its use would not infringe privately-owned rights.
|
||||
|
||||
3. Also, reference herein to any specific commercial products, process, or
|
||||
services by trade name, trademark, manufacturer or otherwise does not
|
||||
necessarily constitute or imply its endorsement, recommendation, or
|
||||
favoring by the United States Government or the University of California.
|
||||
The views and opinions of authors expressed herein do not necessarily
|
||||
state or reflect those of the United States Government or the University
|
||||
of California, and shall not be used for advertising or product endorsement
|
||||
purposes.
|
||||
|
||||
50
src/3rdParty/PyCXX/CXX/Config.hxx
vendored
Normal file
50
src/3rdParty/PyCXX/CXX/Config.hxx
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// 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/WrapPython.h"
|
||||
|
||||
#if defined( PYCXX_6_2_COMPATIBILITY )
|
||||
//typedef int PyCxx_ssize_t;
|
||||
typedef Py_ssize_t PyCxx_ssize_t;
|
||||
#else
|
||||
typedef Py_ssize_t PyCxx_ssize_t;
|
||||
#endif
|
||||
|
||||
#if PY_MAJOR_VERSION == 2
|
||||
#include "CXX/Python2/Config.hxx"
|
||||
#else
|
||||
#include "CXX/Python3/Config.hxx"
|
||||
#endif
|
||||
41
src/3rdParty/PyCXX/CXX/CxxDebug.hxx
vendored
Normal file
41
src/3rdParty/PyCXX/CXX/CxxDebug.hxx
vendored
Normal 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
|
||||
43
src/3rdParty/PyCXX/CXX/Exception.hxx
vendored
Normal file
43
src/3rdParty/PyCXX/CXX/Exception.hxx
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// 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/WrapPython.h"
|
||||
|
||||
#if PY_MAJOR_VERSION == 2
|
||||
#include "CXX/Python2/Exception.hxx"
|
||||
#else
|
||||
#include "CXX/Python3/Exception.hxx"
|
||||
#endif
|
||||
43
src/3rdParty/PyCXX/CXX/Extensions.hxx
vendored
Normal file
43
src/3rdParty/PyCXX/CXX/Extensions.hxx
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// 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/WrapPython.h"
|
||||
|
||||
#if PY_MAJOR_VERSION == 2
|
||||
#include "CXX/Python2/Extensions.hxx"
|
||||
#else
|
||||
#include "CXX/Python3/Extensions.hxx"
|
||||
#endif
|
||||
563
src/3rdParty/PyCXX/CXX/IndirectPythonInterface.cxx
vendored
Normal file
563
src/3rdParty/PyCXX/CXX/IndirectPythonInterface.cxx
vendored
Normal file
@@ -0,0 +1,563 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// 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
|
||||
{
|
||||
static int _IsInstance( PyObject *op, PyTypeObject *type )
|
||||
{
|
||||
return PyObject_IsInstance( op, reinterpret_cast<PyObject *>( type ) );
|
||||
}
|
||||
|
||||
PYCXX_EXPORT bool _CFunction_Check( PyObject *op ) { return _IsInstance( op, _CFunction_Type() ) > 0; }
|
||||
PYCXX_EXPORT bool _Complex_Check( PyObject *op ) { return _IsInstance( op, _Complex_Type() ) > 0; }
|
||||
PYCXX_EXPORT bool _Dict_Check( PyObject *op ) { return _IsInstance( op, _Dict_Type() ) > 0; }
|
||||
PYCXX_EXPORT bool _Float_Check( PyObject *op ) { return _IsInstance( op, _Float_Type() ) > 0; }
|
||||
#if PY_MAJOR_VERSION == 2 || !defined( Py_LIMITED_API )
|
||||
PYCXX_EXPORT bool _Function_Check( PyObject *op ) { return _IsInstance( op, _Function_Type() ) > 0; }
|
||||
#endif
|
||||
PYCXX_EXPORT bool _Boolean_Check( PyObject *op ) { return _IsInstance( op, _Bool_Type() ) > 0; }
|
||||
PYCXX_EXPORT bool _List_Check( PyObject *op ) { return _IsInstance( op, _List_Type() ) > 0; }
|
||||
PYCXX_EXPORT bool _Long_Check( PyObject *op ) { return _IsInstance( op, _Long_Type() ) > 0; }
|
||||
#if PY_MAJOR_VERSION == 2 || !defined( Py_LIMITED_API )
|
||||
PYCXX_EXPORT bool _Method_Check( PyObject *op ) { return _IsInstance( op, _Method_Type() ) > 0; }
|
||||
#endif
|
||||
PYCXX_EXPORT bool _Module_Check( PyObject *op ) { return _IsInstance( op, _Module_Type() ) > 0; }
|
||||
PYCXX_EXPORT bool _Range_Check( PyObject *op ) { return _IsInstance( op, _Range_Type() ) > 0; }
|
||||
PYCXX_EXPORT bool _Slice_Check( PyObject *op ) { return _IsInstance( op, _Slice_Type() ) > 0; }
|
||||
PYCXX_EXPORT bool _TraceBack_Check( PyObject *op ) { return _IsInstance( op, _TraceBack_Type() ) > 0; }
|
||||
PYCXX_EXPORT bool _Tuple_Check( PyObject *op ) { return _IsInstance( op, _Tuple_Type() ) > 0; }
|
||||
PYCXX_EXPORT bool _Type_Check( PyObject *op ) { return _IsInstance( op, _Type_Type() ) > 0; }
|
||||
PYCXX_EXPORT bool _Unicode_Check( PyObject *op ) { return _IsInstance( op, _Unicode_Type() ) > 0; }
|
||||
#if PY_MAJOR_VERSION == 2
|
||||
PYCXX_EXPORT bool _String_Check( PyObject *op ) { return _IsInstance( op, _String_Type() ) > 0; }
|
||||
PYCXX_EXPORT bool _Int_Check( PyObject *op ) { return _IsInstance( op, _Int_Type() ) > 0; }
|
||||
PYCXX_EXPORT bool _CObject_Check( PyObject *op ) { return _IsInstance( op, _CObject_Type() ) > 0; }
|
||||
#endif
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
PYCXX_EXPORT bool _Bytes_Check( PyObject *op ) { return _IsInstance( op, _Bytes_Type() ) > 0; }
|
||||
#endif
|
||||
|
||||
#if defined(PY_WIN32_DELAYLOAD_PYTHON_DLL)
|
||||
|
||||
# if defined(MS_WINDOWS)
|
||||
# include <windows.h>
|
||||
|
||||
|
||||
static HMODULE python_dll;
|
||||
|
||||
# define PYCXX_STANDARD_EXCEPTION( eclass, bclass ) \
|
||||
static PyObject *ptr_Exc_##eclass = NULL;
|
||||
|
||||
# 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
|
||||
|
||||
static PyTypeObject *ptr__CFunction_Type = NULL;
|
||||
static PyTypeObject *ptr__Complex_Type = NULL;
|
||||
static PyTypeObject *ptr__Dict_Type = NULL;
|
||||
static PyTypeObject *ptr__Float_Type = NULL;
|
||||
# if PY_MAJOR_VERSION == 2 || !defined( Py_LIMITED_API )
|
||||
static PyTypeObject *ptr__Function_Type = NULL;
|
||||
# endif
|
||||
static PyTypeObject *ptr__Bool_Type = NULL;
|
||||
static PyTypeObject *ptr__List_Type = NULL;
|
||||
static PyTypeObject *ptr__Long_Type = NULL;
|
||||
# if PY_MAJOR_VERSION == 2 || !defined( Py_LIMITED_API )
|
||||
static PyTypeObject *ptr__Method_Type = NULL;
|
||||
# endif
|
||||
static PyTypeObject *ptr__Module_Type = NULL;
|
||||
static PyTypeObject *ptr__Range_Type = NULL;
|
||||
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;
|
||||
static PyTypeObject *ptr__CObject_Type = NULL;
|
||||
# endif
|
||||
# if PY_MAJOR_VERSION >= 3
|
||||
static PyTypeObject *ptr__Bytes_Type = NULL;
|
||||
# endif
|
||||
|
||||
# if PY_MAJOR_VERSION == 2 || !defined( Py_LIMITED_API )
|
||||
# if PY_MAJOR_VERSION == 2 || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION <= 11)
|
||||
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_VerboseFlag = NULL;
|
||||
# endif
|
||||
|
||||
# if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION <= 11
|
||||
# if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 7
|
||||
static const char **ptr__Py_PackageContext = NULL;
|
||||
# else
|
||||
static char **ptr__Py_PackageContext = NULL;
|
||||
# endif
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# 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;
|
||||
}
|
||||
|
||||
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 7
|
||||
static char **GetConstCharPointer_as_ConstCharPointerPointer( const char *name )
|
||||
{
|
||||
FARPROC addr = GetProcAddress( python_dll, name );
|
||||
if( addr == NULL )
|
||||
throw GetAddressException( name );
|
||||
|
||||
return (const char **)addr;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
# 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)];
|
||||
|
||||
_snprintf( python_dll_name, sizeof(python_dll_name_format) / sizeof(char) - 1, python_dll_name_format, PY_MAJOR_VERSION, PY_MINOR_VERSION );
|
||||
|
||||
python_dll = LoadLibraryA( python_dll_name );
|
||||
if( python_dll == NULL )
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
# ifdef Py_REF_DEBUG
|
||||
ptr_Py_RefTotal = GetInt_as_IntPointer( "_Py_RefTotal" );
|
||||
# endif
|
||||
# if PY_MAJOR_VERSION == 2 || !defined( Py_LIMITED_API )
|
||||
# if PY_MAJOR_VERSION == 2 || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION <= 11)
|
||||
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_VerboseFlag = GetInt_as_IntPointer( "Py_VerboseFlag" );
|
||||
# endif
|
||||
|
||||
# if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION <= 11
|
||||
# if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 7
|
||||
ptr__Py_PackageContext = GetConstCharPointer_as_ConstCharPointerPointer( "_Py_PackageContext" );
|
||||
# else
|
||||
ptr__Py_PackageContext = GetCharPointer_as_CharPointerPointer( "_Py_PackageContext" );
|
||||
# endif
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# define PYCXX_STANDARD_EXCEPTION( eclass, bclass )
|
||||
ptr_Exc_#eclass = GetPyTypeObject_As_PyTypeObjectPointer( "PyExc_" #eclass );
|
||||
|
||||
# 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
|
||||
|
||||
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" );
|
||||
ptr__Complex_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyComplex_Type" );
|
||||
ptr__Dict_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyDict_Type" );
|
||||
ptr__Float_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyFloat_Type" );
|
||||
# if PY_MAJOR_VERSION == 2 || !defined( Py_LIMITED_API )
|
||||
ptr__Function_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyFunction_Type" );
|
||||
# endif
|
||||
ptr__Bool_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyBool_Type" );
|
||||
ptr__List_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyList_Type" );
|
||||
ptr__Long_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyLong_Type" );
|
||||
# if PY_MAJOR_VERSION == 2 || !defined( Py_LIMITED_API )
|
||||
ptr__Method_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyMethod_Type" );
|
||||
# endif
|
||||
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__TraceBack_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyTraceBack_Type" );
|
||||
ptr__Tuple_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyTuple_Type" );
|
||||
ptr__Type_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyType_Type" );
|
||||
ptr__Unicode_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyUnicode_Type" );
|
||||
# if PY_MAJOR_VERSION == 2
|
||||
ptr__String_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyString_Type" );
|
||||
ptr__Int_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyInt_Type" );
|
||||
ptr__CObject_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyCObject_Type" );
|
||||
# endif
|
||||
# if PY_MAJOR_VERSION >= 3
|
||||
ptr__Bytes_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyBytes_Type" );
|
||||
# endif
|
||||
}
|
||||
catch( GetAddressException &e )
|
||||
{
|
||||
OutputDebugStringA( python_dll_name );
|
||||
OutputDebugStringA( " does not contain symbol " );
|
||||
OutputDebugStringA( e.name );
|
||||
OutputDebugStringA( "\n" );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
// Wrap variables as function calls
|
||||
//
|
||||
PYCXX_EXPORT PyObject *_Exc_ArithmeticError() { return ptr__Exc_ArithmeticError; }
|
||||
PYCXX_EXPORT PyObject *_Exc_AssertionError() { return ptr__Exc_AssertionError; }
|
||||
PYCXX_EXPORT PyObject *_Exc_AttributeError() { return ptr__Exc_AttributeError; }
|
||||
PYCXX_EXPORT PyObject *_Exc_EnvironmentError() { return ptr__Exc_EnvironmentError; }
|
||||
PYCXX_EXPORT PyObject *_Exc_EOFError() { return ptr__Exc_EOFError; }
|
||||
PYCXX_EXPORT PyObject *_Exc_Exception() { return ptr__Exc_Exception; }
|
||||
PYCXX_EXPORT PyObject *_Exc_FloatingPointError() { return ptr__Exc_FloatingPointError; }
|
||||
PYCXX_EXPORT PyObject *_Exc_ImportError() { return ptr__Exc_ImportError; }
|
||||
PYCXX_EXPORT PyObject *_Exc_IndexError() { return ptr__Exc_IndexError; }
|
||||
PYCXX_EXPORT PyObject *_Exc_IOError() { return ptr__Exc_IOError; }
|
||||
PYCXX_EXPORT PyObject *_Exc_KeyboardInterrupt() { return ptr__Exc_KeyboardInterrupt; }
|
||||
PYCXX_EXPORT PyObject *_Exc_KeyError() { return ptr__Exc_KeyError; }
|
||||
PYCXX_EXPORT PyObject *_Exc_LookupError() { return ptr__Exc_LookupError; }
|
||||
PYCXX_EXPORT PyObject *_Exc_MemoryError() { return ptr__Exc_MemoryError; }
|
||||
PYCXX_EXPORT PyObject *_Exc_NameError() { return ptr__Exc_NameError; }
|
||||
PYCXX_EXPORT PyObject *_Exc_NotImplementedError() { return ptr__Exc_NotImplementedError; }
|
||||
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; }
|
||||
PYCXX_EXPORT PyObject *_Exc_TypeError() { return ptr__Exc_TypeError; }
|
||||
PYCXX_EXPORT PyObject *_Exc_ValueError() { return ptr__Exc_ValueError; }
|
||||
# ifdef MS_WINDOWS
|
||||
PYCXX_EXPORT PyObject *_Exc_WindowsError() { return ptr__Exc_WindowsError; }
|
||||
# endif
|
||||
PYCXX_EXPORT PyObject *_Exc_ZeroDivisionError() { return ptr__Exc_ZeroDivisionError; }
|
||||
PYCXX_EXPORT PyObject *_Exc_IndentationError() { return ptr__Exc_IndentationError; }
|
||||
PYCXX_EXPORT PyObject *_Exc_TabError() { return ptr__Exc_TabError; }
|
||||
PYCXX_EXPORT PyObject *_Exc_UnboundLocalError() { return ptr__Exc_UnboundLocalError; }
|
||||
PYCXX_EXPORT PyObject *_Exc_UnicodeError() { return ptr__Exc_UnicodeError; }
|
||||
|
||||
//
|
||||
// wrap items in Object.h
|
||||
//
|
||||
PYCXX_EXPORT PyObject *_None() { return ptr__PyNone; }
|
||||
|
||||
PYCXX_EXPORT PyObject *_False() { return ptr__PyFalse; }
|
||||
PYCXX_EXPORT PyObject *_True() { return ptr__PyTrue; }
|
||||
|
||||
PYCXX_EXPORT PyTypeObject *_CFunction_Type() { return ptr__CFunction_Type; }
|
||||
PYCXX_EXPORT PyTypeObject *_Complex_Type() { return ptr__Complex_Type; }
|
||||
PYCXX_EXPORT PyTypeObject *_Dict_Type() { return ptr__Dict_Type; }
|
||||
PYCXX_EXPORT PyTypeObject *_Float_Type() { return ptr__Float_Type; }
|
||||
# if PY_MAJOR_VERSION == 2 || !defined( Py_LIMITED_API )
|
||||
PYCXX_EXPORT PyTypeObject *_Function_Type() { return ptr__Function_Type; }
|
||||
# endif
|
||||
PYCXX_EXPORT PyTypeObject *_Bool_Type() { return ptr__Bool_Type; }
|
||||
PYCXX_EXPORT PyTypeObject *_List_Type() { return ptr__List_Type; }
|
||||
PYCXX_EXPORT PyTypeObject *_Long_Type() { return ptr__Long_Type; }
|
||||
# if PY_MAJOR_VERSION == 2 || !defined( Py_LIMITED_API )
|
||||
PYCXX_EXPORT PyTypeObject *_Method_Type() { return ptr__Method_Type; }
|
||||
# endif
|
||||
PYCXX_EXPORT PyTypeObject *_Module_Type() { return ptr__Module_Type; }
|
||||
PYCXX_EXPORT PyTypeObject *_Range_Type() { return ptr__Range_Type; }
|
||||
PYCXX_EXPORT PyTypeObject *_Slice_Type() { return ptr__Slice_Type; }
|
||||
PYCXX_EXPORT PyTypeObject *_TraceBack_Type() { return ptr__TraceBack_Type; }
|
||||
PYCXX_EXPORT PyTypeObject *_Tuple_Type() { return ptr__Tuple_Type; }
|
||||
PYCXX_EXPORT PyTypeObject *_Type_Type() { return ptr__Type_Type; }
|
||||
PYCXX_EXPORT PyTypeObject *_Unicode_Type() { return ptr__Unicode_Type; }
|
||||
# if PY_MAJOR_VERSION == 2
|
||||
PYCXX_EXPORT PyTypeObject *_String_Type() { return ptr__String_Type; }
|
||||
PYCXX_EXPORT PyTypeObject *_Int_Type() { return ptr__Int_Type; }
|
||||
PYCXX_EXPORT PyTypeObject *_CObject_Type() { return ptr__CObject_Type; }
|
||||
# endif
|
||||
# if PY_MAJOR_VERSION >= 3
|
||||
PYCXX_EXPORT PyTypeObject *_Bytes_Type() { return ptr__Bytes_Type; }
|
||||
# endif
|
||||
|
||||
//
|
||||
// wrap the Python Flag variables
|
||||
//
|
||||
# if PY_MAJOR_VERSION == 2 || !defined( Py_LIMITED_API )
|
||||
# if PY_MAJOR_VERSION == 2 || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION <= 11)
|
||||
PYCXX_EXPORT int &_Py_DebugFlag() { return *ptr_Py_DebugFlag; }
|
||||
PYCXX_EXPORT int &_Py_InteractiveFlag() { return *ptr_Py_InteractiveFlag; }
|
||||
PYCXX_EXPORT int &_Py_OptimizeFlag() { return *ptr_Py_OptimizeFlag; }
|
||||
PYCXX_EXPORT int &_Py_NoSiteFlag() { return *ptr_Py_NoSiteFlag; }
|
||||
PYCXX_EXPORT int &_Py_VerboseFlag() { return *ptr_Py_VerboseFlag; }
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION <= 11
|
||||
# if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 7
|
||||
PYCXX_EXPORT const char *__Py_PackageContext() { return *ptr__Py_PackageContext; }
|
||||
# else
|
||||
PYCXX_EXPORT char *__Py_PackageContext() { return *ptr__Py_PackageContext; }
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# if 0
|
||||
# define Py_INCREF(op) ( \
|
||||
_Py_INC_REFTOTAL _Py_REF_DEBUG_COMMA \
|
||||
((PyObject*)(op))->ob_refcnt++)
|
||||
|
||||
# define Py_DECREF(op) \
|
||||
if (_Py_DEC_REFTOTAL _Py_REF_DEBUG_COMMA \
|
||||
--((PyObject*)(op))->ob_refcnt != 0) \
|
||||
_Py_CHECK_REFCNT(op) \
|
||||
else \
|
||||
_Py_Dealloc((PyObject *)(op))
|
||||
# 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
|
||||
|
||||
//================================================================================
|
||||
//
|
||||
// Map onto Macros
|
||||
//
|
||||
//================================================================================
|
||||
|
||||
//
|
||||
// Wrap variables as function calls
|
||||
//
|
||||
# define PYCXX_STANDARD_EXCEPTION( eclass, bclass ) \
|
||||
PYCXX_EXPORT PyObject *_Exc_##eclass() { return ::PyExc_##eclass; }
|
||||
|
||||
# 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
|
||||
//
|
||||
PYCXX_EXPORT PyObject *_None() { return &::_Py_NoneStruct; }
|
||||
|
||||
PYCXX_EXPORT PyObject *_False() { return Py_False; }
|
||||
PYCXX_EXPORT PyObject *_True() { return Py_True; }
|
||||
|
||||
PYCXX_EXPORT PyTypeObject *_CFunction_Type() { return &PyCFunction_Type; }
|
||||
PYCXX_EXPORT PyTypeObject *_Complex_Type() { return &PyComplex_Type; }
|
||||
PYCXX_EXPORT PyTypeObject *_Dict_Type() { return &PyDict_Type; }
|
||||
PYCXX_EXPORT PyTypeObject *_Float_Type() { return &PyFloat_Type; }
|
||||
# if PY_MAJOR_VERSION == 2 || !defined( Py_LIMITED_API )
|
||||
PYCXX_EXPORT PyTypeObject *_Function_Type() { return &PyFunction_Type; }
|
||||
# endif
|
||||
PYCXX_EXPORT PyTypeObject *_Bool_Type() { return &PyBool_Type; }
|
||||
PYCXX_EXPORT PyTypeObject *_List_Type() { return &PyList_Type; }
|
||||
PYCXX_EXPORT PyTypeObject *_Long_Type() { return &PyLong_Type; }
|
||||
# if PY_MAJOR_VERSION == 2 || !defined( Py_LIMITED_API )
|
||||
PYCXX_EXPORT PyTypeObject *_Method_Type() { return &PyMethod_Type; }
|
||||
# endif
|
||||
PYCXX_EXPORT PyTypeObject *_Module_Type() { return &PyModule_Type; }
|
||||
PYCXX_EXPORT PyTypeObject *_Range_Type() { return &PyRange_Type; }
|
||||
PYCXX_EXPORT PyTypeObject *_Slice_Type() { return &PySlice_Type; }
|
||||
PYCXX_EXPORT PyTypeObject *_TraceBack_Type() { return &PyTraceBack_Type; }
|
||||
PYCXX_EXPORT PyTypeObject *_Tuple_Type() { return &PyTuple_Type; }
|
||||
PYCXX_EXPORT PyTypeObject *_Type_Type() { return &PyType_Type; }
|
||||
PYCXX_EXPORT PyTypeObject *_Unicode_Type() { return &PyUnicode_Type; }
|
||||
# if PY_MAJOR_VERSION == 2
|
||||
PYCXX_EXPORT PyTypeObject *_String_Type() { return &PyString_Type; }
|
||||
PYCXX_EXPORT PyTypeObject *_Int_Type() { return &PyInt_Type; }
|
||||
PYCXX_EXPORT PyTypeObject *_CObject_Type() { return &PyCObject_Type; }
|
||||
# endif
|
||||
# if PY_MAJOR_VERSION >= 3
|
||||
PYCXX_EXPORT PyTypeObject *_Bytes_Type() { return &PyBytes_Type; }
|
||||
# endif
|
||||
|
||||
//
|
||||
// wrap flags
|
||||
//
|
||||
# if PY_MAJOR_VERSION == 2 || !defined( Py_LIMITED_API )
|
||||
# if PY_MAJOR_VERSION == 2 || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION <= 11)
|
||||
PYCXX_EXPORT int &_Py_DebugFlag() { return Py_DebugFlag; }
|
||||
PYCXX_EXPORT int &_Py_InteractiveFlag() { return Py_InteractiveFlag; }
|
||||
PYCXX_EXPORT int &_Py_OptimizeFlag() { return Py_OptimizeFlag; }
|
||||
PYCXX_EXPORT int &_Py_NoSiteFlag() { return Py_NoSiteFlag; }
|
||||
PYCXX_EXPORT int &_Py_VerboseFlag() { return Py_VerboseFlag; }
|
||||
# endif
|
||||
# if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION <= 11
|
||||
# if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 7
|
||||
PYCXX_EXPORT const char *__Py_PackageContext() { return _Py_PackageContext; }
|
||||
# else
|
||||
PYCXX_EXPORT char *__Py_PackageContext() { return _Py_PackageContext; }
|
||||
# endif
|
||||
# endif
|
||||
# endif
|
||||
|
||||
//
|
||||
// Needed to keep the abstractions for delayload interface
|
||||
//
|
||||
void _XINCREF( PyObject *op )
|
||||
{
|
||||
Py_XINCREF( op );
|
||||
}
|
||||
|
||||
void _XDECREF( PyObject *op )
|
||||
{
|
||||
Py_XDECREF( op );
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
7
src/3rdParty/PyCXX/CXX/IndirectPythonInterface.hxx
vendored
Normal file
7
src/3rdParty/PyCXX/CXX/IndirectPythonInterface.hxx
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
#include "CXX/WrapPython.h"
|
||||
|
||||
#if PY_MAJOR_VERSION == 2
|
||||
#include "CXX/Python2/IndirectPythonInterface.hxx"
|
||||
#else
|
||||
#include "CXX/Python3/IndirectPythonInterface.hxx"
|
||||
#endif
|
||||
43
src/3rdParty/PyCXX/CXX/Objects.hxx
vendored
Normal file
43
src/3rdParty/PyCXX/CXX/Objects.hxx
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// 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/WrapPython.h"
|
||||
|
||||
#if PY_MAJOR_VERSION == 2
|
||||
#include "CXX/Python2/Objects.hxx"
|
||||
#else
|
||||
#include "CXX/Python3/Objects.hxx"
|
||||
#endif
|
||||
132
src/3rdParty/PyCXX/CXX/Python2/Config.hxx
vendored
Normal file
132
src/3rdParty/PyCXX/CXX/Python2/Config.hxx
vendored
Normal file
@@ -0,0 +1,132 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef __PyCXX_config_hh__
|
||||
#define __PyCXX_config_hh__
|
||||
|
||||
//
|
||||
// Microsoft VC++ 6.0 has no traits
|
||||
//
|
||||
#if defined( _MSC_VER )
|
||||
|
||||
# define STANDARD_LIBRARY_HAS_ITERATOR_TRAITS 1
|
||||
|
||||
#elif defined( __GNUC__ )
|
||||
# if __GNUC__ >= 3
|
||||
# define STANDARD_LIBRARY_HAS_ITERATOR_TRAITS 1
|
||||
# else
|
||||
# define STANDARD_LIBRARY_HAS_ITERATOR_TRAITS 0
|
||||
#endif
|
||||
|
||||
//
|
||||
// Assume all other compilers do
|
||||
//
|
||||
#else
|
||||
|
||||
// Macros to deal with deficiencies in compilers
|
||||
# define STANDARD_LIBRARY_HAS_ITERATOR_TRAITS 1
|
||||
#endif
|
||||
|
||||
#if STANDARD_LIBRARY_HAS_ITERATOR_TRAITS
|
||||
# define random_access_iterator_parent(itemtype) std::iterator<std::random_access_iterator_tag,itemtype,int>
|
||||
#else
|
||||
# define random_access_iterator_parent(itemtype) std::random_access_iterator<itemtype, int>
|
||||
#endif
|
||||
|
||||
//
|
||||
// Which C++ standard is in use?
|
||||
//
|
||||
#if defined( _MSC_VER )
|
||||
# if _MSC_VER <= 1200
|
||||
// MSVC++ 6.0
|
||||
# define PYCXX_ISO_CPP_LIB 0
|
||||
# define STR_STREAM <strstream>
|
||||
# define TEMPLATE_TYPENAME class
|
||||
# else
|
||||
# define PYCXX_ISO_CPP_LIB 1
|
||||
# define STR_STREAM <sstream>
|
||||
# define TEMPLATE_TYPENAME typename
|
||||
# endif
|
||||
#elif defined( __GNUC__ )
|
||||
# if __GNUC__ >= 3
|
||||
# define PYCXX_ISO_CPP_LIB 1
|
||||
# define STR_STREAM <sstream>
|
||||
# define TEMPLATE_TYPENAME typename
|
||||
# else
|
||||
# define PYCXX_ISO_CPP_LIB 0
|
||||
# define STR_STREAM <strstream>
|
||||
# define TEMPLATE_TYPENAME class
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if PYCXX_ISO_CPP_LIB
|
||||
# define STR_STREAM <sstream>
|
||||
# define OSTRSTREAM ostringstream
|
||||
# define EXPLICIT_TYPENAME typename
|
||||
# define EXPLICIT_CLASS class
|
||||
# define TEMPLATE_TYPENAME typename
|
||||
#else
|
||||
# define STR_STREAM <strstream>
|
||||
# define OSTRSTREAM ostrstream
|
||||
# define EXPLICIT_TYPENAME
|
||||
# define EXPLICIT_CLASS
|
||||
# define TEMPLATE_TYPENAME class
|
||||
#endif
|
||||
|
||||
// before 2.5 Py_ssize_t was missing
|
||||
#ifndef PY_MAJOR_VERSION
|
||||
#error not defined PY_MAJOR_VERSION
|
||||
#endif
|
||||
#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__
|
||||
17
src/3rdParty/PyCXX/CXX/Python2/CxxDebug.hxx
vendored
Normal file
17
src/3rdParty/PyCXX/CXX/Python2/CxxDebug.hxx
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// CxxDebug.hxx
|
||||
//
|
||||
// Copyright (c) 2008 Barry A. Scott
|
||||
//
|
||||
#ifndef __CXX_Debug_hxx
|
||||
#define __CXX_Debug_hxx
|
||||
|
||||
//
|
||||
// Functions useful when debugging PyCXX
|
||||
//
|
||||
#ifdef PYCXX_DEBUG
|
||||
extern void bpt();
|
||||
extern void printRefCount( PyObject *obj );
|
||||
#endif
|
||||
|
||||
#endif
|
||||
260
src/3rdParty/PyCXX/CXX/Python2/Exception.hxx
vendored
Normal file
260
src/3rdParty/PyCXX/CXX/Python2/Exception.hxx
vendored
Normal file
@@ -0,0 +1,260 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef __CXX_Exception_h
|
||||
#define __CXX_Exception_h
|
||||
|
||||
#include "CXX/WrapPython.h"
|
||||
#include "CXX/Version.hxx"
|
||||
#include "CXX/Config.hxx"
|
||||
#include "CXX/IndirectPythonInterface.hxx"
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
// This mimics the Python structure, in order to minimize confusion
|
||||
namespace Py
|
||||
{
|
||||
class ExtensionExceptionType;
|
||||
|
||||
class Object;
|
||||
|
||||
class PYCXX_EXPORT Exception
|
||||
{
|
||||
public:
|
||||
Exception( ExtensionExceptionType &exception, const std::string& reason );
|
||||
Exception( ExtensionExceptionType &exception, Object &reason );
|
||||
|
||||
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();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Abstract
|
||||
class PYCXX_EXPORT StandardError: public Exception
|
||||
{
|
||||
protected:
|
||||
explicit StandardError()
|
||||
{}
|
||||
};
|
||||
|
||||
class PYCXX_EXPORT LookupError: public StandardError
|
||||
{
|
||||
protected:
|
||||
explicit LookupError()
|
||||
{}
|
||||
};
|
||||
|
||||
class PYCXX_EXPORT ArithmeticError: public StandardError
|
||||
{
|
||||
protected:
|
||||
explicit ArithmeticError()
|
||||
{}
|
||||
};
|
||||
|
||||
class PYCXX_EXPORT EnvironmentError: public StandardError
|
||||
{
|
||||
protected:
|
||||
explicit EnvironmentError()
|
||||
{}
|
||||
};
|
||||
|
||||
// Concrete
|
||||
|
||||
class PYCXX_EXPORT TypeError: public StandardError
|
||||
{
|
||||
public:
|
||||
TypeError (const std::string& reason)
|
||||
: StandardError()
|
||||
{
|
||||
PyErr_SetString (Py::_Exc_TypeError(),reason.c_str());
|
||||
}
|
||||
};
|
||||
|
||||
class PYCXX_EXPORT IndexError: public LookupError
|
||||
{
|
||||
public:
|
||||
IndexError (const std::string& reason)
|
||||
: LookupError()
|
||||
{
|
||||
PyErr_SetString (Py::_Exc_IndexError(), reason.c_str());
|
||||
}
|
||||
};
|
||||
|
||||
class PYCXX_EXPORT AttributeError: public StandardError
|
||||
{
|
||||
public:
|
||||
AttributeError (const std::string& reason)
|
||||
: StandardError()
|
||||
{
|
||||
PyErr_SetString (Py::_Exc_AttributeError(), reason.c_str());
|
||||
}
|
||||
};
|
||||
|
||||
class PYCXX_EXPORT NameError: public StandardError
|
||||
{
|
||||
public:
|
||||
NameError (const std::string& reason)
|
||||
: StandardError()
|
||||
{
|
||||
PyErr_SetString (Py::_Exc_NameError(), reason.c_str());
|
||||
}
|
||||
};
|
||||
|
||||
class PYCXX_EXPORT RuntimeError: public StandardError
|
||||
{
|
||||
public:
|
||||
RuntimeError (const std::string& reason)
|
||||
: StandardError()
|
||||
{
|
||||
PyErr_SetString (Py::_Exc_RuntimeError(), reason.c_str());
|
||||
}
|
||||
};
|
||||
|
||||
class NotImplementedError: public StandardError
|
||||
{
|
||||
public:
|
||||
NotImplementedError (const std::string& reason)
|
||||
: StandardError()
|
||||
{
|
||||
PyErr_SetString (Py::_Exc_NotImplementedError(), reason.c_str());
|
||||
}
|
||||
};
|
||||
|
||||
class PYCXX_EXPORT SystemError: public StandardError
|
||||
{
|
||||
public:
|
||||
SystemError (const std::string& reason)
|
||||
: StandardError()
|
||||
{
|
||||
PyErr_SetString (Py::_Exc_SystemError(),reason.c_str());
|
||||
}
|
||||
};
|
||||
|
||||
class PYCXX_EXPORT KeyError: public LookupError
|
||||
{
|
||||
public:
|
||||
KeyError (const std::string& reason)
|
||||
: LookupError()
|
||||
{
|
||||
PyErr_SetString (Py::_Exc_KeyError(),reason.c_str());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class PYCXX_EXPORT ValueError: public StandardError
|
||||
{
|
||||
public:
|
||||
ValueError (const std::string& reason)
|
||||
: StandardError()
|
||||
{
|
||||
PyErr_SetString (Py::_Exc_ValueError(), reason.c_str());
|
||||
}
|
||||
};
|
||||
|
||||
class PYCXX_EXPORT OverflowError: public ArithmeticError
|
||||
{
|
||||
public:
|
||||
OverflowError (const std::string& reason)
|
||||
: ArithmeticError()
|
||||
{
|
||||
PyErr_SetString (Py::_Exc_OverflowError(), reason.c_str());
|
||||
}
|
||||
};
|
||||
|
||||
class PYCXX_EXPORT ZeroDivisionError: public ArithmeticError
|
||||
{
|
||||
public:
|
||||
ZeroDivisionError (const std::string& reason)
|
||||
: ArithmeticError()
|
||||
{
|
||||
PyErr_SetString (Py::_Exc_ZeroDivisionError(), reason.c_str());
|
||||
}
|
||||
};
|
||||
|
||||
class PYCXX_EXPORT FloatingPointError: public ArithmeticError
|
||||
{
|
||||
public:
|
||||
FloatingPointError (const std::string& reason)
|
||||
: ArithmeticError()
|
||||
{
|
||||
PyErr_SetString (Py::_Exc_FloatingPointError(), reason.c_str());
|
||||
}
|
||||
};
|
||||
|
||||
class PYCXX_EXPORT MemoryError: public StandardError
|
||||
{
|
||||
public:
|
||||
MemoryError (const std::string& reason)
|
||||
: StandardError()
|
||||
{
|
||||
PyErr_SetString (Py::_Exc_MemoryError(), reason.c_str());
|
||||
}
|
||||
};
|
||||
|
||||
class PYCXX_EXPORT SystemExit: public StandardError
|
||||
{
|
||||
public:
|
||||
SystemExit (const std::string& reason)
|
||||
: StandardError()
|
||||
{
|
||||
PyErr_SetString (Py::_Exc_SystemExit(),reason.c_str());
|
||||
}
|
||||
};
|
||||
|
||||
}// Py
|
||||
|
||||
#endif
|
||||
207
src/3rdParty/PyCXX/CXX/Python2/ExtensionModule.hxx
vendored
Normal file
207
src/3rdParty/PyCXX/CXX/Python2/ExtensionModule.hxx
vendored
Normal file
@@ -0,0 +1,207 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef __CXX_ExtensionModule__h
|
||||
#define __CXX_ExtensionModule__h
|
||||
|
||||
namespace Py
|
||||
{
|
||||
class PYCXX_EXPORT ExtensionModuleBase
|
||||
{
|
||||
public:
|
||||
ExtensionModuleBase( const char *name );
|
||||
virtual ~ExtensionModuleBase();
|
||||
|
||||
Module module( void ) const; // only valid after initialize() has been called
|
||||
Dict moduleDictionary( void ) const; // only valid after initialize() has been called
|
||||
|
||||
virtual Object invoke_method_noargs( void *method_def ) = 0;
|
||||
virtual Object invoke_method_keyword( void *method_def, const Tuple &_args, const Dict &_keywords ) = 0;
|
||||
virtual Object invoke_method_varargs( void *method_def, const Tuple &_args ) = 0;
|
||||
|
||||
const std::string &name() const;
|
||||
const std::string &fullName() const;
|
||||
|
||||
// what is returned from PyInit_<module> function
|
||||
Object moduleObject( void ) const;
|
||||
|
||||
protected:
|
||||
// Initialize the module
|
||||
void initialize( const char *module_doc );
|
||||
|
||||
const std::string m_module_name;
|
||||
const std::string m_full_module_name;
|
||||
MethodTable m_method_table;
|
||||
PyObject *m_module;
|
||||
|
||||
private:
|
||||
//
|
||||
// prevent the compiler generating these unwanted functions
|
||||
//
|
||||
ExtensionModuleBase( const ExtensionModuleBase & ); //unimplemented
|
||||
void operator=( const ExtensionModuleBase & ); //unimplemented
|
||||
};
|
||||
|
||||
// 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" PYCXX_EXPORT void do_not_dealloc( void * );
|
||||
|
||||
template<TEMPLATE_TYPENAME T>
|
||||
class ExtensionModule : public ExtensionModuleBase
|
||||
{
|
||||
public:
|
||||
ExtensionModule( const char *name )
|
||||
: ExtensionModuleBase( name )
|
||||
{}
|
||||
virtual ~ExtensionModule()
|
||||
{}
|
||||
|
||||
protected:
|
||||
typedef Object (T::*method_noargs_function_t)();
|
||||
typedef Object (T::*method_varargs_function_t)( const Tuple &args );
|
||||
typedef Object (T::*method_keyword_function_t)( const Tuple &args, const Dict &kws );
|
||||
typedef std::map<std::string, MethodDefExt<T> *> method_map_t;
|
||||
|
||||
static void add_noargs_method( const char *name, method_noargs_function_t function, const char *doc="" )
|
||||
{
|
||||
method_map_t &mm = methods();
|
||||
mm[ std::string( name ) ] = new MethodDefExt<T>( name, function, method_noargs_call_handler, doc );
|
||||
}
|
||||
|
||||
static void add_varargs_method( const char *name, method_varargs_function_t function, const char *doc="" )
|
||||
{
|
||||
method_map_t &mm = methods();
|
||||
mm[ std::string( name ) ] = new MethodDefExt<T>( name, function, method_varargs_call_handler, doc );
|
||||
}
|
||||
|
||||
static void add_keyword_method( const char *name, method_keyword_function_t function, const char *doc="" )
|
||||
{
|
||||
method_map_t &mm = methods();
|
||||
mm[ std::string( name ) ] = new MethodDefExt<T>( name, function, method_keyword_call_handler, doc );
|
||||
}
|
||||
|
||||
void initialize( const char *module_doc="" )
|
||||
{
|
||||
ExtensionModuleBase::initialize( module_doc );
|
||||
Dict dict( moduleDictionary() );
|
||||
|
||||
//
|
||||
// put each of the methods into the modules dictionary
|
||||
// so that we get called back at the function in T.
|
||||
//
|
||||
method_map_t &mm = methods();
|
||||
EXPLICIT_TYPENAME method_map_t::const_iterator i = mm.begin();
|
||||
EXPLICIT_TYPENAME method_map_t::const_iterator i_end = mm.end();
|
||||
for ( ; i != i_end; ++i )
|
||||
{
|
||||
MethodDefExt<T> *method_def = (*i).second;
|
||||
|
||||
static PyObject *self = PyCObject_FromVoidPtr( this, do_not_dealloc );
|
||||
|
||||
Tuple args( 2 );
|
||||
args[0] = Object( self, true );
|
||||
args[1] = Object( PyCObject_FromVoidPtr( method_def, do_not_dealloc ), true );
|
||||
|
||||
assert( m_module != NULL );
|
||||
PyObject *func = PyCFunction_NewEx
|
||||
(
|
||||
&method_def->ext_meth_def,
|
||||
new_reference_to( args ),
|
||||
m_module
|
||||
);
|
||||
|
||||
method_def->py_method = Object( func, true );
|
||||
|
||||
dict[ (*i).first ] = method_def->py_method;
|
||||
}
|
||||
}
|
||||
|
||||
protected: // Tom Malcolmson reports that derived classes need access to these
|
||||
static method_map_t &methods( void )
|
||||
{
|
||||
static method_map_t *map_of_methods = NULL;
|
||||
if( map_of_methods == NULL )
|
||||
map_of_methods = new method_map_t;
|
||||
|
||||
return *map_of_methods;
|
||||
}
|
||||
|
||||
// this invoke function must be called from within a try catch block
|
||||
virtual Object invoke_method_noargs( void *method_def )
|
||||
{
|
||||
// cast up to the derived class, method_def and call
|
||||
T *self = static_cast<T *>( this );
|
||||
MethodDefExt<T> *meth_def = reinterpret_cast<MethodDefExt<T> *>( method_def );
|
||||
|
||||
return (self->*meth_def->ext_noargs_function)();
|
||||
}
|
||||
|
||||
// this invoke function must be called from within a try catch block
|
||||
virtual Object invoke_method_varargs( void *method_def, const Tuple &args )
|
||||
{
|
||||
// cast up to the derived class, method_def and call
|
||||
T *self = static_cast<T *>( this );
|
||||
MethodDefExt<T> *meth_def = reinterpret_cast<MethodDefExt<T> *>( method_def );
|
||||
|
||||
return (self->*meth_def->ext_varargs_function)( args );
|
||||
}
|
||||
|
||||
// this invoke function must be called from within a try catch block
|
||||
virtual Object invoke_method_keyword( void *method_def, const Tuple &args, const Dict &keywords )
|
||||
{
|
||||
// cast up to the derived class, method_def and call
|
||||
T *self = static_cast<T *>( this );
|
||||
MethodDefExt<T> *meth_def = reinterpret_cast<MethodDefExt<T> *>( method_def );
|
||||
|
||||
return (self->*meth_def->ext_keyword_function)( args, keywords );
|
||||
}
|
||||
|
||||
private:
|
||||
//
|
||||
// prevent the compiler generating these unwanted functions
|
||||
//
|
||||
ExtensionModule( const ExtensionModule<T> & ); //unimplemented
|
||||
void operator=( const ExtensionModule<T> & ); //unimplemented
|
||||
};
|
||||
} // Namespace Py
|
||||
|
||||
|
||||
// End of __CXX_ExtensionModule__h
|
||||
#endif
|
||||
397
src/3rdParty/PyCXX/CXX/Python2/ExtensionOldType.hxx
vendored
Normal file
397
src/3rdParty/PyCXX/CXX/Python2/ExtensionOldType.hxx
vendored
Normal file
@@ -0,0 +1,397 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef __CXX_ExtensionOldType__h
|
||||
#define __CXX_ExtensionOldType__h
|
||||
|
||||
namespace Py
|
||||
{
|
||||
template<TEMPLATE_TYPENAME T> class PythonExtension
|
||||
: public PythonExtensionBase
|
||||
{
|
||||
public:
|
||||
static PyTypeObject *type_object()
|
||||
{
|
||||
return behaviors().type_object();
|
||||
}
|
||||
|
||||
static bool check( PyObject *p )
|
||||
{
|
||||
// is p like me?
|
||||
return p->ob_type == type_object();
|
||||
}
|
||||
|
||||
static bool check( const Object &ob )
|
||||
{
|
||||
return check( ob.ptr() );
|
||||
}
|
||||
|
||||
//
|
||||
// every object needs getattr implemented
|
||||
// to support methods
|
||||
//
|
||||
virtual Object getattr( const char *name )
|
||||
{
|
||||
return getattr_methods( name );
|
||||
}
|
||||
|
||||
PyObject *selfPtr()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
Object self()
|
||||
{
|
||||
return asObject( this );
|
||||
}
|
||||
|
||||
protected:
|
||||
explicit PythonExtension()
|
||||
: PythonExtensionBase()
|
||||
{
|
||||
PyObject_Init( this, type_object() );
|
||||
|
||||
// every object must support getattr
|
||||
behaviors().supportGetattr();
|
||||
}
|
||||
|
||||
virtual ~PythonExtension()
|
||||
{}
|
||||
|
||||
static PythonType &behaviors()
|
||||
{
|
||||
static PythonType* p;
|
||||
if( p == NULL )
|
||||
{
|
||||
#if defined( _CPPRTTI ) || defined( __GNUG__ )
|
||||
const char *default_name =( typeid( T ) ).name();
|
||||
#else
|
||||
const char *default_name = "unknown";
|
||||
#endif
|
||||
p = new PythonType( sizeof( T ), 0, default_name );
|
||||
p->set_tp_dealloc( extension_object_deallocator );
|
||||
}
|
||||
|
||||
return *p;
|
||||
}
|
||||
|
||||
typedef Object (T::*method_noargs_function_t)();
|
||||
typedef Object (T::*method_varargs_function_t)( const Tuple &args );
|
||||
typedef Object (T::*method_keyword_function_t)( const Tuple &args, const Dict &kws );
|
||||
typedef std::map<std::string, MethodDefExt<T> *> method_map_t;
|
||||
|
||||
// support the default attributes, __name__, __doc__ and methods
|
||||
virtual Object getattr_default( const char *_name )
|
||||
{
|
||||
std::string name( _name );
|
||||
|
||||
if( name == "__name__" && type_object()->tp_name != NULL )
|
||||
{
|
||||
return Py::String( type_object()->tp_name );
|
||||
}
|
||||
|
||||
if( name == "__doc__" && type_object()->tp_doc != NULL )
|
||||
{
|
||||
return Py::String( type_object()->tp_doc );
|
||||
}
|
||||
|
||||
// trying to fake out being a class for help()
|
||||
// else if( name == "__bases__" )
|
||||
// {
|
||||
// return Py::Tuple( 0 );
|
||||
// }
|
||||
// else if( name == "__module__" )
|
||||
// {
|
||||
// return Py::Nothing();
|
||||
// }
|
||||
// else if( name == "__dict__" )
|
||||
// {
|
||||
// return Py::Dict();
|
||||
// }
|
||||
|
||||
return getattr_methods( _name );
|
||||
}
|
||||
|
||||
// turn a name into function object
|
||||
virtual Object getattr_methods( const char *_name )
|
||||
{
|
||||
std::string name( _name );
|
||||
|
||||
method_map_t &mm = methods();
|
||||
|
||||
// see if name exists and get entry with method
|
||||
EXPLICIT_TYPENAME method_map_t::const_iterator i = mm.find( name );
|
||||
if( i == mm.end() )
|
||||
{
|
||||
if( name == "__methods__" )
|
||||
{
|
||||
List methods;
|
||||
|
||||
i = mm.begin();
|
||||
EXPLICIT_TYPENAME method_map_t::const_iterator i_end = mm.end();
|
||||
|
||||
for( ; i != i_end; ++i )
|
||||
methods.append( String( (*i).first ) );
|
||||
|
||||
return methods;
|
||||
}
|
||||
|
||||
throw AttributeError( name );
|
||||
}
|
||||
|
||||
MethodDefExt<T> *method_def = i->second;
|
||||
|
||||
Tuple self( 2 );
|
||||
|
||||
self[0] = Object( this );
|
||||
self[1] = Object( PyCObject_FromVoidPtr( method_def, do_not_dealloc ), true );
|
||||
|
||||
PyObject *func = PyCFunction_NewEx( &method_def->ext_meth_def, self.ptr(), NULL );
|
||||
|
||||
return Object(func, true);
|
||||
}
|
||||
|
||||
// check that all methods added are unique
|
||||
static void check_unique_method_name( const char *name )
|
||||
{
|
||||
method_map_t &mm = methods();
|
||||
EXPLICIT_TYPENAME method_map_t::const_iterator i;
|
||||
i = mm.find( name );
|
||||
if( i != mm.end() )
|
||||
throw AttributeError( name );
|
||||
}
|
||||
|
||||
static void add_noargs_method( const char *name, method_noargs_function_t function, const char *doc="" )
|
||||
{
|
||||
check_unique_method_name( name );
|
||||
method_map_t &mm = methods();
|
||||
mm[ std::string( name ) ] = new MethodDefExt<T>( name, function, method_noargs_call_handler, doc );
|
||||
}
|
||||
|
||||
static void add_varargs_method( const char *name, method_varargs_function_t function, const char *doc="" )
|
||||
{
|
||||
check_unique_method_name( name );
|
||||
method_map_t &mm = methods();
|
||||
mm[ std::string( name ) ] = new MethodDefExt<T>( name, function, method_varargs_call_handler, doc );
|
||||
}
|
||||
|
||||
static void add_keyword_method( const char *name, method_keyword_function_t function, const char *doc="" )
|
||||
{
|
||||
check_unique_method_name( name );
|
||||
method_map_t &mm = methods();
|
||||
mm[ std::string( name ) ] = new MethodDefExt<T>( name, function, method_keyword_call_handler, doc );
|
||||
}
|
||||
|
||||
private:
|
||||
static method_map_t &methods( void )
|
||||
{
|
||||
static method_map_t *map_of_methods = NULL;
|
||||
if( map_of_methods == NULL )
|
||||
map_of_methods = new method_map_t;
|
||||
|
||||
return *map_of_methods;
|
||||
}
|
||||
|
||||
// Note: Python calls noargs as varargs buts args==NULL
|
||||
static 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();
|
||||
T *self = static_cast<T *>( self_in_cobject );
|
||||
MethodDefExt<T> *meth_def = reinterpret_cast<MethodDefExt<T> *>(
|
||||
PyCObject_AsVoidPtr( self_and_name_tuple[1].ptr() ) );
|
||||
Object result;
|
||||
|
||||
// Adding try & catch in case of STL debug-mode exceptions.
|
||||
#ifdef _STLP_DEBUG
|
||||
try
|
||||
{
|
||||
result = (self->*meth_def->ext_noargs_function)();
|
||||
}
|
||||
catch( std::__stl_debug_exception )
|
||||
{
|
||||
// throw cxx::RuntimeError( sErrMsg );
|
||||
throw RuntimeError( "Error message not set yet." );
|
||||
}
|
||||
#else
|
||||
result = (self->*meth_def->ext_noargs_function)();
|
||||
#endif // _STLP_DEBUG
|
||||
|
||||
return new_reference_to( result.ptr() );
|
||||
}
|
||||
catch( BaseException & )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static PyObject *method_varargs_call_handler( PyObject *_self_and_name_tuple, PyObject *_args )
|
||||
{
|
||||
try
|
||||
{
|
||||
Tuple self_and_name_tuple( _self_and_name_tuple );
|
||||
|
||||
PyObject *self_in_cobject = self_and_name_tuple[0].ptr();
|
||||
T *self = static_cast<T *>( self_in_cobject );
|
||||
|
||||
MethodDefExt<T> *meth_def = reinterpret_cast<MethodDefExt<T> *>(
|
||||
PyCObject_AsVoidPtr( self_and_name_tuple[1].ptr() ) );
|
||||
Tuple args( _args );
|
||||
|
||||
Object result;
|
||||
|
||||
// Adding try & catch in case of STL debug-mode exceptions.
|
||||
#ifdef _STLP_DEBUG
|
||||
try
|
||||
{
|
||||
result = (self->*meth_def->ext_varargs_function)( args );
|
||||
}
|
||||
catch( std::__stl_debug_exception )
|
||||
{
|
||||
throw RuntimeError( "Error message not set yet." );
|
||||
}
|
||||
#else
|
||||
result = (self->*meth_def->ext_varargs_function)( args );
|
||||
#endif // _STLP_DEBUG
|
||||
|
||||
return new_reference_to( result.ptr() );
|
||||
}
|
||||
catch( BaseException & )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static PyObject *method_keyword_call_handler( PyObject *_self_and_name_tuple, PyObject *_args, PyObject *_keywords )
|
||||
{
|
||||
try
|
||||
{
|
||||
Tuple self_and_name_tuple( _self_and_name_tuple );
|
||||
|
||||
PyObject *self_in_cobject = self_and_name_tuple[0].ptr();
|
||||
T *self = static_cast<T *>( self_in_cobject );
|
||||
|
||||
MethodDefExt<T> *meth_def = reinterpret_cast<MethodDefExt<T> *>(
|
||||
PyCObject_AsVoidPtr( self_and_name_tuple[1].ptr() ) );
|
||||
|
||||
Tuple args( _args );
|
||||
|
||||
// _keywords may be NULL so be careful about the way the dict is created
|
||||
Dict keywords;
|
||||
if( _keywords != NULL )
|
||||
keywords = Dict( _keywords );
|
||||
|
||||
Object result( ( self->*meth_def->ext_keyword_function )( args, keywords ) );
|
||||
|
||||
return new_reference_to( result.ptr() );
|
||||
}
|
||||
catch( BaseException & )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void extension_object_deallocator( PyObject* t )
|
||||
{
|
||||
delete (T *)( t );
|
||||
}
|
||||
|
||||
//
|
||||
// prevent the compiler generating these unwanted functions
|
||||
//
|
||||
explicit PythonExtension( const PythonExtension<T> &other );
|
||||
void operator=( const PythonExtension<T> &rhs );
|
||||
};
|
||||
|
||||
//
|
||||
// ExtensionObject<T> is an Object that will accept only T's.
|
||||
//
|
||||
template<TEMPLATE_TYPENAME T>
|
||||
class ExtensionObject: public Object
|
||||
{
|
||||
public:
|
||||
|
||||
explicit ExtensionObject( PyObject *pyob )
|
||||
: Object( pyob )
|
||||
{
|
||||
validate();
|
||||
}
|
||||
|
||||
ExtensionObject( const ExtensionObject<T> &other )
|
||||
: Object( *other )
|
||||
{
|
||||
validate();
|
||||
}
|
||||
|
||||
ExtensionObject( const Object &other )
|
||||
: Object( *other )
|
||||
{
|
||||
validate();
|
||||
}
|
||||
|
||||
ExtensionObject &operator=( const Object &rhs )
|
||||
{
|
||||
return( *this = *rhs );
|
||||
}
|
||||
|
||||
ExtensionObject &operator=( PyObject *rhsp )
|
||||
{
|
||||
if( ptr() != rhsp )
|
||||
set( rhsp );
|
||||
return *this;
|
||||
}
|
||||
|
||||
virtual bool accepts( PyObject *pyob ) const
|
||||
{
|
||||
return( pyob && T::check( pyob ) );
|
||||
}
|
||||
|
||||
//
|
||||
// Obtain a pointer to the PythonExtension object
|
||||
//
|
||||
T *extensionObject( void )
|
||||
{
|
||||
return static_cast<T *>( ptr() );
|
||||
}
|
||||
};
|
||||
} // Namespace Py
|
||||
|
||||
// End of __CXX_ExtensionOldType__h
|
||||
#endif
|
||||
403
src/3rdParty/PyCXX/CXX/Python2/ExtensionType.hxx
vendored
Normal file
403
src/3rdParty/PyCXX/CXX/Python2/ExtensionType.hxx
vendored
Normal file
@@ -0,0 +1,403 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef __CXX_ExtensionClass__h
|
||||
#define __CXX_ExtensionClass__h
|
||||
|
||||
#define PYCXX_NOARGS_METHOD_NAME( NAME ) _callNoArgsMethod__##NAME
|
||||
#define PYCXX_VARARGS_METHOD_NAME( NAME ) _callVarArgsMethod__##NAME
|
||||
#define PYCXX_KEYWORDS_METHOD_NAME( NAME ) _callKeywordsMethod__##NAME
|
||||
|
||||
#define PYCXX_NOARGS_METHOD_DECL( CLS, NAME ) \
|
||||
static PyObject *PYCXX_NOARGS_METHOD_NAME( NAME )( PyObject *_self, PyObject *, PyObject * ) \
|
||||
{ \
|
||||
try \
|
||||
{ \
|
||||
Py::PythonClassInstance *self_python = reinterpret_cast< Py::PythonClassInstance * >( _self ); \
|
||||
CLS *self = reinterpret_cast< CLS * >( self_python->m_pycxx_object ); \
|
||||
Py::Object r( (self->NAME)() ); \
|
||||
return Py::new_reference_to( r.ptr() ); \
|
||||
} \
|
||||
catch( Py::Exception & ) \
|
||||
{ \
|
||||
return 0; \
|
||||
} \
|
||||
}
|
||||
#define PYCXX_VARARGS_METHOD_DECL( CLS, NAME ) \
|
||||
static PyObject *PYCXX_VARARGS_METHOD_NAME( NAME )( PyObject *_self, PyObject *_a, PyObject * ) \
|
||||
{ \
|
||||
try \
|
||||
{ \
|
||||
Py::PythonClassInstance *self_python = reinterpret_cast< Py::PythonClassInstance * >( _self ); \
|
||||
CLS *self = reinterpret_cast< CLS * >( self_python->m_pycxx_object ); \
|
||||
Py::Tuple a( _a ); \
|
||||
Py::Object r( (self->NAME)( a ) ); \
|
||||
return Py::new_reference_to( r.ptr() ); \
|
||||
} \
|
||||
catch( Py::Exception & ) \
|
||||
{ \
|
||||
return 0; \
|
||||
} \
|
||||
}
|
||||
#define PYCXX_KEYWORDS_METHOD_DECL( CLS, NAME ) \
|
||||
static PyObject *PYCXX_KEYWORDS_METHOD_NAME( NAME )( PyObject *_self, PyObject *_a, PyObject *_k ) \
|
||||
{ \
|
||||
try \
|
||||
{ \
|
||||
Py::PythonClassInstance *self_python = reinterpret_cast< Py::PythonClassInstance * >( _self ); \
|
||||
CLS *self = reinterpret_cast< CLS * >( self_python->m_pycxx_object ); \
|
||||
Py::Tuple a( _a ); \
|
||||
Py::Dict k; \
|
||||
if( _k != NULL ) \
|
||||
k = _k; \
|
||||
Py::Object r( (self->NAME)( a, k ) ); \
|
||||
return Py::new_reference_to( r.ptr() ); \
|
||||
} \
|
||||
catch( Py::Exception & ) \
|
||||
{ \
|
||||
return 0; \
|
||||
} \
|
||||
}
|
||||
|
||||
// need to support METH_STATIC and METH_CLASS
|
||||
|
||||
#define PYCXX_ADD_NOARGS_METHOD( PYNAME, NAME, docs ) \
|
||||
add_method( #PYNAME, (PyCFunction)PYCXX_NOARGS_METHOD_NAME( NAME ), METH_NOARGS, docs )
|
||||
#define PYCXX_ADD_VARARGS_METHOD( PYNAME, NAME, docs ) \
|
||||
add_method( #PYNAME, (PyCFunction)PYCXX_VARARGS_METHOD_NAME( NAME ), METH_VARARGS, docs )
|
||||
#define PYCXX_ADD_KEYWORDS_METHOD( PYNAME, NAME, docs ) \
|
||||
add_method( #PYNAME, (PyCFunction)PYCXX_KEYWORDS_METHOD_NAME( NAME ), METH_VARARGS | METH_KEYWORDS, docs )
|
||||
|
||||
namespace Py
|
||||
{
|
||||
PYCXX_EXPORT extern PythonExtensionBase *getPythonExtensionBase( PyObject *self );
|
||||
|
||||
struct PythonClassInstance
|
||||
{
|
||||
PyObject_HEAD
|
||||
PythonExtensionBase *m_pycxx_object;
|
||||
};
|
||||
|
||||
|
||||
class PYCXX_EXPORT ExtensionClassMethodsTable
|
||||
{
|
||||
public:
|
||||
ExtensionClassMethodsTable()
|
||||
: m_methods_table( new PyMethodDef[ METHOD_TABLE_SIZE_INCREMENT ] )
|
||||
, m_methods_used( 0 )
|
||||
, m_methods_size( METHOD_TABLE_SIZE_INCREMENT )
|
||||
{
|
||||
}
|
||||
|
||||
~ExtensionClassMethodsTable()
|
||||
{
|
||||
delete[] m_methods_table;
|
||||
}
|
||||
|
||||
// check that all methods added are unique
|
||||
void check_unique_method_name( const char *_name )
|
||||
{
|
||||
std::string name( _name );
|
||||
for( int i=0; i<m_methods_used; i++ )
|
||||
{
|
||||
if( name == m_methods_table[i].ml_name )
|
||||
{
|
||||
throw AttributeError( name );
|
||||
}
|
||||
}
|
||||
}
|
||||
PyMethodDef *add_method( const char *name, PyCFunction function, int flags, const char *doc )
|
||||
{
|
||||
check_unique_method_name( name );
|
||||
|
||||
// see if there is enough space for one more method
|
||||
if( m_methods_used == (m_methods_size-1) )
|
||||
{
|
||||
PyMethodDef *old_mt = m_methods_table;
|
||||
m_methods_size += METHOD_TABLE_SIZE_INCREMENT;
|
||||
PyMethodDef *new_mt = new PyMethodDef[ m_methods_size ];
|
||||
for( int i=0; i<m_methods_used; i++ )
|
||||
{
|
||||
new_mt[ i ] = old_mt[ i ];
|
||||
}
|
||||
delete[] old_mt;
|
||||
m_methods_table = new_mt;
|
||||
}
|
||||
|
||||
// add method into the table
|
||||
PyMethodDef *p = &m_methods_table[ m_methods_used ];
|
||||
p->ml_name = const_cast<char *>( name );
|
||||
p->ml_meth = function;
|
||||
p->ml_flags = flags;
|
||||
p->ml_doc = const_cast<char *>( doc );
|
||||
|
||||
m_methods_used++;
|
||||
p++;
|
||||
|
||||
// add the sentinel marking the table end
|
||||
p->ml_name = NULL;
|
||||
p->ml_meth = NULL;
|
||||
p->ml_flags = 0;
|
||||
p->ml_doc = NULL;
|
||||
|
||||
return m_methods_table;
|
||||
}
|
||||
|
||||
private:
|
||||
enum {METHOD_TABLE_SIZE_INCREMENT = 1};
|
||||
PyMethodDef *m_methods_table;
|
||||
int m_methods_used;
|
||||
int m_methods_size;
|
||||
};
|
||||
|
||||
template<TEMPLATE_TYPENAME T> class PythonClass
|
||||
: public PythonExtensionBase
|
||||
{
|
||||
protected:
|
||||
explicit PythonClass( PythonClassInstance *self, Tuple &/*args*/, Dict &/*kwds*/ )
|
||||
: PythonExtensionBase()
|
||||
, m_class_instance( self )
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~PythonClass()
|
||||
{}
|
||||
|
||||
static ExtensionClassMethodsTable &methodTable()
|
||||
{
|
||||
static ExtensionClassMethodsTable *method_table;
|
||||
if( method_table == NULL )
|
||||
method_table = new ExtensionClassMethodsTable;
|
||||
return *method_table;
|
||||
}
|
||||
|
||||
static void add_method( const char *name, PyCFunction function, int flags, const char *doc=NULL )
|
||||
{
|
||||
behaviors().set_methods( methodTable().add_method( name, function, flags, doc ) );
|
||||
}
|
||||
|
||||
static PythonType &behaviors()
|
||||
{
|
||||
static PythonType *p;
|
||||
if( p == NULL )
|
||||
{
|
||||
#if defined( _CPPRTTI ) || defined( __GNUG__ )
|
||||
const char *default_name = (typeid( T )).name();
|
||||
#else
|
||||
const char *default_name = "unknown";
|
||||
#endif
|
||||
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 );
|
||||
// we are a class
|
||||
p->supportClass();
|
||||
|
||||
// always support get and set attr
|
||||
p->supportGetattro();
|
||||
p->supportSetattro();
|
||||
}
|
||||
|
||||
return *p;
|
||||
}
|
||||
|
||||
static PyObject *extension_object_new( PyTypeObject *subtype, PyObject * /*args*/, PyObject * /*kwds*/ )
|
||||
{
|
||||
#ifdef PYCXX_DEBUG
|
||||
std::cout << "extension_object_new()" << std::endl;
|
||||
#endif
|
||||
PythonClassInstance *o = reinterpret_cast<PythonClassInstance *>( subtype->tp_alloc( subtype, 0 ) );
|
||||
if( o == NULL )
|
||||
return NULL;
|
||||
|
||||
o->m_pycxx_object = NULL;
|
||||
|
||||
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;
|
||||
#endif
|
||||
return self;
|
||||
}
|
||||
|
||||
static int extension_object_init( PyObject *_self, PyObject *args_, PyObject *kwds_ )
|
||||
{
|
||||
try
|
||||
{
|
||||
Py::Tuple args( args_ );
|
||||
Py::Dict kwds;
|
||||
if( kwds_ != NULL )
|
||||
kwds = kwds_;
|
||||
|
||||
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;
|
||||
#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;
|
||||
#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;
|
||||
#endif
|
||||
self->m_pycxx_object->reinit( args, kwds );
|
||||
}
|
||||
}
|
||||
catch( Exception & )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void extension_object_deallocator( PyObject *_self )
|
||||
{
|
||||
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;
|
||||
#endif
|
||||
delete self->m_pycxx_object;
|
||||
_self->ob_type->tp_free( _self );
|
||||
}
|
||||
|
||||
public:
|
||||
static PyTypeObject *type_object()
|
||||
{
|
||||
return behaviors().type_object();
|
||||
}
|
||||
|
||||
static Object type()
|
||||
{
|
||||
return Object( reinterpret_cast<PyObject *>( behaviors().type_object() ) );
|
||||
}
|
||||
|
||||
static bool check( PyObject *p )
|
||||
{
|
||||
// is p like me?
|
||||
return p->ob_type == type_object();
|
||||
}
|
||||
|
||||
static bool check( const Object &ob )
|
||||
{
|
||||
return check( ob.ptr() );
|
||||
}
|
||||
|
||||
virtual PyObject *selfPtr()
|
||||
{
|
||||
return reinterpret_cast<PyObject *>( m_class_instance );
|
||||
}
|
||||
|
||||
virtual Object self()
|
||||
{
|
||||
return Object( reinterpret_cast<PyObject *>( m_class_instance ) );
|
||||
}
|
||||
|
||||
protected:
|
||||
private:
|
||||
PythonClassInstance *m_class_instance;
|
||||
|
||||
private:
|
||||
//
|
||||
// prevent the compiler generating these unwanted functions
|
||||
//
|
||||
explicit PythonClass( const PythonClass<T> &other );
|
||||
void operator=( const PythonClass<T> &rhs );
|
||||
};
|
||||
|
||||
//
|
||||
// ExtensionObject<T> is an Object that will accept only T's.
|
||||
//
|
||||
template<TEMPLATE_TYPENAME T>
|
||||
class PythonClassObject: public Object
|
||||
{
|
||||
public:
|
||||
|
||||
explicit PythonClassObject( PyObject *pyob )
|
||||
: Object( pyob )
|
||||
{
|
||||
validate();
|
||||
}
|
||||
|
||||
PythonClassObject( const PythonClassObject<T> &other )
|
||||
: Object( *other )
|
||||
{
|
||||
validate();
|
||||
}
|
||||
|
||||
PythonClassObject( const Object &other )
|
||||
: Object( *other )
|
||||
{
|
||||
validate();
|
||||
}
|
||||
|
||||
PythonClassObject &operator=( const Object &rhs )
|
||||
{
|
||||
*this = *rhs;
|
||||
return *this;
|
||||
}
|
||||
|
||||
PythonClassObject &operator=( PyObject *rhsp )
|
||||
{
|
||||
if( ptr() != rhsp )
|
||||
set( rhsp );
|
||||
return *this;
|
||||
}
|
||||
|
||||
virtual bool accepts( PyObject *pyob ) const
|
||||
{
|
||||
return( pyob && T::check( pyob ) );
|
||||
}
|
||||
|
||||
//
|
||||
// Obtain a pointer to the PythonExtension object
|
||||
//
|
||||
T *getCxxObject( void )
|
||||
{
|
||||
return dynamic_cast< T * >( getPythonExtensionBase( ptr() ) );
|
||||
}
|
||||
};
|
||||
} // Namespace Py
|
||||
|
||||
// End of __CXX_ExtensionClass__h
|
||||
#endif
|
||||
175
src/3rdParty/PyCXX/CXX/Python2/ExtensionTypeBase.hxx
vendored
Normal file
175
src/3rdParty/PyCXX/CXX/Python2/ExtensionTypeBase.hxx
vendored
Normal file
@@ -0,0 +1,175 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef __CXX_ExtensionTypeBase__h
|
||||
#define __CXX_ExtensionTypeBase__h
|
||||
|
||||
namespace Py
|
||||
{
|
||||
// Class PythonExtension is what you inherit from to create
|
||||
// a new Python extension type. You give your class itself
|
||||
// as the template parameter.
|
||||
|
||||
// There are two ways that extension objects can get destroyed.
|
||||
// 1. Their reference count goes to zero
|
||||
// 2. Someone does an explicit delete on a pointer.
|
||||
// In(1) the problem is to get the destructor called
|
||||
// We register a special deallocator in the Python type object
|
||||
// (see behaviors()) to do this.
|
||||
// In(2) there is no problem, the dtor gets called.
|
||||
|
||||
// PythonExtension does not use the usual Python heap allocator,
|
||||
// instead using new/delete. We do the setting of the type object
|
||||
// and reference count, usually done by PyObject_New, in the
|
||||
// base class ctor.
|
||||
|
||||
// This special deallocator does a delete on the pointer.
|
||||
|
||||
class PYCXX_EXPORT PythonExtensionBase : public PyObject
|
||||
{
|
||||
public:
|
||||
PythonExtensionBase();
|
||||
virtual ~PythonExtensionBase();
|
||||
|
||||
public:
|
||||
// object
|
||||
virtual void reinit( Tuple &args, Dict &kwds );
|
||||
|
||||
// object basics
|
||||
virtual int print( FILE *, int );
|
||||
virtual Object getattr( const char * );
|
||||
virtual int setattr( const char *, const Object & );
|
||||
virtual Object getattro( const String & );
|
||||
Object genericGetAttro( const String & );
|
||||
virtual int setattro( const String &, const Object & );
|
||||
int genericSetAttro( const String &, const Object & );
|
||||
virtual int compare( const Object & );
|
||||
virtual Object rich_compare( const Object &, int );
|
||||
virtual Object repr();
|
||||
virtual Object str();
|
||||
virtual long hash();
|
||||
virtual Object call( const Object &, const Object & );
|
||||
virtual Object iter();
|
||||
virtual PyObject *iternext();
|
||||
|
||||
// Sequence methods
|
||||
virtual int sequence_length();
|
||||
virtual Object sequence_concat( const Object & );
|
||||
virtual Object sequence_repeat( Py_ssize_t );
|
||||
virtual Object sequence_item( Py_ssize_t );
|
||||
virtual Object sequence_slice( Py_ssize_t, Py_ssize_t );
|
||||
virtual int sequence_ass_item( Py_ssize_t, const Object & );
|
||||
virtual int sequence_ass_slice( Py_ssize_t, Py_ssize_t, const Object & );
|
||||
|
||||
// Mapping
|
||||
virtual int mapping_length();
|
||||
virtual Object mapping_subscript( const Object & );
|
||||
virtual int mapping_ass_subscript( const Object &, const Object & );
|
||||
|
||||
// Number
|
||||
virtual int number_nonzero();
|
||||
virtual Object number_negative();
|
||||
virtual Object number_positive();
|
||||
virtual Object number_absolute();
|
||||
virtual Object number_invert();
|
||||
virtual Object number_int();
|
||||
virtual Object number_float();
|
||||
virtual Object number_long();
|
||||
virtual Object number_oct();
|
||||
virtual Object number_hex();
|
||||
virtual Object number_add( const Object & );
|
||||
virtual Object number_subtract( const Object & );
|
||||
virtual Object number_multiply( const Object & );
|
||||
virtual Object number_divide( const Object & );
|
||||
virtual Object number_remainder( const Object & );
|
||||
virtual Object number_divmod( const Object & );
|
||||
virtual Object number_lshift( const Object & );
|
||||
virtual Object number_rshift( const Object & );
|
||||
virtual Object number_and( const Object & );
|
||||
virtual Object number_xor( const Object & );
|
||||
virtual Object number_or( const Object & );
|
||||
virtual Object number_power( const Object &, const Object & );
|
||||
|
||||
// Buffer
|
||||
virtual Py_ssize_t buffer_getreadbuffer( Py_ssize_t, void** );
|
||||
virtual Py_ssize_t buffer_getwritebuffer( Py_ssize_t, void** );
|
||||
virtual Py_ssize_t buffer_getsegcount( Py_ssize_t* );
|
||||
|
||||
public:
|
||||
// helper functions to call function fn_name with 0 to 9 args
|
||||
Object callOnSelf( const std::string &fn_name );
|
||||
Object callOnSelf( const std::string &fn_name,
|
||||
const Object &arg1 );
|
||||
Object callOnSelf( const std::string &fn_name,
|
||||
const Object &arg1, const Object &arg2 );
|
||||
Object callOnSelf( const std::string &fn_name,
|
||||
const Object &arg1, const Object &arg2, const Object &arg3 );
|
||||
Object callOnSelf( const std::string &fn_name,
|
||||
const Object &arg1, const Object &arg2, const Object &arg3,
|
||||
const Object &arg4 );
|
||||
Object callOnSelf( const std::string &fn_name,
|
||||
const Object &arg1, const Object &arg2, const Object &arg3,
|
||||
const Object &arg4, const Object &arg5 );
|
||||
Object callOnSelf( const std::string &fn_name,
|
||||
const Object &arg1, const Object &arg2, const Object &arg3,
|
||||
const Object &arg4, const Object &arg5, const Object &arg6 );
|
||||
Object callOnSelf( const std::string &fn_name,
|
||||
const Object &arg1, const Object &arg2, const Object &arg3,
|
||||
const Object &arg4, const Object &arg5, const Object &arg6,
|
||||
const Object &arg7 );
|
||||
Object callOnSelf( const std::string &fn_name,
|
||||
const Object &arg1, const Object &arg2, const Object &arg3,
|
||||
const Object &arg4, const Object &arg5, const Object &arg6,
|
||||
const Object &arg7, const Object &arg8 );
|
||||
Object callOnSelf( const std::string &fn_name,
|
||||
const Object &arg1, const Object &arg2, const Object &arg3,
|
||||
const Object &arg4, const Object &arg5, const Object &arg6,
|
||||
const Object &arg7, const Object &arg8, const Object &arg9 );
|
||||
|
||||
public:
|
||||
virtual PyObject *selfPtr() = 0;
|
||||
virtual Object self() = 0;
|
||||
|
||||
private:
|
||||
void missing_method( void );
|
||||
static PyObject *method_call_handler( PyObject *self, PyObject *args );
|
||||
};
|
||||
|
||||
} // Namespace Py
|
||||
|
||||
// End of __CXX_ExtensionTypeBase__h
|
||||
#endif
|
||||
189
src/3rdParty/PyCXX/CXX/Python2/Extensions.hxx
vendored
Normal file
189
src/3rdParty/PyCXX/CXX/Python2/Extensions.hxx
vendored
Normal file
@@ -0,0 +1,189 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef __CXX_Extensions__h
|
||||
#define __CXX_Extensions__h
|
||||
|
||||
|
||||
#ifdef _MSC_VER
|
||||
// disable warning C4786: symbol greater than 255 character,
|
||||
// okay to ignore
|
||||
#pragma warning( disable: 4786 )
|
||||
#endif
|
||||
|
||||
#include "CXX/WrapPython.h"
|
||||
#include "CXX/Version.hxx"
|
||||
#include "CXX/Python2/Config.hxx"
|
||||
#include "CXX/Python2/CxxDebug.hxx"
|
||||
#include "CXX/Python2/Objects.hxx"
|
||||
|
||||
extern "C" { extern PyObject py_object_initializer; }
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
namespace Py
|
||||
{
|
||||
class ExtensionModuleBase;
|
||||
|
||||
// Make an Exception Type for use in raising custom exceptions
|
||||
class PYCXX_EXPORT ExtensionExceptionType : public Object
|
||||
{
|
||||
public:
|
||||
ExtensionExceptionType();
|
||||
virtual ~ExtensionExceptionType();
|
||||
|
||||
// call init to create the type
|
||||
void init( ExtensionModuleBase &module, const std::string &name, ExtensionExceptionType &parent );
|
||||
void init( ExtensionModuleBase &module, const std::string &name );
|
||||
};
|
||||
|
||||
class PYCXX_EXPORT MethodTable
|
||||
{
|
||||
public:
|
||||
MethodTable();
|
||||
virtual ~MethodTable();
|
||||
|
||||
void add( const char *method_name, PyCFunction f, const char *doc="", int flag=1 );
|
||||
PyMethodDef *table();
|
||||
|
||||
protected:
|
||||
std::vector<PyMethodDef> t; // accumulator of PyMethodDef's
|
||||
PyMethodDef *mt; // Actual method table produced when full
|
||||
|
||||
static PyMethodDef method( const char* method_name, PyCFunction f, int flags=1, const char* doc="" );
|
||||
|
||||
private:
|
||||
//
|
||||
// prevent the compiler generating these unwanted functions
|
||||
//
|
||||
MethodTable( const MethodTable &m ); //unimplemented
|
||||
void operator=( const MethodTable &m ); //unimplemented
|
||||
|
||||
}; // end class MethodTable
|
||||
|
||||
// Note: Python calls noargs as varargs buts args==NULL
|
||||
extern "C" typedef PyObject *(*method_noargs_call_handler_t)( PyObject *_self, PyObject * );
|
||||
extern "C" typedef PyObject *(*method_varargs_call_handler_t)( PyObject *_self, PyObject *_args );
|
||||
extern "C" typedef PyObject *(*method_keyword_call_handler_t)( PyObject *_self, PyObject *_args, PyObject *_dict );
|
||||
|
||||
template<class T>
|
||||
class MethodDefExt : public PyMethodDef
|
||||
{
|
||||
public:
|
||||
typedef Object (T::*method_noargs_function_t)();
|
||||
typedef Object (T::*method_varargs_function_t)( const Tuple &args );
|
||||
typedef Object (T::*method_keyword_function_t)( const Tuple &args, const Dict &kws );
|
||||
|
||||
// NOARGS
|
||||
MethodDefExt
|
||||
(
|
||||
const char *_name,
|
||||
method_noargs_function_t _function,
|
||||
method_noargs_call_handler_t _handler,
|
||||
const char *_doc
|
||||
)
|
||||
{
|
||||
ext_meth_def.ml_name = const_cast<char *>( _name );
|
||||
ext_meth_def.ml_meth = reinterpret_cast<method_varargs_call_handler_t>( _handler );
|
||||
ext_meth_def.ml_flags = METH_NOARGS;
|
||||
ext_meth_def.ml_doc = const_cast<char *>( _doc );
|
||||
|
||||
ext_noargs_function = _function;
|
||||
ext_varargs_function = NULL;
|
||||
ext_keyword_function = NULL;
|
||||
}
|
||||
|
||||
// VARARGS
|
||||
MethodDefExt
|
||||
(
|
||||
const char *_name,
|
||||
method_varargs_function_t _function,
|
||||
method_varargs_call_handler_t _handler,
|
||||
const char *_doc
|
||||
)
|
||||
{
|
||||
ext_meth_def.ml_name = const_cast<char *>( _name );
|
||||
ext_meth_def.ml_meth = reinterpret_cast<method_varargs_call_handler_t>( _handler );
|
||||
ext_meth_def.ml_flags = METH_VARARGS;
|
||||
ext_meth_def.ml_doc = const_cast<char *>( _doc );
|
||||
|
||||
ext_noargs_function = NULL;
|
||||
ext_varargs_function = _function;
|
||||
ext_keyword_function = NULL;
|
||||
}
|
||||
|
||||
// VARARGS + KEYWORD
|
||||
MethodDefExt
|
||||
(
|
||||
const char *_name,
|
||||
method_keyword_function_t _function,
|
||||
method_keyword_call_handler_t _handler,
|
||||
const char *_doc
|
||||
)
|
||||
{
|
||||
ext_meth_def.ml_name = const_cast<char *>( _name );
|
||||
ext_meth_def.ml_meth = reinterpret_cast<method_varargs_call_handler_t>(reinterpret_cast<void (*) (void)>(_handler));
|
||||
ext_meth_def.ml_flags = METH_VARARGS|METH_KEYWORDS;
|
||||
ext_meth_def.ml_doc = const_cast<char *>( _doc );
|
||||
|
||||
ext_noargs_function = NULL;
|
||||
ext_varargs_function = NULL;
|
||||
ext_keyword_function = _function;
|
||||
}
|
||||
|
||||
~MethodDefExt()
|
||||
{}
|
||||
|
||||
PyMethodDef ext_meth_def;
|
||||
method_noargs_function_t ext_noargs_function;
|
||||
method_varargs_function_t ext_varargs_function;
|
||||
method_keyword_function_t ext_keyword_function;
|
||||
Object py_method;
|
||||
};
|
||||
} // Namespace Py
|
||||
|
||||
#include "CXX/Python2/ExtensionModule.hxx"
|
||||
#include "CXX/Python2/PythonType.hxx"
|
||||
#include "CXX/Python2/ExtensionTypeBase.hxx"
|
||||
#include "CXX/Python2/ExtensionOldType.hxx"
|
||||
#include "CXX/Python2/ExtensionType.hxx"
|
||||
|
||||
// End of CXX_Extensions.h
|
||||
#endif
|
||||
199
src/3rdParty/PyCXX/CXX/Python2/IndirectPythonInterface.hxx
vendored
Normal file
199
src/3rdParty/PyCXX/CXX/Python2/IndirectPythonInterface.hxx
vendored
Normal file
@@ -0,0 +1,199 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef __CXX_INDIRECT_PYTHON_INTERFACE__HXX__
|
||||
#define __CXX_INDIRECT_PYTHON_INTERFACE__HXX__
|
||||
|
||||
#include "CXX/WrapPython.h"
|
||||
#include "CXX/Config.hxx"
|
||||
|
||||
namespace Py
|
||||
{
|
||||
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
|
||||
|
||||
PYCXX_EXPORT 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();
|
||||
#endif
|
||||
|
||||
//
|
||||
// Wrap Object variables as function calls
|
||||
//
|
||||
PYCXX_EXPORT PyObject * _None();
|
||||
|
||||
PYCXX_EXPORT PyObject * _False();
|
||||
PYCXX_EXPORT PyObject * _True();
|
||||
|
||||
//
|
||||
// Wrap Type variables as function calls
|
||||
//
|
||||
PYCXX_EXPORT PyTypeObject * _List_Type();
|
||||
PYCXX_EXPORT bool _List_Check( PyObject *o );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Buffer_Type();
|
||||
PYCXX_EXPORT bool _Buffer_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Class_Type();
|
||||
PYCXX_EXPORT bool _Class_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Instance_Type();
|
||||
PYCXX_EXPORT bool _Instance_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Method_Type();
|
||||
PYCXX_EXPORT bool _Method_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _CObject_Type();
|
||||
PYCXX_EXPORT bool _CObject_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Complex_Type();
|
||||
PYCXX_EXPORT bool _Complex_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Dict_Type();
|
||||
PYCXX_EXPORT bool _Dict_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _File_Type();
|
||||
PYCXX_EXPORT bool _File_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Float_Type();
|
||||
PYCXX_EXPORT bool _Float_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Frame_Type();
|
||||
PYCXX_EXPORT bool _Frame_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Function_Type();
|
||||
PYCXX_EXPORT bool _Function_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Bool_Type();
|
||||
PYCXX_EXPORT bool _Boolean_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Int_Type();
|
||||
PYCXX_EXPORT bool _Int_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _List_Type();
|
||||
PYCXX_EXPORT bool _List_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Long_Type();
|
||||
PYCXX_EXPORT bool _Long_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _CFunction_Type();
|
||||
PYCXX_EXPORT bool _CFunction_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Module_Type();
|
||||
PYCXX_EXPORT bool _Module_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Type_Type();
|
||||
PYCXX_EXPORT bool _Type_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Range_Type();
|
||||
PYCXX_EXPORT bool _Range_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Slice_Type();
|
||||
PYCXX_EXPORT bool _Slice_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _String_Type();
|
||||
PYCXX_EXPORT bool _String_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Unicode_Type();
|
||||
PYCXX_EXPORT bool _Unicode_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _TraceBack_Type();
|
||||
PYCXX_EXPORT bool _TraceBack_Check( PyObject *v );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Tuple_Type();
|
||||
PYCXX_EXPORT bool _Tuple_Check( PyObject *op );
|
||||
|
||||
#if PY_MAJOR_VERSION >= 2
|
||||
PYCXX_EXPORT PyTypeObject * _Unicode_Type();
|
||||
PYCXX_EXPORT 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();
|
||||
|
||||
#if PY_MAJOR_VERSION >= 2
|
||||
PYCXX_EXPORT int &_Py_UnicodeFlag();
|
||||
#endif
|
||||
|
||||
PYCXX_EXPORT void _XINCREF( PyObject *op );
|
||||
PYCXX_EXPORT void _XDECREF( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT const char *__Py_PackageContext();
|
||||
}
|
||||
|
||||
#endif // __CXX_INDIRECT_PYTHON_INTERFACE__HXX__
|
||||
3495
src/3rdParty/PyCXX/CXX/Python2/Objects.hxx
vendored
Normal file
3495
src/3rdParty/PyCXX/CXX/Python2/Objects.hxx
vendored
Normal file
File diff suppressed because it is too large
Load Diff
115
src/3rdParty/PyCXX/CXX/Python2/PythonType.hxx
vendored
Normal file
115
src/3rdParty/PyCXX/CXX/Python2/PythonType.hxx
vendored
Normal file
@@ -0,0 +1,115 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef __CXX_PythonType__h
|
||||
#define __CXX_PythonType__h
|
||||
|
||||
namespace Py
|
||||
{
|
||||
class PYCXX_EXPORT PythonType
|
||||
{
|
||||
public:
|
||||
// if you define one sequence method you must define
|
||||
// all of them except the assigns
|
||||
|
||||
PythonType( size_t base_size, int itemsize, const char *default_name );
|
||||
virtual ~PythonType();
|
||||
|
||||
const char *getName() const;
|
||||
const char *getDoc() const;
|
||||
|
||||
PyTypeObject *type_object() const;
|
||||
PythonType &name( const char *nam );
|
||||
PythonType &doc( const char *d );
|
||||
|
||||
PythonType &supportClass( void );
|
||||
PythonType &dealloc( void (*f)( PyObject* ) );
|
||||
#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 )
|
||||
PythonType &supportCompare( void );
|
||||
#endif
|
||||
PythonType &supportRichCompare( void );
|
||||
PythonType &supportRepr( void );
|
||||
PythonType &supportStr( void );
|
||||
PythonType &supportHash( void );
|
||||
PythonType &supportCall( void );
|
||||
PythonType &supportIter( void );
|
||||
|
||||
PythonType &supportSequenceType( void );
|
||||
PythonType &supportMappingType( void );
|
||||
PythonType &supportNumberType( void );
|
||||
PythonType &supportBufferType( void );
|
||||
|
||||
PythonType &set_tp_dealloc( void (*tp_dealloc)( PyObject * ) );
|
||||
PythonType &set_tp_init( int (*tp_init)( PyObject *self, PyObject *args, PyObject *kwds ) );
|
||||
PythonType &set_tp_new( PyObject *(*tp_new)( PyTypeObject *subtype, PyObject *args, PyObject *kwds ) );
|
||||
PythonType &set_methods( PyMethodDef *methods );
|
||||
|
||||
// call once all support functions have been called to ready the type
|
||||
bool readyType();
|
||||
|
||||
protected:
|
||||
void init_sequence();
|
||||
void init_mapping();
|
||||
void init_number();
|
||||
void init_buffer();
|
||||
|
||||
PyTypeObject *table;
|
||||
PySequenceMethods *sequence_table;
|
||||
PyMappingMethods *mapping_table;
|
||||
PyNumberMethods *number_table;
|
||||
PyBufferProcs *buffer_table;
|
||||
|
||||
private:
|
||||
//
|
||||
// prevent the compiler generating these unwanted functions
|
||||
//
|
||||
PythonType( const PythonType &tb ); // unimplemented
|
||||
void operator=( const PythonType &t ); // unimplemented
|
||||
|
||||
};
|
||||
|
||||
} // Namespace Py
|
||||
|
||||
// End of __CXX_PythonType__h
|
||||
#endif
|
||||
1904
src/3rdParty/PyCXX/CXX/Python2/cxx_extensions.cxx
vendored
Normal file
1904
src/3rdParty/PyCXX/CXX/Python2/cxx_extensions.cxx
vendored
Normal file
File diff suppressed because it is too large
Load Diff
49
src/3rdParty/PyCXX/CXX/Python2/cxxextensions.c
vendored
Normal file
49
src/3rdParty/PyCXX/CXX/Python2/cxxextensions.c
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
/*----------------------------------------------------------------------------
|
||||
//
|
||||
// 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/WrapPython.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
PyObject py_object_initializer = {PyObject_HEAD_INIT(0)};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
174
src/3rdParty/PyCXX/CXX/Python2/cxxsupport.cxx
vendored
Normal file
174
src/3rdParty/PyCXX/CXX/Python2/cxxsupport.cxx
vendored
Normal file
@@ -0,0 +1,174 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// 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/Objects.hxx"
|
||||
namespace Py {
|
||||
|
||||
Py_UNICODE unicode_null_string[1] = { 0 };
|
||||
|
||||
Type Object::type () const
|
||||
{
|
||||
return Type (PyObject_Type (p), true);
|
||||
}
|
||||
|
||||
String Object::str () const
|
||||
{
|
||||
return String (PyObject_Str (p), true);
|
||||
}
|
||||
|
||||
String Object::repr () const
|
||||
{
|
||||
return String (PyObject_Repr (p), true);
|
||||
}
|
||||
|
||||
std::string Object::as_string() const
|
||||
{
|
||||
return static_cast<std::string>(str());
|
||||
}
|
||||
|
||||
List Object::dir () const
|
||||
{
|
||||
return List (PyObject_Dir (p), true);
|
||||
}
|
||||
|
||||
bool Object::isType (const Type& t) const
|
||||
{
|
||||
return type ().ptr() == t.ptr();
|
||||
}
|
||||
|
||||
Char::operator String() const
|
||||
{
|
||||
return String(ptr());
|
||||
}
|
||||
|
||||
// TMM: non-member operaters for iterators - see above
|
||||
// I've also made a bug fix in respect to the cxx code
|
||||
// (dereffed the left.seq and right.seq comparison)
|
||||
bool operator==(const Sequence::iterator& left, const Sequence::iterator& right)
|
||||
{
|
||||
return left.eql( right );
|
||||
}
|
||||
|
||||
bool operator!=(const Sequence::iterator& left, const Sequence::iterator& right)
|
||||
{
|
||||
return left.neq( right );
|
||||
}
|
||||
|
||||
bool operator< (const Sequence::iterator& left, const Sequence::iterator& right)
|
||||
{
|
||||
return left.lss( right );
|
||||
}
|
||||
|
||||
bool operator> (const Sequence::iterator& left, const Sequence::iterator& right)
|
||||
{
|
||||
return left.gtr( right );
|
||||
}
|
||||
|
||||
bool operator<=(const Sequence::iterator& left, const Sequence::iterator& right)
|
||||
{
|
||||
return left.leq( right );
|
||||
}
|
||||
|
||||
bool operator>=(const Sequence::iterator& left, const Sequence::iterator& right)
|
||||
{
|
||||
return left.geq( right );
|
||||
}
|
||||
|
||||
// now for const_iterator
|
||||
bool operator==(const Sequence::const_iterator& left, const Sequence::const_iterator& right)
|
||||
{
|
||||
return left.eql( right );
|
||||
}
|
||||
|
||||
bool operator!=(const Sequence::const_iterator& left, const Sequence::const_iterator& right)
|
||||
{
|
||||
return left.neq( right );
|
||||
}
|
||||
|
||||
bool operator< (const Sequence::const_iterator& left, const Sequence::const_iterator& right)
|
||||
{
|
||||
return left.lss( right );
|
||||
}
|
||||
|
||||
bool operator> (const Sequence::const_iterator& left, const Sequence::const_iterator& right)
|
||||
{
|
||||
return left.gtr( right );
|
||||
}
|
||||
|
||||
bool operator<=(const Sequence::const_iterator& left, const Sequence::const_iterator& right)
|
||||
{
|
||||
return left.leq( right );
|
||||
}
|
||||
|
||||
bool operator>=(const Sequence::const_iterator& left, const Sequence::const_iterator& right)
|
||||
{
|
||||
return left.geq( right );
|
||||
}
|
||||
|
||||
// For mappings:
|
||||
bool operator==(const Mapping::iterator& left, const Mapping::iterator& right)
|
||||
{
|
||||
return left.eql( right );
|
||||
}
|
||||
|
||||
bool operator!=(const Mapping::iterator& left, const Mapping::iterator& right)
|
||||
{
|
||||
return left.neq( right );
|
||||
}
|
||||
|
||||
// now for const_iterator
|
||||
bool operator==(const Mapping::const_iterator& left, const Mapping::const_iterator& right)
|
||||
{
|
||||
return left.eql( right );
|
||||
}
|
||||
|
||||
bool operator!=(const Mapping::const_iterator& left, const Mapping::const_iterator& right)
|
||||
{
|
||||
return left.neq( right );
|
||||
}
|
||||
|
||||
// TMM: 31May'01 - Added the #ifndef so I can exclude iostreams.
|
||||
#ifndef CXX_NO_IOSTREAMS
|
||||
// output
|
||||
|
||||
std::ostream& operator<< (std::ostream& os, const Object& ob)
|
||||
{
|
||||
return (os << static_cast<std::string>(ob.str()));
|
||||
}
|
||||
#endif
|
||||
|
||||
} // Py
|
||||
140
src/3rdParty/PyCXX/CXX/Python3/Config.hxx
vendored
Normal file
140
src/3rdParty/PyCXX/CXX/Python3/Config.hxx
vendored
Normal file
@@ -0,0 +1,140 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef __PyCXX_config_hh__
|
||||
#define __PyCXX_config_hh__
|
||||
|
||||
#if defined( Py_LIMITED_API ) && Py_LIMITED_API+0 < 0x03040000
|
||||
#error "PyCXX support for Python limited API requires version 3.4 or newer. Py_LIMITED_API=0x03040000"
|
||||
#endif
|
||||
|
||||
//
|
||||
// Microsoft VC++ 6.0 has no traits
|
||||
//
|
||||
#if defined( _MSC_VER )
|
||||
|
||||
# define STANDARD_LIBRARY_HAS_ITERATOR_TRAITS 1
|
||||
|
||||
#elif defined( __GNUC__ )
|
||||
# if __GNUC__ >= 3
|
||||
# define STANDARD_LIBRARY_HAS_ITERATOR_TRAITS 1
|
||||
# else
|
||||
# define STANDARD_LIBRARY_HAS_ITERATOR_TRAITS 0
|
||||
#endif
|
||||
|
||||
//
|
||||
// Assume all other compilers do
|
||||
//
|
||||
#else
|
||||
|
||||
// Macros to deal with deficiencies in compilers
|
||||
# define STANDARD_LIBRARY_HAS_ITERATOR_TRAITS 1
|
||||
#endif
|
||||
|
||||
#if STANDARD_LIBRARY_HAS_ITERATOR_TRAITS
|
||||
# define random_access_iterator_parent(itemtype) std::iterator<std::random_access_iterator_tag,itemtype,int>
|
||||
#else
|
||||
# define random_access_iterator_parent(itemtype) std::random_access_iterator<itemtype, int>
|
||||
#endif
|
||||
|
||||
//
|
||||
// Which C++ standard is in use?
|
||||
//
|
||||
#if defined( _MSC_VER )
|
||||
# if _MSC_VER <= 1200
|
||||
// MSVC++ 6.0
|
||||
# define PYCXX_ISO_CPP_LIB 0
|
||||
# define STR_STREAM <strstream>
|
||||
# define TEMPLATE_TYPENAME class
|
||||
# else
|
||||
# define PYCXX_ISO_CPP_LIB 1
|
||||
# define STR_STREAM <sstream>
|
||||
# define TEMPLATE_TYPENAME typename
|
||||
# endif
|
||||
#elif defined( __GNUC__ )
|
||||
# if __GNUC__ >= 3
|
||||
# define PYCXX_ISO_CPP_LIB 1
|
||||
# define STR_STREAM <sstream>
|
||||
# define TEMPLATE_TYPENAME typename
|
||||
# else
|
||||
# define PYCXX_ISO_CPP_LIB 0
|
||||
# define STR_STREAM <strstream>
|
||||
# define TEMPLATE_TYPENAME class
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if PYCXX_ISO_CPP_LIB
|
||||
# define STR_STREAM <sstream>
|
||||
# define OSTRSTREAM ostringstream
|
||||
# define EXPLICIT_TYPENAME typename
|
||||
# define EXPLICIT_CLASS class
|
||||
# define TEMPLATE_TYPENAME typename
|
||||
#else
|
||||
# define STR_STREAM <strstream>
|
||||
# define OSTRSTREAM ostrstream
|
||||
# define EXPLICIT_TYPENAME
|
||||
# define EXPLICIT_CLASS
|
||||
# define TEMPLATE_TYPENAME class
|
||||
#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
|
||||
|
||||
// before 3.2 Py_hash_t was missing
|
||||
#ifndef PY_MAJOR_VERSION
|
||||
#error not defined PY_MAJOR_VERSION
|
||||
#endif
|
||||
#if PY_MINOR_VERSION < 2
|
||||
typedef long int Py_hash_t;
|
||||
#endif
|
||||
|
||||
#ifndef PYCXX_PYTHON_2TO3
|
||||
#define PYCXX_PYTHON_2TO3
|
||||
#endif
|
||||
|
||||
#endif // __PyCXX_config_hh__
|
||||
17
src/3rdParty/PyCXX/CXX/Python3/CxxDebug.hxx
vendored
Normal file
17
src/3rdParty/PyCXX/CXX/Python3/CxxDebug.hxx
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// CxxDebug.hxx
|
||||
//
|
||||
// Copyright (c) 2008 Barry A. Scott
|
||||
//
|
||||
#ifndef __CXX_Debug_hxx
|
||||
#define __CXX_Debug_hxx
|
||||
|
||||
//
|
||||
// Functions useful when debugging PyCXX
|
||||
//
|
||||
#ifdef PYCXX_DEBUG
|
||||
extern void bpt();
|
||||
extern void printRefCount( PyObject *obj );
|
||||
#endif
|
||||
|
||||
#endif
|
||||
173
src/3rdParty/PyCXX/CXX/Python3/Exception.hxx
vendored
Normal file
173
src/3rdParty/PyCXX/CXX/Python3/Exception.hxx
vendored
Normal file
@@ -0,0 +1,173 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef __CXX_Exception_h
|
||||
#define __CXX_Exception_h
|
||||
|
||||
#include "CXX/WrapPython.h"
|
||||
#include "CXX/Version.hxx"
|
||||
#include "CXX/Python3/Config.hxx"
|
||||
#include "CXX/Python3/CxxDebug.hxx"
|
||||
#include "CXX/Python3/IndirectPythonInterface.hxx"
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
// This mimics the Python structure, in order to minimize confusion
|
||||
namespace Py
|
||||
{
|
||||
class ExtensionExceptionType;
|
||||
|
||||
class Object;
|
||||
|
||||
class PYCXX_EXPORT BaseException
|
||||
{
|
||||
public:
|
||||
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();
|
||||
|
||||
void clear(); // clear the error
|
||||
|
||||
// is the exception this specific exception 'exc'
|
||||
bool matches( ExtensionExceptionType &exc );
|
||||
|
||||
Object errorType(); // get the error type of the active exception
|
||||
Object errorValue();// get the error value of the active exception
|
||||
};
|
||||
|
||||
// for user defined exceptions to be made know to pycxx
|
||||
typedef void (*throw_exception_func_t)( void );
|
||||
void addPythonException( ExtensionExceptionType &py_exc_type, throw_exception_func_t throw_func );
|
||||
|
||||
#if defined( PYCXX_6_2_COMPATIBILITY )
|
||||
class PYCXX_EXPORT Exception : public BaseException
|
||||
{
|
||||
public:
|
||||
Exception( ExtensionExceptionType &exception, const std::string &reason )
|
||||
: BaseException( exception, reason )
|
||||
{}
|
||||
|
||||
Exception( ExtensionExceptionType &exception, Object &reason )
|
||||
: BaseException( exception, reason )
|
||||
{}
|
||||
|
||||
Exception( PyObject *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 \
|
||||
{ \
|
||||
public: \
|
||||
eclass() {} \
|
||||
eclass( const char *reason ) { PyErr_SetString( _Exc_##eclass(), reason ); } \
|
||||
eclass( const std::string &reason ) { PyErr_SetString( _Exc_##eclass(), reason.c_str() ); } \
|
||||
~eclass() {} \
|
||||
\
|
||||
static void throwFunc() { throw eclass(); } \
|
||||
static PyObject *exceptionType() { return _Exc_##eclass(); } \
|
||||
}; \
|
||||
|
||||
#include <CXX/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
|
||||
206
src/3rdParty/PyCXX/CXX/Python3/ExtensionModule.hxx
vendored
Normal file
206
src/3rdParty/PyCXX/CXX/Python3/ExtensionModule.hxx
vendored
Normal file
@@ -0,0 +1,206 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef __CXX_ExtensionModule__h
|
||||
#define __CXX_ExtensionModule__h
|
||||
|
||||
namespace Py
|
||||
{
|
||||
class PYCXX_EXPORT ExtensionModuleBase
|
||||
{
|
||||
public:
|
||||
ExtensionModuleBase( const char *name );
|
||||
virtual ~ExtensionModuleBase();
|
||||
|
||||
Module module( void ) const; // only valid after initialize() has been called
|
||||
Dict moduleDictionary( void ) const; // only valid after initialize() has been called
|
||||
|
||||
virtual Object invoke_method_noargs( void *method_def ) = 0;
|
||||
virtual Object invoke_method_keyword( void *method_def, const Tuple &_args, const Dict &_keywords ) = 0;
|
||||
virtual Object invoke_method_varargs( void *method_def, const Tuple &_args ) = 0;
|
||||
|
||||
const std::string &name() const;
|
||||
const std::string &fullName() const;
|
||||
|
||||
// what is returned from PyInit_<module> function
|
||||
Object moduleObject( void ) const;
|
||||
|
||||
protected:
|
||||
// Initialize the module
|
||||
void initialize( const char *module_doc );
|
||||
|
||||
const std::string m_module_name;
|
||||
const std::string m_full_module_name;
|
||||
MethodTable m_method_table;
|
||||
PyModuleDef m_module_def;
|
||||
PyObject *m_module;
|
||||
|
||||
private:
|
||||
//
|
||||
// prevent the compiler generating these unwanted functions
|
||||
//
|
||||
ExtensionModuleBase( const ExtensionModuleBase & ); //unimplemented
|
||||
void operator=( const ExtensionModuleBase & ); //unimplemented
|
||||
};
|
||||
|
||||
// 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 );
|
||||
|
||||
template<TEMPLATE_TYPENAME T>
|
||||
class ExtensionModule : public ExtensionModuleBase
|
||||
{
|
||||
public:
|
||||
ExtensionModule( const char *name )
|
||||
: ExtensionModuleBase( name )
|
||||
{}
|
||||
virtual ~ExtensionModule()
|
||||
{}
|
||||
|
||||
protected:
|
||||
typedef Object (T::*method_noargs_function_t)();
|
||||
typedef Object (T::*method_varargs_function_t)( const Tuple &args );
|
||||
typedef Object (T::*method_keyword_function_t)( const Tuple &args, const Dict &kws );
|
||||
typedef std::map<std::string, MethodDefExt<T> *> method_map_t;
|
||||
|
||||
static void add_noargs_method( const char *name, method_noargs_function_t function, const char *doc="" )
|
||||
{
|
||||
method_map_t &mm = methods();
|
||||
mm[ std::string( name ) ] = new MethodDefExt<T>( name, function, method_noargs_call_handler, doc );
|
||||
}
|
||||
|
||||
static void add_varargs_method( const char *name, method_varargs_function_t function, const char *doc="" )
|
||||
{
|
||||
method_map_t &mm = methods();
|
||||
mm[ std::string( name ) ] = new MethodDefExt<T>( name, function, method_varargs_call_handler, doc );
|
||||
}
|
||||
|
||||
static void add_keyword_method( const char *name, method_keyword_function_t function, const char *doc="" )
|
||||
{
|
||||
method_map_t &mm = methods();
|
||||
mm[ std::string( name ) ] = new MethodDefExt<T>( name, function, method_keyword_call_handler, doc );
|
||||
}
|
||||
|
||||
void initialize( const char *module_doc="" )
|
||||
{
|
||||
ExtensionModuleBase::initialize( module_doc );
|
||||
Dict dict( moduleDictionary() );
|
||||
|
||||
//
|
||||
// put each of the methods into the modules dictionary
|
||||
// so that we get called back at the function in T.
|
||||
//
|
||||
method_map_t &mm = methods();
|
||||
EXPLICIT_TYPENAME method_map_t::const_iterator i = mm.begin();
|
||||
EXPLICIT_TYPENAME method_map_t::const_iterator i_end = mm.end();
|
||||
for ( ; i != i_end; ++i )
|
||||
{
|
||||
MethodDefExt<T> *method_def = (*i).second;
|
||||
|
||||
static PyObject *self = PyCapsule_New( this, NULL, NULL );
|
||||
|
||||
Tuple args( 2 );
|
||||
args[0] = Object( self, true );
|
||||
args[1] = Object( PyCapsule_New( method_def, NULL, NULL ), true );
|
||||
|
||||
assert( m_module != NULL );
|
||||
PyObject *func = PyCFunction_NewEx
|
||||
(
|
||||
&method_def->ext_meth_def,
|
||||
new_reference_to( args ),
|
||||
m_module
|
||||
);
|
||||
|
||||
method_def->py_method = Object( func, true );
|
||||
|
||||
dict[ (*i).first ] = method_def->py_method;
|
||||
}
|
||||
}
|
||||
|
||||
protected: // Tom Malcolmson reports that derived classes need access to these
|
||||
static method_map_t &methods( void )
|
||||
{
|
||||
static method_map_t *map_of_methods = NULL;
|
||||
if( map_of_methods == NULL )
|
||||
map_of_methods = new method_map_t;
|
||||
|
||||
return *map_of_methods;
|
||||
}
|
||||
|
||||
// this invoke function must be called from within a try catch block
|
||||
virtual Object invoke_method_noargs( void *method_def )
|
||||
{
|
||||
// cast up to the derived class, method_def and call
|
||||
T *self = static_cast<T *>( this );
|
||||
MethodDefExt<T> *meth_def = reinterpret_cast<MethodDefExt<T> *>( method_def );
|
||||
|
||||
return (self->*meth_def->ext_noargs_function)();
|
||||
}
|
||||
|
||||
// this invoke function must be called from within a try catch block
|
||||
virtual Object invoke_method_varargs( void *method_def, const Tuple &args )
|
||||
{
|
||||
// cast up to the derived class, method_def and call
|
||||
T *self = static_cast<T *>( this );
|
||||
MethodDefExt<T> *meth_def = reinterpret_cast<MethodDefExt<T> *>( method_def );
|
||||
|
||||
return (self->*meth_def->ext_varargs_function)( args );
|
||||
}
|
||||
|
||||
// this invoke function must be called from within a try catch block
|
||||
virtual Object invoke_method_keyword( void *method_def, const Tuple &args, const Dict &keywords )
|
||||
{
|
||||
// cast up to the derived class, method_def and call
|
||||
T *self = static_cast<T *>( this );
|
||||
MethodDefExt<T> *meth_def = reinterpret_cast<MethodDefExt<T> *>( method_def );
|
||||
|
||||
return (self->*meth_def->ext_keyword_function)( args, keywords );
|
||||
}
|
||||
|
||||
private:
|
||||
//
|
||||
// prevent the compiler generating these unwanted functions
|
||||
//
|
||||
ExtensionModule( const ExtensionModule<T> & ); //unimplemented
|
||||
void operator=( const ExtensionModule<T> & ); //unimplemented
|
||||
};
|
||||
} // Namespace Py
|
||||
|
||||
|
||||
// End of __CXX_ExtensionModule__h
|
||||
#endif
|
||||
414
src/3rdParty/PyCXX/CXX/Python3/ExtensionOldType.hxx
vendored
Normal file
414
src/3rdParty/PyCXX/CXX/Python3/ExtensionOldType.hxx
vendored
Normal file
@@ -0,0 +1,414 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef __CXX_ExtensionOldType__h
|
||||
#define __CXX_ExtensionOldType__h
|
||||
|
||||
namespace Py
|
||||
{
|
||||
template<TEMPLATE_TYPENAME T> class PythonExtension
|
||||
: public PythonExtensionBase
|
||||
{
|
||||
public:
|
||||
static PyTypeObject *type_object()
|
||||
{
|
||||
return behaviors().type_object();
|
||||
}
|
||||
|
||||
static bool check( PyObject *p )
|
||||
{
|
||||
// is p like me?
|
||||
return p->ob_type == type_object();
|
||||
}
|
||||
|
||||
static bool check( const Object &ob )
|
||||
{
|
||||
return check( ob.ptr() );
|
||||
}
|
||||
|
||||
//
|
||||
// every object needs getattr implemented
|
||||
// to support methods
|
||||
//
|
||||
virtual Object getattr( const char *name )
|
||||
{
|
||||
return getattr_methods( name );
|
||||
}
|
||||
|
||||
PyObject *selfPtr()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
Object self()
|
||||
{
|
||||
return asObject( this );
|
||||
}
|
||||
|
||||
protected:
|
||||
explicit PythonExtension()
|
||||
: PythonExtensionBase()
|
||||
{
|
||||
PyObject_Init( this, type_object() );
|
||||
|
||||
// every object must support getattr
|
||||
behaviors().supportGetattr();
|
||||
}
|
||||
|
||||
virtual ~PythonExtension()
|
||||
{}
|
||||
|
||||
static PythonType &behaviors()
|
||||
{
|
||||
static PythonType* p;
|
||||
if( p == NULL )
|
||||
{
|
||||
#if defined( _CPPRTTI ) || defined( __GNUG__ )
|
||||
const char *default_name =( typeid( T ) ).name();
|
||||
#else
|
||||
const char *default_name = "unknown";
|
||||
#endif
|
||||
p = new PythonType( sizeof( T ), 0, default_name );
|
||||
p->set_tp_dealloc( extension_object_deallocator );
|
||||
}
|
||||
|
||||
return *p;
|
||||
}
|
||||
|
||||
typedef Object (T::*method_noargs_function_t)();
|
||||
typedef Object (T::*method_varargs_function_t)( const Tuple &args );
|
||||
typedef Object (T::*method_keyword_function_t)( const Tuple &args, const Dict &kws );
|
||||
typedef std::map<std::string, MethodDefExt<T> *> method_map_t;
|
||||
|
||||
// support the default attributes, __name__, __doc__ and methods
|
||||
virtual Object getattr_default( const char *_name )
|
||||
{
|
||||
std::string name( _name );
|
||||
|
||||
#if !defined( Py_LIMITED_API )
|
||||
if( name == "__name__" && type_object()->tp_name != NULL )
|
||||
{
|
||||
return Py::String( type_object()->tp_name );
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined( Py_LIMITED_API )
|
||||
if( name == "__doc__" && type_object()->tp_doc != NULL )
|
||||
{
|
||||
return Py::String( type_object()->tp_doc );
|
||||
}
|
||||
#endif
|
||||
|
||||
// trying to fake out being a class for help()
|
||||
// else if( name == "__bases__" )
|
||||
// {
|
||||
// return Py::Tuple( 0 );
|
||||
// }
|
||||
// else if( name == "__module__" )
|
||||
// {
|
||||
// return Py::Nothing();
|
||||
// }
|
||||
// else if( name == "__dict__" )
|
||||
// {
|
||||
// return Py::Dict();
|
||||
// }
|
||||
|
||||
return getattr_methods( _name );
|
||||
}
|
||||
|
||||
// turn a name into function object
|
||||
virtual Object getattr_methods( const char *_name )
|
||||
{
|
||||
std::string name( _name );
|
||||
|
||||
method_map_t &mm = methods();
|
||||
|
||||
// see if name exists and get entry with method
|
||||
EXPLICIT_TYPENAME method_map_t::const_iterator i = mm.find( name );
|
||||
if( i == mm.end() )
|
||||
{
|
||||
if( name == "__dict__" ) // __methods__ is not supported in Py3 any more, use __dict__ instead
|
||||
{
|
||||
Dict methods;
|
||||
|
||||
i = mm.begin();
|
||||
EXPLICIT_TYPENAME method_map_t::const_iterator i_end = mm.end();
|
||||
|
||||
for( ; i != i_end; ++i )
|
||||
methods.setItem( String( (*i).first ), String( "" ) );
|
||||
|
||||
return methods;
|
||||
}
|
||||
if( name == "__methods__" )
|
||||
{
|
||||
List methods;
|
||||
|
||||
i = mm.begin();
|
||||
EXPLICIT_TYPENAME method_map_t::const_iterator i_end = mm.end();
|
||||
|
||||
for( ; i != i_end; ++i )
|
||||
methods.append( String( (*i).first ) );
|
||||
|
||||
return methods;
|
||||
}
|
||||
|
||||
throw AttributeError( name );
|
||||
}
|
||||
|
||||
MethodDefExt<T> *method_def = i->second;
|
||||
|
||||
Tuple self( 2 );
|
||||
|
||||
self[0] = Object( this );
|
||||
self[1] = Object( PyCapsule_New( method_def, NULL, NULL ), true );
|
||||
|
||||
PyObject *func = PyCFunction_NewEx( &method_def->ext_meth_def, self.ptr(), NULL );
|
||||
|
||||
return Object(func, true);
|
||||
}
|
||||
|
||||
// check that all methods added are unique
|
||||
static void check_unique_method_name( const char *name )
|
||||
{
|
||||
method_map_t &mm = methods();
|
||||
EXPLICIT_TYPENAME method_map_t::const_iterator i;
|
||||
i = mm.find( name );
|
||||
if( i != mm.end() )
|
||||
throw AttributeError( name );
|
||||
}
|
||||
|
||||
static void add_noargs_method( const char *name, method_noargs_function_t function, const char *doc="" )
|
||||
{
|
||||
check_unique_method_name( name );
|
||||
method_map_t &mm = methods();
|
||||
mm[ std::string( name ) ] = new MethodDefExt<T>( name, function, method_noargs_call_handler, doc );
|
||||
}
|
||||
|
||||
static void add_varargs_method( const char *name, method_varargs_function_t function, const char *doc="" )
|
||||
{
|
||||
check_unique_method_name( name );
|
||||
method_map_t &mm = methods();
|
||||
mm[ std::string( name ) ] = new MethodDefExt<T>( name, function, method_varargs_call_handler, doc );
|
||||
}
|
||||
|
||||
static void add_keyword_method( const char *name, method_keyword_function_t function, const char *doc="" )
|
||||
{
|
||||
check_unique_method_name( name );
|
||||
method_map_t &mm = methods();
|
||||
mm[ std::string( name ) ] = new MethodDefExt<T>( name, function, method_keyword_call_handler, doc );
|
||||
}
|
||||
|
||||
private:
|
||||
static method_map_t &methods( void )
|
||||
{
|
||||
static method_map_t *map_of_methods = NULL;
|
||||
if( map_of_methods == NULL )
|
||||
map_of_methods = new method_map_t;
|
||||
|
||||
return *map_of_methods;
|
||||
}
|
||||
|
||||
// Note: Python calls noargs as varargs buts args==NULL
|
||||
static 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();
|
||||
T *self = static_cast<T *>( self_in_cobject );
|
||||
|
||||
MethodDefExt<T> *meth_def = reinterpret_cast<MethodDefExt<T> *>(
|
||||
PyCapsule_GetPointer( self_and_name_tuple[1].ptr(), NULL ) );
|
||||
|
||||
Object result;
|
||||
|
||||
// Adding try & catch in case of STL debug-mode exceptions.
|
||||
#ifdef _STLP_DEBUG
|
||||
try
|
||||
{
|
||||
result = (self->*meth_def->ext_noargs_function)();
|
||||
}
|
||||
catch( std::__stl_debug_exception )
|
||||
{
|
||||
// throw cxx::RuntimeError( sErrMsg );
|
||||
throw RuntimeError( "Error message not set yet." );
|
||||
}
|
||||
#else
|
||||
result = (self->*meth_def->ext_noargs_function)();
|
||||
#endif // _STLP_DEBUG
|
||||
|
||||
return new_reference_to( result.ptr() );
|
||||
}
|
||||
catch( BaseException & )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static PyObject *method_varargs_call_handler( PyObject *_self_and_name_tuple, PyObject *_args )
|
||||
{
|
||||
try
|
||||
{
|
||||
Tuple self_and_name_tuple( _self_and_name_tuple );
|
||||
|
||||
PyObject *self_in_cobject = self_and_name_tuple[0].ptr();
|
||||
T *self = static_cast<T *>( self_in_cobject );
|
||||
MethodDefExt<T> *meth_def = reinterpret_cast<MethodDefExt<T> *>(
|
||||
PyCapsule_GetPointer( self_and_name_tuple[1].ptr(), NULL ) );
|
||||
|
||||
Tuple args( _args );
|
||||
|
||||
Object result;
|
||||
|
||||
// Adding try & catch in case of STL debug-mode exceptions.
|
||||
#ifdef _STLP_DEBUG
|
||||
try
|
||||
{
|
||||
result = (self->*meth_def->ext_varargs_function)( args );
|
||||
}
|
||||
catch( std::__stl_debug_exception )
|
||||
{
|
||||
throw RuntimeError( "Error message not set yet." );
|
||||
}
|
||||
#else
|
||||
result = (self->*meth_def->ext_varargs_function)( args );
|
||||
#endif // _STLP_DEBUG
|
||||
|
||||
return new_reference_to( result.ptr() );
|
||||
}
|
||||
catch( BaseException & )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static PyObject *method_keyword_call_handler( PyObject *_self_and_name_tuple, PyObject *_args, PyObject *_keywords )
|
||||
{
|
||||
try
|
||||
{
|
||||
Tuple self_and_name_tuple( _self_and_name_tuple );
|
||||
|
||||
PyObject *self_in_cobject = self_and_name_tuple[0].ptr();
|
||||
T *self = static_cast<T *>( self_in_cobject );
|
||||
MethodDefExt<T> *meth_def = reinterpret_cast<MethodDefExt<T> *>(
|
||||
PyCapsule_GetPointer( self_and_name_tuple[1].ptr(), NULL ) );
|
||||
|
||||
Tuple args( _args );
|
||||
|
||||
// _keywords may be NULL so be careful about the way the dict is created
|
||||
Dict keywords;
|
||||
if( _keywords != NULL )
|
||||
keywords = Dict( _keywords );
|
||||
|
||||
Object result( ( self->*meth_def->ext_keyword_function )( args, keywords ) );
|
||||
|
||||
return new_reference_to( result.ptr() );
|
||||
}
|
||||
catch( BaseException & )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void extension_object_deallocator( PyObject* t )
|
||||
{
|
||||
delete (T *)( t );
|
||||
}
|
||||
|
||||
//
|
||||
// prevent the compiler generating these unwanted functions
|
||||
//
|
||||
explicit PythonExtension( const PythonExtension<T> &other );
|
||||
void operator=( const PythonExtension<T> &rhs );
|
||||
};
|
||||
|
||||
//
|
||||
// ExtensionObject<T> is an Object that will accept only T's.
|
||||
//
|
||||
template<TEMPLATE_TYPENAME T>
|
||||
class ExtensionObject: public Object
|
||||
{
|
||||
public:
|
||||
|
||||
explicit ExtensionObject( PyObject *pyob )
|
||||
: Object( pyob )
|
||||
{
|
||||
validate();
|
||||
}
|
||||
|
||||
ExtensionObject( const ExtensionObject<T> &other )
|
||||
: Object( *other )
|
||||
{
|
||||
validate();
|
||||
}
|
||||
|
||||
ExtensionObject( const Object &other )
|
||||
: Object( *other )
|
||||
{
|
||||
validate();
|
||||
}
|
||||
|
||||
ExtensionObject &operator=( const Object &rhs )
|
||||
{
|
||||
return( *this = *rhs );
|
||||
}
|
||||
|
||||
ExtensionObject &operator=( PyObject *rhsp )
|
||||
{
|
||||
if( ptr() != rhsp )
|
||||
set( rhsp );
|
||||
return *this;
|
||||
}
|
||||
|
||||
virtual bool accepts( PyObject *pyob ) const
|
||||
{
|
||||
return( pyob && T::check( pyob ) );
|
||||
}
|
||||
|
||||
//
|
||||
// Obtain a pointer to the PythonExtension object
|
||||
//
|
||||
T *extensionObject( void )
|
||||
{
|
||||
return static_cast<T *>( ptr() );
|
||||
}
|
||||
};
|
||||
} // Namespace Py
|
||||
|
||||
// End of __CXX_ExtensionOldType__h
|
||||
#endif
|
||||
428
src/3rdParty/PyCXX/CXX/Python3/ExtensionType.hxx
vendored
Normal file
428
src/3rdParty/PyCXX/CXX/Python3/ExtensionType.hxx
vendored
Normal file
@@ -0,0 +1,428 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef __CXX_ExtensionClass__h
|
||||
#define __CXX_ExtensionClass__h
|
||||
|
||||
#define PYCXX_NOARGS_METHOD_NAME( NAME ) _callNoArgsMethod__##NAME
|
||||
#define PYCXX_VARARGS_METHOD_NAME( NAME ) _callVarArgsMethod__##NAME
|
||||
#define PYCXX_KEYWORDS_METHOD_NAME( NAME ) _callKeywordsMethod__##NAME
|
||||
|
||||
#define PYCXX_NOARGS_METHOD_DECL( CLS, NAME ) \
|
||||
static PyObject *PYCXX_NOARGS_METHOD_NAME( NAME )( PyObject *_self, PyObject *, PyObject * ) \
|
||||
{ \
|
||||
try \
|
||||
{ \
|
||||
Py::PythonClassInstance *self_python = reinterpret_cast< Py::PythonClassInstance * >( _self ); \
|
||||
CLS *self = reinterpret_cast< CLS * >( self_python->m_pycxx_object ); \
|
||||
Py::Object r( (self->NAME)() ); \
|
||||
return Py::new_reference_to( r.ptr() ); \
|
||||
} \
|
||||
catch( Py::BaseException & ) \
|
||||
{ \
|
||||
return 0; \
|
||||
} \
|
||||
}
|
||||
#define PYCXX_VARARGS_METHOD_DECL( CLS, NAME ) \
|
||||
static PyObject *PYCXX_VARARGS_METHOD_NAME( NAME )( PyObject *_self, PyObject *_a, PyObject * ) \
|
||||
{ \
|
||||
try \
|
||||
{ \
|
||||
Py::PythonClassInstance *self_python = reinterpret_cast< Py::PythonClassInstance * >( _self ); \
|
||||
CLS *self = reinterpret_cast< CLS * >( self_python->m_pycxx_object ); \
|
||||
Py::Tuple a( _a ); \
|
||||
Py::Object r( (self->NAME)( a ) ); \
|
||||
return Py::new_reference_to( r.ptr() ); \
|
||||
} \
|
||||
catch( Py::BaseException & ) \
|
||||
{ \
|
||||
return 0; \
|
||||
} \
|
||||
}
|
||||
#define PYCXX_KEYWORDS_METHOD_DECL( CLS, NAME ) \
|
||||
static PyObject *PYCXX_KEYWORDS_METHOD_NAME( NAME )( PyObject *_self, PyObject *_a, PyObject *_k ) \
|
||||
{ \
|
||||
try \
|
||||
{ \
|
||||
Py::PythonClassInstance *self_python = reinterpret_cast< Py::PythonClassInstance * >( _self ); \
|
||||
CLS *self = reinterpret_cast< CLS * >( self_python->m_pycxx_object ); \
|
||||
Py::Tuple a( _a ); \
|
||||
Py::Dict k; \
|
||||
if( _k != NULL ) \
|
||||
k = _k; \
|
||||
Py::Object r( (self->NAME)( a, k ) ); \
|
||||
return Py::new_reference_to( r.ptr() ); \
|
||||
} \
|
||||
catch( Py::BaseException & ) \
|
||||
{ \
|
||||
return 0; \
|
||||
} \
|
||||
}
|
||||
|
||||
// need to support METH_STATIC and METH_CLASS
|
||||
|
||||
#define PYCXX_ADD_NOARGS_METHOD( PYNAME, NAME, docs ) \
|
||||
add_method( #PYNAME, (PyCFunction)(void (*) (void))PYCXX_NOARGS_METHOD_NAME( NAME ), METH_NOARGS, docs )
|
||||
#define PYCXX_ADD_VARARGS_METHOD( PYNAME, NAME, docs ) \
|
||||
add_method( #PYNAME, (PyCFunction)(void (*) (void))PYCXX_VARARGS_METHOD_NAME( NAME ), METH_VARARGS, docs )
|
||||
#define PYCXX_ADD_KEYWORDS_METHOD( PYNAME, NAME, docs ) \
|
||||
add_method( #PYNAME, (PyCFunction)(void (*) (void))PYCXX_KEYWORDS_METHOD_NAME( NAME ), METH_VARARGS | METH_KEYWORDS, docs )
|
||||
|
||||
namespace Py
|
||||
{
|
||||
PYCXX_EXPORT extern PythonExtensionBase *getPythonExtensionBase( PyObject *self );
|
||||
struct PythonClassInstance
|
||||
{
|
||||
PyObject_HEAD
|
||||
PythonExtensionBase *m_pycxx_object;
|
||||
};
|
||||
|
||||
class PYCXX_EXPORT ExtensionClassMethodsTable
|
||||
{
|
||||
public:
|
||||
ExtensionClassMethodsTable()
|
||||
: m_methods_table( new PyMethodDef[ METHOD_TABLE_SIZE_INCREMENT ] )
|
||||
, m_methods_used( 0 )
|
||||
, m_methods_size( METHOD_TABLE_SIZE_INCREMENT )
|
||||
{
|
||||
// add the sentinel marking the table end
|
||||
PyMethodDef *p = &m_methods_table[ 0 ];
|
||||
|
||||
p->ml_name = NULL;
|
||||
p->ml_meth = NULL;
|
||||
p->ml_flags = 0;
|
||||
p->ml_doc = NULL;
|
||||
}
|
||||
|
||||
~ExtensionClassMethodsTable()
|
||||
{
|
||||
delete[] m_methods_table;
|
||||
}
|
||||
|
||||
// check that all methods added are unique
|
||||
void check_unique_method_name( const char *_name )
|
||||
{
|
||||
std::string name( _name );
|
||||
for( int i=0; i<m_methods_used; i++ )
|
||||
{
|
||||
if( name == m_methods_table[i].ml_name )
|
||||
{
|
||||
throw AttributeError( name );
|
||||
}
|
||||
}
|
||||
}
|
||||
PyMethodDef *add_method( const char *name, PyCFunction function, int flags, const char *doc )
|
||||
{
|
||||
check_unique_method_name( name );
|
||||
|
||||
// see if there is enough space for one more method
|
||||
if( m_methods_used == (m_methods_size-1) )
|
||||
{
|
||||
PyMethodDef *old_mt = m_methods_table;
|
||||
m_methods_size += METHOD_TABLE_SIZE_INCREMENT;
|
||||
PyMethodDef *new_mt = new PyMethodDef[ m_methods_size ];
|
||||
for( int i=0; i<m_methods_used; i++ )
|
||||
{
|
||||
new_mt[ i ] = old_mt[ i ];
|
||||
}
|
||||
delete[] old_mt;
|
||||
m_methods_table = new_mt;
|
||||
}
|
||||
|
||||
// add method into the table
|
||||
PyMethodDef *p = &m_methods_table[ m_methods_used ];
|
||||
p->ml_name = name;
|
||||
p->ml_meth = function;
|
||||
p->ml_flags = flags;
|
||||
p->ml_doc = doc;
|
||||
|
||||
m_methods_used++;
|
||||
p++;
|
||||
|
||||
// add the sentinel marking the table end
|
||||
p->ml_name = NULL;
|
||||
p->ml_meth = NULL;
|
||||
p->ml_flags = 0;
|
||||
p->ml_doc = NULL;
|
||||
|
||||
return m_methods_table;
|
||||
}
|
||||
|
||||
private:
|
||||
enum {METHOD_TABLE_SIZE_INCREMENT = 1};
|
||||
PyMethodDef *m_methods_table;
|
||||
int m_methods_used;
|
||||
int m_methods_size;
|
||||
};
|
||||
|
||||
template<TEMPLATE_TYPENAME T> class PythonClass
|
||||
: public PythonExtensionBase
|
||||
{
|
||||
protected:
|
||||
explicit PythonClass( PythonClassInstance *self, Tuple &/*args*/, Dict &/*kwds*/ )
|
||||
: PythonExtensionBase()
|
||||
, m_class_instance( self )
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~PythonClass()
|
||||
{}
|
||||
|
||||
static ExtensionClassMethodsTable &methodTable()
|
||||
{
|
||||
static ExtensionClassMethodsTable *method_table;
|
||||
if( method_table == NULL )
|
||||
method_table = new ExtensionClassMethodsTable;
|
||||
return *method_table;
|
||||
}
|
||||
|
||||
static void add_method( const char *name, PyCFunction function, int flags, const char *doc=NULL )
|
||||
{
|
||||
behaviors().set_methods( methodTable().add_method( name, function, flags, doc ) );
|
||||
}
|
||||
|
||||
static PythonType &behaviors()
|
||||
{
|
||||
static PythonType *p;
|
||||
if( p == NULL )
|
||||
{
|
||||
#if defined( _CPPRTTI ) || defined( __GNUG__ )
|
||||
const char *default_name = (typeid( T )).name();
|
||||
#else
|
||||
const char *default_name = "unknown";
|
||||
#endif
|
||||
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 );
|
||||
|
||||
// we are a class
|
||||
p->supportClass();
|
||||
|
||||
// always support get and set attr
|
||||
p->supportGetattro();
|
||||
p->supportSetattro();
|
||||
}
|
||||
|
||||
return *p;
|
||||
}
|
||||
|
||||
static PyObject *extension_object_new( PyTypeObject *subtype, PyObject * /*args*/, PyObject * /*kwds*/ )
|
||||
{
|
||||
#ifdef PYCXX_DEBUG
|
||||
std::cout << "extension_object_new()" << std::endl;
|
||||
#endif
|
||||
#if defined( Py_LIMITED_API )
|
||||
PyObject *object = reinterpret_cast<allocfunc>( PyType_GetSlot( subtype, Py_tp_alloc ) )( subtype, 0 );
|
||||
#else
|
||||
PyObject *object = subtype->tp_alloc( subtype, 0 );
|
||||
#endif
|
||||
if( object == NULL )
|
||||
return NULL;
|
||||
|
||||
PythonClassInstance *o = reinterpret_cast<PythonClassInstance *>( object );
|
||||
o->m_pycxx_object = NULL;
|
||||
|
||||
PyObject *self = reinterpret_cast<PyObject *>( o );
|
||||
#ifdef PYCXX_DEBUG
|
||||
std::cout << "extension_object_new() => self=0x" << std::hex << reinterpret_cast< unsigned long >( self ) << std::dec << std::endl;
|
||||
#endif
|
||||
return self;
|
||||
}
|
||||
|
||||
static int extension_object_init( PyObject *_self, PyObject *args_, PyObject *kwds_ )
|
||||
{
|
||||
try
|
||||
{
|
||||
Py::Tuple args( args_ );
|
||||
Py::Dict kwds;
|
||||
if( kwds_ != NULL )
|
||||
kwds = kwds_;
|
||||
|
||||
PythonClassInstance *self = reinterpret_cast<PythonClassInstance *>( _self );
|
||||
#ifdef PYCXX_DEBUG
|
||||
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 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 long >( self->m_pycxx_object ) << std::dec << std::endl;
|
||||
#endif
|
||||
self->m_pycxx_object->reinit( args, kwds );
|
||||
}
|
||||
}
|
||||
catch( BaseException & )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void extension_object_deallocator( PyObject *_self )
|
||||
{
|
||||
PythonClassInstance *self = reinterpret_cast< PythonClassInstance * >( _self );
|
||||
#ifdef PYCXX_DEBUG
|
||||
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;
|
||||
#ifdef Py_LIMITED_API
|
||||
freefunc fn = reinterpret_cast<freefunc>( PyType_GetSlot( _self->ob_type, Py_tp_free ) );
|
||||
fn( _self );
|
||||
#else
|
||||
_self->ob_type->tp_free( _self );
|
||||
#endif
|
||||
}
|
||||
|
||||
public:
|
||||
static PyTypeObject *type_object()
|
||||
{
|
||||
return behaviors().type_object();
|
||||
}
|
||||
|
||||
static Object type()
|
||||
{
|
||||
return Object( reinterpret_cast<PyObject *>( behaviors().type_object() ) );
|
||||
}
|
||||
|
||||
static bool check( PyObject *p )
|
||||
{
|
||||
// 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 )
|
||||
{
|
||||
return check( ob.ptr() );
|
||||
}
|
||||
|
||||
virtual PyObject *selfPtr()
|
||||
{
|
||||
return reinterpret_cast<PyObject *>( m_class_instance );
|
||||
}
|
||||
|
||||
virtual Object self()
|
||||
{
|
||||
return Object( reinterpret_cast<PyObject *>( m_class_instance ) );
|
||||
}
|
||||
|
||||
protected:
|
||||
private:
|
||||
PythonClassInstance *m_class_instance;
|
||||
|
||||
private:
|
||||
//
|
||||
// prevent the compiler generating these unwanted functions
|
||||
//
|
||||
explicit PythonClass( const PythonClass<T> &other );
|
||||
void operator=( const PythonClass<T> &rhs );
|
||||
};
|
||||
|
||||
//
|
||||
// ExtensionObject<T> is an Object that will accept only T's.
|
||||
//
|
||||
template<TEMPLATE_TYPENAME T>
|
||||
class PythonClassObject: public Object
|
||||
{
|
||||
public:
|
||||
|
||||
explicit PythonClassObject( PyObject *pyob )
|
||||
: Object( pyob )
|
||||
{
|
||||
validate();
|
||||
}
|
||||
|
||||
PythonClassObject( const PythonClassObject<T> &other )
|
||||
: Object( *other )
|
||||
{
|
||||
validate();
|
||||
}
|
||||
|
||||
PythonClassObject( const Object &other )
|
||||
: Object( *other )
|
||||
{
|
||||
validate();
|
||||
}
|
||||
|
||||
PythonClassObject &operator=( const Object &rhs )
|
||||
{
|
||||
*this = *rhs;
|
||||
return *this;
|
||||
}
|
||||
|
||||
PythonClassObject &operator=( PyObject *rhsp )
|
||||
{
|
||||
if( ptr() != rhsp )
|
||||
set( rhsp );
|
||||
return *this;
|
||||
}
|
||||
|
||||
virtual bool accepts( PyObject *pyob ) const
|
||||
{
|
||||
return( pyob && T::check( pyob ) );
|
||||
}
|
||||
|
||||
//
|
||||
// Obtain a pointer to the PythonExtension object
|
||||
//
|
||||
T *getCxxObject( void )
|
||||
{
|
||||
return dynamic_cast< T * >( getPythonExtensionBase( ptr() ) );
|
||||
}
|
||||
};
|
||||
} // Namespace Py
|
||||
|
||||
// End of __CXX_ExtensionClass__h
|
||||
#endif
|
||||
200
src/3rdParty/PyCXX/CXX/Python3/ExtensionTypeBase.hxx
vendored
Normal file
200
src/3rdParty/PyCXX/CXX/Python3/ExtensionTypeBase.hxx
vendored
Normal file
@@ -0,0 +1,200 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef __CXX_ExtensionTypeBase__h
|
||||
#define __CXX_ExtensionTypeBase__h
|
||||
|
||||
namespace Py
|
||||
{
|
||||
// Class PythonExtension is what you inherit from to create
|
||||
// a new Python extension type. You give your class itself
|
||||
// as the template parameter.
|
||||
|
||||
// There are two ways that extension objects can get destroyed.
|
||||
// 1. Their reference count goes to zero
|
||||
// 2. Someone does an explicit delete on a pointer.
|
||||
// In(1) the problem is to get the destructor called
|
||||
// We register a special deallocator in the Python type object
|
||||
// (see behaviors()) to do this.
|
||||
// In(2) there is no problem, the dtor gets called.
|
||||
|
||||
// PythonExtension does not use the usual Python heap allocator,
|
||||
// instead using new/delete. We do the setting of the type object
|
||||
// and reference count, usually done by PyObject_New, in the
|
||||
// base class ctor.
|
||||
|
||||
// This special deallocator does a delete on the pointer.
|
||||
|
||||
class PYCXX_EXPORT PythonExtensionBase : public PyObject
|
||||
{
|
||||
public:
|
||||
PythonExtensionBase();
|
||||
virtual ~PythonExtensionBase();
|
||||
|
||||
public:
|
||||
// object
|
||||
virtual void reinit( Tuple &args, Dict &kwds );
|
||||
|
||||
// object basics
|
||||
#if defined( PYCXX_PYTHON_2TO3 ) && !defined( Py_LIMITED_API ) && PY_MINOR_VERSION <= 7
|
||||
virtual int print( FILE *, int );
|
||||
#endif
|
||||
virtual Object getattr( const char * );
|
||||
virtual int setattr( const char *, const Object & );
|
||||
virtual Object getattro( const String & );
|
||||
Object genericGetAttro( const String & );
|
||||
virtual int setattro( const String &, const Object & );
|
||||
int genericSetAttro( const String &, const Object & );
|
||||
virtual int compare( const Object & );
|
||||
virtual Object rich_compare( const Object &, int );
|
||||
virtual Object repr();
|
||||
virtual Object str();
|
||||
virtual long hash();
|
||||
virtual Object call( const Object &, const Object & );
|
||||
virtual Object iter();
|
||||
virtual PyObject *iternext();
|
||||
|
||||
// Sequence methods
|
||||
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 PyCxx_ssize_t mapping_length();
|
||||
virtual Object mapping_subscript( const Object & );
|
||||
|
||||
virtual int mapping_ass_subscript( const Object &, const Object & );
|
||||
|
||||
// Number
|
||||
virtual Object number_negative();
|
||||
virtual Object number_positive();
|
||||
virtual Object number_absolute();
|
||||
virtual Object number_invert();
|
||||
virtual Object number_int();
|
||||
virtual Object number_float();
|
||||
virtual Object number_add( const Object & );
|
||||
virtual Object number_subtract( const Object & );
|
||||
virtual Object number_multiply( const Object & );
|
||||
virtual Object number_remainder( const Object & );
|
||||
virtual Object number_divmod( const Object & );
|
||||
virtual Object number_lshift( const Object & );
|
||||
virtual Object number_rshift( const Object & );
|
||||
virtual Object number_and( const Object & );
|
||||
virtual Object number_xor( const Object & );
|
||||
virtual Object number_or( const Object & );
|
||||
virtual Object number_power( const Object &, const Object & );
|
||||
virtual Object number_floor_divide( const Object & );
|
||||
virtual Object number_true_divide( const Object & );
|
||||
virtual Object number_index();
|
||||
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 5
|
||||
virtual Object number_matrix_multiply( const Object & );
|
||||
#endif
|
||||
|
||||
virtual Object number_inplace_add( const Object & );
|
||||
virtual Object number_inplace_subtract( const Object & );
|
||||
virtual Object number_inplace_multiply( const Object & );
|
||||
virtual Object number_inplace_remainder( const Object & );
|
||||
virtual Object number_inplace_power( const Object &, const Object & );
|
||||
virtual Object number_inplace_lshift( const Object & );
|
||||
virtual Object number_inplace_rshift( const Object & );
|
||||
virtual Object number_inplace_and( const Object & );
|
||||
virtual Object number_inplace_xor( const Object & );
|
||||
virtual Object number_inplace_or( const Object & );
|
||||
virtual Object number_inplace_floor_divide( const Object & );
|
||||
virtual Object number_inplace_true_divide( const Object & );
|
||||
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 5
|
||||
virtual Object number_inplace_matrix_multiply( const Object & );
|
||||
#endif
|
||||
|
||||
#if !defined( Py_LIMITED_API )
|
||||
// Buffer
|
||||
virtual int buffer_get( Py_buffer *, int flags );
|
||||
virtual int buffer_release( Py_buffer *buf );
|
||||
#endif
|
||||
|
||||
public:
|
||||
// helper functions to call function fn_name with 0 to 9 args
|
||||
Object callOnSelf( const std::string &fn_name );
|
||||
Object callOnSelf( const std::string &fn_name,
|
||||
const Object &arg1 );
|
||||
Object callOnSelf( const std::string &fn_name,
|
||||
const Object &arg1, const Object &arg2 );
|
||||
Object callOnSelf( const std::string &fn_name,
|
||||
const Object &arg1, const Object &arg2, const Object &arg3 );
|
||||
Object callOnSelf( const std::string &fn_name,
|
||||
const Object &arg1, const Object &arg2, const Object &arg3,
|
||||
const Object &arg4 );
|
||||
Object callOnSelf( const std::string &fn_name,
|
||||
const Object &arg1, const Object &arg2, const Object &arg3,
|
||||
const Object &arg4, const Object &arg5 );
|
||||
Object callOnSelf( const std::string &fn_name,
|
||||
const Object &arg1, const Object &arg2, const Object &arg3,
|
||||
const Object &arg4, const Object &arg5, const Object &arg6 );
|
||||
Object callOnSelf( const std::string &fn_name,
|
||||
const Object &arg1, const Object &arg2, const Object &arg3,
|
||||
const Object &arg4, const Object &arg5, const Object &arg6,
|
||||
const Object &arg7 );
|
||||
Object callOnSelf( const std::string &fn_name,
|
||||
const Object &arg1, const Object &arg2, const Object &arg3,
|
||||
const Object &arg4, const Object &arg5, const Object &arg6,
|
||||
const Object &arg7, const Object &arg8 );
|
||||
Object callOnSelf( const std::string &fn_name,
|
||||
const Object &arg1, const Object &arg2, const Object &arg3,
|
||||
const Object &arg4, const Object &arg5, const Object &arg6,
|
||||
const Object &arg7, const Object &arg8, const Object &arg9 );
|
||||
|
||||
public:
|
||||
virtual PyObject *selfPtr() = 0;
|
||||
virtual Object self() = 0;
|
||||
|
||||
private:
|
||||
void missing_method( void );
|
||||
static PyObject *method_call_handler( PyObject *self, PyObject *args );
|
||||
};
|
||||
|
||||
} // Namespace Py
|
||||
|
||||
// End of __CXX_ExtensionTypeBase__h
|
||||
#endif
|
||||
189
src/3rdParty/PyCXX/CXX/Python3/Extensions.hxx
vendored
Normal file
189
src/3rdParty/PyCXX/CXX/Python3/Extensions.hxx
vendored
Normal file
@@ -0,0 +1,189 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef __CXX_Extensions__h
|
||||
#define __CXX_Extensions__h
|
||||
|
||||
|
||||
#ifdef _MSC_VER
|
||||
// disable warning C4786: symbol greater than 255 character,
|
||||
// okay to ignore
|
||||
#pragma warning( disable: 4786 )
|
||||
#endif
|
||||
|
||||
#include "CXX/WrapPython.h"
|
||||
#include "CXX/Version.hxx"
|
||||
#include "CXX/Python3/Config.hxx"
|
||||
#include "CXX/Python3/CxxDebug.hxx"
|
||||
#include "CXX/Python3/Objects.hxx"
|
||||
|
||||
extern "C" { extern PyObject py_object_initializer; }
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
namespace Py
|
||||
{
|
||||
class ExtensionModuleBase;
|
||||
|
||||
// Make an Exception Type for use in raising custom exceptions
|
||||
class PYCXX_EXPORT ExtensionExceptionType : public Object
|
||||
{
|
||||
public:
|
||||
ExtensionExceptionType();
|
||||
virtual ~ExtensionExceptionType();
|
||||
|
||||
// call init to create the type
|
||||
void init( ExtensionModuleBase &module, const std::string &name, ExtensionExceptionType &parent );
|
||||
void init( ExtensionModuleBase &module, const std::string &name );
|
||||
};
|
||||
|
||||
class PYCXX_EXPORT MethodTable
|
||||
{
|
||||
public:
|
||||
MethodTable();
|
||||
virtual ~MethodTable();
|
||||
|
||||
void add( const char *method_name, PyCFunction f, const char *doc="", int flag=1 );
|
||||
PyMethodDef *table();
|
||||
|
||||
protected:
|
||||
std::vector<PyMethodDef> t; // accumulator of PyMethodDef's
|
||||
PyMethodDef *mt; // Actual method table produced when full
|
||||
|
||||
static PyMethodDef method( const char* method_name, PyCFunction f, int flags=1, const char* doc="" );
|
||||
|
||||
private:
|
||||
//
|
||||
// prevent the compiler generating these unwanted functions
|
||||
//
|
||||
MethodTable( const MethodTable &m ); //unimplemented
|
||||
void operator=( const MethodTable &m ); //unimplemented
|
||||
|
||||
}; // end class MethodTable
|
||||
|
||||
// Note: Python calls noargs as varargs buts args==NULL
|
||||
extern "C" typedef PyObject *(*method_noargs_call_handler_t)( PyObject *_self, PyObject * );
|
||||
extern "C" typedef PyObject *(*method_varargs_call_handler_t)( PyObject *_self, PyObject *_args );
|
||||
extern "C" typedef PyObject *(*method_keyword_call_handler_t)( PyObject *_self, PyObject *_args, PyObject *_dict );
|
||||
|
||||
template<class T>
|
||||
class MethodDefExt
|
||||
{
|
||||
public:
|
||||
typedef Object (T::*method_noargs_function_t)();
|
||||
typedef Object (T::*method_varargs_function_t)( const Tuple &args );
|
||||
typedef Object (T::*method_keyword_function_t)( const Tuple &args, const Dict &kws );
|
||||
|
||||
// NOARGS
|
||||
MethodDefExt
|
||||
(
|
||||
const char *_name,
|
||||
method_noargs_function_t _function,
|
||||
method_noargs_call_handler_t _handler,
|
||||
const char *_doc
|
||||
)
|
||||
{
|
||||
ext_meth_def.ml_name = const_cast<char *>( _name );
|
||||
ext_meth_def.ml_meth = reinterpret_cast<method_varargs_call_handler_t>( _handler );
|
||||
ext_meth_def.ml_flags = METH_NOARGS;
|
||||
ext_meth_def.ml_doc = const_cast<char *>( _doc );
|
||||
|
||||
ext_noargs_function = _function;
|
||||
ext_varargs_function = NULL;
|
||||
ext_keyword_function = NULL;
|
||||
}
|
||||
|
||||
// VARARGS
|
||||
MethodDefExt
|
||||
(
|
||||
const char *_name,
|
||||
method_varargs_function_t _function,
|
||||
method_varargs_call_handler_t _handler,
|
||||
const char *_doc
|
||||
)
|
||||
{
|
||||
ext_meth_def.ml_name = const_cast<char *>( _name );
|
||||
ext_meth_def.ml_meth = reinterpret_cast<method_varargs_call_handler_t>( _handler );
|
||||
ext_meth_def.ml_flags = METH_VARARGS;
|
||||
ext_meth_def.ml_doc = const_cast<char *>( _doc );
|
||||
|
||||
ext_noargs_function = NULL;
|
||||
ext_varargs_function = _function;
|
||||
ext_keyword_function = NULL;
|
||||
}
|
||||
|
||||
// VARARGS + KEYWORD
|
||||
MethodDefExt
|
||||
(
|
||||
const char *_name,
|
||||
method_keyword_function_t _function,
|
||||
method_keyword_call_handler_t _handler,
|
||||
const char *_doc
|
||||
)
|
||||
{
|
||||
ext_meth_def.ml_name = const_cast<char *>( _name );
|
||||
ext_meth_def.ml_meth = reinterpret_cast<method_varargs_call_handler_t>(reinterpret_cast<void (*) (void)>(_handler));
|
||||
ext_meth_def.ml_flags = METH_VARARGS|METH_KEYWORDS;
|
||||
ext_meth_def.ml_doc = const_cast<char *>( _doc );
|
||||
|
||||
ext_noargs_function = NULL;
|
||||
ext_varargs_function = NULL;
|
||||
ext_keyword_function = _function;
|
||||
}
|
||||
|
||||
~MethodDefExt()
|
||||
{}
|
||||
|
||||
PyMethodDef ext_meth_def;
|
||||
method_noargs_function_t ext_noargs_function;
|
||||
method_varargs_function_t ext_varargs_function;
|
||||
method_keyword_function_t ext_keyword_function;
|
||||
Object py_method;
|
||||
};
|
||||
} // Namespace Py
|
||||
|
||||
#include "CXX/Python3/ExtensionModule.hxx"
|
||||
#include "CXX/Python3/PythonType.hxx"
|
||||
#include "CXX/Python3/ExtensionTypeBase.hxx"
|
||||
#include "CXX/Python3/ExtensionOldType.hxx"
|
||||
#include "CXX/Python3/ExtensionType.hxx"
|
||||
|
||||
// End of CXX_Extensions.h
|
||||
#endif
|
||||
165
src/3rdParty/PyCXX/CXX/Python3/IndirectPythonInterface.hxx
vendored
Normal file
165
src/3rdParty/PyCXX/CXX/Python3/IndirectPythonInterface.hxx
vendored
Normal file
@@ -0,0 +1,165 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef __CXX_INDIRECT_PYTHON_INTERFACE__HXX__
|
||||
# define __CXX_INDIRECT_PYTHON_INTERFACE__HXX__
|
||||
|
||||
# include "CXX/WrapPython.h"
|
||||
#include "CXX/Config.hxx"
|
||||
|
||||
namespace Py
|
||||
{
|
||||
bool InitialisePythonIndirectInterface();
|
||||
|
||||
//
|
||||
// Wrap Exception variables as function calls
|
||||
//
|
||||
PYCXX_EXPORT PyObject * _Exc_BaseException();
|
||||
|
||||
# define PYCXX_STANDARD_EXCEPTION( eclass, bclass ) \
|
||||
PYCXX_EXPORT PyObject * _Exc_##eclass();
|
||||
|
||||
# include "CXX/Python3/cxx_standard_exceptions.hxx"
|
||||
# undef PYCXX_STANDARD_EXCEPTION
|
||||
|
||||
//
|
||||
// Wrap Object variables as function calls
|
||||
//
|
||||
PYCXX_EXPORT PyObject * _None();
|
||||
|
||||
PYCXX_EXPORT PyObject * _False();
|
||||
PYCXX_EXPORT PyObject * _True();
|
||||
|
||||
//
|
||||
// Wrap Type variables as function calls
|
||||
//
|
||||
PYCXX_EXPORT PyTypeObject * _List_Type();
|
||||
PYCXX_EXPORT bool _List_Check( PyObject *o );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Buffer_Type();
|
||||
PYCXX_EXPORT bool _Buffer_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Class_Type();
|
||||
PYCXX_EXPORT bool _Class_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Instance_Type();
|
||||
PYCXX_EXPORT bool _Instance_Check( PyObject *op );
|
||||
|
||||
# if !defined( Py_LIMITED_API )
|
||||
PYCXX_EXPORT PyTypeObject * _Method_Type();
|
||||
PYCXX_EXPORT bool _Method_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Function_Type();
|
||||
PYCXX_EXPORT bool _Function_Check( PyObject *op );
|
||||
# endif
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Complex_Type();
|
||||
PYCXX_EXPORT bool _Complex_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Dict_Type();
|
||||
PYCXX_EXPORT bool _Dict_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _File_Type();
|
||||
PYCXX_EXPORT bool _File_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Float_Type();
|
||||
PYCXX_EXPORT bool _Float_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Frame_Type();
|
||||
PYCXX_EXPORT bool _Frame_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Bool_Type();
|
||||
PYCXX_EXPORT bool _Boolean_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Int_Type();
|
||||
PYCXX_EXPORT bool _Int_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _List_Type();
|
||||
PYCXX_EXPORT bool _List_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Long_Type();
|
||||
PYCXX_EXPORT bool _Long_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _CFunction_Type();
|
||||
PYCXX_EXPORT bool _CFunction_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Module_Type();
|
||||
PYCXX_EXPORT bool _Module_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Type_Type();
|
||||
PYCXX_EXPORT bool _Type_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Range_Type();
|
||||
PYCXX_EXPORT bool _Range_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Slice_Type();
|
||||
PYCXX_EXPORT bool _Slice_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Unicode_Type();
|
||||
PYCXX_EXPORT bool _Unicode_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Bytes_Type();
|
||||
PYCXX_EXPORT bool _Bytes_Check( PyObject *op );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _TraceBack_Type();
|
||||
PYCXX_EXPORT bool _TraceBack_Check( PyObject *v );
|
||||
|
||||
PYCXX_EXPORT PyTypeObject * _Tuple_Type();
|
||||
PYCXX_EXPORT bool _Tuple_Check( PyObject *op );
|
||||
|
||||
# if PY_MAJOR_VERSION == 2 || !defined( Py_LIMITED_API )
|
||||
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();
|
||||
|
||||
# if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION <= 11
|
||||
# if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 7
|
||||
PYCXX_EXPORT const char *__Py_PackageContext();
|
||||
# else
|
||||
PYCXX_EXPORT char *__Py_PackageContext();
|
||||
# endif
|
||||
# endif
|
||||
# endif
|
||||
|
||||
PYCXX_EXPORT void _XINCREF( PyObject *op );
|
||||
PYCXX_EXPORT void _XDECREF( PyObject *op );
|
||||
}
|
||||
|
||||
#endif // __CXX_INDIRECT_PYTHON_INTERFACE__HXX__
|
||||
3588
src/3rdParty/PyCXX/CXX/Python3/Objects.hxx
vendored
Normal file
3588
src/3rdParty/PyCXX/CXX/Python3/Objects.hxx
vendored
Normal file
File diff suppressed because it is too large
Load Diff
229
src/3rdParty/PyCXX/CXX/Python3/PythonType.hxx
vendored
Normal file
229
src/3rdParty/PyCXX/CXX/Python3/PythonType.hxx
vendored
Normal file
@@ -0,0 +1,229 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef __CXX_PythonType__h
|
||||
#define __CXX_PythonType__h
|
||||
|
||||
#if defined( Py_LIMITED_API )
|
||||
#include <unordered_map>
|
||||
#endif
|
||||
|
||||
namespace Py
|
||||
{
|
||||
class PYCXX_EXPORT PythonType
|
||||
{
|
||||
public:
|
||||
// if you define one sequence method you must define
|
||||
// all of them except the assigns
|
||||
|
||||
PythonType( size_t base_size, int itemsize, const char *default_name );
|
||||
virtual ~PythonType();
|
||||
|
||||
const char *getName() const;
|
||||
const char *getDoc() const;
|
||||
|
||||
PyTypeObject *type_object() const;
|
||||
PythonType &name( const char *nam );
|
||||
PythonType &doc( const char *d );
|
||||
|
||||
PythonType &supportClass( void );
|
||||
#if defined( PYCXX_PYTHON_2TO3 ) && !defined( Py_LIMITED_API ) && PY_MINOR_VERSION <= 7
|
||||
PythonType &supportPrint( void );
|
||||
#endif
|
||||
PythonType &supportGetattr( void );
|
||||
PythonType &supportSetattr( void );
|
||||
PythonType &supportGetattro( void );
|
||||
PythonType &supportSetattro( void );
|
||||
#ifdef PYCXX_PYTHON_2TO3
|
||||
PythonType &supportCompare( void );
|
||||
#endif
|
||||
PythonType &supportRichCompare( void );
|
||||
PythonType &supportRepr( void );
|
||||
PythonType &supportStr( void );
|
||||
PythonType &supportHash( void );
|
||||
PythonType &supportCall( 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),
|
||||
support_number_floor_divide = B(17),
|
||||
support_number_true_divide = B(18),
|
||||
support_number_index = B(19),
|
||||
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 5
|
||||
support_number_matrix_multiply = B(20),
|
||||
#endif
|
||||
|
||||
// start a new bit mask for inplace that avoid using more then 32 bits in methods_to_support
|
||||
support_number_inplace_floor_divide = B(0),
|
||||
support_number_inplace_true_divide = B(1),
|
||||
support_number_inplace_add = B(2),
|
||||
support_number_inplace_subtract = B(3),
|
||||
support_number_inplace_multiply = B(4),
|
||||
support_number_inplace_remainder = B(5),
|
||||
support_number_inplace_power = B(6),
|
||||
support_number_inplace_lshift = B(7),
|
||||
support_number_inplace_rshift = B(8),
|
||||
support_number_inplace_and = B(9),
|
||||
support_number_inplace_xor = B(10),
|
||||
support_number_inplace_or = B(11)
|
||||
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 5
|
||||
,
|
||||
support_number_inplace_matrix_multiply = B(12)
|
||||
#endif
|
||||
};
|
||||
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,
|
||||
int inplace_methods_to_support=0
|
||||
);
|
||||
|
||||
#if !defined( Py_LIMITED_API )
|
||||
enum {
|
||||
support_buffer_getbuffer = B(0),
|
||||
support_buffer_releasebuffer = B(1)
|
||||
};
|
||||
PythonType &supportBufferType( int methods_to_support=
|
||||
support_buffer_getbuffer |
|
||||
support_buffer_releasebuffer
|
||||
);
|
||||
#endif
|
||||
#undef B
|
||||
|
||||
PythonType &set_tp_dealloc( void (*tp_dealloc)( PyObject * ) );
|
||||
PythonType &set_tp_init( int (*tp_init)( PyObject *self, PyObject *args, PyObject *kwds ) );
|
||||
PythonType &set_tp_new( PyObject *(*tp_new)( PyTypeObject *subtype, PyObject *args, PyObject *kwds ) );
|
||||
PythonType &set_methods( PyMethodDef *methods );
|
||||
|
||||
// call once all support functions have been called to ready the type
|
||||
bool readyType();
|
||||
|
||||
protected:
|
||||
#if defined( Py_LIMITED_API )
|
||||
std::unordered_map<int, void*> slots;
|
||||
PyType_Spec *spec;
|
||||
PyTypeObject *tp_object;
|
||||
#else
|
||||
PyTypeObject *table;
|
||||
PySequenceMethods *sequence_table;
|
||||
PyMappingMethods *mapping_table;
|
||||
PyNumberMethods *number_table;
|
||||
PyBufferProcs *buffer_table;
|
||||
#endif
|
||||
|
||||
private:
|
||||
//
|
||||
// prevent the compiler generating these unwanted functions
|
||||
//
|
||||
PythonType( const PythonType &tb ); // unimplemented
|
||||
void operator=( const PythonType &t ); // unimplemented
|
||||
|
||||
};
|
||||
|
||||
} // Namespace Py
|
||||
|
||||
// End of __CXX_PythonType__h
|
||||
#endif
|
||||
72
src/3rdParty/PyCXX/CXX/Python3/cxx_exceptions.cxx
vendored
Normal file
72
src/3rdParty/PyCXX/CXX/Python3/cxx_exceptions.cxx
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
//
|
||||
// cxx_exceptions.cxx
|
||||
//
|
||||
#include <CXX/Exception.hxx>
|
||||
#include <CXX/Extensions.hxx>
|
||||
|
||||
#include <map>
|
||||
|
||||
namespace Py
|
||||
{
|
||||
typedef void (*throw_exception_func_t)( void );
|
||||
|
||||
std::map<void *, throw_exception_func_t> py_exc_type_to_exc_func;
|
||||
|
||||
void addPythonException( ExtensionExceptionType &py_exc_type, throw_exception_func_t func )
|
||||
{
|
||||
py_exc_type_to_exc_func.insert( std::make_pair( py_exc_type.ptr(), func ) );
|
||||
}
|
||||
|
||||
void addPythonException( PyObject *py_exc_type, throw_exception_func_t func )
|
||||
{
|
||||
py_exc_type_to_exc_func.insert( std::make_pair( py_exc_type, func ) );
|
||||
}
|
||||
|
||||
void ifPyErrorThrowCxxException()
|
||||
{
|
||||
if( PyErr_Occurred() )
|
||||
{
|
||||
PyObject *ptype, *pvalue, *ptrace;
|
||||
PyErr_Fetch( &ptype, &pvalue, &ptrace );
|
||||
PyErr_Restore( ptype, pvalue, ptrace );
|
||||
|
||||
Object q( ptype );
|
||||
|
||||
std::map<void *, throw_exception_func_t>::iterator func = py_exc_type_to_exc_func.find( ptype );
|
||||
if( func != py_exc_type_to_exc_func.end() )
|
||||
{
|
||||
#ifdef PYCXX_DEBUG
|
||||
std::cout << "ifPyErrorThrowCxxException found throwFunc: " << q << std::endl;
|
||||
#endif
|
||||
(func->second)();
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef PYCXX_DEBUG
|
||||
std::cout << "ifPyErrorThrowCxxException no throwFunc: " << q << std::endl;
|
||||
#endif
|
||||
throw Exception();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void initExceptions()
|
||||
{
|
||||
static bool init_done = false;
|
||||
if( init_done )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
#define PYCXX_STANDARD_EXCEPTION( eclass, bclass ) \
|
||||
addPythonException( eclass::exceptionType(), eclass::throwFunc );
|
||||
|
||||
#include <CXX/Python3/cxx_standard_exceptions.hxx>
|
||||
|
||||
#undef PYCXX_STANDARD_EXCEPTION
|
||||
|
||||
init_done = true;
|
||||
}
|
||||
|
||||
|
||||
} // end of namespace Py
|
||||
2143
src/3rdParty/PyCXX/CXX/Python3/cxx_extensions.cxx
vendored
Normal file
2143
src/3rdParty/PyCXX/CXX/Python3/cxx_extensions.cxx
vendored
Normal file
File diff suppressed because it is too large
Load Diff
78
src/3rdParty/PyCXX/CXX/Python3/cxx_standard_exceptions.hxx
vendored
Normal file
78
src/3rdParty/PyCXX/CXX/Python3/cxx_standard_exceptions.hxx
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
#if !defined( PYCXX_STANDARD_EXCEPTION )
|
||||
#pragma error( "define PYCXX_STANDARD_EXCEPTION before including" )
|
||||
#endif
|
||||
|
||||
// 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 !defined(MS_WINDOWS) && ((defined(Py_LIMITED_API) && Py_LIMITED_API+0 >= 0x03050000 && PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 5) || (!defined( Py_LIMITED_API ) && PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 5))
|
||||
PYCXX_STANDARD_EXCEPTION( StopAsyncIteration, Exception )
|
||||
#endif
|
||||
// Windows builds of python 3.5 do not export the symbol PyExc_StopAsyncIteration - need atleast 3.6
|
||||
#if defined(MS_WINDOWS) && ((defined(Py_LIMITED_API) && Py_LIMITED_API+0 >= 0x03050000 && PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 6) || (!defined( Py_LIMITED_API ) && 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 )
|
||||
#if (defined(Py_LIMITED_API) && Py_LIMITED_API+0 >= 0x03060000 && PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 6) || (!defined( Py_LIMITED_API ) && PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 4)
|
||||
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 )
|
||||
#endif
|
||||
PYCXX_STANDARD_EXCEPTION( ReferenceError, Exception )
|
||||
PYCXX_STANDARD_EXCEPTION( RuntimeError, Exception )
|
||||
PYCXX_STANDARD_EXCEPTION( NotImplementedError, RuntimeError )
|
||||
#if !defined(MS_WINDOWS) && ((defined(Py_LIMITED_API) && Py_LIMITED_API+0 >= 0x03050000 && PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 5) || (!defined( Py_LIMITED_API ) && PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 5))
|
||||
PYCXX_STANDARD_EXCEPTION( RecursionError, RuntimeError )
|
||||
#endif
|
||||
// Windows builds of python 3.5 do not export the symbol PyExc_RecursionError - need atleast 3.6
|
||||
#if defined(MS_WINDOWS) && ((defined(Py_LIMITED_API) && Py_LIMITED_API+0 >= 0x03050000 && PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 6) || (!defined( Py_LIMITED_API ) && 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 )
|
||||
64
src/3rdParty/PyCXX/CXX/Python3/cxxextensions.c
vendored
Normal file
64
src/3rdParty/PyCXX/CXX/Python3/cxxextensions.c
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
/*----------------------------------------------------------------------------
|
||||
//
|
||||
// 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/WrapPython.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 13
|
||||
PyObject py_object_initializer =
|
||||
{
|
||||
{ 1 },
|
||||
NULL // type must be init'ed by user
|
||||
};
|
||||
|
||||
#else
|
||||
PyObject py_object_initializer =
|
||||
{
|
||||
_PyObject_EXTRA_INIT
|
||||
1,
|
||||
NULL // type must be init'ed by user
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
230
src/3rdParty/PyCXX/CXX/Python3/cxxsupport.cxx
vendored
Normal file
230
src/3rdParty/PyCXX/CXX/Python3/cxxsupport.cxx
vendored
Normal file
@@ -0,0 +1,230 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// 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/Objects.hxx"
|
||||
#include <limits>
|
||||
namespace Py
|
||||
{
|
||||
|
||||
Py_ssize_t numeric_limits_max()
|
||||
{
|
||||
return std::numeric_limits<Py_ssize_t>::max();
|
||||
}
|
||||
|
||||
#if !defined(Py_LIMITED_API)
|
||||
Py_UNICODE unicode_null_string[1] = { 0 };
|
||||
#endif
|
||||
Py_UCS4 ucs4_null_string[1] = { 0 };
|
||||
|
||||
Type Object::type() const
|
||||
{
|
||||
return Type( PyObject_Type( p ), true );
|
||||
}
|
||||
|
||||
String Object::str() const
|
||||
{
|
||||
return String( PyObject_Str( p ), true );
|
||||
}
|
||||
|
||||
String Object::repr() const
|
||||
{
|
||||
return String( PyObject_Repr( p ), true );
|
||||
}
|
||||
|
||||
std::string Object::as_string() const
|
||||
{
|
||||
return static_cast<std::string>( str() );
|
||||
}
|
||||
|
||||
List Object::dir() const
|
||||
{
|
||||
return List( PyObject_Dir( p ), true );
|
||||
}
|
||||
|
||||
bool Object::isType( const Type &t ) const
|
||||
{
|
||||
return type().ptr() == t.ptr();
|
||||
}
|
||||
|
||||
Char::operator String() const
|
||||
{
|
||||
return String( ptr() );
|
||||
}
|
||||
|
||||
String Bytes::decode( const char *encoding, const char *error )
|
||||
{
|
||||
return String( PyUnicode_FromEncodedObject( ptr(), encoding, error ), true );
|
||||
}
|
||||
|
||||
// Object compares
|
||||
bool operator==( const Object &o1, const Object &o2 )
|
||||
{
|
||||
int k = PyObject_RichCompareBool( *o1, *o2, Py_EQ );
|
||||
ifPyErrorThrowCxxException();
|
||||
return k != 0;
|
||||
}
|
||||
|
||||
bool operator!=( const Object &o1, const Object &o2 )
|
||||
{
|
||||
int k = PyObject_RichCompareBool( *o1, *o2, Py_NE );
|
||||
ifPyErrorThrowCxxException();
|
||||
return k != 0;
|
||||
}
|
||||
|
||||
bool operator>=( const Object &o1, const Object &o2 )
|
||||
{
|
||||
int k = PyObject_RichCompareBool( *o1, *o2, Py_GE );
|
||||
ifPyErrorThrowCxxException();
|
||||
return k != 0;
|
||||
}
|
||||
|
||||
bool operator<=( const Object &o1, const Object &o2 )
|
||||
{
|
||||
int k = PyObject_RichCompareBool( *o1, *o2, Py_LE );
|
||||
ifPyErrorThrowCxxException();
|
||||
return k != 0;
|
||||
}
|
||||
|
||||
bool operator<( const Object &o1, const Object &o2 )
|
||||
{
|
||||
int k = PyObject_RichCompareBool( *o1, *o2, Py_LT );
|
||||
ifPyErrorThrowCxxException();
|
||||
return k != 0;
|
||||
}
|
||||
|
||||
bool operator>( const Object &o1, const Object &o2 )
|
||||
{
|
||||
int k = PyObject_RichCompareBool( *o1, *o2, Py_GT );
|
||||
ifPyErrorThrowCxxException();
|
||||
return k != 0;
|
||||
}
|
||||
|
||||
// iterator compares
|
||||
bool operator==( const Sequence::iterator &left, const Sequence::iterator &right )
|
||||
{
|
||||
return left.eql( right );
|
||||
}
|
||||
|
||||
bool operator!=( const Sequence::iterator &left, const Sequence::iterator &right )
|
||||
{
|
||||
return left.neq( right );
|
||||
}
|
||||
|
||||
bool operator<( const Sequence::iterator &left, const Sequence::iterator &right )
|
||||
{
|
||||
return left.lss( right );
|
||||
}
|
||||
|
||||
bool operator>( const Sequence::iterator &left, const Sequence::iterator &right )
|
||||
{
|
||||
return left.gtr( right );
|
||||
}
|
||||
|
||||
bool operator<=( const Sequence::iterator &left, const Sequence::iterator &right )
|
||||
{
|
||||
return left.leq( right );
|
||||
}
|
||||
|
||||
bool operator>=( const Sequence::iterator &left, const Sequence::iterator &right )
|
||||
{
|
||||
return left.geq( right );
|
||||
}
|
||||
|
||||
// const_iterator compares
|
||||
bool operator==( const Sequence::const_iterator &left, const Sequence::const_iterator &right )
|
||||
{
|
||||
return left.eql( right );
|
||||
}
|
||||
|
||||
bool operator!=( const Sequence::const_iterator &left, const Sequence::const_iterator &right )
|
||||
{
|
||||
return left.neq( right );
|
||||
}
|
||||
|
||||
bool operator<( const Sequence::const_iterator &left, const Sequence::const_iterator &right )
|
||||
{
|
||||
return left.lss( right );
|
||||
}
|
||||
|
||||
bool operator>( const Sequence::const_iterator &left, const Sequence::const_iterator &right )
|
||||
{
|
||||
return left.gtr( right );
|
||||
}
|
||||
|
||||
bool operator<=( const Sequence::const_iterator &left, const Sequence::const_iterator &right )
|
||||
{
|
||||
return left.leq( right );
|
||||
}
|
||||
|
||||
bool operator>=( const Sequence::const_iterator &left, const Sequence::const_iterator &right )
|
||||
{
|
||||
return left.geq( right );
|
||||
}
|
||||
|
||||
// For mappings:
|
||||
bool operator==( const Mapping::iterator &left, const Mapping::iterator &right )
|
||||
{
|
||||
return left.eql( right );
|
||||
}
|
||||
|
||||
bool operator!=( const Mapping::iterator &left, const Mapping::iterator &right )
|
||||
{
|
||||
return left.neq( right );
|
||||
}
|
||||
|
||||
// now for const_iterator
|
||||
bool operator==( const Mapping::const_iterator &left, const Mapping::const_iterator &right )
|
||||
{
|
||||
return left.eql( right );
|
||||
}
|
||||
|
||||
bool operator!=( const Mapping::const_iterator &left, const Mapping::const_iterator &right )
|
||||
{
|
||||
return left.neq( right );
|
||||
}
|
||||
|
||||
// TMM: 31May'01 - Added the #ifndef so I can exclude iostreams.
|
||||
#ifndef CXX_NO_IOSTREAMS
|
||||
// output
|
||||
|
||||
std::ostream &operator<<( std::ostream &os, const Object &ob )
|
||||
{
|
||||
return( os << static_cast<std::string>( ob.str() ) );
|
||||
}
|
||||
#endif
|
||||
|
||||
} // Py
|
||||
46
src/3rdParty/PyCXX/CXX/Version.hxx
vendored
Normal file
46
src/3rdParty/PyCXX/CXX/Version.hxx
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef __PyCXX_version_hxx__
|
||||
#define __PyCXX_version_hxx__
|
||||
|
||||
#define PYCXX_VERSION_MAJOR 7
|
||||
#define PYCXX_VERSION_MINOR 1
|
||||
#define PYCXX_VERSION_PATCH 9
|
||||
#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
|
||||
71
src/3rdParty/PyCXX/CXX/WrapPython.h
vendored
Normal file
71
src/3rdParty/PyCXX/CXX/WrapPython.h
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef __PyCXX_wrap_python_hxx__
|
||||
#define __PyCXX_wrap_python_hxx__
|
||||
|
||||
// On some platforms we have to include time.h to get select defined
|
||||
#if !defined(__WIN32__) && !defined(WIN32) && !defined(_WIN32) && !defined(_WIN64)
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
// Prevent multiple conflicting definitions of swab from stdlib.h and unistd.h
|
||||
#if defined(__sun) || defined(sun)
|
||||
#if defined(_XPG4)
|
||||
#undef _XPG4
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Python.h will redefine these and generate warning in the process
|
||||
#undef _XOPEN_SOURCE
|
||||
#undef _POSIX_C_SOURCE
|
||||
|
||||
// pull in python definitions
|
||||
#include <Python.h>
|
||||
|
||||
// fix issue with Python assuming that isspace, toupper etc are macros
|
||||
#if defined(isspace) || defined(FC_OS_MACOSX)
|
||||
#undef isspace
|
||||
#undef isupper
|
||||
#undef islower
|
||||
#undef isalnum
|
||||
#undef isalpha
|
||||
#undef toupper
|
||||
#undef tolower
|
||||
#endif
|
||||
|
||||
#endif
|
||||
7
src/3rdParty/PyCXX/CXX/cxx_exceptions.cxx
vendored
Normal file
7
src/3rdParty/PyCXX/CXX/cxx_exceptions.cxx
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
#include "CXX/WrapPython.h"
|
||||
|
||||
#if PY_MAJOR_VERSION == 2
|
||||
#include "Python2/cxx_exceptions.cxx"
|
||||
#else
|
||||
#include "Python3/cxx_exceptions.cxx"
|
||||
#endif
|
||||
43
src/3rdParty/PyCXX/CXX/cxx_extensions.cxx
vendored
Normal file
43
src/3rdParty/PyCXX/CXX/cxx_extensions.cxx
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// 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/WrapPython.h"
|
||||
|
||||
#if PY_MAJOR_VERSION == 2
|
||||
#include "Python2/cxx_extensions.cxx"
|
||||
#else
|
||||
#include "Python3/cxx_extensions.cxx"
|
||||
#endif
|
||||
43
src/3rdParty/PyCXX/CXX/cxxextensions.c
vendored
Normal file
43
src/3rdParty/PyCXX/CXX/cxxextensions.c
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// 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/WrapPython.h"
|
||||
|
||||
#if PY_MAJOR_VERSION == 2
|
||||
#include "Python2/cxxextensions.c"
|
||||
#else
|
||||
#include "Python3/cxxextensions.c"
|
||||
#endif
|
||||
43
src/3rdParty/PyCXX/CXX/cxxsupport.cxx
vendored
Normal file
43
src/3rdParty/PyCXX/CXX/cxxsupport.cxx
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// 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 "WrapPython.h"
|
||||
|
||||
#if PY_MAJOR_VERSION == 2
|
||||
#include "Python2/cxxsupport.cxx"
|
||||
#else
|
||||
#include "Python3/cxxsupport.cxx"
|
||||
#endif
|
||||
35
src/3rdParty/PyCXX/CXX/pycxx.dox
vendored
Normal file
35
src/3rdParty/PyCXX/CXX/pycxx.dox
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
\defgroup PYCXX PyCXX
|
||||
\ingroup EMBEDDED
|
||||
\brief C++ facilities to make it easier to write Python extensions
|
||||
|
||||
CXX/Objects is a set of C++ facilities to make it easier to write
|
||||
Python extensions. The chief way in which PyCXX makes it easier to
|
||||
write Python extensions is that it greatly increases the probability
|
||||
that your program will not make a reference-counting error and will
|
||||
not have to continually check error returns from the Python C API.
|
||||
CXX/Objects integrates Python with C++ in these ways:
|
||||
|
||||
C++ exception handling is relied on to detect errors and clean up.
|
||||
In a complicated function this is often a tremendous problem when
|
||||
writing in C. With PyCXX, we let the compiler keep track of what
|
||||
objects need to be dereferenced when an error occurs.
|
||||
The Standard Template Library (STL) and its many algorithms plug and
|
||||
play with Python containers such as lists and tuples.
|
||||
The optional CXX/Extensions facility allows you to replace the
|
||||
clumsy C tables with objects and method calls that define your
|
||||
modules and extension objects.
|
||||
|
||||
PyCXX documentation is split into <a
|
||||
HREF="http://cxx.sourceforge.net/PyCXX-Python3.html">Python 3</A> and
|
||||
<A HREF="http://cxx.sourceforge.net/PyCXX-Python2.html">Python 2</A>
|
||||
versions. The Python 3 documentation is the most accurate.
|
||||
|
||||
Latest <A HREF="http://cxx.sourceforge.net/README.html">PyCXX
|
||||
README</A> file
|
||||
|
||||
The source code is released under the <A
|
||||
HREF="https://sourceforge.net/p/cxx/code/HEAD/tree/trunk/CXX/COPYRIGHT">BSD
|
||||
License</A>.
|
||||
|
||||
*/
|
||||
Reference in New Issue
Block a user