Disabled external gits

This commit is contained in:
2022-04-07 18:46:57 +02:00
parent 88cb3426ad
commit 15e7120d6d
5316 changed files with 4563444 additions and 6 deletions

View File

@@ -0,0 +1,32 @@
ADD_LIBRARY ( PyIex ${LIB_TYPE}
PyIex.cpp
)
TARGET_LINK_LIBRARIES ( PyIex
${PYTHON_LIBRARIES}
)
INSTALL ( TARGETS PyIex
DESTINATION
lib
)
ADD_LIBRARY ( iexmodule ${LIB_TYPE}
iexmodule.cpp
)
SET_TARGET_PROPERTIES ( iexmodule
PROPERTIES PREFIX "" SUFFIX ".so" BUILD_WITH_INSTALL_RPATH ON
)
TARGET_LINK_LIBRARIES ( iexmodule
PyIex
Iex${ILMBASE_LIBSUFFIX}
${Boost_LIBRARIES}
)
INSTALL ( TARGETS iexmodule
DESTINATION lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages
)

View File

@@ -0,0 +1,23 @@
## Process this file with automake to produce Makefile.in
pyexec_LTLIBRARIES = iexmodule.la
lib_LTLIBRARIES = libPyIex.la
libPyIex_la_SOURCES = PyIex.cpp
libPyIexinclude_HEADERS = PyIex.h PyIexExport.h PyIexTypeTranslator.h
libPyIex_la_LDFLAGS = -version-info @LIBTOOL_VERSION@ \
-no-undefined
libPyIex_la_LIBADD = -lz @ILMBASE_LIBS@ @BOOST_PYTHON_LIBS@
libPyIexincludedir = $(includedir)/OpenEXR
iexmodule_la_SOURCES = iexmodule.cpp
iexmodule_la_LDFLAGS = -avoid-version -module
iexmodule_la_LIBADD = libPyIex.la @BOOST_PYTHON_LIBS@
noinst_HEADERS =
INCLUDES = @ILMBASE_CXXFLAGS@ \
-I$(top_builddir) \
-I$(top_srcdir)/config

View File

@@ -0,0 +1,62 @@
///////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2001-2011, Industrial Light & Magic, a division of Lucas
// Digital Ltd. LLC
//
// All rights reserved.
//
// 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 following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Industrial Light & Magic 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 COPYRIGHT
// OWNER 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.
//
///////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------------
//
// PyIex -- support for mapping C++ exceptions to Python exceptions
//
//-----------------------------------------------------------------------------
#include <PyIex.h>
#include <PyIexExport.h>
#include <IexErrnoExc.h>
namespace PyIex {
namespace {
static TypeTranslator<IEX_NAMESPACE::BaseExc> *_baseExcTranslator = 0;
}
PYIEX_EXPORT TypeTranslator<IEX_NAMESPACE::BaseExc> &baseExcTranslator()
{
return *_baseExcTranslator;
}
PYIEX_EXPORT void setBaseExcTranslator(TypeTranslator<IEX_NAMESPACE::BaseExc> *t)
{
_baseExcTranslator = t;
}
} // namespace PyIex

View File

@@ -0,0 +1,256 @@
///////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2001-2011, Industrial Light & Magic, a division of Lucas
// Digital Ltd. LLC
//
// All rights reserved.
//
// 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 following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Industrial Light & Magic 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 COPYRIGHT
// OWNER 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 INCLUDED_PY_IEX_H
#define INCLUDED_PY_IEX_H
//-----------------------------------------------------------------------------
//
// PyIex -- support for mapping C++ exceptions to Python exceptions
//
//-----------------------------------------------------------------------------
#include <sstream>
#include <Python.h>
#include <boost/python.hpp>
#include <IexMathFloatExc.h>
#include <boost/python/errors.hpp>
#include <boost/format.hpp>
#include <PyIexTypeTranslator.h>
#include <PyIexExport.h>
namespace PyIex {
//
// Macros to catch C++ exceptions and translate them into Python exceptions
// for use in python C api code:
//
// PY_TRY
// PY_CATCH
//
// Usage:
//
// Insert PY_TRY and PY_CATCH at the beginning and end of every
// wrapper function to make sure that all possible exceptions
// are caught and translated to corresponding Python exceptions.
// Example:
//
// PyObject *
// setSpeed (PyCar *self, PyObject *args)
// {
// PY_TRY
//
// float length;
// PY_ARG_PARSE ((args, "f", &length));
//
// self->data->setSpeed (length); // may throw
//
// PY_RETURN_NONE;
// PY_CATCH
// }
//
#define PY_TRY \
try \
{ \
IEX_NAMESPACE::MathExcOn mathexcon (IEX_NAMESPACE::IEEE_OVERFLOW | \
IEX_NAMESPACE::IEEE_DIVZERO | \
IEX_NAMESPACE::IEEE_INVALID);
#define PY_CATCH \
} \
catch (boost::python::error_already_set) \
{ \
return 0; \
} \
catch (...) \
{ \
boost::python::handle_exception(); \
return 0; \
}
#define PY_CATCH_WITH_COMMENT(text) \
} \
catch (boost::python::error_already_set) \
{ \
/* Can't use text here without messing with */ \
/* the existing python exception state, so */ \
/* ignore */ \
return 0; \
} \
catch (...) \
{ \
boost::python::handle_exception(); \
return 0; \
}
// In most case, PY_CATCH should be used. But in a few cases, the Python
// interpreter treats a return code of 0 as success rather than failure
// (e.g., the tp_print routine in a PyTypeObject struct).
#define PY_CATCH_RETURN_CODE(CODE) \
} \
catch (...) \
{ \
boost::python::handle_exception(); \
return (CODE); \
}
PYIEX_EXPORT TypeTranslator<IEX_NAMESPACE::BaseExc> &baseExcTranslator();
// this should only be called from iexmodule.cpp during iex
// module initialization.
PYIEX_EXPORT void setBaseExcTranslator(TypeTranslator<IEX_NAMESPACE::BaseExc> *t);
//
// Since there's currently no mechanism in boost to inherit off of
// a python type (RuntimeError in this case), we instead use a
// parallel exception hierarchy defined in python, and create
// and register custom converters with boost::python to go between
// the c++ and corresponding python types.
//
// To register exceptions derived from IEX_NAMESPACE::BaseExc, call
// registerException with the type and base type as template
// parameters, and the name and module as arguments. e.g.:
//
// registerException<EpermExc,ErrnoExc>("EpermExc","iex");
//
//
// ExcTranslator provides the methods needed for boost to convert
// the parallel exception types between c++ and python.
//
template <class T>
class ExcTranslator
{
public:
// to python
static PyObject *convert(const T &exc)
{
using namespace boost::python;
object excType = object(handle<>(borrowed(baseExcTranslator().typeObject(&exc))));
return incref(excType(exc.what()).ptr());
}
// from python
static void *convertible(PyObject *exc)
{
#ifdef Py_TYPE
if (!PyType_IsSubtype(Py_TYPE(exc),(PyTypeObject *)baseExcTranslator().baseTypeObject())) return 0;
#else
// prior to python 2.6, access an object's type via it's ob_type member
if (!PyType_IsSubtype(exc->ob_type,(PyTypeObject *)baseExcTranslator().baseTypeObject())) return 0;
#endif
return exc;
}
static void construct(PyObject* raw_exc, boost::python::converter::rvalue_from_python_stage1_data* data)
{
using namespace boost::python;
object exc(handle<>(borrowed(raw_exc)));
std::string s = extract<std::string>(exc.attr("__str__")());
void *storage = ((converter::rvalue_from_python_storage<T>*)data)->storage.bytes;
new (storage) T(s);
data->convertible = storage;
}
};
//
// This function creates the proxy python type for a given exception.
//
static inline boost::python::object
createExceptionProxy(const std::string &name, const std::string &module,
const std::string &baseName, const std::string &baseModule,
PyObject *baseType)
{
using namespace boost::python;
dict tmpDict;
tmpDict["__builtins__"] = handle<>(borrowed(PyEval_GetBuiltins()));
std::string base = baseName;
std::string definition;
if (baseModule != module)
{
definition += (boost::format("import %s\n") % baseModule).str();
base = (boost::format("%s.%s") % baseModule % baseName).str();
}
else
{
tmpDict[base] = object(handle<>(borrowed(baseType)));
}
definition += (boost::format("class %s (%s):\n"
" def __init__ (self, v=''):\n"
" super(%s,self).__init__(v)\n"
" def __repr__ (self):\n"
" return \"%s.%s('%%s')\"%%(self.args[0])\n")
% name % base % name % module % name).str();
handle<> tmp(PyRun_String(definition.c_str(),Py_file_input,tmpDict.ptr(),tmpDict.ptr()));
return tmpDict[name];
}
//
// register an excpetion derived from IEX_NAMESPACE::BaseExc out to python using
// the proxy mechanism described above.
//
template<class Exc, class ExcBase>
void
registerExc(const std::string &name, const std::string &module)
{
using namespace boost::python;
const TypeTranslator<IEX_NAMESPACE::BaseExc>::ClassDesc *baseDesc = baseExcTranslator().template findClassDesc<ExcBase>(baseExcTranslator().firstClassDesc());
std::string baseName = baseDesc->typeName();
std::string baseModule = baseDesc->moduleName();
object exc_class = createExceptionProxy(name, module, baseName, baseModule, baseDesc->typeObject());
scope().attr(name.c_str()) = exc_class;
baseExcTranslator().registerClass<Exc,ExcBase>(name, module, exc_class.ptr());
// to python
to_python_converter<Exc,ExcTranslator<Exc> >();
// from python
converter::registry::push_back(&ExcTranslator<Exc>::convertible,
&ExcTranslator<Exc>::construct,type_id<Exc>());
}
} // namespace PyIex
#endif

View File

@@ -0,0 +1,63 @@
///////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2001-2012, Industrial Light & Magic, a division of Lucas
// Digital Ltd. LLC
//
// All rights reserved.
//
// 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 following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Industrial Light & Magic 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 COPYRIGHT
// OWNER 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 PYIEXEXPORT_H
#define PYIEXEXPORT_H
#if defined(PLATFORM_WINDOWS)
# if defined(PLATFORM_BUILD_STATIC)
# define PYIEX_EXPORT_DEFINITION
# define PYIEX_IMPORT_DEFINITION
# else
# define PYIEX_EXPORT_DEFINITION __declspec(dllexport)
# define PYIEX_IMPORT_DEFINITION __declspec(dllimport)
# endif
#else // linux/macos
# if defined(PLATFORM_VISIBILITY_AVAILABLE)
# define PYIEX_EXPORT_DEFINITION __attribute__((visibility("default")))
# define PYIEX_IMPORT_DEFINITION
# else
# define PYIEX_EXPORT_DEFINITION
# define PYIEX_IMPORT_DEFINITION
# endif
#endif
#if defined(PYIEX_EXPORTS) // create library
# define PYIEX_EXPORT PYIEX_EXPORT_DEFINITION
#else // use library
# define PYIEX_EXPORT PYIEX_IMPORT_DEFINITION
#endif
#endif // #ifndef PYIEXEXPORT_H

View File

@@ -0,0 +1,418 @@
///////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2001-2011, Industrial Light & Magic, a division of Lucas
// Digital Ltd. LLC
//
// All rights reserved.
//
// 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 following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Industrial Light & Magic 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 COPYRIGHT
// OWNER 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 INCLUDED_PYIEX_TYPETRANSLATOR_H
#define INCLUDED_PYIEX_TYPETRANSLATOR_H
//-----------------------------------------------------------------------------
//
// PyIex -- support for mapping C++ exceptions to Python exceptions
//
//-----------------------------------------------------------------------------
#include <Python.h>
#include <string>
#include <vector>
#include <stdexcept>
#include <typeinfo>
namespace PyIex {
//
// TypeTranslator stores a class hierarchy along with corresponding
// python types and metadata for use in Python/C++ type translation.
//
template <class BaseClass>
class TypeTranslator
{
public:
TypeTranslator (const std::string &typeName, const std::string &moduleName, PyObject *typeObject);
~TypeTranslator ();
PyObject * typeObject (const BaseClass *ptr) const;
PyObject * baseTypeObject () const;
template <class NewClass, class DerivedFrom>
void registerClass (const std::string &typeName,
const std::string &moduleName,
PyObject *typeObject);
class ClassDesc
{
public:
ClassDesc (const std::string &typeName,
const std::string &moduleName,
PyObject *typeObject,
const ClassDesc *baseClass);
virtual ~ClassDesc ();
virtual bool typeMatches (const BaseClass *ptr) const = 0;
virtual const std::type_info &
typeInfo () const = 0;
const std::string & typeName() const;
const std::string & moduleName() const;
PyObject * typeObject () const;
const ClassDesc * baseClass () const;
int numDerivedClasses () const;
const ClassDesc * derivedClass (int i) const;
ClassDesc * derivedClass (int i);
void addDerivedClass (ClassDesc *cd);
const ClassDesc * next () const;
private:
const std::string _typeName;
const std::string _moduleName;
PyObject * _typeObject;
const ClassDesc * _baseClass;
std::vector <ClassDesc *> _derivedClasses;
const ClassDesc * _next;
};
template <class T>
class ClassDescT: public ClassDesc
{
public:
ClassDescT (const std::string &typeName,
const std::string &moduleName,
PyObject *typeObject,
const ClassDesc *baseClass);
virtual bool typeMatches (const BaseClass *ptr) const;
virtual const std::type_info &
typeInfo () const;
};
template <class T>
ClassDesc * findClassDesc (ClassDesc *cd);
template <class T>
const ClassDesc * findClassDesc (const ClassDesc *cd) const;
const ClassDesc * firstClassDesc () const;
const ClassDesc * nextClassDesc (const ClassDesc *cd) const;
private:
ClassDesc * _classes;
};
template <class BaseClass>
TypeTranslator<BaseClass>::TypeTranslator
(const std::string &typeName, const std::string &moduleName, PyObject *typeObject)
{
_classes = new ClassDescT <BaseClass> (typeName, moduleName, typeObject, 0);
}
template <class BaseClass>
TypeTranslator<BaseClass>::~TypeTranslator ()
{
delete _classes;
}
template <class BaseClass>
PyObject *
TypeTranslator<BaseClass>::typeObject (const BaseClass *ptr) const
{
const ClassDesc *cd = _classes;
assert (cd->typeMatches (ptr));
while (true)
{
const ClassDesc *matchingCd = 0;
for (int i = 0; i < cd->numDerivedClasses(); ++i)
{
const ClassDesc *derivedCd = cd->derivedClass (i);
if (derivedCd->typeMatches (ptr))
{
matchingCd = derivedCd;
break;
}
}
if (matchingCd)
cd = matchingCd;
else
break;
}
return cd->typeObject ();
}
template <class BaseClass>
PyObject *
TypeTranslator<BaseClass>::baseTypeObject () const
{
return _classes->typeObject ();
}
template <class BaseClass>
template <class NewClass, class DerivedFrom>
void
TypeTranslator<BaseClass>::registerClass
(const std::string &typeName, const std::string &moduleName, PyObject *typeObject)
{
ClassDesc *df = findClassDesc <DerivedFrom> (_classes);
if (df == 0)
throw std::invalid_argument ("PyIex::TypeTranslator: "
"Base class must be registered "
"before derived class.");
ClassDesc *nc = findClassDesc <NewClass> (_classes);
if (nc != 0)
{
//
// Calling registerClass() more than once with the same
// NewClass and DerivedFrom arguments is a no-op.
// Calling registerClass() multiple times with the same
// NewClass but with different DerivedFrom arguments is
// an error.
//
for (int i = 0; i < df->numDerivedClasses(); ++i)
{
if (df->derivedClass (i) == nc)
return;
}
throw std::invalid_argument ("PyIex::TypeTranslator: "
"Derived class registered twice "
"with different base classes.");
}
df->addDerivedClass (new ClassDescT<NewClass> (typeName, moduleName, typeObject, df));
}
template <class BaseClass>
template <class T>
typename TypeTranslator<BaseClass>::ClassDesc *
TypeTranslator<BaseClass>::findClassDesc (ClassDesc *cd)
{
if (cd->typeInfo() == typeid (T))
return cd;
for (int i = 0; i < cd->numDerivedClasses(); ++i)
{
ClassDesc *match = findClassDesc<T> (cd->derivedClass(i));
if (match)
return match;
}
return 0;
}
template <class BaseClass>
template <class T>
const typename TypeTranslator<BaseClass>::ClassDesc *
TypeTranslator<BaseClass>::findClassDesc (const ClassDesc *cd) const
{
if (cd->typeInfo() == typeid (T))
return cd;
for (int i = 0; i < cd->numDerivedClasses(); ++i)
{
const ClassDesc *match = findClassDesc<T> (cd->derivedClass(i));
if (match)
return match;
}
return 0;
}
template <class BaseClass>
inline const typename TypeTranslator<BaseClass>::ClassDesc *
TypeTranslator<BaseClass>::firstClassDesc () const
{
return _classes;
}
template <class BaseClass>
inline const typename TypeTranslator<BaseClass>::ClassDesc *
TypeTranslator<BaseClass>::nextClassDesc (const ClassDesc *cd) const
{
return cd->next();
}
template <class BaseClass>
TypeTranslator<BaseClass>::ClassDesc::ClassDesc
(const std::string &typeName,
const std::string &moduleName,
PyObject *typeObject,
const ClassDesc *baseClass)
: _typeName(typeName), _moduleName(moduleName),
_typeObject (typeObject), _baseClass (baseClass), _next (0)
{
// emtpy
}
template <class BaseClass>
TypeTranslator<BaseClass>::ClassDesc::~ClassDesc ()
{
for (int i = 0; i < _derivedClasses.size(); ++i)
delete _derivedClasses[i];
}
template <class BaseClass>
inline const std::string &
TypeTranslator<BaseClass>::ClassDesc::typeName () const
{
return _typeName;
}
template <class BaseClass>
inline const std::string &
TypeTranslator<BaseClass>::ClassDesc::moduleName () const
{
return _moduleName;
}
template <class BaseClass>
inline PyObject *
TypeTranslator<BaseClass>::ClassDesc::typeObject () const
{
return _typeObject;
}
template <class BaseClass>
inline const typename TypeTranslator<BaseClass>::ClassDesc *
TypeTranslator<BaseClass>::ClassDesc::baseClass () const
{
return _baseClass;
}
template <class BaseClass>
int
TypeTranslator<BaseClass>::ClassDesc::numDerivedClasses () const
{
return _derivedClasses.size();
}
template <class BaseClass>
inline const typename TypeTranslator<BaseClass>::ClassDesc *
TypeTranslator<BaseClass>::ClassDesc::derivedClass (int i) const
{
return _derivedClasses[i];
}
template <class BaseClass>
inline typename TypeTranslator<BaseClass>::ClassDesc *
TypeTranslator<BaseClass>::ClassDesc::derivedClass (int i)
{
return _derivedClasses[i];
}
template <class BaseClass>
void
TypeTranslator<BaseClass>::ClassDesc::addDerivedClass (ClassDesc *cd)
{
_derivedClasses.push_back (cd);
cd->_next = _next;
_next = cd;
}
template <class BaseClass>
inline const typename TypeTranslator<BaseClass>::ClassDesc *
TypeTranslator<BaseClass>::ClassDesc::next () const
{
return _next;
}
template <class BaseClass>
template <class T>
TypeTranslator<BaseClass>::ClassDescT<T>::ClassDescT
(const std::string &typeName,
const std::string &moduleName,
PyObject *typeObject,
const ClassDesc *baseClass):
TypeTranslator<BaseClass>::ClassDesc (typeName, moduleName, typeObject, baseClass)
{
// empty
}
template <class BaseClass>
template <class T>
bool
TypeTranslator<BaseClass>::ClassDescT<T>::typeMatches (const BaseClass *ptr) const
{
return 0 != dynamic_cast <const T *> (ptr);
}
template <class BaseClass>
template <class T>
const std::type_info &
TypeTranslator<BaseClass>::ClassDescT<T>::typeInfo () const
{
return typeid (T);
}
} // namespace PyIex
#endif

View File

@@ -0,0 +1,316 @@
///////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2001-2011, Industrial Light & Magic, a division of Lucas
// Digital Ltd. LLC
//
// All rights reserved.
//
// 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 following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Industrial Light & Magic 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 COPYRIGHT
// OWNER 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 <Python.h>
#include <boost/python.hpp>
#include <boost/format.hpp>
#include <Iex.h>
#include <PyIex.h>
#include <PyIexExport.h>
#include <IexErrnoExc.h>
#include <iostream>
using namespace boost::python;
using namespace IEX_NAMESPACE;
namespace PyIex {
namespace {
static void translateBaseExc(const IEX_NAMESPACE::BaseExc &exc)
{
PyErr_SetObject(baseExcTranslator().typeObject(&exc),ExcTranslator<IEX_NAMESPACE::BaseExc>::convert(exc));
}
void
registerBaseExc()
{
using namespace boost::python;
std::string name = "BaseExc";
std::string module = "iex";
std::string baseName = "RuntimeError";
std::string baseModule = "__builtin__";
// if module != baseModule, the type object isn't used
object exc_class = createExceptionProxy(name, module, baseName, baseModule, 0);
scope().attr(name.c_str()) = exc_class;
setBaseExcTranslator(new TypeTranslator<IEX_NAMESPACE::BaseExc>(name, module, exc_class.ptr()));
// to python
to_python_converter<IEX_NAMESPACE::BaseExc,ExcTranslator<IEX_NAMESPACE::BaseExc> >();
// from python
converter::registry::push_back(&ExcTranslator<IEX_NAMESPACE::BaseExc>::convertible,
&ExcTranslator<IEX_NAMESPACE::BaseExc>::construct,type_id<IEX_NAMESPACE::BaseExc>());
// exception translation for BaseExc and subtypes
register_exception_translator<IEX_NAMESPACE::BaseExc>(&translateBaseExc);
}
void
testCxxExceptions (int i)
{
//
// This function is only for testing.
// It exercises the PY_TRY / PY_CATCH macros
// and the C++ to Python exception translation.
//
switch (i)
{
case 1:
throw int (1);
case 2:
throw std::invalid_argument ("2");
case 3:
throw IEX_NAMESPACE::BaseExc ("3");
case 4:
throw IEX_NAMESPACE::ArgExc ("4");
default:
;
}
}
std::string
testBaseExcString(const BaseExc &exc)
{
return exc.what();
}
std::string
testArgExcString(const ArgExc &exc)
{
return exc.what();
}
BaseExc
testMakeBaseExc(const std::string &s)
{
return BaseExc(s);
}
ArgExc
testMakeArgExc(const std::string &s)
{
return ArgExc(s);
}
} // namespace
} // namespace PyIex
using namespace PyIex;
BOOST_PYTHON_MODULE(iex)
{
using namespace IEX_NAMESPACE;
def("testCxxExceptions", &testCxxExceptions);
def("testBaseExcString", &testBaseExcString);
def("testArgExcString", &testArgExcString);
def("testMakeBaseExc", &testMakeBaseExc);
def("testMakeArgExc", &testMakeArgExc);
registerBaseExc();
registerExc<ArgExc,BaseExc>("ArgExc","iex");
registerExc<LogicExc,BaseExc>("LogicExc","iex");
registerExc<InputExc,BaseExc>("InputExc","iex");
registerExc<IoExc,BaseExc>("IoExc","iex");
registerExc<MathExc,BaseExc>("MathExc","iex");
registerExc<NoImplExc,BaseExc>("NoImplExc","iex");
registerExc<NullExc,BaseExc>("NullExc","iex");
registerExc<TypeExc,BaseExc>("TypeExc","iex");
registerExc<ErrnoExc,BaseExc>("ErrnoExc","iex");
registerExc<EpermExc,ErrnoExc>("EpermExc","iex");
registerExc<EnoentExc,ErrnoExc>("EnoentExc","iex");
registerExc<EsrchExc,ErrnoExc>("EsrchExc","iex");
registerExc<EintrExc,ErrnoExc>("EintrExc","iex");
registerExc<EioExc,ErrnoExc>("EioExc","iex");
registerExc<EnxioExc,ErrnoExc>("EnxioExc","iex");
registerExc<E2bigExc,ErrnoExc>("E2bigExc","iex");
registerExc<EnoexecExc,ErrnoExc>("EnoexecExc","iex");
registerExc<EbadfExc,ErrnoExc>("EbadfExc","iex");
registerExc<EchildExc,ErrnoExc>("EchildExc","iex");
registerExc<EagainExc,ErrnoExc>("EagainExc","iex");
registerExc<EnomemExc,ErrnoExc>("EnomemExc","iex");
registerExc<EaccesExc,ErrnoExc>("EaccesExc","iex");
registerExc<EfaultExc,ErrnoExc>("EfaultExc","iex");
registerExc<EnotblkExc,ErrnoExc>("EnotblkExc","iex");
registerExc<EbusyExc,ErrnoExc>("EbusyExc","iex");
registerExc<EexistExc,ErrnoExc>("EexistExc","iex");
registerExc<ExdevExc,ErrnoExc>("ExdevExc","iex");
registerExc<EnodevExc,ErrnoExc>("EnodevExc","iex");
registerExc<EnotdirExc,ErrnoExc>("EnotdirExc","iex");
registerExc<EisdirExc,ErrnoExc>("EisdirExc","iex");
registerExc<EinvalExc,ErrnoExc>("EinvalExc","iex");
registerExc<EnfileExc,ErrnoExc>("EnfileExc","iex");
registerExc<EmfileExc,ErrnoExc>("EmfileExc","iex");
registerExc<EnottyExc,ErrnoExc>("EnottyExc","iex");
registerExc<EtxtbsyExc,ErrnoExc>("EtxtbsyExc","iex");
registerExc<EfbigExc,ErrnoExc>("EfbigExc","iex");
registerExc<EnospcExc,ErrnoExc>("EnospcExc","iex");
registerExc<EspipeExc,ErrnoExc>("EspipeExc","iex");
registerExc<ErofsExc,ErrnoExc>("ErofsExc","iex");
registerExc<EmlinkExc,ErrnoExc>("EmlinkExc","iex");
registerExc<EpipeExc,ErrnoExc>("EpipeExc","iex");
registerExc<EdomExc,ErrnoExc>("EdomExc","iex");
registerExc<ErangeExc,ErrnoExc>("ErangeExc","iex");
registerExc<EnomsgExc,ErrnoExc>("EnomsgExc","iex");
registerExc<EidrmExc,ErrnoExc>("EidrmExc","iex");
registerExc<EchrngExc,ErrnoExc>("EchrngExc","iex");
registerExc<El2nsyncExc,ErrnoExc>("El2nsyncExc","iex");
registerExc<El3hltExc,ErrnoExc>("El3hltExc","iex");
registerExc<El3rstExc,ErrnoExc>("El3rstExc","iex");
registerExc<ElnrngExc,ErrnoExc>("ElnrngExc","iex");
registerExc<EunatchExc,ErrnoExc>("EunatchExc","iex");
registerExc<EnocsiExc,ErrnoExc>("EnocsiExc","iex");
registerExc<El2hltExc,ErrnoExc>("El2hltExc","iex");
registerExc<EdeadlkExc,ErrnoExc>("EdeadlkExc","iex");
registerExc<EnolckExc,ErrnoExc>("EnolckExc","iex");
registerExc<EbadeExc,ErrnoExc>("EbadeExc","iex");
registerExc<EbadrExc,ErrnoExc>("EbadrExc","iex");
registerExc<ExfullExc,ErrnoExc>("ExfullExc","iex");
registerExc<EnoanoExc,ErrnoExc>("EnoanoExc","iex");
registerExc<EbadrqcExc,ErrnoExc>("EbadrqcExc","iex");
registerExc<EbadsltExc,ErrnoExc>("EbadsltExc","iex");
registerExc<EdeadlockExc,ErrnoExc>("EdeadlockExc","iex");
registerExc<EbfontExc,ErrnoExc>("EbfontExc","iex");
registerExc<EnostrExc,ErrnoExc>("EnostrExc","iex");
registerExc<EnodataExc,ErrnoExc>("EnodataExc","iex");
registerExc<EtimeExc,ErrnoExc>("EtimeExc","iex");
registerExc<EnosrExc,ErrnoExc>("EnosrExc","iex");
registerExc<EnonetExc,ErrnoExc>("EnonetExc","iex");
registerExc<EnopkgExc,ErrnoExc>("EnopkgExc","iex");
registerExc<EremoteExc,ErrnoExc>("EremoteExc","iex");
registerExc<EnolinkExc,ErrnoExc>("EnolinkExc","iex");
registerExc<EadvExc,ErrnoExc>("EadvExc","iex");
registerExc<EsrmntExc,ErrnoExc>("EsrmntExc","iex");
registerExc<EcommExc,ErrnoExc>("EcommExc","iex");
registerExc<EprotoExc,ErrnoExc>("EprotoExc","iex");
registerExc<EmultihopExc,ErrnoExc>("EmultihopExc","iex");
registerExc<EbadmsgExc,ErrnoExc>("EbadmsgExc","iex");
registerExc<EnametoolongExc,ErrnoExc>("EnametoolongExc","iex");
registerExc<EoverflowExc,ErrnoExc>("EoverflowExc","iex");
registerExc<EnotuniqExc,ErrnoExc>("EnotuniqExc","iex");
registerExc<EbadfdExc,ErrnoExc>("EbadfdExc","iex");
registerExc<EremchgExc,ErrnoExc>("EremchgExc","iex");
registerExc<ElibaccExc,ErrnoExc>("ElibaccExc","iex");
registerExc<ElibbadExc,ErrnoExc>("ElibbadExc","iex");
registerExc<ElibscnExc,ErrnoExc>("ElibscnExc","iex");
registerExc<ElibmaxExc,ErrnoExc>("ElibmaxExc","iex");
registerExc<ElibexecExc,ErrnoExc>("ElibexecExc","iex");
registerExc<EilseqExc,ErrnoExc>("EilseqExc","iex");
registerExc<EnosysExc,ErrnoExc>("EnosysExc","iex");
registerExc<EloopExc,ErrnoExc>("EloopExc","iex");
registerExc<ErestartExc,ErrnoExc>("ErestartExc","iex");
registerExc<EstrpipeExc,ErrnoExc>("EstrpipeExc","iex");
registerExc<EnotemptyExc,ErrnoExc>("EnotemptyExc","iex");
registerExc<EusersExc,ErrnoExc>("EusersExc","iex");
registerExc<EnotsockExc,ErrnoExc>("EnotsockExc","iex");
registerExc<EdestaddrreqExc,ErrnoExc>("EdestaddrreqExc","iex");
registerExc<EmsgsizeExc,ErrnoExc>("EmsgsizeExc","iex");
registerExc<EprototypeExc,ErrnoExc>("EprototypeExc","iex");
registerExc<EnoprotooptExc,ErrnoExc>("EnoprotooptExc","iex");
registerExc<EprotonosupportExc,ErrnoExc>("EprotonosupportExc","iex");
registerExc<EsocktnosupportExc,ErrnoExc>("EsocktnosupportExc","iex");
registerExc<EopnotsuppExc,ErrnoExc>("EopnotsuppExc","iex");
registerExc<EpfnosupportExc,ErrnoExc>("EpfnosupportExc","iex");
registerExc<EafnosupportExc,ErrnoExc>("EafnosupportExc","iex");
registerExc<EaddrinuseExc,ErrnoExc>("EaddrinuseExc","iex");
registerExc<EaddrnotavailExc,ErrnoExc>("EaddrnotavailExc","iex");
registerExc<EnetdownExc,ErrnoExc>("EnetdownExc","iex");
registerExc<EnetunreachExc,ErrnoExc>("EnetunreachExc","iex");
registerExc<EnetresetExc,ErrnoExc>("EnetresetExc","iex");
registerExc<EconnabortedExc,ErrnoExc>("EconnabortedExc","iex");
registerExc<EconnresetExc,ErrnoExc>("EconnresetExc","iex");
registerExc<EnobufsExc,ErrnoExc>("EnobufsExc","iex");
registerExc<EisconnExc,ErrnoExc>("EisconnExc","iex");
registerExc<EnotconnExc,ErrnoExc>("EnotconnExc","iex");
registerExc<EshutdownExc,ErrnoExc>("EshutdownExc","iex");
registerExc<EtoomanyrefsExc,ErrnoExc>("EtoomanyrefsExc","iex");
registerExc<EtimedoutExc,ErrnoExc>("EtimedoutExc","iex");
registerExc<EconnrefusedExc,ErrnoExc>("EconnrefusedExc","iex");
registerExc<EhostdownExc,ErrnoExc>("EhostdownExc","iex");
registerExc<EhostunreachExc,ErrnoExc>("EhostunreachExc","iex");
registerExc<EalreadyExc,ErrnoExc>("EalreadyExc","iex");
registerExc<EinprogressExc,ErrnoExc>("EinprogressExc","iex");
registerExc<EstaleExc,ErrnoExc>("EstaleExc","iex");
registerExc<EioresidExc,ErrnoExc>("EioresidExc","iex");
registerExc<EucleanExc,ErrnoExc>("EucleanExc","iex");
registerExc<EnotnamExc,ErrnoExc>("EnotnamExc","iex");
registerExc<EnavailExc,ErrnoExc>("EnavailExc","iex");
registerExc<EisnamExc,ErrnoExc>("EisnamExc","iex");
registerExc<EremoteioExc,ErrnoExc>("EremoteioExc","iex");
registerExc<EinitExc,ErrnoExc>("EinitExc","iex");
registerExc<EremdevExc,ErrnoExc>("EremdevExc","iex");
registerExc<EcanceledExc,ErrnoExc>("EcanceledExc","iex");
registerExc<EnolimfileExc,ErrnoExc>("EnolimfileExc","iex");
registerExc<EproclimExc,ErrnoExc>("EproclimExc","iex");
registerExc<EdisjointExc,ErrnoExc>("EdisjointExc","iex");
registerExc<EnologinExc,ErrnoExc>("EnologinExc","iex");
registerExc<EloginlimExc,ErrnoExc>("EloginlimExc","iex");
registerExc<EgrouploopExc,ErrnoExc>("EgrouploopExc","iex");
registerExc<EnoattachExc,ErrnoExc>("EnoattachExc","iex");
registerExc<EnotsupExc,ErrnoExc>("EnotsupExc","iex");
registerExc<EnoattrExc,ErrnoExc>("EnoattrExc","iex");
registerExc<EdircorruptedExc,ErrnoExc>("EdircorruptedExc","iex");
registerExc<EdquotExc,ErrnoExc>("EdquotExc","iex");
registerExc<EnfsremoteExc,ErrnoExc>("EnfsremoteExc","iex");
registerExc<EcontrollerExc,ErrnoExc>("EcontrollerExc","iex");
registerExc<EnotcontrollerExc,ErrnoExc>("EnotcontrollerExc","iex");
registerExc<EenqueuedExc,ErrnoExc>("EenqueuedExc","iex");
registerExc<EnotenqueuedExc,ErrnoExc>("EnotenqueuedExc","iex");
registerExc<EjoinedExc,ErrnoExc>("EjoinedExc","iex");
registerExc<EnotjoinedExc,ErrnoExc>("EnotjoinedExc","iex");
registerExc<EnoprocExc,ErrnoExc>("EnoprocExc","iex");
registerExc<EmustrunExc,ErrnoExc>("EmustrunExc","iex");
registerExc<EnotstoppedExc,ErrnoExc>("EnotstoppedExc","iex");
registerExc<EclockcpuExc,ErrnoExc>("EclockcpuExc","iex");
registerExc<EinvalstateExc,ErrnoExc>("EinvalstateExc","iex");
registerExc<EnoexistExc,ErrnoExc>("EnoexistExc","iex");
registerExc<EendofminorExc,ErrnoExc>("EendofminorExc","iex");
registerExc<EbufsizeExc,ErrnoExc>("EbufsizeExc","iex");
registerExc<EemptyExc,ErrnoExc>("EemptyExc","iex");
registerExc<EnointrgroupExc,ErrnoExc>("EnointrgroupExc","iex");
registerExc<EinvalmodeExc,ErrnoExc>("EinvalmodeExc","iex");
registerExc<EcantextentExc,ErrnoExc>("EcantextentExc","iex");
registerExc<EinvaltimeExc,ErrnoExc>("EinvaltimeExc","iex");
registerExc<EdestroyedExc,ErrnoExc>("EdestroyedExc","iex");
}