From: ishmal Date: Mon, 10 Mar 2008 00:03:28 +0000 (+0000) Subject: Switch to newer binding stuff X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=c0e87a5eb79228e59beec3e9cf4a84f13ec29cc1;p=inkscape.git Switch to newer binding stuff --- diff --git a/src/extension/script/.cvsignore b/src/extension/script/.cvsignore deleted file mode 100644 index 38efca7bc..000000000 --- a/src/extension/script/.cvsignore +++ /dev/null @@ -1,3 +0,0 @@ -.deps -.dirstamp -makefile diff --git a/src/extension/script/CXX/Config.hxx b/src/extension/script/CXX/Config.hxx deleted file mode 100644 index b27f9ba28..000000000 --- a/src/extension/script/CXX/Config.hxx +++ /dev/null @@ -1,118 +0,0 @@ -//----------------------------------------------------------------------------- -// -// Copyright (c) 1998 - 2007, The Regents of the University of California -// Produced at the Lawrence Livermore National Laboratory -// All rights reserved. -// -// This file is part of PyCXX. For details,see http://cxx.sourceforge.net/. The -// full copyright notice is contained in the file COPYRIGHT located at the root -// of the PyCXX distribution. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// - Redistributions of source code must retain the above copyright notice, -// this list of conditions and the disclaimer below. -// - Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the disclaimer (as noted below) in the -// documentation and/or materials provided with the distribution. -// - Neither the name of the UC/LLNL nor the names of its contributors may be -// used to endorse or promote products derived from this software without -// specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OF THE UNIVERSITY OF -// CALIFORNIA, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR -// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH -// DAMAGE. -// -//----------------------------------------------------------------------------- - -#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 -#else -# define random_access_iterator_parent(itemtype) std::random_access_iterator -#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 -# define TEMPLATE_TYPENAME class -# else -# define PYCXX_ISO_CPP_LIB 1 -# define STR_STREAM -# define TEMPLATE_TYPENAME typename -# endif -#elif defined( __GNUC__ ) -# if __GNUC__ >= 3 -# define PYCXX_ISO_CPP_LIB 1 -# define STR_STREAM -# define TEMPLATE_TYPENAME typename -# else -# define PYCXX_ISO_CPP_LIB 0 -# define STR_STREAM -# define TEMPLATE_TYPENAME class -# endif -#endif - -#if PYCXX_ISO_CPP_LIB -# define STR_STREAM -# define OSTRSTREAM ostringstream -# define EXPLICIT_TYPENAME typename -# define EXPLICIT_CLASS class -# define TEMPLATE_TYPENAME typename -#else -# define STR_STREAM -# 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 - -#endif // __PyCXX_config_hh__ diff --git a/src/extension/script/CXX/Exception.hxx b/src/extension/script/CXX/Exception.hxx deleted file mode 100644 index 1ef087cac..000000000 --- a/src/extension/script/CXX/Exception.hxx +++ /dev/null @@ -1,249 +0,0 @@ -//----------------------------------------------------------------------------- -// -// Copyright (c) 1998 - 2007, The Regents of the University of California -// Produced at the Lawrence Livermore National Laboratory -// All rights reserved. -// -// This file is part of PyCXX. For details,see http://cxx.sourceforge.net/. The -// full copyright notice is contained in the file COPYRIGHT located at the root -// of the PyCXX distribution. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// - Redistributions of source code must retain the above copyright notice, -// this list of conditions and the disclaimer below. -// - Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the disclaimer (as noted below) in the -// documentation and/or materials provided with the distribution. -// - Neither the name of the UC/LLNL nor the names of its contributors may be -// used to endorse or promote products derived from this software without -// specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OF THE UNIVERSITY OF -// CALIFORNIA, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR -// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH -// DAMAGE. -// -//----------------------------------------------------------------------------- - -#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 -#include - -// This mimics the Python structure, in order to minimize confusion -namespace Py -{ - class ExtensionExceptionType; - - class Object; - - class Exception - { - public: - Exception( ExtensionExceptionType &exception, const std::string& reason ); - Exception( ExtensionExceptionType &exception, Object &reason ); - - explicit Exception () - {} - - 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 StandardError: public Exception - { - protected: - explicit StandardError() - {} - }; - - class LookupError: public StandardError - { - protected: - explicit LookupError() - {} - }; - - class ArithmeticError: public StandardError - { - protected: - explicit ArithmeticError() - {} - }; - - class EnvironmentError: public StandardError - { - protected: - explicit EnvironmentError() - {} - }; - - // Concrete - - class TypeError: public StandardError - { - public: - TypeError (const std::string& reason) - : StandardError() - { - PyErr_SetString (Py::_Exc_TypeError(),reason.c_str()); - } - }; - - class IndexError: public LookupError - { - public: - IndexError (const std::string& reason) - : LookupError() - { - PyErr_SetString (Py::_Exc_IndexError(), reason.c_str()); - } - }; - - class AttributeError: public StandardError - { - public: - AttributeError (const std::string& reason) - : StandardError() - { - PyErr_SetString (Py::_Exc_AttributeError(), reason.c_str()); - } - }; - - class NameError: public StandardError - { - public: - NameError (const std::string& reason) - : StandardError() - { - PyErr_SetString (Py::_Exc_NameError(), reason.c_str()); - } - }; - - class RuntimeError: public StandardError - { - public: - RuntimeError (const std::string& reason) - : StandardError() - { - PyErr_SetString (Py::_Exc_RuntimeError(), reason.c_str()); - } - }; - - class SystemError: public StandardError - { - public: - SystemError (const std::string& reason) - : StandardError() - { - PyErr_SetString (Py::_Exc_SystemError(),reason.c_str()); - } - }; - - class KeyError: public LookupError - { - public: - KeyError (const std::string& reason) - : LookupError() - { - PyErr_SetString (Py::_Exc_KeyError(),reason.c_str()); - } - }; - - - class ValueError: public StandardError - { - public: - ValueError (const std::string& reason) - : StandardError() - { - PyErr_SetString (Py::_Exc_ValueError(), reason.c_str()); - } - }; - - class OverflowError: public ArithmeticError - { - public: - OverflowError (const std::string& reason) - : ArithmeticError() - { - PyErr_SetString (Py::_Exc_OverflowError(), reason.c_str()); - } - }; - - class ZeroDivisionError: public ArithmeticError - { - public: - ZeroDivisionError (const std::string& reason) - : ArithmeticError() - { - PyErr_SetString (Py::_Exc_ZeroDivisionError(), reason.c_str()); - } - }; - - class FloatingPointError: public ArithmeticError - { - public: - FloatingPointError (const std::string& reason) - : ArithmeticError() - { - PyErr_SetString (Py::_Exc_FloatingPointError(), reason.c_str()); - } - }; - - class MemoryError: public StandardError - { - public: - MemoryError (const std::string& reason) - : StandardError() - { - PyErr_SetString (Py::_Exc_MemoryError(), reason.c_str()); - } - }; - - class SystemExit: public StandardError - { - public: - SystemExit (const std::string& reason) - : StandardError() - { - PyErr_SetString (Py::_Exc_SystemExit(),reason.c_str()); - } - }; - -}// Py - -#endif diff --git a/src/extension/script/CXX/Extensions.hxx b/src/extension/script/CXX/Extensions.hxx deleted file mode 100644 index 83738c9af..000000000 --- a/src/extension/script/CXX/Extensions.hxx +++ /dev/null @@ -1,791 +0,0 @@ -//----------------------------------------------------------------------------- -// -// Copyright (c) 1998 - 2007, The Regents of the University of California -// Produced at the Lawrence Livermore National Laboratory -// All rights reserved. -// -// This file is part of PyCXX. For details,see http://cxx.sourceforge.net/. The -// full copyright notice is contained in the file COPYRIGHT located at the root -// of the PyCXX distribution. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// - Redistributions of source code must retain the above copyright notice, -// this list of conditions and the disclaimer below. -// - Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the disclaimer (as noted below) in the -// documentation and/or materials provided with the distribution. -// - Neither the name of the UC/LLNL nor the names of its contributors may be -// used to endorse or promote products derived from this software without -// specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OF THE UNIVERSITY OF -// CALIFORNIA, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR -// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH -// DAMAGE. -// -//----------------------------------------------------------------------------- - -#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/Config.hxx" -#include "CXX/Objects.hxx" - -extern "C" -{ - extern PyObject py_object_initializer; -} - -#include -#include - -namespace Py -{ - class ExtensionModuleBase; - - // Make an Exception Type for use in raising custom exceptions - class 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 MethodTable - { - public: - MethodTable(); - virtual ~MethodTable(); - - void add(const char* method_name, PyCFunction f, const char* doc="", int flag=1); - PyMethodDef* table(); - - protected: - std::vector 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 - - extern "C" - { - typedef PyObject *(*method_varargs_call_handler_t)( PyObject *_self, PyObject *_args ); - typedef PyObject *(*method_keyword_call_handler_t)( PyObject *_self, PyObject *_args, PyObject *_dict ); - }; - - template - class MethodDefExt : public PyMethodDef - { - public: - typedef Object (T::*method_varargs_function_t)( const Tuple &args ); - typedef Object (T::*method_keyword_function_t)( const Tuple &args, const Dict &kws ); - - 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(_name); - ext_meth_def.ml_meth = _handler; - ext_meth_def.ml_flags = METH_VARARGS; - ext_meth_def.ml_doc = const_cast(_doc); - - ext_varargs_function = _function; - ext_keyword_function = NULL; - } - - 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(_name); - ext_meth_def.ml_meth = method_varargs_call_handler_t( _handler ); - ext_meth_def.ml_flags = METH_VARARGS|METH_KEYWORDS; - ext_meth_def.ml_doc = const_cast(_doc); - - ext_varargs_function = NULL; - ext_keyword_function = _function; - } - - ~MethodDefExt() - {} - - PyMethodDef ext_meth_def; - method_varargs_function_t ext_varargs_function; - method_keyword_function_t ext_keyword_function; - }; - - class 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_keyword( const std::string &_name, const Tuple &_args, const Dict &_keywords ) = 0; - virtual Object invoke_method_varargs( const std::string &_name, const Tuple &_args ) = 0; - - const std::string &name() const; - const std::string &fullName() const; - - protected: - // Initialize the module - void initialize( const char *module_doc ); - - const std::string module_name; - const std::string full_module_name; - MethodTable method_table; - - private: - - // - // prevent the compiler generating these unwanted functions - // - ExtensionModuleBase( const ExtensionModuleBase & ); //unimplemented - void operator=( const ExtensionModuleBase & ); //unimplemented - - }; - - extern "C" PyObject *method_keyword_call_handler( PyObject *_self_and_name_tuple, PyObject *_args, PyObject *_keywords ); - extern "C" PyObject *method_varargs_call_handler( PyObject *_self_and_name_tuple, PyObject *_args ); - extern "C" void do_not_dealloc( void * ); - - - template - class ExtensionModule : public ExtensionModuleBase - { - public: - ExtensionModule( const char *name ) - : ExtensionModuleBase( name ) - {} - virtual ~ExtensionModule() - {} - - protected: - 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 *> method_map_t; - - static void add_varargs_method( const char *name, method_varargs_function_t function, const char *doc="" ) - { - method_map_t &mm = methods(); - - MethodDefExt *method_definition = new MethodDefExt - ( - name, - function, - method_varargs_call_handler, - doc - ); - - mm[std::string( name )] = method_definition; - } - - static void add_keyword_method( const char *name, method_keyword_function_t function, const char *doc="" ) - { - method_map_t &mm = methods(); - - MethodDefExt *method_definition = new MethodDefExt - ( - name, - function, - method_keyword_call_handler, - doc - ); - - mm[std::string( name )] = method_definition; - } - - 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::iterator i; - - for( i=mm.begin(); i != mm.end(); ++i ) - { - MethodDefExt *method_definition = (*i).second; - - static PyObject *self = PyCObject_FromVoidPtr( this, do_not_dealloc ); - - Tuple args( 2 ); - args[0] = Object( self ); - args[1] = String( (*i).first ); - - PyObject *func = PyCFunction_New - ( - &method_definition->ext_meth_def, - new_reference_to( args ) - ); - - dict[ (*i).first ] = Object( func ); - } - } - - 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_keyword( const std::string &name, const Tuple &args, const Dict &keywords ) - { - method_map_t &mm = methods(); - MethodDefExt *meth_def = mm[ name ]; - if( meth_def == NULL ) - { - std::string error_msg( "CXX - cannot invoke keyword method named " ); - error_msg += name; - throw RuntimeError( error_msg ); - } - - // cast up to the derived class - T *self = static_cast(this); - - return (self->*meth_def->ext_keyword_function)( args, keywords ); - } - - // this invoke function must be called from within a try catch block - virtual Object invoke_method_varargs( const std::string &name, const Tuple &args ) - { - method_map_t &mm = methods(); - MethodDefExt *meth_def = mm[ name ]; - if( meth_def == NULL ) - { - std::string error_msg( "CXX - cannot invoke varargs method named " ); - error_msg += name; - throw RuntimeError( error_msg ); - } - - // cast up to the derived class - T *self = static_cast(this); - - return (self->*meth_def->ext_varargs_function)( args ); - } - - private: - // - // prevent the compiler generating these unwanted functions - // - ExtensionModule( const ExtensionModule & ); //unimplemented - void operator=( const ExtensionModule & ); //unimplemented - }; - - - class 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 & dealloc(void (*f)(PyObject*)); - - PythonType & supportPrint(void); - PythonType & supportGetattr(void); - PythonType & supportSetattr(void); - PythonType & supportGetattro(void); - PythonType & supportSetattro(void); - PythonType & supportCompare(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); - - protected: - PyTypeObject *table; - PySequenceMethods *sequence_table; - PyMappingMethods *mapping_table; - PyNumberMethods *number_table; - PyBufferProcs *buffer_table; - - void init_sequence(); - void init_mapping(); - void init_number(); - void init_buffer(); - - private: - // - // prevent the compiler generating these unwanted functions - // - PythonType (const PythonType& tb); // unimplemented - void operator=(const PythonType& t); // unimplemented - - }; // end of PythonType - - - - // Class PythonExtension is what you inherit from to create - // a new Python extension type. You give your class itself - // as the template paramter. - - // 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 PythonExtensionBase : public PyObject - { - public: - PythonExtensionBase(); - virtual ~PythonExtensionBase(); - - public: - virtual int print( FILE *, int ); - virtual Object getattr( const char * ) = 0; - virtual int setattr( const char *, const Object & ); - virtual Object getattro( const Object & ); - virtual int setattro( const Object &, const Object & ); - virtual int compare( const Object & ); - 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* ); - - private: - void missing_method( void ); - static PyObject *method_call_handler( PyObject *self, PyObject *args ); - }; - - template - class PythonExtension: public PythonExtensionBase - { - public: - static PyTypeObject* type_object() - { - return behaviors().type_object(); - } - - static int check( PyObject *p ) - { - // is p like me? - return p->ob_type == type_object(); - } - - static int 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 ); - } - - protected: - explicit PythonExtension() - : PythonExtensionBase() - { - #ifdef PyObject_INIT - (void)PyObject_INIT( this, type_object() ); - #else - ob_refcnt = 1; - ob_type = type_object(); - #endif - - // 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->dealloc( extension_object_deallocator ); - } - - return *p; - } - - - 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 *> 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(); - - if( name == "__methods__" ) - { - List methods; - - for( EXPLICIT_TYPENAME method_map_t::iterator i = mm.begin(); i != mm.end(); ++i ) - methods.append( String( (*i).first ) ); - - return methods; - } - - // see if name exists - if( mm.find( name ) == mm.end() ) - throw AttributeError( name ); - - Tuple self( 2 ); - - self[0] = Object( this ); - self[1] = String( name ); - - MethodDefExt *method_definition = mm[ name ]; - - PyObject *func = PyCFunction_New( &method_definition->ext_meth_def, self.ptr() ); - - return Object(func, true); - } - - static void add_varargs_method( const char *name, method_varargs_function_t function, const char *doc="" ) - { - method_map_t &mm = methods(); - - MethodDefExt *method_definition = new MethodDefExt - ( - name, - function, - method_varargs_call_handler, - doc - ); - - mm[std::string( name )] = method_definition; - } - - static void add_keyword_method( const char *name, method_keyword_function_t function, const char *doc="" ) - { - method_map_t &mm = methods(); - - MethodDefExt *method_definition = new MethodDefExt - ( - name, - function, - method_keyword_call_handler, - doc - ); - - mm[std::string( name )] = method_definition; - } - - 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; - } - - 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( self_in_cobject ); - - String name( self_and_name_tuple[1] ); - - method_map_t &mm = methods(); - MethodDefExt *meth_def = mm[ name ]; - if( meth_def == NULL ) - return 0; - - 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( Exception & ) - { - 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( self_in_cobject ); - - String name( self_and_name_tuple[1] ); - - method_map_t &mm = methods(); - MethodDefExt *meth_def = mm[ name ]; - if( meth_def == NULL ) - return 0; - - Tuple args( _args ); - - Object result; - - // TMM: 7Jun'01 - 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 cxx::RuntimeError( sErrMsg ); - throw cxx::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( Exception & ) - { - return 0; - } - } - - static void extension_object_deallocator ( PyObject* t ) - { - delete (T *)( t ); - } - - // - // prevent the compiler generating these unwanted functions - // - explicit PythonExtension( const PythonExtension& other ); - void operator=( const PythonExtension& rhs ); - }; - - // - // ExtensionObject is an Object that will accept only T's. - // - template - class ExtensionObject: public Object - { - public: - - explicit ExtensionObject ( PyObject *pyob ) - : Object( pyob ) - { - validate(); - } - - ExtensionObject( const ExtensionObject& 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 ) - return *this; - 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( ptr() ); - } - }; - -} // Namespace Py -// End of CXX_Extensions.h -#endif diff --git a/src/extension/script/CXX/IndirectPythonInterface.cxx b/src/extension/script/CXX/IndirectPythonInterface.cxx deleted file mode 100644 index 1ab83bd76..000000000 --- a/src/extension/script/CXX/IndirectPythonInterface.cxx +++ /dev/null @@ -1,583 +0,0 @@ -//----------------------------------------------------------------------------- -// -// Copyright (c) 1998 - 2007, The Regents of the University of California -// Produced at the Lawrence Livermore National Laboratory -// All rights reserved. -// -// This file is part of PyCXX. For details,see http://cxx.sourceforge.net/. The -// full copyright notice is contained in the file COPYRIGHT located at the root -// of the PyCXX distribution. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// - Redistributions of source code must retain the above copyright notice, -// this list of conditions and the disclaimer below. -// - Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the disclaimer (as noted below) in the -// documentation and/or materials provided with the distribution. -// - Neither the name of the UC/LLNL nor the names of its contributors may be -// used to endorse or promote products derived from this software without -// specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OF THE UNIVERSITY OF -// CALIFORNIA, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR -// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH -// DAMAGE. -// -//----------------------------------------------------------------------------- - -#include "CXX/IndirectPythonInterface.hxx" - -namespace Py -{ -bool _Buffer_Check( PyObject *op ) { return (op)->ob_type == _Buffer_Type(); } -bool _CFunction_Check( PyObject *op ) { return (op)->ob_type == _CFunction_Type(); } -bool _Class_Check( PyObject *op ) { return (op)->ob_type == _Class_Type(); } -bool _CObject_Check( PyObject *op ) { return (op)->ob_type == _CObject_Type(); } -bool _Complex_Check( PyObject *op ) { return (op)->ob_type == _Complex_Type(); } -bool _Dict_Check( PyObject *op ) { return (op)->ob_type == _Dict_Type(); } -bool _File_Check( PyObject *op ) { return (op)->ob_type == _File_Type(); } -bool _Float_Check( PyObject *op ) { return (op)->ob_type == _Float_Type(); } -bool _Function_Check( PyObject *op ) { return (op)->ob_type == _Function_Type(); } -bool _Instance_Check( PyObject *op ) { return (op)->ob_type == _Instance_Type(); } -bool _Int_Check( PyObject *op ) { return (op)->ob_type == _Int_Type(); } -bool _List_Check( PyObject *o ) { return o->ob_type == _List_Type(); } -bool _Long_Check( PyObject *op ) { return (op)->ob_type == _Long_Type(); } -bool _Method_Check( PyObject *op ) { return (op)->ob_type == _Method_Type(); } -bool _Module_Check( PyObject *op ) { return (op)->ob_type == _Module_Type(); } -bool _Range_Check( PyObject *op ) { return (op)->ob_type == _Range_Type(); } -bool _Slice_Check( PyObject *op ) { return (op)->ob_type == _Slice_Type(); } -bool _String_Check( PyObject *o ) { return o->ob_type == _String_Type(); } -bool _TraceBack_Check( PyObject *v ) { return (v)->ob_type == _TraceBack_Type(); } -bool _Tuple_Check( PyObject *op ) { return (op)->ob_type == _Tuple_Type(); } -bool _Type_Check( PyObject *op ) { return (op)->ob_type == _Type_Type(); } - -#if PY_MAJOR_VERSION >= 2 -bool _Unicode_Check( PyObject *op ) { return (op)->ob_type == _Unicode_Type(); } -#endif - - - -#if defined(PY_WIN32_DELAYLOAD_PYTHON_DLL) - -#if defined(MS_WINDOWS) -#include - - -static HMODULE python_dll; - -static PyObject *ptr__Exc_ArithmeticError = NULL; -static PyObject *ptr__Exc_AssertionError = NULL; -static PyObject *ptr__Exc_AttributeError = NULL; -static PyObject *ptr__Exc_EnvironmentError = NULL; -static PyObject *ptr__Exc_EOFError = NULL; -static PyObject *ptr__Exc_Exception = NULL; -static PyObject *ptr__Exc_FloatingPointError = NULL; -static PyObject *ptr__Exc_ImportError = NULL; -static PyObject *ptr__Exc_IndexError = NULL; -static PyObject *ptr__Exc_IOError = NULL; -static PyObject *ptr__Exc_KeyboardInterrupt = NULL; -static PyObject *ptr__Exc_KeyError = NULL; -static PyObject *ptr__Exc_LookupError = NULL; -static PyObject *ptr__Exc_MemoryError = NULL; -static PyObject *ptr__Exc_MemoryErrorInst = NULL; -static PyObject *ptr__Exc_NameError = NULL; -static PyObject *ptr__Exc_NotImplementedError = NULL; -static PyObject *ptr__Exc_OSError = NULL; -static PyObject *ptr__Exc_OverflowError = NULL; -static PyObject *ptr__Exc_RuntimeError = NULL; -static PyObject *ptr__Exc_StandardError = NULL; -static PyObject *ptr__Exc_SyntaxError = NULL; -static PyObject *ptr__Exc_SystemError = NULL; -static PyObject *ptr__Exc_SystemExit = NULL; -static PyObject *ptr__Exc_TypeError = NULL; -static PyObject *ptr__Exc_ValueError = NULL; -static PyObject *ptr__Exc_ZeroDivisionError = NULL; - -#ifdef MS_WINDOWS -static PyObject *ptr__Exc_WindowsError = NULL; -#endif - -#if PY_MAJOR_VERSION >= 2 -static PyObject *ptr__Exc_IndentationError = NULL; -static PyObject *ptr__Exc_TabError = NULL; -static PyObject *ptr__Exc_UnboundLocalError = NULL; -static PyObject *ptr__Exc_UnicodeError = NULL; -#endif - -static PyObject *ptr__PyNone = NULL; - -static PyTypeObject *ptr__Buffer_Type = NULL; -static PyTypeObject *ptr__CFunction_Type = NULL; -static PyTypeObject *ptr__Class_Type = NULL; -static PyTypeObject *ptr__CObject_Type = NULL; -static PyTypeObject *ptr__Complex_Type = NULL; -static PyTypeObject *ptr__Dict_Type = NULL; -static PyTypeObject *ptr__File_Type = NULL; -static PyTypeObject *ptr__Float_Type = NULL; -static PyTypeObject *ptr__Function_Type = NULL; -static PyTypeObject *ptr__Instance_Type = NULL; -static PyTypeObject *ptr__Int_Type = NULL; -static PyTypeObject *ptr__List_Type = NULL; -static PyTypeObject *ptr__Long_Type = NULL; -static PyTypeObject *ptr__Method_Type = NULL; -static PyTypeObject *ptr__Module_Type = NULL; -static PyTypeObject *ptr__Range_Type = NULL; -static PyTypeObject *ptr__Slice_Type = NULL; -static PyTypeObject *ptr__String_Type = NULL; -static PyTypeObject *ptr__TraceBack_Type = NULL; -static PyTypeObject *ptr__Tuple_Type = NULL; -static PyTypeObject *ptr__Type_Type = NULL; - -#if PY_MAJOR_VERSION >= 2 -static PyTypeObject *ptr__Unicode_Type = NULL; -#endif - -static int *ptr_Py_DebugFlag = NULL; -static int *ptr_Py_InteractiveFlag = NULL; -static int *ptr_Py_OptimizeFlag = NULL; -static int *ptr_Py_NoSiteFlag = NULL; -static int *ptr_Py_TabcheckFlag = NULL; -static int *ptr_Py_VerboseFlag = NULL; - -#if PY_MAJOR_VERSION >= 2 -static int *ptr_Py_UnicodeFlag = NULL; -#endif - -static char **ptr__Py_PackageContext = NULL; - -#ifdef Py_REF_DEBUG -int *ptr_Py_RefTotal; -#endif - - -//-------------------------------------------------------------------------------- -class GetAddressException -{ -public: - GetAddressException( const char *_name ) - : name( _name ) - {} - virtual ~GetAddressException() {} - const char *name; -}; - - -//-------------------------------------------------------------------------------- -static PyObject *GetPyObjectPointer_As_PyObjectPointer( const char *name ) -{ - FARPROC addr = GetProcAddress( python_dll, name ); - if( addr == NULL ) - throw GetAddressException( name ); - - return *(PyObject **)addr; -} - -static PyObject *GetPyObject_As_PyObjectPointer( const char *name ) -{ - FARPROC addr = GetProcAddress( python_dll, name ); - if( addr == NULL ) - throw GetAddressException( name ); - - return (PyObject *)addr; -} - -static PyTypeObject *GetPyTypeObjectPointer_As_PyTypeObjectPointer( const char *name ) -{ - FARPROC addr = GetProcAddress( python_dll, name ); - if( addr == NULL ) - throw GetAddressException( name ); - - return *(PyTypeObject **)addr; -} - -static PyTypeObject *GetPyTypeObject_As_PyTypeObjectPointer( const char *name ) -{ - FARPROC addr = GetProcAddress( python_dll, name ); - if( addr == NULL ) - throw GetAddressException( name ); - - return (PyTypeObject *)addr; -} - -static int *GetInt_as_IntPointer( const char *name ) -{ - FARPROC addr = GetProcAddress( python_dll, name ); - if( addr == NULL ) - throw GetAddressException( name ); - - return (int *)addr; -} - -static char **GetCharPointer_as_CharPointerPointer( const char *name ) -{ - FARPROC addr = GetProcAddress( python_dll, name ); - if( addr == NULL ) - throw GetAddressException( name ); - - return (char **)addr; -} - - -#ifdef _DEBUG -static const char python_dll_name_format[] = "PYTHON%1.1d%1.1d_D.DLL"; -#else -static const char python_dll_name_format[] = "PYTHON%1.1d%1.1d.DLL"; -#endif - -//-------------------------------------------------------------------------------- -bool InitialisePythonIndirectInterface() -{ - char python_dll_name[sizeof(python_dll_name_format)]; - - sprintf( python_dll_name, python_dll_name_format, PY_MAJOR_VERSION, PY_MINOR_VERSION ); - - python_dll = LoadLibrary( python_dll_name ); - if( python_dll == NULL ) - return false; - - try -{ -#ifdef Py_REF_DEBUG - ptr_Py_RefTotal = GetInt_as_IntPointer( "_Py_RefTotal" ); -#endif - ptr_Py_DebugFlag = GetInt_as_IntPointer( "Py_DebugFlag" ); - ptr_Py_InteractiveFlag = GetInt_as_IntPointer( "Py_InteractiveFlag" ); - ptr_Py_OptimizeFlag = GetInt_as_IntPointer( "Py_OptimizeFlag" ); - ptr_Py_NoSiteFlag = GetInt_as_IntPointer( "Py_NoSiteFlag" ); - ptr_Py_TabcheckFlag = GetInt_as_IntPointer( "Py_TabcheckFlag" ); - ptr_Py_VerboseFlag = GetInt_as_IntPointer( "Py_VerboseFlag" ); -#if PY_MAJOR_VERSION >= 2 - ptr_Py_UnicodeFlag = GetInt_as_IntPointer( "Py_UnicodeFlag" ); -#endif - ptr__Py_PackageContext = GetCharPointer_as_CharPointerPointer( "_Py_PackageContext" ); - - ptr__Exc_ArithmeticError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_ArithmeticError" ); - ptr__Exc_AssertionError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_AssertionError" ); - ptr__Exc_AttributeError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_AttributeError" ); - ptr__Exc_EnvironmentError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_EnvironmentError" ); - ptr__Exc_EOFError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_EOFError" ); - ptr__Exc_Exception = GetPyObjectPointer_As_PyObjectPointer( "PyExc_Exception" ); - ptr__Exc_FloatingPointError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_FloatingPointError" ); - ptr__Exc_ImportError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_ImportError" ); - ptr__Exc_IndexError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_IndexError" ); - ptr__Exc_IOError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_IOError" ); - ptr__Exc_KeyboardInterrupt = GetPyObjectPointer_As_PyObjectPointer( "PyExc_KeyboardInterrupt" ); - ptr__Exc_KeyError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_KeyError" ); - ptr__Exc_LookupError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_LookupError" ); - ptr__Exc_MemoryError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_MemoryError" ); - ptr__Exc_MemoryErrorInst = GetPyObjectPointer_As_PyObjectPointer( "PyExc_MemoryErrorInst" ); - ptr__Exc_NameError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_NameError" ); - ptr__Exc_NotImplementedError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_NotImplementedError" ); - ptr__Exc_OSError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_OSError" ); - ptr__Exc_OverflowError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_OverflowError" ); - ptr__Exc_RuntimeError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_RuntimeError" ); - ptr__Exc_StandardError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_StandardError" ); - ptr__Exc_SyntaxError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_SyntaxError" ); - ptr__Exc_SystemError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_SystemError" ); - ptr__Exc_SystemExit = GetPyObjectPointer_As_PyObjectPointer( "PyExc_SystemExit" ); - ptr__Exc_TypeError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_TypeError" ); - ptr__Exc_ValueError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_ValueError" ); -#ifdef MS_WINDOWS - ptr__Exc_WindowsError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_WindowsError" ); -#endif - ptr__Exc_ZeroDivisionError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_ZeroDivisionError" ); - -#if PY_MAJOR_VERSION >= 2 - ptr__Exc_IndentationError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_IndentationError" ); - ptr__Exc_TabError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_TabError" ); - ptr__Exc_UnboundLocalError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_UnboundLocalError" ); - ptr__Exc_UnicodeError = GetPyObjectPointer_As_PyObjectPointer( "PyExc_UnicodeError" ); -#endif - ptr__PyNone = GetPyObject_As_PyObjectPointer( "_Py_NoneStruct" ); - - ptr__Buffer_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyBuffer_Type" ); - ptr__CFunction_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyCFunction_Type" ); - ptr__Class_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyClass_Type" ); - ptr__CObject_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyCObject_Type" ); - ptr__Complex_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyComplex_Type" ); - ptr__Dict_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyDict_Type" ); - ptr__File_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyFile_Type" ); - ptr__Float_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyFloat_Type" ); - ptr__Function_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyFunction_Type" ); - ptr__Instance_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyInstance_Type" ); - ptr__Int_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyInt_Type" ); - ptr__List_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyList_Type" ); - ptr__Long_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyLong_Type" ); - ptr__Method_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyMethod_Type" ); - ptr__Module_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyModule_Type" ); - ptr__Range_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyRange_Type" ); - ptr__Slice_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PySlice_Type" ); - ptr__String_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyString_Type" ); - ptr__TraceBack_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyTraceBack_Type" ); - ptr__Tuple_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyTuple_Type" ); - ptr__Type_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyType_Type" ); - -#if PY_MAJOR_VERSION >= 2 - ptr__Unicode_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyUnicode_Type" ); -#endif -} - catch( GetAddressException &e ) - { - OutputDebugString( python_dll_name ); - OutputDebugString( " does not contain symbol "); - OutputDebugString( e.name ); - OutputDebugString( "\n" ); - - return false; - } - - return true; -} - -// -// Wrap variables as function calls -// -PyObject * _Exc_ArithmeticError(){ return ptr__Exc_ArithmeticError; } -PyObject * _Exc_AssertionError(){ return ptr__Exc_AssertionError; } -PyObject * _Exc_AttributeError(){ return ptr__Exc_AttributeError; } -PyObject * _Exc_EnvironmentError(){ return ptr__Exc_EnvironmentError; } -PyObject * _Exc_EOFError() { return ptr__Exc_EOFError; } -PyObject * _Exc_Exception() { return ptr__Exc_Exception; } -PyObject * _Exc_FloatingPointError(){ return ptr__Exc_FloatingPointError; } -PyObject * _Exc_ImportError() { return ptr__Exc_ImportError; } -PyObject * _Exc_IndexError() { return ptr__Exc_IndexError; } -PyObject * _Exc_IOError() { return ptr__Exc_IOError; } -PyObject * _Exc_KeyboardInterrupt(){ return ptr__Exc_KeyboardInterrupt; } -PyObject * _Exc_KeyError() { return ptr__Exc_KeyError; } -PyObject * _Exc_LookupError() { return ptr__Exc_LookupError; } -PyObject * _Exc_MemoryError() { return ptr__Exc_MemoryError; } -PyObject * _Exc_MemoryErrorInst(){ return ptr__Exc_MemoryErrorInst; } -PyObject * _Exc_NameError() { return ptr__Exc_NameError; } -PyObject * _Exc_NotImplementedError(){ return ptr__Exc_NotImplementedError; } -PyObject * _Exc_OSError() { return ptr__Exc_OSError; } -PyObject * _Exc_OverflowError() { return ptr__Exc_OverflowError; } -PyObject * _Exc_RuntimeError() { return ptr__Exc_RuntimeError; } -PyObject * _Exc_StandardError() { return ptr__Exc_StandardError; } -PyObject * _Exc_SyntaxError() { return ptr__Exc_SyntaxError; } -PyObject * _Exc_SystemError() { return ptr__Exc_SystemError; } -PyObject * _Exc_SystemExit() { return ptr__Exc_SystemExit; } -PyObject * _Exc_TypeError() { return ptr__Exc_TypeError; } -PyObject * _Exc_ValueError() { return ptr__Exc_ValueError; } -#ifdef MS_WINDOWS -PyObject * _Exc_WindowsError() { return ptr__Exc_WindowsError; } -#endif -PyObject * _Exc_ZeroDivisionError(){ return ptr__Exc_ZeroDivisionError; } - -#if PY_MAJOR_VERSION >= 2 -PyObject * _Exc_IndentationError(){ return ptr__Exc_IndentationError; } -PyObject * _Exc_TabError() { return ptr__Exc_TabError; } -PyObject * _Exc_UnboundLocalError(){ return ptr__Exc_UnboundLocalError; } -PyObject * _Exc_UnicodeError() { return ptr__Exc_UnicodeError; } -#endif - -// -// wrap items in Object.h -// -PyObject * _None() { return ptr__PyNone; } - - -PyTypeObject * _Buffer_Type() { return ptr__Buffer_Type; } -PyTypeObject * _CFunction_Type(){ return ptr__CFunction_Type; } -PyTypeObject * _Class_Type() { return ptr__Class_Type; } -PyTypeObject * _CObject_Type() { return ptr__CObject_Type; } -PyTypeObject * _Complex_Type() { return ptr__Complex_Type; } -PyTypeObject * _Dict_Type() { return ptr__Dict_Type; } -PyTypeObject * _File_Type() { return ptr__File_Type; } -PyTypeObject * _Float_Type() { return ptr__Float_Type; } -PyTypeObject * _Function_Type() { return ptr__Function_Type; } -PyTypeObject * _Instance_Type() { return ptr__Instance_Type; } -PyTypeObject * _Int_Type() { return ptr__Int_Type; } -PyTypeObject * _List_Type() { return ptr__List_Type; } -PyTypeObject * _Long_Type() { return ptr__Long_Type; } -PyTypeObject * _Method_Type() { return ptr__Method_Type; } -PyTypeObject * _Module_Type() { return ptr__Module_Type; } -PyTypeObject * _Range_Type() { return ptr__Range_Type; } -PyTypeObject * _Slice_Type() { return ptr__Slice_Type; } -PyTypeObject * _String_Type() { return ptr__String_Type; } -PyTypeObject * _TraceBack_Type(){ return ptr__TraceBack_Type; } -PyTypeObject * _Tuple_Type() { return ptr__Tuple_Type; } -PyTypeObject * _Type_Type() { return ptr__Type_Type; } - -#if PY_MAJOR_VERSION >= 2 -PyTypeObject * _Unicode_Type() { return ptr__Unicode_Type; } -#endif - -char *__Py_PackageContext() { return *ptr__Py_PackageContext; } - - -// -// wrap the Python Flag variables -// -int &_Py_DebugFlag() { return *ptr_Py_DebugFlag; } -int &_Py_InteractiveFlag() { return *ptr_Py_InteractiveFlag; } -int &_Py_OptimizeFlag() { return *ptr_Py_OptimizeFlag; } -int &_Py_NoSiteFlag() { return *ptr_Py_NoSiteFlag; } -int &_Py_TabcheckFlag() { return *ptr_Py_TabcheckFlag; } -int &_Py_VerboseFlag() { return *ptr_Py_VerboseFlag; } -#if PY_MAJOR_VERSION >= 2 -int &_Py_UnicodeFlag() { return *ptr_Py_UnicodeFlag; } -#endif - -void _XINCREF( PyObject *op ) -{ - // This function must match the contents of Py_XINCREF(op) - if( op == NULL ) - return; - -#ifdef Py_REF_DEBUG - (*ptr_Py_RefTotal)++; -#endif - (op)->ob_refcnt++; - -} - -void _XDECREF( PyObject *op ) -{ - // This function must match the contents of Py_XDECREF(op); - if( op == NULL ) - return; - -#ifdef Py_REF_DEBUG - (*ptr_Py_RefTotal)--; -#endif - - if (--(op)->ob_refcnt == 0) - _Py_Dealloc((PyObject *)(op)); -} - - -#else -#error "Can only delay load under Win32" -#endif - -#else - -// -// Duplicated these declarations from rangeobject.h which is missing the -// extern "C". This has been reported as a bug upto and include 2.1 -// -extern "C" DL_IMPORT(PyTypeObject) PyRange_Type; -extern "C" DL_IMPORT(PyObject *) PyRange_New(long, long, long, int); - - -//================================================================================ -// -// Map onto Macros -// -//================================================================================ - -// -// Wrap variables as function calls -// - -PyObject * _Exc_ArithmeticError() { return ::PyExc_ArithmeticError; } -PyObject * _Exc_AssertionError() { return ::PyExc_AssertionError; } -PyObject * _Exc_AttributeError() { return ::PyExc_AttributeError; } -PyObject * _Exc_EnvironmentError() { return ::PyExc_EnvironmentError; } -PyObject * _Exc_EOFError() { return ::PyExc_EOFError; } -PyObject * _Exc_Exception() { return ::PyExc_Exception; } -PyObject * _Exc_FloatingPointError() { return ::PyExc_FloatingPointError; } -PyObject * _Exc_ImportError() { return ::PyExc_ImportError; } -PyObject * _Exc_IndexError() { return ::PyExc_IndexError; } -PyObject * _Exc_IOError() { return ::PyExc_IOError; } -PyObject * _Exc_KeyboardInterrupt() { return ::PyExc_KeyboardInterrupt; } -PyObject * _Exc_KeyError() { return ::PyExc_KeyError; } -PyObject * _Exc_LookupError() { return ::PyExc_LookupError; } -PyObject * _Exc_MemoryError() { return ::PyExc_MemoryError; } -PyObject * _Exc_MemoryErrorInst() { return ::PyExc_MemoryErrorInst; } -PyObject * _Exc_NameError() { return ::PyExc_NameError; } -PyObject * _Exc_NotImplementedError() { return ::PyExc_NotImplementedError; } -PyObject * _Exc_OSError() { return ::PyExc_OSError; } -PyObject * _Exc_OverflowError() { return ::PyExc_OverflowError; } -PyObject * _Exc_RuntimeError() { return ::PyExc_RuntimeError; } -PyObject * _Exc_StandardError() { return ::PyExc_StandardError; } -PyObject * _Exc_SyntaxError() { return ::PyExc_SyntaxError; } -PyObject * _Exc_SystemError() { return ::PyExc_SystemError; } -PyObject * _Exc_SystemExit() { return ::PyExc_SystemExit; } -PyObject * _Exc_TypeError() { return ::PyExc_TypeError; } -PyObject * _Exc_ValueError() { return ::PyExc_ValueError; } -PyObject * _Exc_ZeroDivisionError() { return ::PyExc_ZeroDivisionError; } - -#ifdef MS_WINDOWS -PyObject * _Exc_WindowsError() { return ::PyExc_WindowsError; } -#endif - - -#if PY_MAJOR_VERSION >= 2 -PyObject * _Exc_IndentationError() { return ::PyExc_IndentationError; } -PyObject * _Exc_TabError() { return ::PyExc_TabError; } -PyObject * _Exc_UnboundLocalError() { return ::PyExc_UnboundLocalError; } -PyObject * _Exc_UnicodeError() { return ::PyExc_UnicodeError; } -#endif - - -// -// wrap items in Object.h -// -PyObject * _None() { return &::_Py_NoneStruct; } - -PyTypeObject * _Buffer_Type() { return &PyBuffer_Type; } -PyTypeObject * _CFunction_Type() { return &PyCFunction_Type; } -PyTypeObject * _Class_Type() { return &PyClass_Type; } -PyTypeObject * _CObject_Type() { return &PyCObject_Type; } -PyTypeObject * _Complex_Type() { return &PyComplex_Type; } -PyTypeObject * _Dict_Type() { return &PyDict_Type; } -PyTypeObject * _File_Type() { return &PyFile_Type; } -PyTypeObject * _Float_Type() { return &PyFloat_Type; } -PyTypeObject * _Function_Type() { return &PyFunction_Type; } -PyTypeObject * _Instance_Type() { return &PyInstance_Type; } -PyTypeObject * _Int_Type() { return &PyInt_Type; } -PyTypeObject * _List_Type() { return &PyList_Type; } -PyTypeObject * _Long_Type() { return &PyLong_Type; } -PyTypeObject * _Method_Type() { return &PyMethod_Type; } -PyTypeObject * _Module_Type() { return &PyModule_Type; } -PyTypeObject * _Range_Type() { return &PyRange_Type; } -PyTypeObject * _Slice_Type() { return &PySlice_Type; } -PyTypeObject * _String_Type() { return &PyString_Type; } -PyTypeObject * _TraceBack_Type() { return &PyTraceBack_Type; } -PyTypeObject * _Tuple_Type() { return &PyTuple_Type; } -PyTypeObject * _Type_Type() { return &PyType_Type; } - -#if PY_MAJOR_VERSION >= 2 -PyTypeObject * _Unicode_Type() { return &PyUnicode_Type; } -#endif - -// -// wrap flags -// -int &_Py_DebugFlag() { return Py_DebugFlag; } -int &_Py_InteractiveFlag(){ return Py_InteractiveFlag; } -int &_Py_OptimizeFlag() { return Py_OptimizeFlag; } -int &_Py_NoSiteFlag() { return Py_NoSiteFlag; } -int &_Py_TabcheckFlag() { return Py_TabcheckFlag; } -int &_Py_VerboseFlag() { return Py_VerboseFlag; } -#if PY_MAJOR_VERSION >= 2 -int &_Py_UnicodeFlag() { return Py_UnicodeFlag; } -#endif -char *__Py_PackageContext(){ return _Py_PackageContext; } - -// -// Needed to keep the abstactions for delayload interface -// -void _XINCREF( PyObject *op ) -{ - Py_XINCREF(op); -} - -void _XDECREF( PyObject *op ) -{ - Py_XDECREF(op); -} - -#endif -} diff --git a/src/extension/script/CXX/IndirectPythonInterface.hxx b/src/extension/script/CXX/IndirectPythonInterface.hxx deleted file mode 100644 index e8fccf570..000000000 --- a/src/extension/script/CXX/IndirectPythonInterface.hxx +++ /dev/null @@ -1,193 +0,0 @@ -//----------------------------------------------------------------------------- -// -// Copyright (c) 1998 - 2007, The Regents of the University of California -// Produced at the Lawrence Livermore National Laboratory -// All rights reserved. -// -// This file is part of PyCXX. For details,see http://cxx.sourceforge.net/. The -// full copyright notice is contained in the file COPYRIGHT located at the root -// of the PyCXX distribution. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// - Redistributions of source code must retain the above copyright notice, -// this list of conditions and the disclaimer below. -// - Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the disclaimer (as noted below) in the -// documentation and/or materials provided with the distribution. -// - Neither the name of the UC/LLNL nor the names of its contributors may be -// used to endorse or promote products derived from this software without -// specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OF THE UNIVERSITY OF -// CALIFORNIA, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR -// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH -// DAMAGE. -// -//----------------------------------------------------------------------------- - -#ifndef __CXX_INDIRECT_PYTHON_INTERFACE__HXX__ -#define __CXX_INDIRECT_PYTHON_INTERFACE__HXX__ - -#include "CXX/WrapPython.h" - -namespace Py -{ -bool InitialisePythonIndirectInterface(); - -// -// Wrap Exception variables as function calls -// -PyObject * _Exc_Exception(); -PyObject * _Exc_StandardError(); -PyObject * _Exc_ArithmeticError(); -PyObject * _Exc_LookupError(); - -PyObject * _Exc_AssertionError(); -PyObject * _Exc_AttributeError(); -PyObject * _Exc_EOFError(); -PyObject * _Exc_FloatingPointError(); -PyObject * _Exc_EnvironmentError(); -PyObject * _Exc_IOError(); -PyObject * _Exc_OSError(); -PyObject * _Exc_ImportError(); -PyObject * _Exc_IndexError(); -PyObject * _Exc_KeyError(); -PyObject * _Exc_KeyboardInterrupt(); -PyObject * _Exc_MemoryError(); -PyObject * _Exc_NameError(); -PyObject * _Exc_OverflowError(); -PyObject * _Exc_RuntimeError(); -PyObject * _Exc_NotImplementedError(); -PyObject * _Exc_SyntaxError(); -PyObject * _Exc_SystemError(); -PyObject * _Exc_SystemExit(); -PyObject * _Exc_TypeError(); -PyObject * _Exc_ValueError(); -PyObject * _Exc_ZeroDivisionError(); -#ifdef MS_WINDOWS -PyObject * _Exc_WindowsError(); -#endif - -PyObject * _Exc_MemoryErrorInst(); - -#if PY_MAJOR_VERSION >= 2 -PyObject * _Exc_IndentationError(); -PyObject * _Exc_TabError(); -PyObject * _Exc_UnboundLocalError(); -PyObject * _Exc_UnicodeError(); -#endif - -// -// Wrap Object variables as function calls -// -PyObject * _None(); - - -// -// Wrap Type variables as function calls -// -PyTypeObject * _List_Type(); -bool _List_Check( PyObject *o ); - -PyTypeObject * _Buffer_Type(); -bool _Buffer_Check( PyObject *op ); - -PyTypeObject * _Class_Type(); -bool _Class_Check( PyObject *op ); - -PyTypeObject * _Instance_Type(); -bool _Instance_Check( PyObject *op ); - -PyTypeObject * _Method_Type(); -bool _Method_Check( PyObject *op ); - -PyTypeObject * _CObject_Type(); -bool _CObject_Check( PyObject *op ); - -PyTypeObject * _Complex_Type(); -bool _Complex_Check( PyObject *op ); - -PyTypeObject * _Dict_Type(); -bool _Dict_Check( PyObject *op ); - -PyTypeObject * _File_Type(); -bool _File_Check( PyObject *op ); - -PyTypeObject * _Float_Type(); -bool _Float_Check( PyObject *op ); - -PyTypeObject * _Frame_Type(); -bool _Frame_Check( PyObject *op ); - -PyTypeObject * _Function_Type(); -bool _Function_Check( PyObject *op ); - -PyTypeObject * _Int_Type(); -bool _Int_Check( PyObject *op ); - -PyTypeObject * _List_Type(); -bool _List_Check( PyObject *op ); - -PyTypeObject * _Long_Type(); -bool _Long_Check( PyObject *op ); - -PyTypeObject * _CFunction_Type(); -bool _CFunction_Check( PyObject *op ); - -PyTypeObject * _Module_Type(); -bool _Module_Check( PyObject *op ); - -PyTypeObject * _Type_Type(); -bool _Type_Check( PyObject *op ); - -PyTypeObject * _Range_Type(); -bool _Range_Check( PyObject *op ); - -PyTypeObject * _Slice_Type(); -bool _Slice_Check( PyObject *op ); - -PyTypeObject * _String_Type(); -bool _String_Check( PyObject *op ); - -PyTypeObject * _Unicode_Type(); -bool _Unicode_Check( PyObject *op ); - -PyTypeObject * _TraceBack_Type(); -bool _TraceBack_Check( PyObject *v ); - -PyTypeObject * _Tuple_Type(); -bool _Tuple_Check( PyObject *op ); - -#if PY_MAJOR_VERSION >= 2 -PyTypeObject * _Unicode_Type(); -bool _Unicode_Check( PyObject *op ); -#endif - -int &_Py_DebugFlag(); -int &_Py_InteractiveFlag(); -int &_Py_OptimizeFlag(); -int &_Py_NoSiteFlag(); -int &_Py_TabcheckFlag(); -int &_Py_VerboseFlag(); - -#if PY_MAJOR_VERSION >= 2 -int &_Py_UnicodeFlag(); -#endif - -void _XINCREF( PyObject *op ); -void _XDECREF( PyObject *op ); - -char *__Py_PackageContext(); -}; - -#endif // __CXX_INDIRECT_PYTHON_INTERFACE__HXX__ diff --git a/src/extension/script/CXX/Objects.hxx b/src/extension/script/CXX/Objects.hxx deleted file mode 100644 index 30dc085b8..000000000 --- a/src/extension/script/CXX/Objects.hxx +++ /dev/null @@ -1,3019 +0,0 @@ -//----------------------------------------------------------------------------- -// -// Copyright (c) 1998 - 2007, The Regents of the University of California -// Produced at the Lawrence Livermore National Laboratory -// All rights reserved. -// -// This file is part of PyCXX. For details,see http://cxx.sourceforge.net/. The -// full copyright notice is contained in the file COPYRIGHT located at the root -// of the PyCXX distribution. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// - Redistributions of source code must retain the above copyright notice, -// this list of conditions and the disclaimer below. -// - Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the disclaimer (as noted below) in the -// documentation and/or materials provided with the distribution. -// - Neither the name of the UC/LLNL nor the names of its contributors may be -// used to endorse or promote products derived from this software without -// specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OF THE UNIVERSITY OF -// CALIFORNIA, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR -// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH -// DAMAGE. -// -//----------------------------------------------------------------------------- - -#ifndef __CXX_Objects__h -#define __CXX_Objects__h - -#include "CXX/WrapPython.h" -#include "CXX/Version.hxx" -#include "CXX/Config.hxx" -#include "CXX/Exception.hxx" - -#include -#include STR_STREAM -#include -#include -#include -#include - -namespace Py -{ - typedef int sequence_index_type; // type of an index into a sequence - - // Forward declarations - class Object; - class Type; - template class SeqBase; - class String; - class List; - template class MapBase; - - // new_reference_to also overloaded below on Object - inline PyObject* new_reference_to(PyObject* p) - { - Py::_XINCREF(p); - return p; - } - - // returning Null() from an extension method triggers a - // Python exception - inline PyObject* Null() - { - return (static_cast(0)); - } - - //===========================================================================// - // class Object - // The purpose of this class is to serve as the most general kind of - // Python object, for the purpose of writing C++ extensions in Python - // Objects hold a PyObject* which they own. This pointer is always a - // valid pointer to a Python object. In children we must maintain this behavior. - // - // Instructions on how to make your own class MyType descended from Object: - // (0) Pick a base class, either Object or perhaps SeqBase or MapBase. - // This example assumes Object. - - // (1) Write a routine int MyType_Check (PyObject *) modeled after PyInt_Check, - // PyFloat_Check, etc. - - // (2) Add method accepts: - // virtual bool accepts (PyObject *pyob) const { - // return pyob && MyType_Check (pyob); - // } - - // (3) Include the following constructor and copy constructor - // - /* - explicit MyType (PyObject *pyob): Object(pyob) { - validate(); -} - - MyType(const Object& other): Object(other.ptr()) { - validate(); -} - */ - - // Alernate version for the constructor to allow for construction from owned pointers: - /* - explicit MyType (PyObject *pyob): Object(pyob) { - validate(); -} - */ - - // You may wish to add other constructors; see the classes below for examples. - // Each constructor must use "set" to set the pointer - // and end by validating the pointer you have created. - - // (4) Each class needs at least these two assignment operators: - /* - MyType& operator= (const Object& rhs) { - return (*this = *rhs); -} - - Mytype& operator= (PyObject* rhsp) { - if(ptr() == rhsp) return *this; - set(rhsp); - return *this; -} - */ - // Note on accepts: constructors call the base class - // version of a virtual when calling the base class constructor, - // so the test has to be done explicitly in a descendent. - - // If you are inheriting from PythonExtension to define an object - // note that it contains PythonExtension::check - // which you can use in accepts when writing a wrapper class. - // See Demo/range.h and Demo/range.cxx for an example. - - class Object - { - private: - // the pointer to the Python object - // Only Object sets this directly. - // The default constructor for Object sets it to Py_None and - // child classes must use "set" to set it - // - PyObject* p; - - protected: - - void set (PyObject* pyob, bool owned = false) - { - release(); - p = pyob; - if (!owned) - { - Py::_XINCREF (p); - } - validate(); - } - - void release () - { - Py::_XDECREF (p); - p = 0; - } - - void validate() - { - // release pointer if not the right type - if (! accepts (p)) - { - release (); - if(PyErr_Occurred()) - { // Error message already set - throw Exception(); - } - // Better error message if RTTI available -#if defined( _CPPRTTI ) || defined(__GNUG__) - std::string s("CXX : Error creating object of type "); - s += (typeid (*this)).name(); - throw TypeError (s); -#else - throw TypeError ("CXX: type error."); -#endif - } - } - - public: - // Constructor acquires new ownership of pointer unless explicitly told not to. - explicit Object (PyObject* pyob=Py::_None(), bool owned = false): p (pyob) - { - if(!owned) - { - Py::_XINCREF (p); - } - validate(); - } - - // Copy constructor acquires new ownership of pointer - Object (const Object& ob): p(ob.p) - { - Py::_XINCREF (p); - validate(); - } - - // Assignment acquires new ownership of pointer - Object& operator= (const Object& rhs) - { - set(rhs.p); - return *this; - } - - Object& operator= (PyObject* rhsp) - { - if(ptr() == rhsp) return *this; - set (rhsp); - return *this; - } - - // Destructor - virtual ~Object () - { - release (); - } - - // Loaning the pointer to others, retain ownership - PyObject* operator* () const - { - return p; - } - - // Explicit reference_counting changes - void increment_reference_count() - { - Py::_XINCREF(p); - } - - void decrement_reference_count() - { - // not allowed to commit suicide, however - if(reference_count() == 1) - throw RuntimeError("Object::decrement_reference_count error."); - Py::_XDECREF(p); - } - // Would like to call this pointer() but messes up STL in SeqBase - PyObject* ptr () const - { - return p; - } - - // - // Queries - // - - // Can pyob be used in this object's constructor? - virtual bool accepts (PyObject *pyob) const - { - return (pyob != 0); - } - - Py_ssize_t reference_count () const - { // the reference count - return p ? p->ob_refcnt : 0; - } - - Type type () const; // the type object associated with this one - - String str () const; // the str() representation - - std::string as_string() const; - - String repr () const; // the repr () representation - - List dir () const; // the dir() list - - bool hasAttr (const std::string& s) const - { - return PyObject_HasAttrString (p, const_cast(s.c_str())) ? true: false; - } - - Object getAttr (const std::string& s) const - { - return Object (PyObject_GetAttrString (p, const_cast(s.c_str())), true); - } - - Object getItem (const Object& key) const - { - return Object (PyObject_GetItem(p, *key), true); - } - - long hashValue () const - { - return PyObject_Hash (p); - } - - // - // int print (FILE* fp, int flags=Py_Print_RAW) - //{ - // return PyObject_Print (p, fp, flags); - //} - // - bool is(PyObject *pother) const - { // identity test - return p == pother; - } - - bool is(const Object& other) const - { // identity test - return p == other.p; - } - - bool isNone() const - { - return p == Py_None; - } - - bool isCallable () const - { - return PyCallable_Check (p) != 0; - } - - bool isInstance () const - { - return PyInstance_Check (p) != 0; - } - - bool isDict () const - { - return Py::_Dict_Check (p); - } - - bool isList () const - { - return Py::_List_Check (p); - } - - bool isMapping () const - { - return PyMapping_Check (p) != 0; - } - - bool isNumeric () const - { - return PyNumber_Check (p) != 0; - } - - bool isSequence () const - { - return PySequence_Check (p) != 0; - } - - bool isTrue () const - { - return PyObject_IsTrue (p) != 0; - } - - bool isType (const Type& t) const; - - bool isTuple() const - { - return Py::_Tuple_Check(p); - } - - bool isString() const - { - return Py::_String_Check(p) || Py::_Unicode_Check(p); - } - - bool isUnicode() const - { - return Py::_Unicode_Check(p); - } - - // Commands - void setAttr (const std::string& s, const Object& value) - { - if(PyObject_SetAttrString (p, const_cast(s.c_str()), *value) == -1) - throw AttributeError ("getAttr failed."); - } - - void delAttr (const std::string& s) - { - if(PyObject_DelAttrString (p, const_cast(s.c_str())) == -1) - throw AttributeError ("delAttr failed."); - } - - // PyObject_SetItem is too weird to be using from C++ - // so it is intentionally omitted. - - void delItem (const Object& key) - { - //if(PyObject_DelItem(p, *key) == -1) - // failed to link on Windows? - throw KeyError("delItem failed."); - } - // Equality and comparison use PyObject_Compare - - bool operator==(const Object& o2) const - { - int k = PyObject_Compare (p, *o2); - if (PyErr_Occurred()) throw Exception(); - return k == 0; - } - - bool operator!=(const Object& o2) const - { - int k = PyObject_Compare (p, *o2); - if (PyErr_Occurred()) throw Exception(); - return k != 0; - - } - - bool operator>=(const Object& o2) const - { - int k = PyObject_Compare (p, *o2); - if (PyErr_Occurred()) throw Exception(); - return k >= 0; - } - - bool operator<=(const Object& o2) const - { - int k = PyObject_Compare (p, *o2); - if (PyErr_Occurred()) throw Exception(); - return k <= 0; - } - - bool operator<(const Object& o2) const - { - int k = PyObject_Compare (p, *o2); - if (PyErr_Occurred()) throw Exception(); - return k < 0; - } - - bool operator>(const Object& o2) const - { - int k = PyObject_Compare (p, *o2); - if (PyErr_Occurred()) throw Exception(); - return k > 0; - } - }; - // End of class Object - inline PyObject* new_reference_to(const Object& g) - { - PyObject* p = g.ptr(); - Py::_XINCREF(p); - return p; - } - - // Nothing() is what an extension method returns if - // there is no other return value. - inline Object Nothing() - { - return Object(Py::_None()); - } - - // Python special None value - inline Object None() - { - return Object(Py::_None()); - } - - // TMM: 31May'01 - Added the #ifndef so I can exlude iostreams. -#ifndef CXX_NO_IOSTREAMS - std::ostream& operator<< (std::ostream& os, const Object& ob); -#endif - - // Class Type - class Type: public Object - { - public: - explicit Type (PyObject* pyob, bool owned = false): Object(pyob, owned) - { - validate(); - } - - Type (const Object& ob): Object(*ob) - { - validate(); - } - - Type(const Type& t): Object(t) - { - validate(); - } - - Type& operator= (const Object& rhs) - { - return (*this = *rhs); - } - - Type& operator= (PyObject* rhsp) - { - if(ptr() == rhsp) return *this; - set (rhsp); - return *this; - } - virtual bool accepts (PyObject *pyob) const - { - return pyob && Py::_Type_Check (pyob); - } - }; - - - // - // Convert an owned Python pointer into a CXX Object - // - inline Object asObject (PyObject *p) - { - return Object(p, true); - } - - - - - // =============================================== - // class Int - class Int: public Object - { - public: - // Constructor - Int (PyObject *pyob, bool owned = false): Object (pyob, owned) - { - validate(); - } - - Int (const Int& ob): Object(*ob) - { - validate(); - } - - // create from long - Int (long v = 0L): Object(PyInt_FromLong(v), true) - { - validate(); - } - -#ifdef HAVE_LONG_LONG - // create from long long - Int (PY_LONG_LONG v): Object(PyLong_FromLongLong(v), true) - { - validate(); - } - // create from unsigned long long - Int (unsigned PY_LONG_LONG v): Object(PyLong_FromUnsignedLongLong(v), true) - { - validate(); - } -#endif - - // create from int - Int (int v) - { - long w = v; - set(PyInt_FromLong(w), true); - validate(); - } - - // create from bool - Int (bool v) - { - long w = v ? 1 : 0; - set(PyInt_FromLong(w), true); - validate(); - } - - explicit Int (const Object& ob) - { - set(PyNumber_Int(*ob), true); - validate(); - } - - // Assignment acquires new ownership of pointer - - Int& operator= (const Object& rhs) - { - return (*this = *rhs); - } - - Int& operator= (PyObject* rhsp) - { - if(ptr() == rhsp) return *this; - set (PyNumber_Int(rhsp), true); - return *this; - } - - // Membership - virtual bool accepts (PyObject *pyob) const - { - return pyob && Py::_Int_Check (pyob); - } - - // convert to long - operator long() const - { - return PyInt_AsLong (ptr()); - } - -#ifdef HAVE_LONG_LONG - // convert to long long - PY_LONG_LONG asLongLong() const - { - return PyLong_AsLongLong (ptr()); - } - // convert to unsigned long long - unsigned PY_LONG_LONG asUnsignedLongLong() const - { - return PyLong_AsUnsignedLongLong (ptr()); - } -#endif - - // assign from an int - Int& operator= (int v) - { - set (PyInt_FromLong (long(v)), true); - return *this; - } - - // assign from long - Int& operator= (long v) - { - set (PyInt_FromLong (v), true); - return *this; - } - -#ifdef HAVE_LONG_LONG - // assign from long long - Int& operator= (PY_LONG_LONG v) - { - set (PyLong_FromLongLong (v), true); - return *this; - } - // assign from unsigned long long - Int& operator= (unsigned PY_LONG_LONG v) - { - set (PyLong_FromUnsignedLongLong (v), true); - return *this; - } -#endif - }; - - // =============================================== - // class Long - class Long: public Object - { - public: - // Constructor - explicit Long (PyObject *pyob, bool owned = false): Object (pyob, owned) - { - validate(); - } - - Long (const Long& ob): Object(ob.ptr()) - { - validate(); - } - - // create from long - explicit Long (long v = 0L) - : Object(PyLong_FromLong(v), true) - { - validate(); - } - // create from unsigned long - explicit Long (unsigned long v) - : Object(PyLong_FromUnsignedLong(v), true) - { - validate(); - } - // create from int - explicit Long (int v) - : Object(PyLong_FromLong(static_cast(v)), true) - { - validate(); - } - - // try to create from any object - Long (const Object& ob) - : Object(PyNumber_Long(*ob), true) - { - validate(); - } - - // Assignment acquires new ownership of pointer - - Long& operator= (const Object& rhs) - { - return (*this = *rhs); - } - - Long& operator= (PyObject* rhsp) - { - if(ptr() == rhsp) return *this; - set (PyNumber_Long(rhsp), true); - return *this; - } - // Membership - virtual bool accepts (PyObject *pyob) const - { - return pyob && Py::_Long_Check (pyob); - } - // convert to long - operator long() const - { - return PyLong_AsLong (ptr()); - } - // convert to unsigned - operator unsigned long() const - { - return PyLong_AsUnsignedLong (ptr()); - } - operator double() const - { - return PyLong_AsDouble (ptr()); - } - // assign from an int - Long& operator= (int v) - { - set(PyLong_FromLong (long(v)), true); - return *this; - } - // assign from long - Long& operator= (long v) - { - set(PyLong_FromLong (v), true); - return *this; - } - // assign from unsigned long - Long& operator= (unsigned long v) - { - set(PyLong_FromUnsignedLong (v), true); - return *this; - } - }; - -#ifdef HAVE_LONG_LONG - // =============================================== - // class LongLong - class LongLong: public Object - { - public: - // Constructor - explicit LongLong (PyObject *pyob, bool owned = false): Object (pyob, owned) - { - validate(); - } - - LongLong (const LongLong& ob): Object(ob.ptr()) - { - validate(); - } - // create from long long - explicit LongLong (long long v = 0L) - : Object(PyLong_FromLongLong(v), true) - { - validate(); - } - // create from unsigned long long - explicit LongLong (unsigned long long v) - : Object(PyLong_FromUnsignedLongLong(v), true) - { - validate(); - } - // create from long - explicit LongLong (long v) - : Object(PyLong_FromLongLong(v), true) - { - validate(); - } - // create from unsigned long - explicit LongLong (unsigned long v) - : Object(PyLong_FromUnsignedLongLong(v), true) - { - validate(); - } - // create from int - explicit LongLong (int v) - : Object(PyLong_FromLongLong(static_cast(v)), true) - { - validate(); - } - - // try to create from any object - LongLong (const Object& ob) - : Object(PyNumber_Long(*ob), true) - { - validate(); - } - - // Assignment acquires new ownership of pointer - - LongLong& operator= (const Object& rhs) - { - return (*this = *rhs); - } - - LongLong& operator= (PyObject* rhsp) - { - if(ptr() == rhsp) return *this; - set (PyNumber_Long(rhsp), true); - return *this; - } - // Membership - virtual bool accepts (PyObject *pyob) const - { - return pyob && Py::_Long_Check (pyob); - } - // convert to long long - operator long long() const - { - return PyLong_AsLongLong (ptr()); - } - // convert to unsigned long - operator unsigned long long() const - { - return PyLong_AsUnsignedLongLong (ptr()); - } - // convert to long - operator long() const - { - return PyLong_AsLong (ptr()); - } - // convert to unsigned - operator unsigned long() const - { - return PyLong_AsUnsignedLong (ptr()); - } - operator double() const - { - return PyLong_AsDouble (ptr()); - } - // assign from an int - LongLong& operator= (int v) - { - set(PyLong_FromLongLong (long(v)), true); - return *this; - } - // assign from long long - LongLong& operator= (long long v) - { - set(PyLong_FromLongLong (v), true); - return *this; - } - // assign from unsigned long long - LongLong& operator= (unsigned long long v) - { - set(PyLong_FromUnsignedLongLong (v), true); - return *this; - } - // assign from long - LongLong& operator= (long v) - { - set(PyLong_FromLongLong (v), true); - return *this; - } - // assign from unsigned long - LongLong& operator= (unsigned long v) - { - set(PyLong_FromUnsignedLongLong (v), true); - return *this; - } - }; -#endif - - // =============================================== - // class Float - // - class Float: public Object - { - public: - // Constructor - explicit Float (PyObject *pyob, bool owned = false): Object(pyob, owned) - { - validate(); - } - - Float (const Float& f): Object(f) - { - validate(); - } - - // make from double - explicit Float (double v=0.0) - : Object(PyFloat_FromDouble (v), true) - { - validate(); - } - - // try to make from any object - Float (const Object& ob) - : Object(PyNumber_Float(*ob), true) - { - validate(); - } - - Float& operator= (const Object& rhs) - { - return (*this = *rhs); - } - - Float& operator= (PyObject* rhsp) - { - if(ptr() == rhsp) return *this; - set (PyNumber_Float(rhsp), true); - return *this; - } - // Membership - virtual bool accepts (PyObject *pyob) const - { - return pyob && Py::_Float_Check (pyob); - } - // convert to double - operator double () const - { - return PyFloat_AsDouble (ptr()); - } - // assign from a double - Float& operator= (double v) - { - set(PyFloat_FromDouble (v), true); - return *this; - } - // assign from an int - Float& operator= (int v) - { - set(PyFloat_FromDouble (double(v)), true); - return *this; - } - // assign from long - Float& operator= (long v) - { - set(PyFloat_FromDouble (double(v)), true); - return *this; - } - // assign from an Int - Float& operator= (const Int& iob) - { - set(PyFloat_FromDouble (double(long(iob))), true); - return *this; - } - }; - - // =============================================== - // class Complex - class Complex: public Object - { - public: - // Constructor - explicit Complex (PyObject *pyob, bool owned = false): Object(pyob, owned) - { - validate(); - } - - Complex (const Complex& f): Object(f) - { - validate(); - } - - // make from double - explicit Complex (double v=0.0, double w=0.0) - :Object(PyComplex_FromDoubles (v, w), true) - { - validate(); - } - - Complex& operator= (const Object& rhs) - { - return (*this = *rhs); - } - - Complex& operator= (PyObject* rhsp) - { - if(ptr() == rhsp) return *this; - set (rhsp); - return *this; - } - // Membership - virtual bool accepts (PyObject *pyob) const - { - return pyob && Py::_Complex_Check (pyob); - } - // convert to Py_complex - operator Py_complex () const - { - return PyComplex_AsCComplex (ptr()); - } - // assign from a Py_complex - Complex& operator= (const Py_complex& v) - { - set(PyComplex_FromCComplex (v), true); - return *this; - } - // assign from a double - Complex& operator= (double v) - { - set(PyComplex_FromDoubles (v, 0.0), true); - return *this; - } - // assign from an int - Complex& operator= (int v) - { - set(PyComplex_FromDoubles (double(v), 0.0), true); - return *this; - } - // assign from long - Complex& operator= (long v) - { - set(PyComplex_FromDoubles (double(v), 0.0), true); - return *this; - } - // assign from an Int - Complex& operator= (const Int& iob) - { - set(PyComplex_FromDoubles (double(long(iob)), 0.0), true); - return *this; - } - - double real() const - { - return PyComplex_RealAsDouble(ptr()); - } - - double imag() const - { - return PyComplex_ImagAsDouble(ptr()); - } - }; - // Sequences - // Sequences are here represented as sequences of items of type T. - // The base class SeqBase represents that. - // In basic Python T is always "Object". - - // seqref is what you get if you get elements from a non-const SeqBase. - // Note: seqref could probably be a nested class in SeqBase but that might stress - // some compilers needlessly. Simlarly for mapref later. - - // While this class is not intended for enduser use, it needs some public - // constructors for the benefit of the STL. - - // See Scott Meyer's More Essential C++ for a description of proxies. - // This application is even more complicated. We are doing an unusual thing - // in having a double proxy. If we want the STL to work - // properly we have to compromise by storing the rvalue inside. The - // entire Object API is repeated so that things like s[i].isList() will - // work properly. - - // Still, once in a while a weird compiler message may occur using expressions like x[i] - // Changing them to Object(x[i]) helps the compiler to understand that the - // conversion of a seqref to an Object is wanted. - - template - class seqref - { - protected: - SeqBase& s; // the sequence - int offset; // item number - T the_item; // lvalue - public: - - seqref (SeqBase& seq, sequence_index_type j) - : s(seq), offset(j), the_item (s.getItem(j)) - {} - - seqref (const seqref& range) - : s(range.s), offset(range.offset), the_item(range.the_item) - {} - - // TMM: added this seqref ctor for use with STL algorithms - seqref (Object& obj) - : s(dynamic_cast< SeqBase&>(obj)) - , offset( NULL ) - , the_item(s.getItem(offset)) - {} - ~seqref() - {} - - operator T() const - { // rvalue - return the_item; - } - - seqref& operator=(const seqref& rhs) - { //used as lvalue - the_item = rhs.the_item; - s.setItem(offset, the_item); - return *this; - } - - seqref& operator=(const T& ob) - { // used as lvalue - the_item = ob; - s.setItem(offset, ob); - return *this; - } - - // forward everything else to the item - PyObject* ptr () const - { - return the_item.ptr(); - } - - int reference_count () const - { // the reference count - return the_item.reference_count(); - } - - Type type () const - { - return the_item.type(); - } - - String str () const; - - String repr () const; - - bool hasAttr (const std::string& attr_name) const - { - return the_item.hasAttr(attr_name); - } - - Object getAttr (const std::string& attr_name) const - { - return the_item.getAttr(attr_name); - } - - Object getItem (const Object& key) const - { - return the_item.getItem(key); - } - - long hashValue () const - { - return the_item.hashValue(); - } - - bool isCallable () const - { - return the_item.isCallable(); - } - - bool isInstance () const - { - return the_item.isInstance(); - } - - bool isDict () const - { - return the_item.isDict(); - } - - bool isList () const - { - return the_item.isList(); - } - - bool isMapping () const - { - return the_item.isMapping(); - } - - bool isNumeric () const - { - return the_item.isNumeric(); - } - - bool isSequence () const - { - return the_item.isSequence(); - } - - bool isTrue () const - { - return the_item.isTrue(); - } - - bool isType (const Type& t) const - { - return the_item.isType (t); - } - - bool isTuple() const - { - return the_item.isTuple(); - } - - bool isString() const - { - return the_item.isString(); - } - // Commands - void setAttr (const std::string& attr_name, const Object& value) - { - the_item.setAttr(attr_name, value); - } - - void delAttr (const std::string& attr_name) - { - the_item.delAttr(attr_name); - } - - void delItem (const Object& key) - { - the_item.delItem(key); - } - - bool operator==(const Object& o2) const - { - return the_item == o2; - } - - bool operator!=(const Object& o2) const - { - return the_item != o2; - } - - bool operator>=(const Object& o2) const - { - return the_item >= o2; - } - - bool operator<=(const Object& o2) const - { - return the_item <= o2; - } - - bool operator<(const Object& o2) const - { - return the_item < o2; - } - - bool operator>(const Object& o2) const - { - return the_item > o2; - } - }; // end of seqref - - - // class SeqBase - // ...the base class for all sequence types - - template - class SeqBase: public Object - { - public: - // STL definitions - typedef size_t size_type; - typedef seqref reference; - typedef T const_reference; - typedef seqref* pointer; - typedef int difference_type; - typedef T value_type; // TMM: 26Jun'01 - - virtual size_type max_size() const - { - return std::string::npos; // ? - } - - virtual size_type capacity() const - { - return size(); - } - - virtual void swap(SeqBase& c) - { - SeqBase temp = c; - c = ptr(); - set(temp.ptr()); - } - - virtual size_type size () const - { - return PySequence_Length (ptr()); - } - - explicit SeqBase () - :Object(PyTuple_New(0), true) - { - validate(); - } - - explicit SeqBase (PyObject* pyob, bool owned=false) - : Object(pyob, owned) - { - validate(); - } - - SeqBase (const Object& ob): Object(ob) - { - validate(); - } - - // Assignment acquires new ownership of pointer - - SeqBase& operator= (const Object& rhs) - { - return (*this = *rhs); - } - - SeqBase& operator= (PyObject* rhsp) - { - if(ptr() == rhsp) return *this; - set (rhsp); - return *this; - } - - virtual bool accepts (PyObject *pyob) const - { - return pyob && PySequence_Check (pyob); - } - - size_type length () const - { - return PySequence_Length (ptr()); - } - - // Element access - const T operator[](sequence_index_type index) const - { - return getItem(index); - } - - seqref operator[](sequence_index_type index) - { - return seqref(*this, index); - } - - virtual T getItem (sequence_index_type i) const - { - return T(asObject(PySequence_GetItem (ptr(), i))); - } - - virtual void setItem (sequence_index_type i, const T& ob) - { - if (PySequence_SetItem (ptr(), i, *ob) == -1) - { - throw Exception(); - } - } - - SeqBase repeat (int count) const - { - return SeqBase (PySequence_Repeat (ptr(), count), true); - } - - SeqBase concat (const SeqBase& other) const - { - return SeqBase (PySequence_Concat(ptr(), *other), true); - } - - // more STL compatability - const T front () const - { - return getItem(0); - } - - seqref front() - { - return seqref(this, 0); - } - - const T back () const - { - return getItem(size()-1); - } - - seqref back() - { - return seqref(this, size()-1); - } - - void verify_length(size_type required_size) const - { - if (size() != required_size) - throw IndexError ("Unexpected SeqBase length."); - } - - void verify_length(size_type min_size, size_type max_size) const - { - size_type n = size(); - if (n < min_size || n > max_size) - throw IndexError ("Unexpected SeqBase length."); - } - - class iterator - : public random_access_iterator_parent(seqref) - { - protected: - friend class SeqBase; - SeqBase* seq; - int count; - - public: - ~iterator () - {} - - iterator () - : seq( 0 ) - , count( 0 ) - {} - - iterator (SeqBase* s, int where) - : seq( s ) - , count( where ) - {} - - iterator (const iterator& other) - : seq( other.seq ) - , count( other.count ) - {} - - bool eql (const iterator& other) const - { - return (*seq == *other.seq) && (count == other.count); - } - - bool neq (const iterator& other) const - { - return (*seq != *other.seq) || (count != other.count); - } - - bool lss (const iterator& other) const - { - return (count < other.count); - } - - bool gtr (const iterator& other) const - { - return (count > other.count); - } - - bool leq (const iterator& other) const - { - return (count <= other.count); - } - - bool geq (const iterator& other) const - { - return (count >= other.count); - } - - seqref operator*() - { - return seqref(*seq, count); - } - - seqref operator[] (sequence_index_type i) - { - return seqref(*seq, count + i); - } - - iterator& operator=(const iterator& other) - { - if (this == &other) return *this; - seq = other.seq; - count = other.count; - return *this; - } - - iterator operator+(int n) const - { - return iterator(seq, count + n); - } - - iterator operator-(int n) const - { - return iterator(seq, count - n); - } - - iterator& operator+=(int n) - { - count = count + n; - return *this; - } - - iterator& operator-=(int n) - { - count = count - n; - return *this; - } - - int operator-(const iterator& other) const - { - if (*seq != *other.seq) - throw RuntimeError ("SeqBase::iterator comparison error"); - return count - other.count; - } - - // prefix ++ - iterator& operator++ () - { count++; return *this;} - // postfix ++ - iterator operator++ (int) - { return iterator(seq, count++);} - // prefix -- - iterator& operator-- () - { count--; return *this;} - // postfix -- - iterator operator-- (int) - { return iterator(seq, count--);} - - std::string diagnose() const - { - std::OSTRSTREAM oss; - oss << "iterator diagnosis " << seq << ", " << count << std::ends; - return std::string(oss.str()); - } - }; // end of class SeqBase::iterator - - iterator begin () - { - return iterator(this, 0); - } - - iterator end () - { - return iterator(this, length()); - } - - class const_iterator - : public random_access_iterator_parent(const Object) - { - protected: - friend class SeqBase; - const SeqBase* seq; - sequence_index_type count; - - public: - ~const_iterator () - {} - - const_iterator () - : seq( 0 ) - , count( 0 ) - {} - - const_iterator (const SeqBase* s, int where) - : seq( s ) - , count( where ) - {} - - const_iterator(const const_iterator& other) - : seq( other.seq ) - , count( other.count ) - {} - - const T operator*() const - { - return seq->getItem(count); - } - - const T operator[] (sequence_index_type i) const - { - return seq->getItem(count + i); - } - - const_iterator& operator=(const const_iterator& other) - { - if (this == &other) return *this; - seq = other.seq; - count = other.count; - return *this; - } - - const_iterator operator+(int n) const - { - return const_iterator(seq, count + n); - } - - bool eql (const const_iterator& other) const - { - return (*seq == *other.seq) && (count == other.count); - } - - bool neq (const const_iterator& other) const - { - return (*seq != *other.seq) || (count != other.count); - } - - bool lss (const const_iterator& other) const - { - return (count < other.count); - } - - bool gtr (const const_iterator& other) const - { - return (count > other.count); - } - - bool leq (const const_iterator& other) const - { - return (count <= other.count); - } - - bool geq (const const_iterator& other) const - { - return (count >= other.count); - } - - const_iterator operator-(int n) - { - return const_iterator(seq, count - n); - } - - const_iterator& operator+=(int n) - { - count = count + n; - return *this; - } - - const_iterator& operator-=(int n) - { - count = count - n; - return *this; - } - - int operator-(const const_iterator& other) const - { - if (*seq != *other.seq) - throw RuntimeError ("SeqBase::const_iterator::- error"); - return count - other.count; - } - // prefix ++ - const_iterator& operator++ () - { count++; return *this;} - // postfix ++ - const_iterator operator++ (int) - { return const_iterator(seq, count++);} - // prefix -- - const_iterator& operator-- () - { count--; return *this;} - // postfix -- - const_iterator operator-- (int) - { return const_iterator(seq, count--);} - }; // end of class SeqBase::const_iterator - - const_iterator begin () const - { - return const_iterator(this, 0); - } - - const_iterator end () const - { - return const_iterator(this, length()); - } - }; - - // Here's an important typedef you might miss if reading too fast... - typedef SeqBase Sequence; - - template bool operator==(const EXPLICIT_TYPENAME SeqBase::iterator& left, const EXPLICIT_TYPENAME SeqBase::iterator& right); - template bool operator!=(const EXPLICIT_TYPENAME SeqBase::iterator& left, const EXPLICIT_TYPENAME SeqBase::iterator& right); - template bool operator< (const EXPLICIT_TYPENAME SeqBase::iterator& left, const EXPLICIT_TYPENAME SeqBase::iterator& right); - template bool operator> (const EXPLICIT_TYPENAME SeqBase::iterator& left, const EXPLICIT_TYPENAME SeqBase::iterator& right); - template bool operator<=(const EXPLICIT_TYPENAME SeqBase::iterator& left, const EXPLICIT_TYPENAME SeqBase::iterator& right); - template bool operator>=(const EXPLICIT_TYPENAME SeqBase::iterator& left, const EXPLICIT_TYPENAME SeqBase::iterator& right); - - template bool operator==(const EXPLICIT_TYPENAME SeqBase::const_iterator& left, const EXPLICIT_TYPENAME SeqBase::const_iterator& right); - template bool operator!=(const EXPLICIT_TYPENAME SeqBase::const_iterator& left, const EXPLICIT_TYPENAME SeqBase::const_iterator& right); - template bool operator< (const EXPLICIT_TYPENAME SeqBase::const_iterator& left, const EXPLICIT_TYPENAME SeqBase::const_iterator& right); - template bool operator> (const EXPLICIT_TYPENAME SeqBase::const_iterator& left, const EXPLICIT_TYPENAME SeqBase::const_iterator& right); - template bool operator<=(const EXPLICIT_TYPENAME SeqBase::const_iterator& left, const EXPLICIT_TYPENAME SeqBase::const_iterator& right); - template bool operator>=(const EXPLICIT_TYPENAME SeqBase::const_iterator& left, const EXPLICIT_TYPENAME SeqBase::const_iterator& right); - - - extern bool operator==(const Sequence::iterator& left, const Sequence::iterator& right); - extern bool operator!=(const Sequence::iterator& left, const Sequence::iterator& right); - extern bool operator< (const Sequence::iterator& left, const Sequence::iterator& right); - extern bool operator> (const Sequence::iterator& left, const Sequence::iterator& right); - extern bool operator<=(const Sequence::iterator& left, const Sequence::iterator& right); - extern bool operator>=(const Sequence::iterator& left, const Sequence::iterator& right); - - extern bool operator==(const Sequence::const_iterator& left, const Sequence::const_iterator& right); - extern bool operator!=(const Sequence::const_iterator& left, const Sequence::const_iterator& right); - extern bool operator< (const Sequence::const_iterator& left, const Sequence::const_iterator& right); - extern bool operator> (const Sequence::const_iterator& left, const Sequence::const_iterator& right); - extern bool operator<=(const Sequence::const_iterator& left, const Sequence::const_iterator& right); - extern bool operator>=(const Sequence::const_iterator& left, const Sequence::const_iterator& right); - - // ================================================== - // class Char - // Python strings return strings as individual elements. - // I'll try having a class Char which is a String of length 1 - // - typedef std::basic_string unicodestring; - extern Py_UNICODE unicode_null_string[1]; - - class Char: public Object - { - public: - explicit Char (PyObject *pyob, bool owned = false): Object(pyob, owned) - { - validate(); - } - - Char (const Object& ob): Object(ob) - { - validate(); - } - - Char (const std::string& v = "") - :Object(PyString_FromStringAndSize (const_cast(v.c_str()),1), true) - { - validate(); - } - - Char (char v) - : Object(PyString_FromStringAndSize (&v, 1), true) - { - validate(); - } - - Char (Py_UNICODE v) - : Object(PyUnicode_FromUnicode (&v, 1), true) - { - validate(); - } - // Assignment acquires new ownership of pointer - Char& operator= (const Object& rhs) - { - return (*this = *rhs); - } - - Char& operator= (PyObject* rhsp) - { - if(ptr() == rhsp) return *this; - set (rhsp); - return *this; - } - - // Membership - virtual bool accepts (PyObject *pyob) const - { - return pyob && (Py::_String_Check(pyob) || Py::_Unicode_Check(pyob)) && PySequence_Length (pyob) == 1; - } - - // Assignment from C string - Char& operator= (const std::string& v) - { - set(PyString_FromStringAndSize (const_cast(v.c_str()),1), true); - return *this; - } - - Char& operator= (char v) - { - set(PyString_FromStringAndSize (&v, 1), true); - return *this; - } - - Char& operator= (const unicodestring& v) - { - set(PyUnicode_FromUnicode (const_cast(v.data()),1), true); - return *this; - } - - Char& operator= (Py_UNICODE v) - { - set(PyUnicode_FromUnicode (&v, 1), true); - return *this; - } - - // Conversion - operator String() const; - - operator std::string () const - { - return std::string(PyString_AsString (ptr())); - } - }; - - class String: public SeqBase - { - public: - virtual size_type capacity() const - { - return max_size(); - } - - explicit String (PyObject *pyob, bool owned = false): SeqBase(pyob, owned) - { - validate(); - } - - String (const Object& ob): SeqBase(ob) - { - validate(); - } - - String() - : SeqBase( PyString_FromStringAndSize( "", 0 ), true ) - { - validate(); - } - - String( const std::string& v ) - : SeqBase( PyString_FromStringAndSize( const_cast(v.data()), - static_cast( v.length() ) ), true ) - { - validate(); - } - - String( const char *s, const char *encoding, const char *error="strict" ) - : SeqBase( PyUnicode_Decode( s, strlen( s ), encoding, error ), true ) - { - validate(); - } - - String( const char *s, int len, const char *encoding, const char *error="strict" ) - : SeqBase( PyUnicode_Decode( s, len, encoding, error ), true ) - { - validate(); - } - - String( const std::string &s, const char *encoding, const char *error="strict" ) - : SeqBase( PyUnicode_Decode( s.c_str(), s.length(), encoding, error ), true ) - { - validate(); - } - - String( const std::string& v, std::string::size_type vsize ) - : SeqBase(PyString_FromStringAndSize( const_cast(v.data()), - static_cast( vsize ) ), true) - { - validate(); - } - - String( const char *v, int vsize ) - : SeqBase(PyString_FromStringAndSize( const_cast(v), vsize ), true ) - { - validate(); - } - - String( const char* v ) - : SeqBase( PyString_FromString( v ), true ) - { - validate(); - } - - // Assignment acquires new ownership of pointer - String& operator= ( const Object& rhs ) - { - return *this = *rhs; - } - - String& operator= (PyObject* rhsp) - { - if( ptr() == rhsp ) - return *this; - set (rhsp); - return *this; - } - // Membership - virtual bool accepts (PyObject *pyob) const - { - return pyob && (Py::_String_Check(pyob) || Py::_Unicode_Check(pyob)); - } - - // Assignment from C string - String& operator= (const std::string& v) - { - set( PyString_FromStringAndSize( const_cast( v.data() ), - static_cast( v.length() ) ), true ); - return *this; - } - String& operator= (const unicodestring& v) - { - set( PyUnicode_FromUnicode( const_cast( v.data() ), - static_cast( v.length() ) ), true ); - return *this; - } - - - // Encode - String encode( const char *encoding, const char *error="strict" ) - { - if( isUnicode() ) - { - return String( PyUnicode_AsEncodedString( ptr(), encoding, error ) ); - } - else - { - return String( PyString_AsEncodedObject( ptr(), encoding, error ) ); - } - } - - String decode( const char *encoding, const char *error="strict" ) - { - return Object( PyString_AsDecodedObject( ptr(), encoding, error ) ); - } - - // Queries - virtual size_type size () const - { - if( isUnicode() ) - { - return static_cast( PyUnicode_GET_SIZE (ptr()) ); - } - else - { - return static_cast( PyString_Size (ptr()) ); - } - } - - operator std::string () const - { - return as_std_string(); - } - - std::string as_std_string() const - { - if( isUnicode() ) - { - throw TypeError("cannot return std::string from Unicode object"); - } - else - { - return std::string( PyString_AsString( ptr() ), static_cast( PyString_Size( ptr() ) ) ); - } - } - - unicodestring as_unicodestring() const - { - if( isUnicode() ) - { - return unicodestring( PyUnicode_AS_UNICODE( ptr() ), - static_cast( PyUnicode_GET_SIZE( ptr() ) ) ); - } - else - { - throw TypeError("can only return unicodestring from Unicode object"); - } - } - }; - - // ================================================== - // class Tuple - class Tuple: public Sequence - { - public: - virtual void setItem (sequence_index_type offset, const Object&ob) - { - // note PyTuple_SetItem is a thief... - if(PyTuple_SetItem (ptr(), offset, new_reference_to(ob)) == -1) - { - throw Exception(); - } - } - - // Constructor - explicit Tuple (PyObject *pyob, bool owned = false): Sequence (pyob, owned) - { - validate(); - } - - Tuple (const Object& ob): Sequence(ob) - { - validate(); - } - - // New tuple of a given size - explicit Tuple (int size = 0) - { - set(PyTuple_New (size), true); - validate (); - for (sequence_index_type i=0; i < size; i++) - { - if(PyTuple_SetItem (ptr(), i, new_reference_to(Py::_None())) == -1) - { - throw Exception(); - } - } - } - // Tuple from any sequence - explicit Tuple (const Sequence& s) - { - sequence_index_type limit( sequence_index_type( s.length() ) ); - - set(PyTuple_New (limit), true); - validate(); - - for(sequence_index_type i=0; i < limit; i++) - { - if(PyTuple_SetItem (ptr(), i, new_reference_to(s[i])) == -1) - { - throw Exception(); - } - } - } - // Assignment acquires new ownership of pointer - - Tuple& operator= (const Object& rhs) - { - return (*this = *rhs); - } - - Tuple& operator= (PyObject* rhsp) - { - if(ptr() == rhsp) return *this; - set (rhsp); - return *this; - } - // Membership - virtual bool accepts (PyObject *pyob) const - { - return pyob && Py::_Tuple_Check (pyob); - } - - Tuple getSlice (int i, int j) const - { - return Tuple (PySequence_GetSlice (ptr(), i, j), true); - } - - }; - - // ================================================== - // class List - - class List: public Sequence - { - public: - // Constructor - explicit List (PyObject *pyob, bool owned = false): Sequence(pyob, owned) - { - validate(); - } - List (const Object& ob): Sequence(ob) - { - validate(); - } - // Creation at a fixed size - List (int size = 0) - { - set(PyList_New (size), true); - validate(); - for (sequence_index_type i=0; i < size; i++) - { - if(PyList_SetItem (ptr(), i, new_reference_to(Py::_None())) == -1) - { - throw Exception(); - } - } - } - - // List from a sequence - List (const Sequence& s): Sequence() - { - int n = (int)s.length(); - set(PyList_New (n), true); - validate(); - for (sequence_index_type i=0; i < n; i++) - { - if(PyList_SetItem (ptr(), i, new_reference_to(s[i])) == -1) - { - throw Exception(); - } - } - } - - virtual size_type capacity() const - { - return max_size(); - } - // Assignment acquires new ownership of pointer - - List& operator= (const Object& rhs) - { - return (*this = *rhs); - } - - List& operator= (PyObject* rhsp) - { - if(ptr() == rhsp) return *this; - set (rhsp); - return *this; - } - // Membership - virtual bool accepts (PyObject *pyob) const - { - return pyob && Py::_List_Check (pyob); - } - - List getSlice (int i, int j) const - { - return List (PyList_GetSlice (ptr(), i, j), true); - } - - void setSlice (int i, int j, const Object& v) - { - if(PyList_SetSlice (ptr(), i, j, *v) == -1) - { - throw Exception(); - } - } - - void append (const Object& ob) - { - if(PyList_Append (ptr(), *ob) == -1) - { - throw Exception(); - } - } - - void insert (int i, const Object& ob) - { - if(PyList_Insert (ptr(), i, *ob) == -1) - { - throw Exception(); - } - } - - void sort () - { - if(PyList_Sort(ptr()) == -1) - { - throw Exception(); - } - } - - void reverse () - { - if(PyList_Reverse(ptr()) == -1) - { - throw Exception(); - } - } - }; - - - // Mappings - // ================================================== - template - class mapref - { - protected: - MapBase& s; // the map - Object key; // item key - T the_item; - - public: - mapref (MapBase& map, const std::string& k) - : s(map), the_item() - { - key = String(k); - if(map.hasKey(key)) the_item = map.getItem(key); - } - - mapref (MapBase& map, const Object& k) - : s(map), key(k), the_item() - { - if(map.hasKey(key)) the_item = map.getItem(key); - } - - virtual ~mapref() - {} - - // MapBase stuff - // lvalue - mapref& operator=(const mapref& other) - { - if(this == &other) return *this; - the_item = other.the_item; - s.setItem(key, other.the_item); - return *this; - } - - mapref& operator= (const T& ob) - { - the_item = ob; - s.setItem (key, ob); - return *this; - } - - // rvalue - operator T() const - { - return the_item; - } - - // forward everything else to the_item - PyObject* ptr () const - { - return the_item.ptr(); - } - - int reference_count () const - { // the mapref count - return the_item.reference_count(); - } - - Type type () const - { - return the_item.type(); - } - - String str () const - { - return the_item.str(); - } - - String repr () const - { - return the_item.repr(); - } - - bool hasAttr (const std::string& attr_name) const - { - return the_item.hasAttr(attr_name); - } - - Object getAttr (const std::string& attr_name) const - { - return the_item.getAttr(attr_name); - } - - Object getItem (const Object& k) const - { - return the_item.getItem(k); - } - - long hashValue () const - { - return the_item.hashValue(); - } - - bool isCallable () const - { - return the_item.isCallable(); - } - - bool isInstance () const - { - return the_item.isInstance(); - } - - bool isList () const - { - return the_item.isList(); - } - - bool isMapping () const - { - return the_item.isMapping(); - } - - bool isNumeric () const - { - return the_item.isNumeric(); - } - - bool isSequence () const - { - return the_item.isSequence(); - } - - bool isTrue () const - { - return the_item.isTrue(); - } - - bool isType (const Type& t) const - { - return the_item.isType (t); - } - - bool isTuple() const - { - return the_item.isTuple(); - } - - bool isString() const - { - return the_item.isString(); - } - - // Commands - void setAttr (const std::string& attr_name, const Object& value) - { - the_item.setAttr(attr_name, value); - } - - void delAttr (const std::string& attr_name) - { - the_item.delAttr(attr_name); - } - - void delItem (const Object& k) - { - the_item.delItem(k); - } - }; // end of mapref - - // TMM: now for mapref - template< class T > - bool operator==(const mapref& left, const mapref& right) - { - return true; // NOT completed. - } - - template< class T > - bool operator!=(const mapref& left, const mapref& right) - { - return true; // not completed. - } - - template - class MapBase: public Object - { - protected: - explicit MapBase() - {} - public: - // reference: proxy class for implementing [] - // TMM: 26Jun'01 - the types - // If you assume that Python mapping is a hash_map... - // hash_map::value_type is not assignable, but - // (*it).second = data must be a valid expression - typedef size_t size_type; - typedef Object key_type; - typedef mapref data_type; - typedef std::pair< const T, T > value_type; - typedef std::pair< const T, mapref > reference; - typedef const std::pair< const T, const T > const_reference; - typedef std::pair< const T, mapref > pointer; - - // Constructor - explicit MapBase (PyObject *pyob, bool owned = false): Object(pyob, owned) - { - validate(); - } - - // TMM: 02Jul'01 - changed MapBase to Object in next line - MapBase (const Object& ob): Object(ob) - { - validate(); - } - - // Assignment acquires new ownership of pointer - MapBase& operator= (const Object& rhs) - { - return (*this = *rhs); - } - - MapBase& operator= (PyObject* rhsp) - { - if(ptr() == rhsp) return *this; - set (rhsp); - return *this; - } - // Membership - virtual bool accepts (PyObject *pyob) const - { - return pyob && PyMapping_Check(pyob); - } - - // Clear -- PyMapping Clear is missing - // - - void clear () - { - List k = keys(); - for(List::iterator i = k.begin(); i != k.end(); i++) - { - delItem(*i); - } - } - - virtual size_type size() const - { - return PyMapping_Length (ptr()); - } - - // Element Access - T operator[](const std::string& key) const - { - return getItem(key); - } - - T operator[](const Object& key) const - { - return getItem(key); - } - - mapref operator[](const std::string& key) - { - return mapref(*this, key); - } - - mapref operator[](const Object& key) - { - return mapref(*this, key); - } - - int length () const - { - return PyMapping_Length (ptr()); - } - - bool hasKey (const std::string& s) const - { - return PyMapping_HasKeyString (ptr(),const_cast(s.c_str())) != 0; - } - - bool hasKey (const Object& s) const - { - return PyMapping_HasKey (ptr(), s.ptr()) != 0; - } - - T getItem (const std::string& s) const - { - return T( - asObject(PyMapping_GetItemString (ptr(),const_cast(s.c_str()))) - ); - } - - T getItem (const Object& s) const - { - return T( - asObject(PyObject_GetItem (ptr(), s.ptr())) - ); - } - - virtual void setItem (const char *s, const Object& ob) - { - if (PyMapping_SetItemString (ptr(), const_cast(s), *ob) == -1) - { - throw Exception(); - } - } - - virtual void setItem (const std::string& s, const Object& ob) - { - if (PyMapping_SetItemString (ptr(), const_cast(s.c_str()), *ob) == -1) - { - throw Exception(); - } - } - - virtual void setItem (const Object& s, const Object& ob) - { - if (PyObject_SetItem (ptr(), s.ptr(), ob.ptr()) == -1) - { - throw Exception(); - } - } - - void delItem (const std::string& s) - { - if (PyMapping_DelItemString (ptr(), const_cast(s.c_str())) == -1) - { - throw Exception(); - } - } - - void delItem (const Object& s) - { - if (PyMapping_DelItem (ptr(), *s) == -1) - { - throw Exception(); - } - } - // Queries - List keys () const - { - return List(PyMapping_Keys(ptr()), true); - } - - List values () const - { // each returned item is a (key, value) pair - return List(PyMapping_Values(ptr()), true); - } - - List items () const - { - return List(PyMapping_Items(ptr()), true); - } - - // iterators for MapBase - // Added by TMM: 2Jul'01 - NOT COMPLETED - // There is still a bug. I decided to stop, before fixing the bug, because - // this can't be halfway efficient until Python gets built-in iterators. - // My current soln is to iterate over the map by getting a copy of its keys - // and iterating over that. Not a good solution. - - // The iterator holds a MapBase* rather than a MapBase because that's - // how the sequence iterator is implemented and it works. But it does seem - // odd to me - we are iterating over the map object, not the reference. - -#if 0 // here is the test code with which I found the (still existing) bug - typedef cxx::Dict d_t; - d_t d; - cxx::String s1("blah"); - cxx::String s2("gorf"); - d[ "one" ] = s1; - d[ "two" ] = s1; - d[ "three" ] = s2; - d[ "four" ] = s2; - - d_t::iterator it; - it = d.begin(); // this (using the assignment operator) is causing - // a problem; if I just use the copy ctor it works fine. - for( ; it != d.end(); ++it ) - { - d_t::value_type vt( *it ); - cxx::String rs = vt.second.repr(); - std::string ls = rs.operator std::string(); - fprintf( stderr, "%s\n", ls ); - } -#endif // 0 - - class iterator - { - // : public forward_iterator_parent( std::pair ) { - protected: - typedef std::forward_iterator_tag iterator_category; - typedef std::pair< const T, T > value_type; - typedef int difference_type; - typedef std::pair< const T, mapref > pointer; - typedef std::pair< const T, mapref > reference; - - friend class MapBase; - // - MapBase* map; - List keys; // for iterating over the map - List::iterator pos; // index into the keys - - public: - ~iterator () - {} - - iterator () - : map( 0 ) - , keys() - , pos() - {} - - iterator (MapBase* m, bool end = false ) - : map( m ) - , keys( m->keys() ) - , pos( end ? keys.end() : keys.begin() ) - {} - - iterator (const iterator& other) - : map( other.map ) - , keys( other.keys ) - , pos( other.pos ) - {} - - reference operator*() - { - Object key = *pos; - return std::make_pair(key, mapref(*map,key)); - } - - iterator& operator=(const iterator& other) - { - if (this == &other) - return *this; - map = other.map; - keys = other.keys; - pos = other.pos; - return *this; - } - - bool eql(const iterator& right) const - { - return *map == *right.map && pos == right.pos; - } - bool neq( const iterator& right ) const - { - return *map != *right.map || pos != right.pos; - } - - // pointer operator->() { - // return ; - // } - - // prefix ++ - iterator& operator++ () - { pos++; return *this;} - // postfix ++ - iterator operator++ (int) - { return iterator(map, keys, pos++);} - // prefix -- - iterator& operator-- () - { pos--; return *this;} - // postfix -- - iterator operator-- (int) - { return iterator(map, keys, pos--);} - - std::string diagnose() const - { - std::OSTRSTREAM oss; - oss << "iterator diagnosis " << map << ", " << pos << std::ends; - return std::string(oss.str()); - } - }; // end of class MapBase::iterator - - iterator begin () - { - return iterator(this); - } - - iterator end () - { - return iterator(this, true); - } - - class const_iterator - { - protected: - typedef std::forward_iterator_tag iterator_category; - typedef const std::pair< const T, T > value_type; - typedef int difference_type; - typedef const std::pair< const T, T > pointer; - typedef const std::pair< const T, T > reference; - - friend class MapBase; - const MapBase* map; - List keys; // for iterating over the map - List::iterator pos; // index into the keys - - public: - ~const_iterator () - {} - - const_iterator () - : map( 0 ) - , keys() - , pos() - {} - - const_iterator (const MapBase* m, List k, List::iterator p ) - : map( m ) - , keys( k ) - , pos( p ) - {} - - const_iterator(const const_iterator& other) - : map( other.map ) - , keys( other.keys ) - , pos( other.pos ) - {} - - bool eql(const const_iterator& right) const - { - return *map == *right.map && pos == right.pos; - } - bool neq( const const_iterator& right ) const - { - return *map != *right.map || pos != right.pos; - } - - - // const_reference operator*() { - // Object key = *pos; - // return std::make_pair( key, map->[key] ); - // GCC < 3 barfes on this line at the '['. - // } - - const_iterator& operator=(const const_iterator& other) - { - if (this == &other) return *this; - map = other.map; - keys = other.keys; - pos = other.pos; - return *this; - } - - // prefix ++ - const_iterator& operator++ () - { pos++; return *this;} - // postfix ++ - const_iterator operator++ (int) - { return const_iterator(map, keys, pos++);} - // prefix -- - const_iterator& operator-- () - { pos--; return *this;} - // postfix -- - const_iterator operator-- (int) - { return const_iterator(map, keys, pos--);} - }; // end of class MapBase::const_iterator - - const_iterator begin () const - { - return const_iterator(this, 0); - } - - const_iterator end () const - { - return const_iterator(this, length()); - } - - }; // end of MapBase - - typedef MapBase Mapping; - - template bool operator==(const EXPLICIT_TYPENAME MapBase::iterator& left, const EXPLICIT_TYPENAME MapBase::iterator& right); - template bool operator!=(const EXPLICIT_TYPENAME MapBase::iterator& left, const EXPLICIT_TYPENAME MapBase::iterator& right); - template bool operator==(const EXPLICIT_TYPENAME MapBase::const_iterator& left, const EXPLICIT_TYPENAME MapBase::const_iterator& right); - template bool operator!=(const EXPLICIT_TYPENAME MapBase::const_iterator& left, const EXPLICIT_TYPENAME MapBase::const_iterator& right); - - extern bool operator==(const Mapping::iterator& left, const Mapping::iterator& right); - extern bool operator!=(const Mapping::iterator& left, const Mapping::iterator& right); - extern bool operator==(const Mapping::const_iterator& left, const Mapping::const_iterator& right); - extern bool operator!=(const Mapping::const_iterator& left, const Mapping::const_iterator& right); - - - // ================================================== - // class Dict - class Dict: public Mapping - { - public: - // Constructor - explicit Dict (PyObject *pyob, bool owned=false): Mapping (pyob, owned) - { - validate(); - } - Dict (const Dict& ob): Mapping(ob) - { - validate(); - } - // Creation - Dict () - { - set(PyDict_New (), true); - validate(); - } - // Assignment acquires new ownership of pointer - - Dict& operator= (const Object& rhs) - { - return (*this = *rhs); - } - - Dict& operator= (PyObject* rhsp) - { - if(ptr() == rhsp) return *this; - set(rhsp); - return *this; - } - // Membership - virtual bool accepts (PyObject *pyob) const - { - return pyob && Py::_Dict_Check (pyob); - } - }; - - class Callable: public Object - { - public: - // Constructor - explicit Callable (): Object() {} - explicit Callable (PyObject *pyob, bool owned = false): Object (pyob, owned) - { - validate(); - } - - Callable (const Object& ob): Object(ob) - { - validate(); - } - - // Assignment acquires new ownership of pointer - - Callable& operator= (const Object& rhs) - { - return (*this = *rhs); - } - - Callable& operator= (PyObject* rhsp) - { - if(ptr() == rhsp) return *this; - set (rhsp); - return *this; - } - - // Membership - virtual bool accepts (PyObject *pyob) const - { - return pyob && PyCallable_Check (pyob); - } - - // Call - Object apply(const Tuple& args) const - { - return asObject(PyObject_CallObject(ptr(), args.ptr())); - } - - // Call with keywords - Object apply(const Tuple& args, const Dict& kw) const - { - return asObject( PyEval_CallObjectWithKeywords( ptr(), args.ptr(), kw.ptr() ) ); - } - - Object apply(PyObject* pargs = 0) const - { - return apply (Tuple(pargs)); - } - }; - - class Module: public Object - { - public: - explicit Module (PyObject* pyob, bool owned = false): Object (pyob, owned) - { - validate(); - } - - // Construct from module name - explicit Module (const std::string&s): Object() - { - PyObject *m = PyImport_AddModule( const_cast(s.c_str()) ); - set( m, false ); - validate (); - } - - // Copy constructor acquires new ownership of pointer - Module (const Module& ob): Object(*ob) - { - validate(); - } - - Module& operator= (const Object& rhs) - { - return (*this = *rhs); - } - - Module& operator= (PyObject* rhsp) - { - if(ptr() == rhsp) return *this; - set(rhsp); - return *this; - } - - Dict getDict() - { - return Dict(PyModule_GetDict(ptr())); - // Caution -- PyModule_GetDict returns borrowed reference! - } - }; - - // Numeric interface - inline Object operator+ (const Object& a) - { - return asObject(PyNumber_Positive(*a)); - } - inline Object operator- (const Object& a) - { - return asObject(PyNumber_Negative(*a)); - } - - inline Object abs(const Object& a) - { - return asObject(PyNumber_Absolute(*a)); - } - - inline std::pair coerce(const Object& a, const Object& b) - { - PyObject *p1, *p2; - p1 = *a; - p2 = *b; - if(PyNumber_Coerce(&p1,&p2) == -1) - { - throw Exception(); - } - return std::pair(asObject(p1), asObject(p2)); - } - - inline Object operator+ (const Object& a, const Object& b) - { - return asObject(PyNumber_Add(*a, *b)); - } - inline Object operator+ (const Object& a, int j) - { - return asObject(PyNumber_Add(*a, *Int(j))); - } - inline Object operator+ (const Object& a, double v) - { - return asObject(PyNumber_Add(*a, *Float(v))); - } - inline Object operator+ (int j, const Object& b) - { - return asObject(PyNumber_Add(*Int(j), *b)); - } - inline Object operator+ (double v, const Object& b) - { - return asObject(PyNumber_Add(*Float(v), *b)); - } - - inline Object operator- (const Object& a, const Object& b) - { - return asObject(PyNumber_Subtract(*a, *b)); - } - inline Object operator- (const Object& a, int j) - { - return asObject(PyNumber_Subtract(*a, *Int(j))); - } - inline Object operator- (const Object& a, double v) - { - return asObject(PyNumber_Subtract(*a, *Float(v))); - } - inline Object operator- (int j, const Object& b) - { - return asObject(PyNumber_Subtract(*Int(j), *b)); - } - inline Object operator- (double v, const Object& b) - { - return asObject(PyNumber_Subtract(*Float(v), *b)); - } - - inline Object operator* (const Object& a, const Object& b) - { - return asObject(PyNumber_Multiply(*a, *b)); - } - inline Object operator* (const Object& a, int j) - { - return asObject(PyNumber_Multiply(*a, *Int(j))); - } - inline Object operator* (const Object& a, double v) - { - return asObject(PyNumber_Multiply(*a, *Float(v))); - } - inline Object operator* (int j, const Object& b) - { - return asObject(PyNumber_Multiply(*Int(j), *b)); - } - inline Object operator* (double v, const Object& b) - { - return asObject(PyNumber_Multiply(*Float(v), *b)); - } - - inline Object operator/ (const Object& a, const Object& b) - { - return asObject(PyNumber_Divide(*a, *b)); - } - inline Object operator/ (const Object& a, int j) - { - return asObject(PyNumber_Divide(*a, *Int(j))); - } - inline Object operator/ (const Object& a, double v) - { - return asObject(PyNumber_Divide(*a, *Float(v))); - } - inline Object operator/ (int j, const Object& b) - { - return asObject(PyNumber_Divide(*Int(j), *b)); - } - inline Object operator/ (double v, const Object& b) - { - return asObject(PyNumber_Divide(*Float(v), *b)); - } - - inline Object operator% (const Object& a, const Object& b) - { - return asObject(PyNumber_Remainder(*a, *b)); - } - inline Object operator% (const Object& a, int j) - { - return asObject(PyNumber_Remainder(*a, *Int(j))); - } - inline Object operator% (const Object& a, double v) - { - return asObject(PyNumber_Remainder(*a, *Float(v))); - } - inline Object operator% (int j, const Object& b) - { - return asObject(PyNumber_Remainder(*Int(j), *b)); - } - inline Object operator% (double v, const Object& b) - { - return asObject(PyNumber_Remainder(*Float(v), *b)); - } - - inline Object type(const Exception&) // return the type of the error - { - PyObject *ptype, *pvalue, *ptrace; - PyErr_Fetch(&ptype, &pvalue, &ptrace); - Object result; - if(ptype) result = ptype; - PyErr_Restore(ptype, pvalue, ptrace); - return result; - } - - inline Object value(const Exception&) // return the value of the error - { - PyObject *ptype, *pvalue, *ptrace; - PyErr_Fetch(&ptype, &pvalue, &ptrace); - Object result; - if(pvalue) result = pvalue; - PyErr_Restore(ptype, pvalue, ptrace); - return result; - } - - inline Object trace(const Exception&) // return the traceback of the error - { - PyObject *ptype, *pvalue, *ptrace; - PyErr_Fetch(&ptype, &pvalue, &ptrace); - Object result; - if(ptrace) result = ptrace; - PyErr_Restore(ptype, pvalue, ptrace); - return result; - } - -template -String seqref::str () const -{ - return the_item.str(); -} - -template -String seqref::repr () const -{ - return the_item.repr(); -} - -} // namespace Py -#endif // __CXX_Objects__h diff --git a/src/extension/script/CXX/Version.hxx b/src/extension/script/CXX/Version.hxx deleted file mode 100644 index 8286e2feb..000000000 --- a/src/extension/script/CXX/Version.hxx +++ /dev/null @@ -1,46 +0,0 @@ -//----------------------------------------------------------------------------- -// -// Copyright (c) 1998 - 2007, The Regents of the University of California -// Produced at the Lawrence Livermore National Laboratory -// All rights reserved. -// -// This file is part of PyCXX. For details,see http://cxx.sourceforge.net/. The -// full copyright notice is contained in the file COPYRIGHT located at the root -// of the PyCXX distribution. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// - Redistributions of source code must retain the above copyright notice, -// this list of conditions and the disclaimer below. -// - Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the disclaimer (as noted below) in the -// documentation and/or materials provided with the distribution. -// - Neither the name of the UC/LLNL nor the names of its contributors may be -// used to endorse or promote products derived from this software without -// specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OF THE UNIVERSITY OF -// CALIFORNIA, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR -// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH -// DAMAGE. -// -//----------------------------------------------------------------------------- - -#ifndef __PyCXX_version_hxx__ -#define __PyCXX_version_hxx__ - -#define PYCXX_VERSION_MAJOR 5 -#define PYCXX_VERSION_MINOR 4 -#define PYCXX_VERSION_PATCH 0 -#define PYCXX_MAKEVERSION( major, minor, patch ) ((major<<16)|(minor<<8)|(patch)) -#define PYCXX_VERSION PYCXX_MAKEVERSION( PYCXX_VERSION_MAJOR, PYCXX_VERSION_MINOR, PYCXX_VERSION_PATCH ) -#endif diff --git a/src/extension/script/CXX/WrapPython.h b/src/extension/script/CXX/WrapPython.h deleted file mode 100644 index 51b939163..000000000 --- a/src/extension/script/CXX/WrapPython.h +++ /dev/null @@ -1,49 +0,0 @@ -//----------------------------------------------------------------------------- -// -// Copyright (c) 1998 - 2007, The Regents of the University of California -// Produced at the Lawrence Livermore National Laboratory -// All rights reserved. -// -// This file is part of PyCXX. For details,see http://cxx.sourceforge.net/. The -// full copyright notice is contained in the file COPYRIGHT located at the root -// of the PyCXX distribution. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// - Redistributions of source code must retain the above copyright notice, -// this list of conditions and the disclaimer below. -// - Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the disclaimer (as noted below) in the -// documentation and/or materials provided with the distribution. -// - Neither the name of the UC/LLNL nor the names of its contributors may be -// used to endorse or promote products derived from this software without -// specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OF THE UNIVERSITY OF -// CALIFORNIA, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR -// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH -// DAMAGE. -// -//----------------------------------------------------------------------------- - -#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 -#endif - -// pull in python definitions -#include - -#endif diff --git a/src/extension/script/CXX/cxx_extensions.cxx b/src/extension/script/CXX/cxx_extensions.cxx deleted file mode 100644 index 102dc26d4..000000000 --- a/src/extension/script/CXX/cxx_extensions.cxx +++ /dev/null @@ -1,1400 +0,0 @@ -//----------------------------------------------------------------------------- -// -// Copyright (c) 1998 - 2007, The Regents of the University of California -// Produced at the Lawrence Livermore National Laboratory -// All rights reserved. -// -// This file is part of PyCXX. For details,see http://cxx.sourceforge.net/. The -// full copyright notice is contained in the file COPYRIGHT located at the root -// of the PyCXX distribution. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// - Redistributions of source code must retain the above copyright notice, -// this list of conditions and the disclaimer below. -// - Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the disclaimer (as noted below) in the -// documentation and/or materials provided with the distribution. -// - Neither the name of the UC/LLNL nor the names of its contributors may be -// used to endorse or promote products derived from this software without -// specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OF THE UNIVERSITY OF -// CALIFORNIA, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR -// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH -// DAMAGE. -// -//----------------------------------------------------------------------------- -#include "CXX/Extensions.hxx" -#include "CXX/Exception.hxx" - -#include - -namespace Py -{ -//================================================================================ -// -// Implementation of MethodTable -// -//================================================================================ - -PyMethodDef MethodTable::method( const char* method_name, PyCFunction f, int flags, const char* doc ) -{ - PyMethodDef m; - m.ml_name = const_cast( method_name ); - m.ml_meth = f; - m.ml_flags = flags; - m.ml_doc = const_cast( doc ); - return m; -} - -MethodTable::MethodTable() -{ - t.push_back( method( 0, 0, 0, 0 ) ); - mt = 0; -} - -MethodTable::~MethodTable() -{ - delete [] mt; -} - -void MethodTable::add( const char* method_name, PyCFunction f, const char* doc, int flag ) -{ - if( !mt ) - { - t.insert( t.end()-1, method( method_name, f, flag, doc ) ); - } - else - { - throw RuntimeError( "Too late to add a module method!" ); - } -} - -PyMethodDef* MethodTable::table() -{ - if( !mt ) - { - Py_ssize_t t1size = t.size(); - mt = new PyMethodDef[t1size]; - int j = 0; - for( std::vector::iterator i = t.begin(); i != t.end(); i++ ) - { - mt[j++] = *i; - } - } - return mt; -} - -//================================================================================ -// -// Implementation of ExtensionModule -// -//================================================================================ -ExtensionModuleBase::ExtensionModuleBase( const char *name ) - : module_name( name ) - , full_module_name( __Py_PackageContext() != NULL ? std::string( __Py_PackageContext() ) : module_name ) - , method_table() -{} - -ExtensionModuleBase::~ExtensionModuleBase() -{} - -const std::string &ExtensionModuleBase::name() const -{ - return module_name; -} - -const std::string &ExtensionModuleBase::fullName() const -{ - return full_module_name; -} - -class ExtensionModuleBasePtr : public PythonExtension -{ -public: - ExtensionModuleBasePtr( ExtensionModuleBase *_module ) - : module( _module ) - {} - virtual ~ExtensionModuleBasePtr() - {} - - ExtensionModuleBase *module; -}; - - -void ExtensionModuleBase::initialize( const char *module_doc ) -{ - PyObject *module_ptr = new ExtensionModuleBasePtr( this ); - - Py_InitModule4 - ( - const_cast( module_name.c_str() ), // name - method_table.table(), // methods - const_cast( module_doc ), // docs - module_ptr, // pass to functions as "self" - PYTHON_API_VERSION // API version - ); -} - -Py::Module ExtensionModuleBase::module(void) const -{ - return Module( full_module_name ); -} - -Py::Dict ExtensionModuleBase::moduleDictionary(void) const -{ - return module().getDict(); -} - -//-------------------------------------------------------------------------------- - -//================================================================================ -// -// Implementation of PythonType -// -//================================================================================ - -extern "C" -{ - static void standard_dealloc(PyObject* p); - // - // All the following functions redirect the call from Python - // onto the matching virtual function in PythonExtensionBase - // - static int print_handler (PyObject*, FILE *, int); - static PyObject* getattr_handler (PyObject*, char*); - static int setattr_handler (PyObject*, char*, PyObject*); - static PyObject* getattro_handler (PyObject*, PyObject*); - static int setattro_handler (PyObject*, PyObject*, PyObject*); - static int compare_handler (PyObject*, PyObject*); - static PyObject* repr_handler (PyObject*); - static PyObject* str_handler (PyObject*); - static long hash_handler (PyObject*); - static PyObject* call_handler (PyObject*, PyObject*, PyObject*); - static PyObject* iter_handler (PyObject*); - static PyObject* iternext_handler (PyObject*); - - // Sequence methods - static Py_ssize_t sequence_length_handler(PyObject*); - static PyObject* sequence_concat_handler(PyObject*,PyObject*); - static PyObject* sequence_repeat_handler(PyObject*, Py_ssize_t); - static PyObject* sequence_item_handler(PyObject*, Py_ssize_t); - static PyObject* sequence_slice_handler(PyObject*, Py_ssize_t, Py_ssize_t); - static int sequence_ass_item_handler(PyObject*, Py_ssize_t, PyObject*); - static int sequence_ass_slice_handler(PyObject*, Py_ssize_t, Py_ssize_t, PyObject*); - // Mapping - static Py_ssize_t mapping_length_handler(PyObject*); - static PyObject* mapping_subscript_handler(PyObject*, PyObject*); - static int mapping_ass_subscript_handler(PyObject*, PyObject*, PyObject*); - - // Numeric methods - static int number_nonzero_handler (PyObject*); - static PyObject* number_negative_handler (PyObject*); - static PyObject* number_positive_handler (PyObject*); - static PyObject* number_absolute_handler (PyObject*); - static PyObject* number_invert_handler (PyObject*); - static PyObject* number_int_handler (PyObject*); - static PyObject* number_float_handler (PyObject*); - static PyObject* number_long_handler (PyObject*); - static PyObject* number_oct_handler (PyObject*); - static PyObject* number_hex_handler (PyObject*); - static PyObject* number_add_handler (PyObject*, PyObject*); - static PyObject* number_subtract_handler (PyObject*, PyObject*); - static PyObject* number_multiply_handler (PyObject*, PyObject*); - static PyObject* number_divide_handler (PyObject*, PyObject*); - static PyObject* number_remainder_handler (PyObject*, PyObject*); - static PyObject* number_divmod_handler (PyObject*, PyObject*); - static PyObject* number_lshift_handler (PyObject*, PyObject*); - static PyObject* number_rshift_handler (PyObject*, PyObject*); - static PyObject* number_and_handler (PyObject*, PyObject*); - static PyObject* number_xor_handler (PyObject*, PyObject*); - static PyObject* number_or_handler (PyObject*, PyObject*); - static PyObject* number_power_handler(PyObject*, PyObject*, PyObject*); - - // Buffer - static Py_ssize_t buffer_getreadbuffer_handler (PyObject*, Py_ssize_t, void**); - static Py_ssize_t buffer_getwritebuffer_handler (PyObject*, Py_ssize_t, void**); - static Py_ssize_t buffer_getsegcount_handler (PyObject*, Py_ssize_t*); -} - - -extern "C" void standard_dealloc( PyObject* p ) -{ - PyMem_DEL( p ); -} - -PythonType & PythonType::supportSequenceType() -{ - if( !sequence_table ) - { - sequence_table = new PySequenceMethods; - memset( sequence_table, 0, sizeof( PySequenceMethods ) ); // ensure new fields are 0 - table->tp_as_sequence = sequence_table; - sequence_table->sq_length = sequence_length_handler; - sequence_table->sq_concat = sequence_concat_handler; - sequence_table->sq_repeat = sequence_repeat_handler; - sequence_table->sq_item = sequence_item_handler; - sequence_table->sq_slice = sequence_slice_handler; - - sequence_table->sq_ass_item = sequence_ass_item_handler; // BAS setup seperately? - sequence_table->sq_ass_slice = sequence_ass_slice_handler; // BAS setup seperately? - } - return *this; -} - -PythonType & PythonType::supportMappingType() -{ - if( !mapping_table ) - { - mapping_table = new PyMappingMethods; - memset( mapping_table, 0, sizeof( PyMappingMethods ) ); // ensure new fields are 0 - table->tp_as_mapping = mapping_table; - mapping_table->mp_length = mapping_length_handler; - mapping_table->mp_subscript = mapping_subscript_handler; - mapping_table->mp_ass_subscript = mapping_ass_subscript_handler; // BAS setup seperately? - } - return *this; -} - -PythonType & PythonType::supportNumberType() -{ - if( !number_table ) - { - number_table = new PyNumberMethods; - memset( number_table, 0, sizeof( PyNumberMethods ) ); // ensure new fields are 0 - table->tp_as_number = number_table; - number_table->nb_add = number_add_handler; - number_table->nb_subtract = number_subtract_handler; - number_table->nb_multiply = number_multiply_handler; - number_table->nb_divide = number_divide_handler; - number_table->nb_remainder = number_remainder_handler; - number_table->nb_divmod = number_divmod_handler; - number_table->nb_power = number_power_handler; - number_table->nb_negative = number_negative_handler; - number_table->nb_positive = number_positive_handler; - number_table->nb_absolute = number_absolute_handler; - number_table->nb_nonzero = number_nonzero_handler; - number_table->nb_invert = number_invert_handler; - number_table->nb_lshift = number_lshift_handler; - number_table->nb_rshift = number_rshift_handler; - number_table->nb_and = number_and_handler; - number_table->nb_xor = number_xor_handler; - number_table->nb_or = number_or_handler; - number_table->nb_coerce = 0; - number_table->nb_int = number_int_handler; - number_table->nb_long = number_long_handler; - number_table->nb_float = number_float_handler; - number_table->nb_oct = number_oct_handler; - number_table->nb_hex = number_hex_handler; - } - return *this; -} - -PythonType & PythonType::supportBufferType() -{ - if( !buffer_table ) - { - buffer_table = new PyBufferProcs; - memset( buffer_table, 0, sizeof( PyBufferProcs ) ); // ensure new fields are 0 - table->tp_as_buffer = buffer_table; - buffer_table->bf_getreadbuffer = buffer_getreadbuffer_handler; - buffer_table->bf_getwritebuffer = buffer_getwritebuffer_handler; - buffer_table->bf_getsegcount = buffer_getsegcount_handler; - } - return *this; -} - -// if you define one sequence method you must define -// all of them except the assigns - -PythonType::PythonType( size_t basic_size, int itemsize, const char *default_name ) - : table( new PyTypeObject ) - , sequence_table( NULL ) - , mapping_table( NULL ) - , number_table( NULL ) - , buffer_table( NULL ) -{ - memset( table, 0, sizeof( PyTypeObject ) ); // ensure new fields are 0 - *reinterpret_cast( table ) = py_object_initializer; - table->ob_type = _Type_Type(); - table->ob_size = 0; - table->tp_name = const_cast( default_name ); - table->tp_basicsize = basic_size; - table->tp_itemsize = itemsize; - table->tp_dealloc = ( destructor ) standard_dealloc; - table->tp_print = 0; - table->tp_getattr = 0; - table->tp_setattr = 0; - table->tp_compare = 0; - table->tp_repr = 0; - table->tp_as_number = 0; - table->tp_as_sequence = 0; - table->tp_as_mapping = 0; - table->tp_hash = 0; - table->tp_call = 0; - table->tp_str = 0; - table->tp_getattro = 0; - table->tp_setattro = 0; - table->tp_as_buffer = 0; - table->tp_flags = Py_TPFLAGS_DEFAULT; - table->tp_doc = 0; -#if PY_MAJOR_VERSION > 2 || (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION >= 0) - // first use in 2.0 - table->tp_traverse = 0L; - table->tp_clear = 0L; -#else - table->tp_xxx5 = 0L; - table->tp_xxx6 = 0L; -#endif -#if PY_MAJOR_VERSION > 2 || (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION >= 1) - // first defined in 2.1 - table->tp_richcompare = 0L; - table->tp_weaklistoffset = 0L; -#else - table->tp_xxx7 = 0L; - table->tp_xxx8 = 0L; -#endif - -#if PY_MAJOR_VERSION > 2 || (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION >= 2) - // first defined in 2.3 - table->tp_iter = 0L; - table->tp_iternext = 0L; -#endif - -#ifdef COUNT_ALLOCS - table->tp_alloc = 0; - table->tp_free = 0; - table->tp_maxalloc = 0; - table->tp_next = 0; -#endif -} - -PythonType::~PythonType( ) -{ - delete table; - delete sequence_table; - delete mapping_table; - delete number_table; - delete buffer_table; -} - -PyTypeObject* PythonType::type_object( ) const -{return table;} - -PythonType & PythonType::name( const char* nam ) -{ - table->tp_name = const_cast( nam ); - return *this; -} - -const char *PythonType::getName() const -{ - return table->tp_name; -} - -PythonType & PythonType::doc( const char* d ) -{ - table->tp_doc = const_cast( d ); - return *this; -} - -const char *PythonType::getDoc() const -{ - return table->tp_doc; -} - -PythonType & PythonType::dealloc( void( *f )( PyObject* )) -{ - table->tp_dealloc = f; - return *this; -} - -PythonType & PythonType::supportPrint() -{ - table->tp_print = print_handler; - return *this; -} - -PythonType & PythonType::supportGetattr() -{ - table->tp_getattr = getattr_handler; - return *this; -} - -PythonType & PythonType::supportSetattr() -{ - table->tp_setattr = setattr_handler; - return *this; -} - -PythonType & PythonType::supportGetattro() -{ - table->tp_getattro = getattro_handler; - return *this; -} - -PythonType & PythonType::supportSetattro() -{ - table->tp_setattro = setattro_handler; - return *this; -} - -PythonType & PythonType::supportCompare() -{ - table->tp_compare = compare_handler; - return *this; -} - -PythonType & PythonType::supportRepr() -{ - table->tp_repr = repr_handler; - return *this; -} - -PythonType & PythonType::supportStr() -{ - table->tp_str = str_handler; - return *this; -} - -PythonType & PythonType::supportHash() -{ - table->tp_hash = hash_handler; - return *this; -} - -PythonType & PythonType::supportCall() -{ - table->tp_call = call_handler; - return *this; -} - -PythonType & PythonType::supportIter() -{ - table->tp_iter = iter_handler; - table->tp_iternext = iternext_handler; - return *this; -} - -//-------------------------------------------------------------------------------- -// -// Handlers -// -//-------------------------------------------------------------------------------- -extern "C" int print_handler( PyObject *self, FILE *fp, int flags ) -{ - try - { - PythonExtensionBase *p = static_cast( self ); - return p->print( fp, flags ); - } - catch( Py::Exception & ) - { - return -1; // indicate error - } -} - -extern "C" PyObject* getattr_handler( PyObject *self, char *name ) -{ - try - { - PythonExtensionBase *p = static_cast( self ); - return new_reference_to( p->getattr( name ) ); - } - catch( Py::Exception & ) - { - return NULL; // indicate error - } -} - -extern "C" int setattr_handler( PyObject *self, char *name, PyObject *value ) -{ - try - { - PythonExtensionBase *p = static_cast( self ); - return p->setattr( name, Py::Object( value ) ); - } - catch( Py::Exception & ) - { - return -1; // indicate error - } -} - -extern "C" PyObject* getattro_handler( PyObject *self, PyObject *name ) -{ - try - { - PythonExtensionBase *p = static_cast( self ); - return new_reference_to( p->getattro( Py::Object( name ) ) ); - } - catch( Py::Exception & ) - { - return NULL; // indicate error - } -} - -extern "C" int setattro_handler( PyObject *self, PyObject *name, PyObject *value ) -{ - try - { - PythonExtensionBase *p = static_cast( self ); - return p->setattro( Py::Object( name ), Py::Object( value ) ); - } - catch( Py::Exception & ) - { - return -1; // indicate error - } -} - -extern "C" int compare_handler( PyObject *self, PyObject *other ) -{ - try - { - PythonExtensionBase *p = static_cast( self ); - return p->compare( Py::Object( other ) ); - } - catch( Py::Exception & ) - { - return -1; // indicate error - } -} - -extern "C" PyObject* repr_handler( PyObject *self ) -{ - try - { - PythonExtensionBase *p = static_cast( self ); - return new_reference_to( p->repr() ); - } - catch( Py::Exception & ) - { - return NULL; // indicate error - } -} - -extern "C" PyObject* str_handler( PyObject *self ) -{ - try - { - PythonExtensionBase *p = static_cast( self ); - return new_reference_to( p->str() ); - } - catch( Py::Exception & ) - { - return NULL; // indicate error - } -} - -extern "C" long hash_handler( PyObject *self ) -{ - try - { - PythonExtensionBase *p = static_cast( self ); - return p->hash(); - } - catch( Py::Exception & ) - { - return -1; // indicate error - } -} - -extern "C" PyObject* call_handler( PyObject *self, PyObject *args, PyObject *kw ) -{ - try - { - PythonExtensionBase *p = static_cast( self ); - if( kw != NULL ) - return new_reference_to( p->call( Py::Object( args ), Py::Object( kw ) ) ); - else - return new_reference_to( p->call( Py::Object( args ), Py::Object() ) ); - } - catch( Py::Exception & ) - { - return NULL; // indicate error - } -} - -extern "C" PyObject* iter_handler( PyObject *self ) -{ - try - { - PythonExtensionBase *p = static_cast( self ); - return new_reference_to( p->iter() ); - } - catch( Py::Exception & ) - { - return NULL; // indicate error - } -} - -extern "C" PyObject* iternext_handler( PyObject *self ) -{ - try - { - PythonExtensionBase *p = static_cast( self ); - return p->iternext(); // might be a NULL ptr on end of iteration - } - catch( Py::Exception & ) - { - return NULL; // indicate error - } -} - - -// Sequence methods -extern "C" Py_ssize_t sequence_length_handler( PyObject *self ) -{ - try - { - PythonExtensionBase *p = static_cast( self ); - return p->sequence_length(); - } - catch( Py::Exception & ) - { - return -1; // indicate error - } -} - -extern "C" PyObject* sequence_concat_handler( PyObject *self, PyObject *other ) -{ - try - { - PythonExtensionBase *p = static_cast( self ); - return new_reference_to( p->sequence_concat( Py::Object( other ) ) ); - } - catch( Py::Exception & ) - { - return NULL; // indicate error - } -} - -extern "C" PyObject* sequence_repeat_handler( PyObject *self, Py_ssize_t count ) -{ - try - { - PythonExtensionBase *p = static_cast( self ); - return new_reference_to( p->sequence_repeat( count ) ); - } - catch( Py::Exception & ) - { - return NULL; // indicate error - } -} - -extern "C" PyObject* sequence_item_handler( PyObject *self, Py_ssize_t index ) -{ - try - { - PythonExtensionBase *p = static_cast( self ); - return new_reference_to( p->sequence_item( index ) ); - } - catch( Py::Exception & ) - { - return NULL; // indicate error - } -} - -extern "C" PyObject* sequence_slice_handler( PyObject *self, Py_ssize_t first, Py_ssize_t last ) -{ - try - { - PythonExtensionBase *p = static_cast( self ); - return new_reference_to( p->sequence_slice( first, last ) ); - } - catch( Py::Exception & ) - { - return NULL; // indicate error - } -} - -extern "C" int sequence_ass_item_handler( PyObject *self, Py_ssize_t index, PyObject *value ) -{ - try - { - PythonExtensionBase *p = static_cast( self ); - return p->sequence_ass_item( index, Py::Object( value ) ); - } - catch( Py::Exception & ) - { - return -1; // indicate error - } -} - -extern "C" int sequence_ass_slice_handler( PyObject *self, Py_ssize_t first, Py_ssize_t last, PyObject *value ) -{ - try - { - PythonExtensionBase *p = static_cast( self ); - return p->sequence_ass_slice( first, last, Py::Object( value ) ); - } - catch( Py::Exception & ) - { - return -1; // indicate error - } -} - -// Mapping -extern "C" Py_ssize_t mapping_length_handler( PyObject *self ) -{ - try - { - PythonExtensionBase *p = static_cast( self ); - return p->mapping_length(); - } - catch( Py::Exception & ) - { - return -1; // indicate error - } -} - -extern "C" PyObject* mapping_subscript_handler( PyObject *self, PyObject *key ) -{ - try - { - PythonExtensionBase *p = static_cast( self ); - return new_reference_to( p->mapping_subscript( Py::Object( key ) ) ); - } - catch( Py::Exception & ) - { - return NULL; // indicate error - } -} - -extern "C" int mapping_ass_subscript_handler( PyObject *self, PyObject *key, PyObject *value ) -{ - try - { - PythonExtensionBase *p = static_cast( self ); - return p->mapping_ass_subscript( Py::Object( key ), Py::Object( value ) ); - } - catch( Py::Exception & ) - { - return -1; // indicate error - } -} - -// Number -extern "C" int number_nonzero_handler( PyObject *self ) -{ - try - { - PythonExtensionBase *p = static_cast( self ); - return p->number_nonzero(); - } - catch( Py::Exception & ) - { - return -1; // indicate error - } -} - -extern "C" PyObject* number_negative_handler( PyObject *self ) -{ - try - { - PythonExtensionBase *p = static_cast( self ); - return new_reference_to( p->number_negative() ); - } - catch( Py::Exception & ) - { - return NULL; // indicate error - } -} - -extern "C" PyObject* number_positive_handler( PyObject *self ) -{ - try - { - PythonExtensionBase *p = static_cast( self ); - return new_reference_to( p->number_positive() ); - } - catch( Py::Exception & ) - { - return NULL; // indicate error - } -} - -extern "C" PyObject* number_absolute_handler( PyObject *self ) -{ - try - { - PythonExtensionBase *p = static_cast( self ); - return new_reference_to( p->number_absolute() ); - } - catch( Py::Exception & ) - { - return NULL; // indicate error - } -} - -extern "C" PyObject* number_invert_handler( PyObject *self ) -{ - try - { - PythonExtensionBase *p = static_cast( self ); - return new_reference_to( p->number_invert() ); - } - catch( Py::Exception & ) - { - return NULL; // indicate error - } -} - -extern "C" PyObject* number_int_handler( PyObject *self ) -{ - try - { - PythonExtensionBase *p = static_cast( self ); - return new_reference_to( p->number_int() ); - } - catch( Py::Exception & ) - { - return NULL; // indicate error - } -} - -extern "C" PyObject* number_float_handler( PyObject *self ) -{ - try - { - PythonExtensionBase *p = static_cast( self ); - return new_reference_to( p->number_float() ); - } - catch( Py::Exception & ) - { - return NULL; // indicate error - } -} - -extern "C" PyObject* number_long_handler( PyObject *self ) -{ - try - { - PythonExtensionBase *p = static_cast( self ); - return new_reference_to( p->number_long() ); - } - catch( Py::Exception & ) - { - return NULL; // indicate error - } -} - -extern "C" PyObject* number_oct_handler( PyObject *self ) -{ - try - { - PythonExtensionBase *p = static_cast( self ); - return new_reference_to( p->number_oct() ); - } - catch( Py::Exception & ) - { - return NULL; // indicate error - } -} - -extern "C" PyObject* number_hex_handler( PyObject *self ) -{ - try - { - PythonExtensionBase *p = static_cast( self ); - return new_reference_to( p->number_hex() ); - } - catch( Py::Exception & ) - { - return NULL; // indicate error - } -} - -extern "C" PyObject* number_add_handler( PyObject *self, PyObject *other ) -{ - try - { - PythonExtensionBase *p = static_cast( self ); - return new_reference_to( p->number_add( Py::Object( other ) ) ); - } - catch( Py::Exception & ) - { - return NULL; // indicate error - } -} - -extern "C" PyObject* number_subtract_handler( PyObject *self, PyObject *other ) -{ - try - { - PythonExtensionBase *p = static_cast( self ); - return new_reference_to( p->number_subtract( Py::Object( other ) ) ); - } - catch( Py::Exception & ) - { - return NULL; // indicate error - } -} - -extern "C" PyObject* number_multiply_handler( PyObject *self, PyObject *other ) -{ - try - { - PythonExtensionBase *p = static_cast( self ); - return new_reference_to( p->number_multiply( Py::Object( other ) ) ); - } - catch( Py::Exception & ) - { - return NULL; // indicate error - } -} - -extern "C" PyObject* number_divide_handler( PyObject *self, PyObject *other ) -{ - try - { - PythonExtensionBase *p = static_cast( self ); - return new_reference_to( p->number_divide( Py::Object( other ) ) ); - } - catch( Py::Exception & ) - { - return NULL; // indicate error - } -} - -extern "C" PyObject* number_remainder_handler( PyObject *self, PyObject *other ) -{ - try - { - PythonExtensionBase *p = static_cast( self ); - return new_reference_to( p->number_remainder( Py::Object( other ) ) ); - } - catch( Py::Exception & ) - { - return NULL; // indicate error - } -} - -extern "C" PyObject* number_divmod_handler( PyObject *self, PyObject *other ) -{ - try - { - PythonExtensionBase *p = static_cast( self ); - return new_reference_to( p->number_divmod( Py::Object( other ) ) ); - } - catch( Py::Exception & ) - { - return NULL; // indicate error - } -} - -extern "C" PyObject* number_lshift_handler( PyObject *self, PyObject *other ) -{ - try - { - PythonExtensionBase *p = static_cast( self ); - return new_reference_to( p->number_lshift( Py::Object( other ) ) ); - } - catch( Py::Exception & ) - { - return NULL; // indicate error - } -} - -extern "C" PyObject* number_rshift_handler( PyObject *self, PyObject *other ) -{ - try - { - PythonExtensionBase *p = static_cast( self ); - return new_reference_to( p->number_rshift( Py::Object( other ) ) ); - } - catch( Py::Exception & ) - { - return NULL; // indicate error - } -} - -extern "C" PyObject* number_and_handler( PyObject *self, PyObject *other ) -{ - try - { - PythonExtensionBase *p = static_cast( self ); - return new_reference_to( p->number_and( Py::Object( other ) ) ); - } - catch( Py::Exception & ) - { - return NULL; // indicate error - } -} - -extern "C" PyObject* number_xor_handler( PyObject *self, PyObject *other ) -{ - try - { - PythonExtensionBase *p = static_cast( self ); - return new_reference_to( p->number_xor( Py::Object( other ) ) ); - } - catch( Py::Exception & ) - { - return NULL; // indicate error - } -} - -extern "C" PyObject* number_or_handler( PyObject *self, PyObject *other ) -{ - try - { - PythonExtensionBase *p = static_cast( self ); - return new_reference_to( p->number_or( Py::Object( other ) ) ); - } - catch( Py::Exception & ) - { - return NULL; // indicate error - } -} - -extern "C" PyObject* number_power_handler( PyObject *self, PyObject *x1, PyObject *x2 ) -{ - try - { - PythonExtensionBase *p = static_cast( self ); - return new_reference_to( p->number_power( Py::Object( x1 ), Py::Object( x2 ) ) ); - } - catch( Py::Exception & ) - { - return NULL; // indicate error - } -} - -// Buffer -extern "C" Py_ssize_t buffer_getreadbuffer_handler( PyObject *self, Py_ssize_t index, void **pp ) -{ - try - { - PythonExtensionBase *p = static_cast( self ); - return p->buffer_getreadbuffer( index, pp ); - } - catch( Py::Exception & ) - { - return -1; // indicate error - } -} - -extern "C" Py_ssize_t buffer_getwritebuffer_handler( PyObject *self, Py_ssize_t index, void **pp ) -{ - try - { - PythonExtensionBase *p = static_cast( self ); - return p->buffer_getwritebuffer( index, pp ); - } - catch( Py::Exception & ) - { - return -1; // indicate error - } -} - -extern "C" Py_ssize_t buffer_getsegcount_handler( PyObject *self, Py_ssize_t *count ) -{ - try - { - PythonExtensionBase *p = static_cast( self ); - return p->buffer_getsegcount( count ); - } - catch( Py::Exception & ) - { - return -1; // indicate error - } -} - - -//================================================================================ -// -// Implementation of PythonExtensionBase -// -//================================================================================ -#define missing_method( method ) \ -throw RuntimeError( "Extension object does not support method " #method ); - -PythonExtensionBase::PythonExtensionBase() -{ -} - -PythonExtensionBase::~PythonExtensionBase() -{ - assert( ob_refcnt == 0 ); -} - -int PythonExtensionBase::print( FILE *, int ) -{ missing_method( print ); return -1; } - -int PythonExtensionBase::setattr( const char*, const Py::Object & ) -{ missing_method( setattr ); return -1; } - -Py::Object PythonExtensionBase::getattro( const Py::Object & ) -{ missing_method( getattro ); return Py::Nothing(); } - -int PythonExtensionBase::setattro( const Py::Object &, const Py::Object & ) -{ missing_method( setattro ); return -1; } - -int PythonExtensionBase::compare( const Py::Object & ) -{ missing_method( compare ); return -1; } - -Py::Object PythonExtensionBase::repr() -{ missing_method( repr ); return Py::Nothing(); } - -Py::Object PythonExtensionBase::str() -{ missing_method( str ); return Py::Nothing(); } - -long PythonExtensionBase::hash() -{ missing_method( hash ); return -1; } - -Py::Object PythonExtensionBase::call( const Py::Object &, const Py::Object & ) -{ missing_method( call ); return Py::Nothing(); } - -Py::Object PythonExtensionBase::iter() -{ missing_method( iter ); return Py::Nothing(); } - -PyObject* PythonExtensionBase::iternext() -{ missing_method( iternext ); return NULL; } - - -// Sequence methods -int PythonExtensionBase::sequence_length() -{ missing_method( sequence_length ); return -1; } - -Py::Object PythonExtensionBase::sequence_concat( const Py::Object & ) -{ missing_method( sequence_concat ); return Py::Nothing(); } - -Py::Object PythonExtensionBase::sequence_repeat( Py_ssize_t ) -{ missing_method( sequence_repeat ); return Py::Nothing(); } - -Py::Object PythonExtensionBase::sequence_item( Py_ssize_t ) -{ missing_method( sequence_item ); return Py::Nothing(); } - -Py::Object PythonExtensionBase::sequence_slice( Py_ssize_t, Py_ssize_t ) -{ missing_method( sequence_slice ); return Py::Nothing(); } - -int PythonExtensionBase::sequence_ass_item( Py_ssize_t, const Py::Object & ) -{ missing_method( sequence_ass_item ); return -1; } - -int PythonExtensionBase::sequence_ass_slice( Py_ssize_t, Py_ssize_t, const Py::Object & ) -{ missing_method( sequence_ass_slice ); return -1; } - - -// Mapping -int PythonExtensionBase::mapping_length() -{ missing_method( mapping_length ); return -1; } - -Py::Object PythonExtensionBase::mapping_subscript( const Py::Object & ) -{ missing_method( mapping_subscript ); return Py::Nothing(); } - -int PythonExtensionBase::mapping_ass_subscript( const Py::Object &, const Py::Object & ) -{ missing_method( mapping_ass_subscript ); return -1; } - - -// Number -int PythonExtensionBase::number_nonzero() -{ missing_method( number_nonzero ); return -1; } - -Py::Object PythonExtensionBase::number_negative() -{ missing_method( number_negative ); return Py::Nothing(); } - -Py::Object PythonExtensionBase::number_positive() -{ missing_method( number_positive ); return Py::Nothing(); } - -Py::Object PythonExtensionBase::number_absolute() -{ missing_method( number_absolute ); return Py::Nothing(); } - -Py::Object PythonExtensionBase::number_invert() -{ missing_method( number_invert ); return Py::Nothing(); } - -Py::Object PythonExtensionBase::number_int() -{ missing_method( number_int ); return Py::Nothing(); } - -Py::Object PythonExtensionBase::number_float() -{ missing_method( number_float ); return Py::Nothing(); } - -Py::Object PythonExtensionBase::number_long() -{ missing_method( number_long ); return Py::Nothing(); } - -Py::Object PythonExtensionBase::number_oct() -{ missing_method( number_oct ); return Py::Nothing(); } - -Py::Object PythonExtensionBase::number_hex() -{ missing_method( number_hex ); return Py::Nothing(); } - -Py::Object PythonExtensionBase::number_add( const Py::Object & ) -{ missing_method( number_add ); return Py::Nothing(); } - -Py::Object PythonExtensionBase::number_subtract( const Py::Object & ) -{ missing_method( number_subtract ); return Py::Nothing(); } - -Py::Object PythonExtensionBase::number_multiply( const Py::Object & ) -{ missing_method( number_multiply ); return Py::Nothing(); } - -Py::Object PythonExtensionBase::number_divide( const Py::Object & ) -{ missing_method( number_divide ); return Py::Nothing(); } - -Py::Object PythonExtensionBase::number_remainder( const Py::Object & ) -{ missing_method( number_remainder ); return Py::Nothing(); } - -Py::Object PythonExtensionBase::number_divmod( const Py::Object & ) -{ missing_method( number_divmod ); return Py::Nothing(); } - -Py::Object PythonExtensionBase::number_lshift( const Py::Object & ) -{ missing_method( number_lshift ); return Py::Nothing(); } - -Py::Object PythonExtensionBase::number_rshift( const Py::Object & ) -{ missing_method( number_rshift ); return Py::Nothing(); } - -Py::Object PythonExtensionBase::number_and( const Py::Object & ) -{ missing_method( number_and ); return Py::Nothing(); } - -Py::Object PythonExtensionBase::number_xor( const Py::Object & ) -{ missing_method( number_xor ); return Py::Nothing(); } - -Py::Object PythonExtensionBase::number_or( const Py::Object & ) -{ missing_method( number_or ); return Py::Nothing(); } - -Py::Object PythonExtensionBase::number_power( const Py::Object &, const Py::Object & ) -{ missing_method( number_power ); return Py::Nothing(); } - - -// Buffer -Py_ssize_t PythonExtensionBase::buffer_getreadbuffer( Py_ssize_t, void** ) -{ missing_method( buffer_getreadbuffer ); return -1; } - -Py_ssize_t PythonExtensionBase::buffer_getwritebuffer( Py_ssize_t, void** ) -{ missing_method( buffer_getwritebuffer ); return -1; } - -Py_ssize_t PythonExtensionBase::buffer_getsegcount( Py_ssize_t* ) -{ missing_method( buffer_getsegcount ); return -1; } - -//-------------------------------------------------------------------------------- -// -// Method call handlers for -// PythonExtensionBase -// ExtensionModuleBase -// -//-------------------------------------------------------------------------------- - -extern "C" 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(); - void *self_as_void = PyCObject_AsVoidPtr( self_in_cobject ); - if( self_as_void == NULL ) - return NULL; - - ExtensionModuleBase *self = static_cast( self_as_void ); - - String py_name( self_and_name_tuple[1] ); - std::string name( py_name.as_std_string() ); - - Tuple args( _args ); - if( _keywords == NULL ) - { - Dict keywords; // pass an empty dict - - Object result( self->invoke_method_keyword( name, args, keywords ) ); - return new_reference_to( result.ptr() ); - } - - Dict keywords( _keywords ); - - Object result( self->invoke_method_keyword( name, args, keywords ) ); - return new_reference_to( result.ptr() ); - } - catch( Exception & ) - { - return 0; - } -} - -extern "C" 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(); - void *self_as_void = PyCObject_AsVoidPtr( self_in_cobject ); - if( self_as_void == NULL ) - return NULL; - - ExtensionModuleBase *self = static_cast( self_as_void ); - - String py_name( self_and_name_tuple[1] ); - std::string name( py_name.as_std_string() ); - - Tuple args( _args ); - - Object result( self->invoke_method_varargs( name, args ) ); - - return new_reference_to( result.ptr() ); - } - catch( Exception & ) - { - return 0; - } -} - -extern "C" void do_not_dealloc( void * ) -{} - - -//-------------------------------------------------------------------------------- -// -// ExtensionExceptionType -// -//-------------------------------------------------------------------------------- -ExtensionExceptionType::ExtensionExceptionType() - : Py::Object() -{ -} - -void ExtensionExceptionType::init( ExtensionModuleBase &module, const std::string& name ) -{ - std::string module_name( module.fullName() ); - module_name += "."; - module_name += name; - - set( PyErr_NewException( const_cast( module_name.c_str() ), NULL, NULL ), true ); -} - -void ExtensionExceptionType::init( ExtensionModuleBase &module, const std::string& name, ExtensionExceptionType &parent) - { - std::string module_name( module.fullName() ); - module_name += "."; - module_name += name; - - set( PyErr_NewException( const_cast( module_name.c_str() ), parent.ptr(), NULL ), true ); -} - -ExtensionExceptionType::~ExtensionExceptionType() -{ -} - -Exception::Exception( ExtensionExceptionType &exception, const std::string& reason ) -{ - PyErr_SetString (exception.ptr(), reason.c_str()); -} - -Exception::Exception( ExtensionExceptionType &exception, Object &reason ) -{ - PyErr_SetObject (exception.ptr(), reason.ptr()); -} - -Exception::Exception( PyObject* exception, Object &reason ) -{ - PyErr_SetObject (exception, reason.ptr()); -} - -} // end of namespace Py diff --git a/src/extension/script/CXX/cxxextensions.c b/src/extension/script/CXX/cxxextensions.c deleted file mode 100644 index edae3be6b..000000000 --- a/src/extension/script/CXX/cxxextensions.c +++ /dev/null @@ -1,49 +0,0 @@ -/*---------------------------------------------------------------------------- -// -// Copyright (c) 1998 - 2007, The Regents of the University of California -// Produced at the Lawrence Livermore National Laboratory -// All rights reserved. -// -// This file is part of PyCXX. For details,see http://cxx.sourceforge.net/. The -// full copyright notice is contained in the file COPYRIGHT located at the root -// of the PyCXX distribution. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// - Redistributions of source code must retain the above copyright notice, -// this list of conditions and the disclaimer below. -// - Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the disclaimer (as noted below) in the -// documentation and/or materials provided with the distribution. -// - Neither the name of the UC/LLNL nor the names of its contributors may be -// used to endorse or promote products derived from this software without -// specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OF THE UNIVERSITY OF -// CALIFORNIA, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR -// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH -// DAMAGE. -// -//---------------------------------------------------------------------------*/ - -#include "CXX/WrapPython.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -PyObject py_object_initializer = {PyObject_HEAD_INIT(0)}; - -#ifdef __cplusplus -} -#endif diff --git a/src/extension/script/CXX/cxxsupport.cxx b/src/extension/script/CXX/cxxsupport.cxx deleted file mode 100644 index 1dfba5a19..000000000 --- a/src/extension/script/CXX/cxxsupport.cxx +++ /dev/null @@ -1,174 +0,0 @@ -//----------------------------------------------------------------------------- -// -// Copyright (c) 1998 - 2007, The Regents of the University of California -// Produced at the Lawrence Livermore National Laboratory -// All rights reserved. -// -// This file is part of PyCXX. For details,see http://cxx.sourceforge.net/. The -// full copyright notice is contained in the file COPYRIGHT located at the root -// of the PyCXX distribution. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// - Redistributions of source code must retain the above copyright notice, -// this list of conditions and the disclaimer below. -// - Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the disclaimer (as noted below) in the -// documentation and/or materials provided with the distribution. -// - Neither the name of the UC/LLNL nor the names of its contributors may be -// used to endorse or promote products derived from this software without -// specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OF THE UNIVERSITY OF -// CALIFORNIA, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR -// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH -// DAMAGE. -// -//----------------------------------------------------------------------------- - -#include "CXX/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(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(ob.str())); -} -#endif - -} // Py diff --git a/src/extension/script/InkscapeBinding.cpp b/src/extension/script/InkscapeBinding.cpp deleted file mode 100644 index 4658f684b..000000000 --- a/src/extension/script/InkscapeBinding.cpp +++ /dev/null @@ -1,216 +0,0 @@ -/** - * This file is an attempt to provide a hierarchical design - * to wrap Inkscape in an OO model. This file is parsed by Swig - * to produce scripting extension modules for such interpreters - * as Python or Perl - * - * Authors: - * Bob Jamison - * - * Copyright (C) 2004-2007 Authors - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "InkscapeBinding.h" -#include "help.h" - -namespace Inkscape { -namespace Extension { -namespace Script { - - -class InkscapeImpl; -class DesktopImpl; -class DocumentImpl; - - -//######################################################################### -//# D O C U M E N T -//######################################################################### -class DocumentImpl : public Document -{ -public: - - DocumentImpl(); - - virtual ~DocumentImpl(); - - virtual void hello(); - -private: - - -}; - - -DocumentImpl::DocumentImpl() -{ - - -} - -DocumentImpl::~DocumentImpl() -{ - - -} - -void DocumentImpl::hello() -{ - //printf("######## HELLO, WORLD! #######\n"); -} - - - -//######################################################################### -//# D E S K T O P -//######################################################################### -class DesktopImpl : public Desktop -{ -public: - DesktopImpl(); - - virtual ~DesktopImpl(); - - virtual Document *getDocument(); - -private: - - DocumentImpl document; - -}; - - -DesktopImpl::DesktopImpl() -{ - - -} - -DesktopImpl::~DesktopImpl() -{ - - -} - - -Document *DesktopImpl::getDocument() -{ - return &document; -} - - - -//######################################################################### -//# D I A L O G M A N A G E R -//######################################################################### - -class DialogManagerImpl : public DialogManager -{ -public: - DialogManagerImpl(); - - virtual ~DialogManagerImpl(); - - virtual void showAbout(); - -private: - - -}; - -DialogManagerImpl::DialogManagerImpl() -{ - -} - - -DialogManagerImpl::~DialogManagerImpl() -{ - -} - - -void DialogManagerImpl::showAbout() -{ - sp_help_about(); - -} - - - -//######################################################################### -//# I N K S C A P E -//######################################################################### - -class InkscapeImpl : public Inkscape -{ -public: - InkscapeImpl(); - - virtual ~InkscapeImpl(); - - virtual Desktop *getDesktop(); - - virtual DialogManager *getDialogManager(); - -private: - - DesktopImpl desktop; - - DialogManagerImpl dialogManager; - -}; - -Inkscape *getInkscape() -{ - Inkscape *inkscape = new InkscapeImpl(); - return inkscape; -} - - -InkscapeImpl::InkscapeImpl() -{ - -} - - -InkscapeImpl::~InkscapeImpl() -{ - -} - - -Desktop *InkscapeImpl::getDesktop() -{ - return &desktop; -} - -DialogManager *InkscapeImpl::getDialogManager() -{ - return &dialogManager; -} - - - -}//namespace Script -}//namespace Extension -}//namespace Inkscape - - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : diff --git a/src/extension/script/InkscapeBinding.h b/src/extension/script/InkscapeBinding.h deleted file mode 100644 index 18d33f8f3..000000000 --- a/src/extension/script/InkscapeBinding.h +++ /dev/null @@ -1,168 +0,0 @@ -#ifndef __INKSCAPE_BINDING_H__ -#define __INKSCAPE_BINDING_H__ -/** - * This file is an attempt to provide a hierarchical design - * to wrap Inkscape in an OO model. This file is parsed by Swig - * to produce scripting extension modules for such interpreters - * as Python or Perl - * - * Authors: - * Bob Jamison - * - * Copyright (C) 2004-2007 Authors - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -/* - * Note: we are doc-ing this file instead of the .cpp since - * the .cpp file has impl's, not def's of these classes. - * Also note that you need to understand Swig before you edit this file. - */ - - -namespace Inkscape { -namespace Extension { -namespace Script { - -class Inkscape; -class DialogManager; -class Desktop; -class Document; - - - -/** - * Get the root Inkscape object. The module wrapper should - * always call this first so that there will be an 'inkscape' - * object available to the user. - */ -Inkscape *getInkscape(); - - -/** - * Root inkscape object. Owner of everything - */ -class Inkscape -{ -public: - - /** - * - */ - Inkscape(){} - - /** - * - */ - virtual ~Inkscape(){}; - - /** - * - */ - virtual Desktop *getDesktop() = 0; - - /** - * - */ - virtual DialogManager *getDialogManager() = 0; - -}; - -/** - * Controller for the various Inkscape dialogs - */ -class DialogManager -{ -public: - - /** - * - */ - DialogManager(){} - - /** - * - */ - virtual ~DialogManager(){}; - - /** - * - */ - virtual void showAbout() = 0; - -}; - - -/** - * - */ -class Desktop -{ - -public: - - /** - * - */ - Desktop() {} - - /** - * - */ - virtual ~Desktop(){}; - - /** - * - */ - virtual Document *getDocument() = 0; - -}; - - - -/** - * - */ -class Document -{ - -public: - - /** - * - */ - Document() {}; - - /** - * - */ - virtual ~Document(){}; - - /** - * - */ - virtual void hello() = 0; - - -}; - - -}//namespace Script -}//namespace Extension -}//namespace Inkscape - - - -#endif /*__INKSCAPE_BINDING_H__*/ - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : diff --git a/src/extension/script/InkscapeInterpreter.cpp b/src/extension/script/InkscapeInterpreter.cpp deleted file mode 100644 index c28163489..000000000 --- a/src/extension/script/InkscapeInterpreter.cpp +++ /dev/null @@ -1,93 +0,0 @@ -/** - * Python Interpreter wrapper for Inkscape - * - * Authors: - * Bob Jamison - * - * Copyright (C) 2004 Authors - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include "InkscapeInterpreter.h" - -#include - -namespace Inkscape { -namespace Extension { -namespace Script { - -/* - * - */ -InkscapeInterpreter::InkscapeInterpreter() -{ -} - - - -/* - * - */ -InkscapeInterpreter::~InkscapeInterpreter() -{ - -} - - - - -/* - * Interpret an in-memory string - */ -bool InkscapeInterpreter::interpretScript(const Glib::ustring &script, - Glib::ustring &output, - Glib::ustring &error) -{ - //do nothing. let the subclasses implement this - return true; -} - - - - -/* - * Interpret a named file - */ -bool InkscapeInterpreter::interpretUri(const Glib::ustring &uri, - Glib::ustring &output, - Glib::ustring &error) -{ - char *curi = (char *)uri.raw().c_str(); - std::ifstream ins(curi); - if (!ins.good()) - { - g_error("interpretUri: Could not open %s for reading\n", curi); - return false; - } - - Glib::ustring buf; - - while (!ins.eof()) - { - gunichar ch = (gunichar) ins.get(); - buf.push_back(ch); - } - - ins.close(); - - bool ret = interpretScript(buf, output, error); - - return ret; - -} - - - -} // namespace Script -} // namespace Extension -} // namespace Inkscape - -//######################################################################### -//# E N D O F F I L E -//######################################################################### diff --git a/src/extension/script/InkscapeInterpreter.h b/src/extension/script/InkscapeInterpreter.h deleted file mode 100644 index 7d16ed979..000000000 --- a/src/extension/script/InkscapeInterpreter.h +++ /dev/null @@ -1,68 +0,0 @@ -#ifndef __INKSCAPE_INTERPRETER_H__ -#define __INKSCAPE_INTERPRETER_H__ - -/** - * Base class for interpreter implementations, (InkscapePython, etc) - * - * Authors: - * Bob Jamison - * - * Copyright (C) 2004 Authors - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include - -namespace Inkscape { -namespace Extension { -namespace Script { - - -class InkscapeInterpreter -{ -public: - - /** - * - */ - InkscapeInterpreter(); - - /** - * - */ - virtual ~InkscapeInterpreter(); - - /** - * - */ - virtual bool interpretScript(const Glib::ustring &script, - Glib::ustring &output, - Glib::ustring &error); - - /** - * - */ - virtual bool interpretUri(const Glib::ustring &uri, - Glib::ustring &output, - Glib::ustring &error); - - - -}; //class InkscapeInterpreter - - - - -} // namespace Script -} // namespace Extension -} // namespace Inkscape - - - -#endif /* __INKSCAPE_INTERPRETER_H__ */ -//######################################################################### -//# E N D O F F I L E -//######################################################################### - - diff --git a/src/extension/script/InkscapePerl.cpp b/src/extension/script/InkscapePerl.cpp deleted file mode 100644 index 1a4c61bcc..000000000 --- a/src/extension/script/InkscapePerl.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/** - * Perl Interpreter wrapper for Inkscape - * - * Authors: - * Bob Jamison - * - * Copyright (C) 2004 Authors - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - - - -#include "InkscapePerl.h" - -#include "EXTERN.h" -#include "perl.h" -#include "XSUB.h" - - -#include - -#include "inkscape_perl.pm.h" - -/* - * Generated by SWIG - */ -extern "C" int -InkscapePerlParseBuf(char *startupCodeBuf, char *codeBuf); - -namespace Inkscape { -namespace Extension { -namespace Script { - - -/* - * - */ -InkscapePerl::InkscapePerl() -{ -} - - - -/* - * - */ -InkscapePerl::~InkscapePerl() -{ - -} - - - - - -bool InkscapePerl::interpretScript(const Glib::ustring &script, - Glib::ustring &output, - Glib::ustring &error) -{ - char *codeBuf = (char *)script.raw().c_str(); - int ret = InkscapePerlParseBuf(inkscape_module_script, codeBuf); - if (!ret) - { - return false; - } - return true; -} - - - - - -} // namespace Script -} // namespace Extension -} // namespace Inkscape - -//######################################################################### -//# E N D O F F I L E -//######################################################################### diff --git a/src/extension/script/InkscapePerl.h b/src/extension/script/InkscapePerl.h deleted file mode 100644 index 0b9314009..000000000 --- a/src/extension/script/InkscapePerl.h +++ /dev/null @@ -1,73 +0,0 @@ -#ifndef __INKSCAPE_PERL_H__ -#define __INKSCAPE_PERL_H__ - -/** - * Perl Interpreter wrapper for Inkscape - * - * Authors: - * Bob Jamison - * - * Copyright (C) 2004 Authors - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include "InkscapeInterpreter.h" -#include - -namespace Inkscape { -namespace Extension { -namespace Script { - - -class InkscapePerl : public InkscapeInterpreter -{ -public: - - /* - * - */ - InkscapePerl(); - - - /* - * - */ - virtual ~InkscapePerl(); - - - - /* - * - */ - bool interpretScript(const Glib::ustring &script, - Glib::ustring &output, - Glib::ustring &error); - - - - - -private: - - -}; - -} // namespace Script -} // namespace Extension -} // namespace Inkscape - - - -#endif /*__INKSCAPE_PERL_H__ */ - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : diff --git a/src/extension/script/InkscapePython.cpp b/src/extension/script/InkscapePython.cpp deleted file mode 100644 index c5835441b..000000000 --- a/src/extension/script/InkscapePython.cpp +++ /dev/null @@ -1,509 +0,0 @@ -/** - * Python Interpreter wrapper for Inkscape - * - * Authors: - * Bob Jamison - * - * Copyright (C) 2004-2007 Authors - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - - -#include - -#include "InkscapePython.h" - - -#include -#include "CXX/Extensions.hxx" -#include "CXX/Objects.hxx" - - -#include -#include -#include -#include - -//only for sp_help_about() -#include "help.h" - -namespace Inkscape -{ -namespace Extension -{ -namespace Script -{ - - - - -//######################################################################## -//# D I A L O G M A N A G E R -//######################################################################## - -class PyDialogManager : public Py::PythonExtension -{ -public: - - PyDialogManager(Inkscape::UI::Dialog::DialogManager *dm) : - dialogManager(dm) - { - } - - virtual ~PyDialogManager() - { - } - - virtual Py::Object getattr(const char *name) - { - /* - if (strcmp(name, "activeDesktop")==0) - { - PyDesktop obj(SP_ACTIVE_DESKTOP); - return obj; - } - */ - return getattr_methods(name); - } - - virtual Py::Object showAbout(const Py::Tuple &args) - { - sp_help_about(); - return Py::Nothing(); - } - - - static void init_type() - { - behaviors().name("DialogManager"); - behaviors().doc("dialogManager objects: "); - behaviors().supportRepr(); - behaviors().supportGetattr(); - - add_varargs_method("showAbout", &PyDialogManager::showAbout, - "Shows a silly dialog"); - } - -private: - - Inkscape::UI::Dialog::DialogManager *dialogManager; -}; - - - -//######################################################################## -//# D E S K T O P -//######################################################################## - -class PyDesktop : public Py::PythonExtension -{ -public: - - PyDesktop(SPDesktop *dt) : desktop(dt) - { - } - - virtual ~PyDesktop() - { - } - - virtual Py::Object getattr(const char *name) - { - if (strcmp(name, "dialogManager")==0) - { - Py::Object obj(Py::asObject( - new PyDialogManager(desktop->_dlg_mgr))); - return obj; - } - return getattr_methods(name); - } - - static void init_type() - { - behaviors().name("Desktop"); - behaviors().doc("desktop objects: dialogManager"); - behaviors().supportRepr(); - behaviors().supportGetattr(); - } - - - -private: - - SPDesktop *desktop; - -}; - - - -//######################################################################## -//# D O C U M E N T -//######################################################################## - - -class PyDocument : public Py::PythonExtension -{ -public: - - PyDocument(SPDocument *doc) : document(doc) - { - } - - virtual ~PyDocument() - { - } - - virtual Py::Object getattr(const char *name) - { - return getattr_methods(name); - } - - - static void init_type() - { - behaviors().name("Document"); - behaviors().doc("document objects: "); - behaviors().supportRepr(); - behaviors().supportGetattr(); - } - -private: - - SPDocument *document; -}; - - - - - - - -//######################################################################## -//# I N K S C A P E and siblings -//# -//# The following are children of PyInkscapeModule and are spawned -//# by its methods. The classes above are spawned by PyInkscape and -//# it descendants. -//# -//######################################################################## - - -class PyInkscape : public Py::PythonExtension -{ -public: - - PyInkscape(InkscapePython &par) : parent(par) - { - inkscape = INKSCAPE; - } - - virtual ~PyInkscape() - { - } - - - virtual Py::Object getattr(const char *name) - { - if (strcmp(name, "activeDesktop")==0) - { - Py::Object obj(Py::asObject( - new PyDesktop(SP_ACTIVE_DESKTOP))); - return obj; - } - else if (strcmp(name, "activeDocument")==0) - { - Py::Object obj(Py::asObject( - new PyDocument(SP_ACTIVE_DOCUMENT))); - return obj; - } - return getattr_methods(name); - } - - virtual Py::Object exit(const Py::Tuple &args) - { - //exit(); - return Py::Nothing(); //like a void - } - - virtual Py::Object hello(const Py::Tuple &args) - { - //exit(); - //throw Py::RuntimeError("some error message"); - return Py::String("Hello, world!"); - } - - static void init_type() - { - behaviors().name("Inkscape"); - behaviors().doc("inkscape objects: activeDesktop activeDocument"); - behaviors().supportRepr(); - behaviors().supportGetattr(); - - add_varargs_method("hello", &PyInkscape::hello, - "Does a hello, world"); - add_varargs_method("exit", &PyInkscape::exit, - "exit from the current application"); - } - -private: - - InkscapePython &parent; - - Inkscape::Application *inkscape; - -}; - - - - -//######################################################################## -//# O U T P U T S -//######################################################################## - - - -class PyStdOut : public Py::PythonExtension -{ -public: - - PyStdOut(InkscapePython &par) : parent(par) - { - } - - virtual ~PyStdOut() - { - } - - - virtual Py::Object write(const Py::Tuple &args) - { - for(unsigned int i=0 ; i -{ -public: - - PyStdErr(InkscapePython &par) : parent(par) - { - } - - virtual ~PyStdErr() - { - } - - - virtual Py::Object write(const Py::Tuple &args) - { - for(unsigned int i=0 ; i -{ -public: - PyInkscapeModule(InkscapePython &par) - : Py::ExtensionModule( "PyInkscapeModule" ), - parent(par) - { - //# Init our module's classes - PyInkscape::init_type(); - PyDocument::init_type(); - PyDesktop::init_type(); - PyDialogManager::init_type(); - PyStdOut::init_type(); - PyStdErr::init_type(); - - add_varargs_method("getInkscape", - &PyInkscapeModule::getInkscape, "returns global inkscape app"); - add_varargs_method("getStdOut", - &PyInkscapeModule::getStdOut, "gets redirected output"); - add_varargs_method("getStdErr", - &PyInkscapeModule::getStdErr, "gets redirected output"); - - initialize( "main Inkscape module" ); - } - - virtual ~PyInkscapeModule() - { - } - - virtual Py::Object getInkscape(const Py::Tuple &args) - { - Py::Object obj(Py::asObject(new PyInkscape(parent))); - return obj; - } - virtual Py::Object getStdOut(const Py::Tuple &args) - { - Py::Object obj(Py::asObject(new PyStdOut(parent))); - return obj; - } - virtual Py::Object getStdErr(const Py::Tuple &args) - { - Py::Object obj(Py::asObject(new PyStdErr(parent))); - return obj; - } - -private: - - InkscapePython &parent; - - -}; - - - -//######################################################################## -//# M A I N -//######################################################################## - - - - -/** - * Interpret an in-memory string - */ -bool InkscapePython::interpretScript(const Glib::ustring &script, - Glib::ustring &output, Glib::ustring &error) -{ - - stdOut.clear(); - stdErr.clear(); - - //## First bind our classes - Py_Initialize(); - - - //# Init our custom objects - PyInkscapeModule inkscapeModule(*this); - - PyObject *globalMod = PyImport_AddModule("__main__"); - PyObject *globalDict = PyModule_GetDict(globalMod); - PyObject *localDict = inkscapeModule.moduleDictionary().ptr(); - - Glib::ustring buf = - "import sys\n" - "sys.stdout = getStdOut()\n" - "sys.stderr = getStdErr()\n" - "\n" - "inkscape = getInkscape()\n" - "\n"; - buf.append(script); - - - char *codeStr = (char *)buf.c_str(); - PyRun_String(codeStr, Py_file_input, globalDict, localDict); - - output = stdOut; - //output = "hello, world\n"; - error = stdErr; - - - //## Check for errors - if (PyErr_Occurred()) - { - PyObject *errtype = NULL; - PyObject *errval = NULL; - PyObject *errtraceback = NULL; - - PyErr_Fetch(&errtype, &errval, &errtraceback); - //PyErr_Clear(); - - if (errval && PyString_Check(errval)) - { - PyObject *pystring = PyObject_Str(errval); - char *errStr = PyString_AsString(pystring); - int line = ((PyTracebackObject*)errtraceback)->tb_lineno; - //error = "Line "; - //error.append(line); - //error.append(" : "); - error.append(errStr); - Py_XDECREF(pystring); - } - else - { - error = "Error occurred"; - } - Py_XDECREF(errtype); - Py_XDECREF(errval); - Py_XDECREF(errtraceback); - Py_Finalize(); - return false; - } - - - Py_Finalize(); - - return true; -} - - - - - - - -} // namespace Script -} // namespace Extension -} // namespace Inkscape - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : diff --git a/src/extension/script/InkscapePython.h b/src/extension/script/InkscapePython.h deleted file mode 100644 index a97c945c8..000000000 --- a/src/extension/script/InkscapePython.h +++ /dev/null @@ -1,97 +0,0 @@ -#ifndef __INKSCAPE_PYTHON_H__ -#define __INKSCAPE_PYTHON_H__ - -/** - * Python Interpreter wrapper for Inkscape - * - * Authors: - * Bob Jamison - * - * Copyright (C) 2004-2007 Authors - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include "InkscapeInterpreter.h" -#include - - - -namespace Inkscape -{ -namespace Extension -{ -namespace Script -{ - - - -class InkscapePython : public InkscapeInterpreter -{ -public: - - /** - * Constructor. Create and initialize python binding. - * Note that we will only actually start up the Python - * interpreter when there is a demand. - */ - InkscapePython() - { - } - - - /** - * Destructor - */ - virtual ~InkscapePython() - { - } - - - - /** - * Overloaded from InkscapeInterpreter - */ - virtual bool interpretScript(const Glib::ustring &script, - Glib::ustring &output, - Glib::ustring &error); - - - virtual void writeStdOut(const Glib::ustring &txt) - { - stdOut.append(txt); - } - - virtual void writeStdErr(const Glib::ustring &txt) - { - stdErr.append(txt); - } - -private: - - Glib::ustring stdOut; - Glib::ustring stdErr; - -}; - - - - -} // namespace Script -} // namespace Extension -} // namespace Inkscape - - - -#endif /*__INKSCAPE_PYTHON_H__ */ - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : diff --git a/src/extension/script/InkscapeScript.cpp b/src/extension/script/InkscapeScript.cpp index dfdbabcc5..806eb7b31 100644 --- a/src/extension/script/InkscapeScript.cpp +++ b/src/extension/script/InkscapeScript.cpp @@ -11,22 +11,15 @@ #include "InkscapeScript.h" -#include "InkscapeInterpreter.h" - -#ifdef WITH_PERL -# include "InkscapePerl.h" -#endif - -#ifdef WITH_PYTHON -# include "InkscapePython.h" -#endif - +#include namespace Inkscape { namespace Extension { namespace Script { +typedef Inkscape::Bind::Value Value; + /** * */ @@ -58,28 +51,19 @@ bool InkscapeScript::interpretScript(const Glib::ustring &script, Glib::ustring &error, ScriptLanguage language) { - char * langname=NULL; - InkscapeInterpreter *interp = NULL; + const char *langname=NULL; //if() instead of switch() lets us scope vars - if (language == InkscapeScript::PERL) + if (language == InkscapeScript::JAVASCRIPT) { -#ifdef WITH_PERL - langname="Perl"; - interp = new InkscapePerl(); -#else - g_print ("Internal Perl script functionality requested, but it was not compiled in!\n"); - return false; -#endif + langname="Javascript"; } else if (language == InkscapeScript::PYTHON) { -#ifdef WITH_PYTHON langname="Python"; - interp = new InkscapePython(); -#else - g_print ("Internal Python script functionality requested, but it was not compiled in!\n"); - return false; -#endif + } + else if (language == InkscapeScript::RUBY) + { + langname="Ruby"; } else { @@ -88,70 +72,94 @@ bool InkscapeScript::interpretScript(const Glib::ustring &script, return false; } - if (!interp) + Inkscape::Bind::JavaBindery *binder = + Inkscape::Bind::JavaBindery::getInstance(); + if (!binder->loadJVM()) //idempotent { - g_warning("interpretScript: error starting Language '%s'\n", - langname); + g_warning("interpretScript: unable to start JVM\n"); return false; - } - - if (!interp->interpretScript(script, output, error)) + } + std::vector parms; + Value retval; + Value parm; + parm.setString(langname); + parms.push_back(parm); + parm.setString(script); + parms.push_back(parm); + bool ret = binder->callStatic(Value::BIND_BOOLEAN, + "org/inkscape/cmn/ScriptRunner", + "run", + "(Ljava/lang/String;Ljava/lang/String;)Z", + parms, + retval); + if (!ret) { - g_warning("interpretScript: error in executing %s script\n", - langname); - return false; - } - - delete interp; - + g_warning("interpretScript: failed\n"); + return false; + } + return true; } + /** - * Interprets the script in the 'script' buffer, + * Interprets the script in the named file, * storing the stdout output in 'output', and any * error messages in 'error.' Language is one of the * enumerated types in ScriptLanguage above. */ -bool InkscapeScript::interpretUri(const Glib::ustring &uri, +bool InkscapeScript::interpretFile(const Glib::ustring &fname, Glib::ustring &output, Glib::ustring &error, ScriptLanguage language) { - - InkscapeInterpreter *interp = NULL; + const char *langname=NULL; //if() instead of switch() lets us scope vars - if (language == InkscapeScript::PERL) + if (language == InkscapeScript::JAVASCRIPT) { -#ifdef WITH_PERL - interp = new InkscapePerl(); -#endif + langname="Javascript"; } else if (language == InkscapeScript::PYTHON) { -#ifdef WITH_PYTHON - interp = new InkscapePython(); -#endif + langname="Python"; + } + else if (language == InkscapeScript::RUBY) + { + langname="Ruby"; } else { - g_warning("interpretUri: Unknown Script Language type:%d\n", - language); + g_warning("interpretFile: Unknown Script Language type: %d\n", + language); return false; } - if (!interp) - return false; - - if (!interp->interpretUri(uri, output, error)) + Inkscape::Bind::JavaBindery *binder = + Inkscape::Bind::JavaBindery::getInstance(); + if (!binder->loadJVM()) //idempotent { - g_warning("interpretUri: error in executing script '%s'\n", - uri.raw().c_str()); + g_warning("interpretFile: unable to start JVM\n"); return false; - } - - delete interp; - + } + std::vector parms; + Value retval; + Value parm; + parm.setString(langname); + parms.push_back(parm); + parm.setString(fname); + parms.push_back(parm); + bool ret = binder->callStatic(Value::BIND_BOOLEAN, + "org/inkscape/cmn/ScriptRunner", + "runFile", + "(Ljava/lang/String;Ljava/lang/String;)Z", + parms, + retval); + if (!ret) + { + g_warning("interpretFile: failed\n"); + return false; + } + return true; } diff --git a/src/extension/script/InkscapeScript.h b/src/extension/script/InkscapeScript.h index 256b18a2c..b6334fde1 100644 --- a/src/extension/script/InkscapeScript.h +++ b/src/extension/script/InkscapeScript.h @@ -30,8 +30,9 @@ public: */ typedef enum { + JAVASCRIPT, PYTHON, - PERL + RUBY } ScriptLanguage; /** @@ -56,12 +57,12 @@ public: ScriptLanguage language); /** - * Interprets the script at the uri (file) named by 'uri', + * Interprets the script in the named file, * storing the stdout output in 'output', and any * error messages in 'error.' Language is one of the * enumerated types in ScriptLanguage above. */ - bool interpretUri(const Glib::ustring &uri, + bool interpretFile(const Glib::ustring &fname, Glib::ustring &output, Glib::ustring &error, ScriptLanguage language); diff --git a/src/extension/script/Makefile.tmp b/src/extension/script/Makefile.tmp deleted file mode 100644 index a952f2ba3..000000000 --- a/src/extension/script/Makefile.tmp +++ /dev/null @@ -1,89 +0,0 @@ -############################################# -# Makefile for testing embedding -# -# This temporary makefile is for designing -# and testing a generic structure for embedding -# interpreters in Inkscape, and binding back -# from them into the Inkscape internals. This -# would allow users to automate some Inkscape -# functionality. -############################################# - -CXX = g++ - -WRAPS = \ -inkscape_py_wrap.o \ -inkscape_perl_wrap.o - -OBJ = \ -InkscapeScript.o \ -InkscapeInterpreter.o \ -InkscapeBinding.o \ -InkscapePython.o \ -InkscapePerl.o \ -$(WRAPS) - -######################################################### -# NOTE that we are using the interpreters themselves, to -# discover the settings for compiling and linking -######################################################### - -PERL_CFLAGS := $(shell perl -MExtUtils::Embed -e ccopts ) -PERL_LDFLAGS := $(shell perl -MExtUtils::Embed -e ldopts ) - -#INCLUDEPY, LIBPL, LIBRARY -PYTHON_CFLAGS := -I$(shell python -c "import distutils.sysconfig ; print distutils.sysconfig.get_config_var('INCLUDEPY')" ) -PYTHON_LDPATH := $(shell python -c "import distutils.sysconfig ; print distutils.sysconfig.get_config_var('LIBPL')" ) -PYTHON_LIB := $(shell python -c "import distutils.sysconfig ; print distutils.sysconfig.get_config_var('LIBRARY')" ) -PYTHON_LDFLAGS = $(PYTHON_LDPATH)/$(PYTHON_LIB) -#PYTHON_LDFLAGS = $(PYTHON_LDPATH) - -GLIB_INC := $(shell pkg-config --cflags glib-2.0) -GLIB_LIB := $(shell pkg-config --libs glib-2.0) - -INC = -I. -I../.. $(GLIB_INC) - -CFLAGS = -g $(PYTHON_CFLAGS) $(PERL_CFLAGS) -CXXFLAGS = $(CFLAGS) - -LIBS = $(PYTHON_LDFLAGS) $(PERL_LDFLAGS) $(GLIB_LIB) - -all: bindtest cpptest - -wraps: $(WRAPS) - -bindtest: bindtest.o $(OBJ) - $(CXX) -o $@ bindtest.o $(OBJ) $(LIBS) - -cpptest: cpptest.o $(OBJ) - $(CXX) -o $@ cpptest.o $(OBJ) $(LIBS) - - -#_inkscape_py.so : inkscape_py_wrap.o $(OBJ) -# $(CXX) -shared -o _inkscape_py.so $(OBJ) - -inkscape_py_wrap.cpp: InkscapeBinding.h inkscape_py.i - swig -c++ -python -o inkscape_py_wrap.cpp inkscape_py.i - perl quotefile.pl inkscape_py.py inkscape_py.py.h - -InkscapePython.o: InkscapePython.cpp InkscapePython.h inkscape_py_wrap.o - $(CXX) $(CXXFLAGS) $(INC) $(PYINC) -o $@ -c InkscapePython.cpp - -inkscape_perl_wrap.cpp: InkscapeBinding.h inkscape_perl.i - swig -c++ -perl5 -static -o inkscape_perl_wrap.cpp inkscape_perl.i - perl quotefile.pl inkscape_perl.pm inkscape_perl.pm.h - -InkscapePerl.o: InkscapePerl.cpp InkscapePerl.h inkscape_perl_wrap.o - $(CXX) $(CXXFLAGS) $(INC) $(PERLINC) -o $@ -c InkscapePerl.cpp - -.cpp.o: - $(CXX) $(CXXFLAGS) $(INC) -o $@ -c $< - -clean: - -$(RM) bindtest - -$(RM) cpptest - -$(RM) *.o - -$(RM) *.so - -$(RM) *.pyc - - diff --git a/src/extension/script/Makefile_insert b/src/extension/script/Makefile_insert index da1b0b876..e9edddee3 100644 --- a/src/extension/script/Makefile_insert +++ b/src/extension/script/Makefile_insert @@ -6,39 +6,8 @@ extension/script/clean: rm -f extension/script/libscript.a rm -f $(extension_script_libscript_a_OBJECTS) -if WITH_PERL -perl_sources = \ - extension/script/InkscapePerl.h \ - extension/script/InkscapePerl.cpp \ - extension/script/inkscape_perl_wrap.cpp \ - extension/script/inkscape_perl.pm \ - extension/script/inkscape_perl.pm.h -endif - -if WITH_PYTHON -python_sources = \ - extension/script/InkscapePython.h \ - extension/script/InkscapePython.cpp \ - extension/script/CXX/Config.hxx \ - extension/script/CXX/cxxextensions.c \ - extension/script/CXX/cxxsupport.cxx \ - extension/script/CXX/cxx_extensions.cxx \ - extension/script/CXX/Exception.hxx \ - extension/script/CXX/Extensions.hxx \ - extension/script/CXX/IndirectPythonInterface.cxx \ - extension/script/CXX/IndirectPythonInterface.hxx \ - extension/script/CXX/Objects.hxx \ - extension/script/CXX/Version.hxx \ - extension/script/CXX/WrapPython.h -endif extension_script_libscript_a_SOURCES = \ - extension/script/InkscapeBinding.h \ - extension/script/InkscapeBinding.cpp \ - extension/script/InkscapeInterpreter.h \ - extension/script/InkscapeInterpreter.cpp \ extension/script/InkscapeScript.h \ - extension/script/InkscapeScript.cpp \ - $(perl_sources) \ - $(python_sources) + extension/script/InkscapeScript.cpp diff --git a/src/extension/script/README.txt b/src/extension/script/README.txt deleted file mode 100644 index 796c52cae..000000000 --- a/src/extension/script/README.txt +++ /dev/null @@ -1,41 +0,0 @@ -SWIG Scripting Notes -==================== -by Ishmal - -The code in this directory is an initial start -at providing application-level scripting to Inkscape -via SWIG and interpreter embedding. Please do not -modify these files until you have become well -acquainted with SWIG and the various methods of -embedding scripting languages in a C/C++ program. - - -The classes defined in InkscapeBinding.h and -implemented in InkscapeBinding.cpp are destined to -be a thin shell for scripting Inkscape. Since -Inkscape currently is not organized in a heirarchical -tree, nor is it threadsafe, this binding tree will merely -mimic such an arrangement. - -Note that this -NOT- the same as ECMAScript binding on an -SVG page. That is another task, coupled with XPath. - -Currently, the way to update InkscapeBinding is to: - -1. Modify InkscapeBinding.h and InkscapeBinding.cpp -2. Run 'make -f Makefile.tmp wraps' -3. cd to the src or toplevel directory, and build -4. when this works well, commit the files in this directory - -#### SWIG is available here: - -http://www.swig.org - -#### Information on embedding Python is here - -http://docs.python.org/ext/ext.html - - -#### Information on embedding PERL is available here: - -http://perldoc.com/perl5.8.4/pod/perlembed.html diff --git a/src/extension/script/bindtest.cpp b/src/extension/script/bindtest.cpp deleted file mode 100644 index 97970381d..000000000 --- a/src/extension/script/bindtest.cpp +++ /dev/null @@ -1,86 +0,0 @@ - -#include - -#include "InkscapeScript.h" - -#ifndef TRUE -#define TRUE 1 -#endif -#ifndef FALSE -#define FALSE 0 -#endif - -static char *pythonCodeStr = -//"\n" -//"inkscape = _inkscape_py.getInkscape()\n" -"desktop = inkscape.getDesktop()\n" -"document = desktop.getDocument()\n" -"document.hello()\n" -""; - -int testPython() -{ - Inkscape::Extension::Script::InkscapeScript scriptEngine; - printf("##### Python Test #####\n"); - printf("===== CODE ====\n%s\n==============\n", pythonCodeStr); - scriptEngine.interpretScript(pythonCodeStr, - Inkscape::Extension::Script::InkscapeScript::PYTHON); - printf("##### End Python #####\n\n"); - return TRUE; -} - -static char *perlCodeStr = -//"\n" -//"$inkscape = inkscape_perlc::getInkscape();\n" -"print \"inkscape: '$inkscape'\\n\"; \n" -"$desktop = $inkscape->getDesktop();\n" -"$document = $desktop->getDocument();\n" -"$document->hello()\n" -//"reverse 'rekcaH lreP rehtonA tsuJ'\n" -""; - -int testPerl() -{ - Inkscape::Extension::Script::InkscapeScript scriptEngine; - printf("##### Perl Test #####\n"); - printf("===== CODE ====\n%s\n==============\n", perlCodeStr); - scriptEngine.interpretScript(perlCodeStr, - Inkscape::Extension::Script::InkscapeScript::PERL); - printf("##### End Perl #####\n\n"); - return TRUE; -} - - - -int doTest() -{ - if (!testPython()) - { - printf("Failed Python test\n"); - return FALSE; - } - if (!testPerl()) - { - printf("Failed Perl test\n"); - return FALSE; - } - return TRUE; -} - - - -int main(int argc, char **argv) -{ - - if (doTest()) - printf("Tests succeeded\n"); - else - printf("Tests failed\n"); - return 0; -} - - - - - - diff --git a/src/extension/script/cpptest.cpp b/src/extension/script/cpptest.cpp deleted file mode 100644 index e5c9d34de..000000000 --- a/src/extension/script/cpptest.cpp +++ /dev/null @@ -1,22 +0,0 @@ - -#include - -#include "InkscapeBinding.h" - -void doTest() -{ - Inkscape::Extension::Script::Inkscape *inkscape = - Inkscape::Extension::Script::getInkscape(); - Inkscape::Extension::Script::Desktop *desktop = inkscape->getDesktop(); - Inkscape::Extension::Script::Document *document = desktop->getDocument(); - document->hello(); -} - -int main(int argc, char **argv) -{ - - doTest(); - -} - - diff --git a/src/extension/script/inkscape_perl.i b/src/extension/script/inkscape_perl.i deleted file mode 100644 index ccb31c117..000000000 --- a/src/extension/script/inkscape_perl.i +++ /dev/null @@ -1,77 +0,0 @@ -%module inkscape_perl -%{ -#include "InkscapeBinding.h" - - -static void xs_init _((pTHX)); -static PerlInterpreter *my_perl; - -int perl_eval(char *string) { - char *argv[2]; - argv[0] = string; - argv[1] = (char *) 0; - return perl_call_argv("eval",0,argv); -} - -extern "C" int -InkscapePerlParseBuf(char *startupCodeBuf, char *codeBuf) -{ - STRLEN n_a; - int exitstatus; - char *embedding[] = { "", "-e", "0" }; - - my_perl = perl_alloc(); - if (!my_perl) - return 0; - perl_construct( my_perl ); - - exitstatus = perl_parse( my_perl, xs_init, 3, - embedding, (char **) NULL ); - if (exitstatus) - return 0; - - /* Initialize all of the module variables */ - - exitstatus = perl_run( my_perl ); - - SV *retSV = eval_pv(startupCodeBuf, TRUE); - char *ret = SvPV(retSV, n_a); - //printf("## module ret:%s\n", ret); - - retSV = eval_pv("$inkscape = inkscape_perlc::getInkscape();\n", TRUE); - ret = SvPV(retSV, n_a); - //printf("## inkscape ret:%s\n", ret); - - retSV = eval_pv(codeBuf, TRUE); - ret = SvPV(retSV, n_a); - //printf("## code ret:%s\n", ret); - - perl_destruct( my_perl ); - perl_free( my_perl ); - - return 1; -} - -/* Register any extra external extensions */ - -/* Do not delete this line--writemain depends on it */ -/* EXTERN_C void boot_DynaLoader _((CV* cv)); */ - -static void -xs_init(pTHX) -{ -/* dXSUB_SYS; */ - char *file = __FILE__; - { - /* newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file); */ - newXS(SWIG_name, SWIG_init, file); -#ifdef SWIGMODINIT - SWIGMODINIT -#endif - } -} - - -%} - -%include "InkscapeBinding.h" diff --git a/src/extension/script/inkscape_perl.pm b/src/extension/script/inkscape_perl.pm deleted file mode 100644 index 86f8a5e02..000000000 --- a/src/extension/script/inkscape_perl.pm +++ /dev/null @@ -1,178 +0,0 @@ -# This file was automatically generated by SWIG -package inkscape_perl; -require Exporter; -@ISA = qw(Exporter); -package inkscape_perlc; -boot_inkscape_perl(); -package inkscape_perl; -@EXPORT = qw( ); - -# ---------- BASE METHODS ------------- - -package inkscape_perl; - -sub TIEHASH { - my ($classname,$obj) = @_; - return bless $obj, $classname; -} - -sub CLEAR { } - -sub FIRSTKEY { } - -sub NEXTKEY { } - -sub FETCH { - my ($self,$field) = @_; - my $member_func = "swig_${field}_get"; - $self->$member_func(); -} - -sub STORE { - my ($self,$field,$newval) = @_; - my $member_func = "swig_${field}_set"; - $self->$member_func($newval); -} - -sub this { - my $ptr = shift; - return tied(%$ptr); -} - - -# ------- FUNCTION WRAPPERS -------- - -package inkscape_perl; - -*getInkscape = *inkscape_perlc::getInkscape; - -############# Class : inkscape_perl::Inkscape ############## - -package inkscape_perl::Inkscape; -@ISA = qw( inkscape_perl ); -%OWNER = (); -%ITERATORS = (); -sub DESTROY { - return unless $_[0]->isa('HASH'); - my $self = tied(%{$_[0]}); - return unless defined $self; - delete $ITERATORS{$self}; - if (exists $OWNER{$self}) { - inkscape_perlc::delete_Inkscape($self); - delete $OWNER{$self}; - } -} - -*getDesktop = *inkscape_perlc::Inkscape_getDesktop; -*getDialogManager = *inkscape_perlc::Inkscape_getDialogManager; -sub DISOWN { - my $self = shift; - my $ptr = tied(%$self); - delete $OWNER{$ptr}; -} - -sub ACQUIRE { - my $self = shift; - my $ptr = tied(%$self); - $OWNER{$ptr} = 1; -} - - -############# Class : inkscape_perl::DialogManager ############## - -package inkscape_perl::DialogManager; -@ISA = qw( inkscape_perl ); -%OWNER = (); -%ITERATORS = (); -sub DESTROY { - return unless $_[0]->isa('HASH'); - my $self = tied(%{$_[0]}); - return unless defined $self; - delete $ITERATORS{$self}; - if (exists $OWNER{$self}) { - inkscape_perlc::delete_DialogManager($self); - delete $OWNER{$self}; - } -} - -*showAbout = *inkscape_perlc::DialogManager_showAbout; -sub DISOWN { - my $self = shift; - my $ptr = tied(%$self); - delete $OWNER{$ptr}; -} - -sub ACQUIRE { - my $self = shift; - my $ptr = tied(%$self); - $OWNER{$ptr} = 1; -} - - -############# Class : inkscape_perl::Desktop ############## - -package inkscape_perl::Desktop; -@ISA = qw( inkscape_perl ); -%OWNER = (); -%ITERATORS = (); -sub DESTROY { - return unless $_[0]->isa('HASH'); - my $self = tied(%{$_[0]}); - return unless defined $self; - delete $ITERATORS{$self}; - if (exists $OWNER{$self}) { - inkscape_perlc::delete_Desktop($self); - delete $OWNER{$self}; - } -} - -*getDocument = *inkscape_perlc::Desktop_getDocument; -sub DISOWN { - my $self = shift; - my $ptr = tied(%$self); - delete $OWNER{$ptr}; -} - -sub ACQUIRE { - my $self = shift; - my $ptr = tied(%$self); - $OWNER{$ptr} = 1; -} - - -############# Class : inkscape_perl::Document ############## - -package inkscape_perl::Document; -@ISA = qw( inkscape_perl ); -%OWNER = (); -%ITERATORS = (); -sub DESTROY { - return unless $_[0]->isa('HASH'); - my $self = tied(%{$_[0]}); - return unless defined $self; - delete $ITERATORS{$self}; - if (exists $OWNER{$self}) { - inkscape_perlc::delete_Document($self); - delete $OWNER{$self}; - } -} - -*hello = *inkscape_perlc::Document_hello; -sub DISOWN { - my $self = shift; - my $ptr = tied(%$self); - delete $OWNER{$ptr}; -} - -sub ACQUIRE { - my $self = shift; - my $ptr = tied(%$self); - $OWNER{$ptr} = 1; -} - - -# ------- VARIABLE STUBS -------- - -package inkscape_perl; - -1; diff --git a/src/extension/script/inkscape_perl.pm.h b/src/extension/script/inkscape_perl.pm.h deleted file mode 100644 index b33b16045..000000000 --- a/src/extension/script/inkscape_perl.pm.h +++ /dev/null @@ -1,187 +0,0 @@ - -/* ################################################### -## This file generated by quotefile.pl from -## inkscape_perl.pm on Thu Dec 16 15:35:48 2004 -## DO NOT EDIT -################################################### */ - -static char *inkscape_module_script = -"# This file was automatically generated by SWIG\n" -"package inkscape_perl;\n" -"require Exporter;\n" -"@ISA = qw(Exporter);\n" -"package inkscape_perlc;\n" -"boot_inkscape_perl();\n" -"package inkscape_perl;\n" -"@EXPORT = qw( );\n" -"\n" -"# ---------- BASE METHODS -------------\n" -"\n" -"package inkscape_perl;\n" -"\n" -"sub TIEHASH {\n" -" my ($classname,$obj) = @_;\n" -" return bless $obj, $classname;\n" -"}\n" -"\n" -"sub CLEAR { }\n" -"\n" -"sub FIRSTKEY { }\n" -"\n" -"sub NEXTKEY { }\n" -"\n" -"sub FETCH {\n" -" my ($self,$field) = @_;\n" -" my $member_func = \"swig_${field}_get\";\n" -" $self->$member_func();\n" -"}\n" -"\n" -"sub STORE {\n" -" my ($self,$field,$newval) = @_;\n" -" my $member_func = \"swig_${field}_set\";\n" -" $self->$member_func($newval);\n" -"}\n" -"\n" -"sub this {\n" -" my $ptr = shift;\n" -" return tied(%$ptr);\n" -"}\n" -"\n" -"\n" -"# ------- FUNCTION WRAPPERS --------\n" -"\n" -"package inkscape_perl;\n" -"\n" -"*getInkscape = *inkscape_perlc::getInkscape;\n" -"\n" -"############# Class : inkscape_perl::Inkscape ##############\n" -"\n" -"package inkscape_perl::Inkscape;\n" -"@ISA = qw( inkscape_perl );\n" -"%OWNER = ();\n" -"%ITERATORS = ();\n" -"sub DESTROY {\n" -" return unless $_[0]->isa('HASH');\n" -" my $self = tied(%{$_[0]});\n" -" return unless defined $self;\n" -" delete $ITERATORS{$self};\n" -" if (exists $OWNER{$self}) {\n" -" inkscape_perlc::delete_Inkscape($self);\n" -" delete $OWNER{$self};\n" -" }\n" -"}\n" -"\n" -"*getDesktop = *inkscape_perlc::Inkscape_getDesktop;\n" -"*getDialogManager = *inkscape_perlc::Inkscape_getDialogManager;\n" -"sub DISOWN {\n" -" my $self = shift;\n" -" my $ptr = tied(%$self);\n" -" delete $OWNER{$ptr};\n" -"}\n" -"\n" -"sub ACQUIRE {\n" -" my $self = shift;\n" -" my $ptr = tied(%$self);\n" -" $OWNER{$ptr} = 1;\n" -"}\n" -"\n" -"\n" -"############# Class : inkscape_perl::DialogManager ##############\n" -"\n" -"package inkscape_perl::DialogManager;\n" -"@ISA = qw( inkscape_perl );\n" -"%OWNER = ();\n" -"%ITERATORS = ();\n" -"sub DESTROY {\n" -" return unless $_[0]->isa('HASH');\n" -" my $self = tied(%{$_[0]});\n" -" return unless defined $self;\n" -" delete $ITERATORS{$self};\n" -" if (exists $OWNER{$self}) {\n" -" inkscape_perlc::delete_DialogManager($self);\n" -" delete $OWNER{$self};\n" -" }\n" -"}\n" -"\n" -"*showAbout = *inkscape_perlc::DialogManager_showAbout;\n" -"sub DISOWN {\n" -" my $self = shift;\n" -" my $ptr = tied(%$self);\n" -" delete $OWNER{$ptr};\n" -"}\n" -"\n" -"sub ACQUIRE {\n" -" my $self = shift;\n" -" my $ptr = tied(%$self);\n" -" $OWNER{$ptr} = 1;\n" -"}\n" -"\n" -"\n" -"############# Class : inkscape_perl::Desktop ##############\n" -"\n" -"package inkscape_perl::Desktop;\n" -"@ISA = qw( inkscape_perl );\n" -"%OWNER = ();\n" -"%ITERATORS = ();\n" -"sub DESTROY {\n" -" return unless $_[0]->isa('HASH');\n" -" my $self = tied(%{$_[0]});\n" -" return unless defined $self;\n" -" delete $ITERATORS{$self};\n" -" if (exists $OWNER{$self}) {\n" -" inkscape_perlc::delete_Desktop($self);\n" -" delete $OWNER{$self};\n" -" }\n" -"}\n" -"\n" -"*getDocument = *inkscape_perlc::Desktop_getDocument;\n" -"sub DISOWN {\n" -" my $self = shift;\n" -" my $ptr = tied(%$self);\n" -" delete $OWNER{$ptr};\n" -"}\n" -"\n" -"sub ACQUIRE {\n" -" my $self = shift;\n" -" my $ptr = tied(%$self);\n" -" $OWNER{$ptr} = 1;\n" -"}\n" -"\n" -"\n" -"############# Class : inkscape_perl::Document ##############\n" -"\n" -"package inkscape_perl::Document;\n" -"@ISA = qw( inkscape_perl );\n" -"%OWNER = ();\n" -"%ITERATORS = ();\n" -"sub DESTROY {\n" -" return unless $_[0]->isa('HASH');\n" -" my $self = tied(%{$_[0]});\n" -" return unless defined $self;\n" -" delete $ITERATORS{$self};\n" -" if (exists $OWNER{$self}) {\n" -" inkscape_perlc::delete_Document($self);\n" -" delete $OWNER{$self};\n" -" }\n" -"}\n" -"\n" -"*hello = *inkscape_perlc::Document_hello;\n" -"sub DISOWN {\n" -" my $self = shift;\n" -" my $ptr = tied(%$self);\n" -" delete $OWNER{$ptr};\n" -"}\n" -"\n" -"sub ACQUIRE {\n" -" my $self = shift;\n" -" my $ptr = tied(%$self);\n" -" $OWNER{$ptr} = 1;\n" -"}\n" -"\n" -"\n" -"# ------- VARIABLE STUBS --------\n" -"\n" -"package inkscape_perl;\n" -"\n" -"1;\n" -""; diff --git a/src/extension/script/inkscape_perl_wrap.cpp b/src/extension/script/inkscape_perl_wrap.cpp deleted file mode 100644 index 2f674d49f..000000000 --- a/src/extension/script/inkscape_perl_wrap.cpp +++ /dev/null @@ -1,1334 +0,0 @@ -/* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 1.3.23 - * - * This file is not intended to be easily readable and contains a number of - * coding conventions designed to improve portability and efficiency. Do not make - * changes to this file unless you know what you are doing--modify the SWIG - * interface file instead. - * ----------------------------------------------------------------------------- */ - - -#ifdef __cplusplus -template class SwigValueWrapper { - T *tt; -public: - SwigValueWrapper() : tt(0) { } - SwigValueWrapper(const SwigValueWrapper& rhs) : tt(new T(*rhs.tt)) { } - SwigValueWrapper(const T& t) : tt(new T(t)) { } - ~SwigValueWrapper() { delete tt; } - SwigValueWrapper& operator=(const T& t) { delete tt; tt = new T(t); return *this; } - operator T&() const { return *tt; } - T *operator&() { return tt; } -private: - SwigValueWrapper& operator=(const SwigValueWrapper& rhs); -}; -#endif - - -#ifndef SWIG_TEMPLATE_DISAMBIGUATOR -# if defined(__SUNPRO_CC) -# define SWIG_TEMPLATE_DISAMBIGUATOR template -# else -# define SWIG_TEMPLATE_DISAMBIGUATOR -# endif -#endif - -/*********************************************************************** - * common.swg - * - * This file contains generic SWIG runtime support for pointer - * type checking as well as a few commonly used macros to control - * external linkage. - * - * Author : David Beazley (beazley@cs.uchicago.edu) - * - * Copyright (c) 1999-2000, The University of Chicago - * - * This file may be freely redistributed without license or fee provided - * this copyright message remains intact. - ************************************************************************/ - -#include - -#if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) -# if !defined(STATIC_LINKED) -# define SWIGEXPORT(a) __declspec(dllexport) a -# else -# define SWIGEXPORT(a) a -# endif -#else -# define SWIGEXPORT(a) a -#endif - -#define SWIGRUNTIME(x) static x - -#ifndef SWIGINLINE -#if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__)) -# define SWIGINLINE inline -#else -# define SWIGINLINE -#endif -#endif - - -/* This should only be incremented when either the layout of swig_type_info changes, - or for whatever reason, the runtime changes incompatibly */ -#define SWIG_RUNTIME_VERSION "1" - -/* define SWIG_TYPE_TABLE_NAME as "SWIG_TYPE_TABLE" */ -#ifdef SWIG_TYPE_TABLE -#define SWIG_QUOTE_STRING(x) #x -#define SWIG_EXPAND_AND_QUOTE_STRING(x) SWIG_QUOTE_STRING(x) -#define SWIG_TYPE_TABLE_NAME SWIG_EXPAND_AND_QUOTE_STRING(SWIG_TYPE_TABLE) -#else -#define SWIG_TYPE_TABLE_NAME -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -typedef void *(*swig_converter_func)(void *); -typedef struct swig_type_info *(*swig_dycast_func)(void **); - -typedef struct swig_type_info { - const char *name; - swig_converter_func converter; - const char *str; - void *clientdata; - swig_dycast_func dcast; - struct swig_type_info *next; - struct swig_type_info *prev; -} swig_type_info; - -static swig_type_info *swig_type_list = 0; -static swig_type_info **swig_type_list_handle = &swig_type_list; - -/* - Compare two type names skipping the space characters, therefore - "char*" == "char *" and "Class" == "Class", etc. - - Return 0 when the two name types are equivalent, as in - strncmp, but skipping ' '. -*/ -static int -SWIG_TypeNameComp(const char *f1, const char *l1, - const char *f2, const char *l2) { - for (;(f1 != l1) && (f2 != l2); ++f1, ++f2) { - while ((*f1 == ' ') && (f1 != l1)) ++f1; - while ((*f2 == ' ') && (f2 != l2)) ++f2; - if (*f1 != *f2) return *f1 - *f2; - } - return (l1 - f1) - (l2 - f2); -} - -/* - Check type equivalence in a name list like ||... -*/ -static int -SWIG_TypeEquiv(const char *nb, const char *tb) { - int equiv = 0; - const char* te = tb + strlen(tb); - const char* ne = nb; - while (!equiv && *ne) { - for (nb = ne; *ne; ++ne) { - if (*ne == '|') break; - } - equiv = SWIG_TypeNameComp(nb, ne, tb, te) == 0; - if (*ne) ++ne; - } - return equiv; -} - - -/* Register a type mapping with the type-checking */ -static swig_type_info * -SWIG_TypeRegister(swig_type_info *ti) { - swig_type_info *tc, *head, *ret, *next; - /* Check to see if this type has already been registered */ - tc = *swig_type_list_handle; - while (tc) { - /* check simple type equivalence */ - int typeequiv = (strcmp(tc->name, ti->name) == 0); - /* check full type equivalence, resolving typedefs */ - if (!typeequiv) { - /* only if tc is not a typedef (no '|' on it) */ - if (tc->str && ti->str && !strstr(tc->str,"|")) { - typeequiv = SWIG_TypeEquiv(ti->str,tc->str); - } - } - if (typeequiv) { - /* Already exists in the table. Just add additional types to the list */ - if (ti->clientdata) tc->clientdata = ti->clientdata; - head = tc; - next = tc->next; - goto l1; - } - tc = tc->prev; - } - head = ti; - next = 0; - - /* Place in list */ - ti->prev = *swig_type_list_handle; - *swig_type_list_handle = ti; - - /* Build linked lists */ - l1: - ret = head; - tc = ti + 1; - /* Patch up the rest of the links */ - while (tc->name) { - head->next = tc; - tc->prev = head; - head = tc; - tc++; - } - if (next) next->prev = head; - head->next = next; - - return ret; -} - -/* Check the typename */ -static swig_type_info * -SWIG_TypeCheck(char *c, swig_type_info *ty) { - swig_type_info *s; - if (!ty) return 0; /* Void pointer */ - s = ty->next; /* First element always just a name */ - do { - if (strcmp(s->name,c) == 0) { - if (s == ty->next) return s; - /* Move s to the top of the linked list */ - s->prev->next = s->next; - if (s->next) { - s->next->prev = s->prev; - } - /* Insert s as second element in the list */ - s->next = ty->next; - if (ty->next) ty->next->prev = s; - ty->next = s; - s->prev = ty; - return s; - } - s = s->next; - } while (s && (s != ty->next)); - return 0; -} - -/* Cast a pointer up an inheritance hierarchy */ -static SWIGINLINE void * -SWIG_TypeCast(swig_type_info *ty, void *ptr) { - if ((!ty) || (!ty->converter)) return ptr; - return (*ty->converter)(ptr); -} - -/* Dynamic pointer casting. Down an inheritance hierarchy */ -static swig_type_info * -SWIG_TypeDynamicCast(swig_type_info *ty, void **ptr) { - swig_type_info *lastty = ty; - if (!ty || !ty->dcast) return ty; - while (ty && (ty->dcast)) { - ty = (*ty->dcast)(ptr); - if (ty) lastty = ty; - } - return lastty; -} - -/* Return the name associated with this type */ -static SWIGINLINE const char * -SWIG_TypeName(const swig_type_info *ty) { - return ty->name; -} - -/* Return the pretty name associated with this type, - that is an unmangled type name in a form presentable to the user. -*/ -static const char * -SWIG_TypePrettyName(const swig_type_info *type) { - /* The "str" field contains the equivalent pretty names of the - type, separated by vertical-bar characters. We choose - to print the last name, as it is often (?) the most - specific. */ - if (type->str != NULL) { - const char *last_name = type->str; - const char *s; - for (s = type->str; *s; s++) - if (*s == '|') last_name = s+1; - return last_name; - } - else - return type->name; -} - -/* Search for a swig_type_info structure */ -static swig_type_info * -SWIG_TypeQuery(const char *name) { - swig_type_info *ty = *swig_type_list_handle; - while (ty) { - if (ty->str && (SWIG_TypeEquiv(ty->str,name))) return ty; - if (ty->name && (strcmp(name,ty->name) == 0)) return ty; - ty = ty->prev; - } - return 0; -} - -/* Set the clientdata field for a type */ -static void -SWIG_TypeClientData(swig_type_info *ti, void *clientdata) { - swig_type_info *tc, *equiv; - if (ti->clientdata) return; - /* if (ti->clientdata == clientdata) return; */ - ti->clientdata = clientdata; - equiv = ti->next; - while (equiv) { - if (!equiv->converter) { - tc = *swig_type_list_handle; - while (tc) { - if ((strcmp(tc->name, equiv->name) == 0)) - SWIG_TypeClientData(tc,clientdata); - tc = tc->prev; - } - } - equiv = equiv->next; - } -} - -/* Pack binary data into a string */ -static char * -SWIG_PackData(char *c, void *ptr, size_t sz) { - static char hex[17] = "0123456789abcdef"; - unsigned char *u = (unsigned char *) ptr; - const unsigned char *eu = u + sz; - register unsigned char uu; - for (; u != eu; ++u) { - uu = *u; - *(c++) = hex[(uu & 0xf0) >> 4]; - *(c++) = hex[uu & 0xf]; - } - return c; -} - -/* Unpack binary data from a string */ -static char * -SWIG_UnpackData(char *c, void *ptr, size_t sz) { - register unsigned char uu = 0; - register int d; - unsigned char *u = (unsigned char *) ptr; - const unsigned char *eu = u + sz; - for (; u != eu; ++u) { - d = *(c++); - if ((d >= '0') && (d <= '9')) - uu = ((d - '0') << 4); - else if ((d >= 'a') && (d <= 'f')) - uu = ((d - ('a'-10)) << 4); - d = *(c++); - if ((d >= '0') && (d <= '9')) - uu |= (d - '0'); - else if ((d >= 'a') && (d <= 'f')) - uu |= (d - ('a'-10)); - *u = uu; - } - return c; -} - -/* This function will propagate the clientdata field of type to -* any new swig_type_info structures that have been added into the list -* of equivalent types. It is like calling -* SWIG_TypeClientData(type, clientdata) a second time. -*/ -static void -SWIG_PropagateClientData(swig_type_info *type) { - swig_type_info *equiv = type->next; - swig_type_info *tc; - if (!type->clientdata) return; - while (equiv) { - if (!equiv->converter) { - tc = *swig_type_list_handle; - while (tc) { - if ((strcmp(tc->name, equiv->name) == 0) && !tc->clientdata) - SWIG_TypeClientData(tc, type->clientdata); - tc = tc->prev; - } - } - equiv = equiv->next; - } -} - -#ifdef __cplusplus -} -#endif - -/* ---------------------------------------------------------------------- -*- c -*- - * perl5.swg - * - * Perl5 runtime library - * $Header$ - * ----------------------------------------------------------------------------- */ - -#define SWIGPERL -#define SWIGPERL5 -#ifdef __cplusplus -/* Needed on some windows machines---since MS plays funny games with the header files under C++ */ -#include -#include -extern "C" { -#endif -#include "EXTERN.h" -#include "perl.h" -#include "XSUB.h" - -/* Get rid of free and malloc defined by perl */ -#undef free -#undef malloc - -#ifndef pTHX_ -#define pTHX_ -#endif - -#include -#ifdef __cplusplus -} -#endif - -/* Macro to call an XS function */ - -#ifdef PERL_OBJECT -# define SWIG_CALLXS(_name) _name(cv,pPerl) -#else -# ifndef MULTIPLICITY -# define SWIG_CALLXS(_name) _name(cv) -# else -# define SWIG_CALLXS(_name) _name(PERL_GET_THX, cv) -# endif -#endif - -/* Contract support */ - -#define SWIG_contract_assert(expr,msg) if (!(expr)) { SWIG_croak(msg); } else - -/* Note: SwigMagicFuncHack is a typedef used to get the C++ compiler to just shut up already */ - -#ifdef PERL_OBJECT -#define MAGIC_PPERL CPerlObj *pPerl = (CPerlObj *) this; -typedef int (CPerlObj::*SwigMagicFunc)(SV *, MAGIC *); - -#ifdef __cplusplus -extern "C" { -#endif -typedef int (CPerlObj::*SwigMagicFuncHack)(SV *, MAGIC *); -#ifdef __cplusplus -} -#endif - -#define SWIG_MAGIC(a,b) (SV *a, MAGIC *b) -#define SWIGCLASS_STATIC -#else -#define MAGIC_PPERL -#define SWIGCLASS_STATIC static -#ifndef MULTIPLICITY -#define SWIG_MAGIC(a,b) (SV *a, MAGIC *b) -typedef int (*SwigMagicFunc)(SV *, MAGIC *); - -#ifdef __cplusplus -extern "C" { -#endif -typedef int (*SwigMagicFuncHack)(SV *, MAGIC *); -#ifdef __cplusplus -} -#endif - - -#else -#define SWIG_MAGIC(a,b) (struct interpreter *interp, SV *a, MAGIC *b) -typedef int (*SwigMagicFunc)(struct interpreter *, SV *, MAGIC *); -#ifdef __cplusplus -extern "C" { -#endif -typedef int (*SwigMagicFuncHack)(struct interpreter *, SV *, MAGIC *); -#ifdef __cplusplus -} -#endif - -#endif -#endif - -#if defined(WIN32) && defined(PERL_OBJECT) && !defined(PerlIO_exportFILE) -#define PerlIO_exportFILE(fh,fl) (FILE*)(fh) -#endif - -/* Modifications for newer Perl 5.005 releases */ - -#if !defined(PERL_REVISION) || ((PERL_REVISION >= 5) && ((PERL_VERSION < 5) || ((PERL_VERSION == 5) && (PERL_SUBVERSION < 50)))) -# ifndef PL_sv_yes -# define PL_sv_yes sv_yes -# endif -# ifndef PL_sv_undef -# define PL_sv_undef sv_undef -# endif -# ifndef PL_na -# define PL_na na -# endif -#endif - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define SWIG_OWNER 1 -#define SWIG_SHADOW 2 - -/* Common SWIG API */ - -#ifdef PERL_OBJECT -# define SWIG_ConvertPtr(obj, pp, type, flags) \ - SWIG_Perl_ConvertPtr(pPerl, obj, pp, type, flags) -# define SWIG_NewPointerObj(p, type, flags) \ - SWIG_Perl_NewPointerObj(pPerl, p, type, flags) -# define SWIG_MakePackedObj(sv, p, s, type) \ - SWIG_Perl_MakePackedObj(pPerl, sv, p, s, type) -# define SWIG_ConvertPacked(obj, p, s, type, flags) \ - SWIG_Perl_ConvertPacked(pPerl, obj, p, s, type, flags) - -#else -# define SWIG_ConvertPtr(obj, pp, type, flags) \ - SWIG_Perl_ConvertPtr(obj, pp, type, flags) -# define SWIG_NewPointerObj(p, type, flags) \ - SWIG_Perl_NewPointerObj(p, type, flags) -# define SWIG_MakePackedObj(sv, p, s, type) \ - SWIG_Perl_MakePackedObj(sv, p, s, type ) -# define SWIG_ConvertPacked(obj, p, s, type, flags) \ - SWIG_Perl_ConvertPacked(obj, p, s, type, flags) -#endif - -/* Perl-specific API */ -#ifdef PERL_OBJECT -# define SWIG_MakePtr(sv, ptr, type, flags) \ - SWIG_Perl_MakePtr(pPerl, sv, ptr, type, flags) -# define SWIG_SetError(str) \ - SWIG_Perl_SetError(pPerl, str) -#else -# define SWIG_MakePtr(sv, ptr, type, flags) \ - SWIG_Perl_MakePtr(sv, ptr, type, flags) -# define SWIG_SetError(str) \ - SWIG_Perl_SetError(str) -# define SWIG_SetErrorSV(str) \ - SWIG_Perl_SetErrorSV(str) -#endif - -#define SWIG_SetErrorf SWIG_Perl_SetErrorf - - -#ifdef PERL_OBJECT -# define SWIG_MAYBE_PERL_OBJECT CPerlObj *pPerl, -#else -# define SWIG_MAYBE_PERL_OBJECT -#endif - -/* load the swig_runtime_list_handle variable from the interpreter */ -static void SWIG_Perl_LookupTypePointer() { - SV *pointer; - - /* first check if pointer already created */ - pointer = get_sv("swig_runtime_data::type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME, FALSE); - if (pointer && SvOK(pointer)) { - swig_type_list_handle = INT2PTR(swig_type_info **, SvIV(pointer)); - } else { - /* create a new pointer */ - pointer = get_sv("swig_runtime_data::type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME, TRUE); - sv_setiv(pointer, PTR2IV(swig_type_list_handle)); - } -} - -static swig_type_info * -SWIG_Perl_TypeCheckRV(SWIG_MAYBE_PERL_OBJECT SV *rv, swig_type_info *ty) { - swig_type_info *s; - if (!ty) return 0; /* Void pointer */ - s = ty->next; /* First element always just a name */ - do { - if (sv_derived_from(rv, (char *) s->name)) { - if (s == ty->next) return s; - /* Move s to the top of the linked list */ - s->prev->next = s->next; - if (s->next) { - s->next->prev = s->prev; - } - /* Insert s as second element in the list */ - s->next = ty->next; - if (ty->next) ty->next->prev = s; - ty->next = s; - s->prev = ty; - return s; - } - s = s->next; - } while (s && (s != ty->next)); - return 0; -} - -/* Function for getting a pointer value */ - -static int -SWIG_Perl_ConvertPtr(SWIG_MAYBE_PERL_OBJECT SV *sv, void **ptr, swig_type_info *_t, int flags) { - swig_type_info *tc; - void *voidptr = (void *)0; - - /* If magical, apply more magic */ - if (SvGMAGICAL(sv)) - mg_get(sv); - - /* Check to see if this is an object */ - if (sv_isobject(sv)) { - SV *tsv = (SV*) SvRV(sv); - IV tmp = 0; - if ((SvTYPE(tsv) == SVt_PVHV)) { - MAGIC *mg; - if (SvMAGICAL(tsv)) { - mg = mg_find(tsv,'P'); - if (mg) { - sv = mg->mg_obj; - if (sv_isobject(sv)) { - tmp = SvIV((SV*)SvRV(sv)); - } - } - } else { - return -1; - } - } else { - tmp = SvIV((SV*)SvRV(sv)); - } - voidptr = (void *)tmp; - if (!_t) { - *(ptr) = voidptr; - return 0; - } - } else if (! SvOK(sv)) { /* Check for undef */ - *(ptr) = (void *) 0; - return 0; - } else if (SvTYPE(sv) == SVt_RV) { /* Check for NULL pointer */ - *(ptr) = (void *) 0; - if (!SvROK(sv)) - return 0; - else - return -1; - } else { /* Don't know what it is */ - *(ptr) = (void *) 0; - return -1; - } - if (_t) { - /* Now see if the types match */ - char *_c = HvNAME(SvSTASH(SvRV(sv))); - tc = SWIG_TypeCheck(_c,_t); - if (!tc) { - *ptr = voidptr; - return -1; - } - *ptr = SWIG_TypeCast(tc,voidptr); - return 0; - } - *ptr = voidptr; - return 0; -} - -static void -SWIG_Perl_MakePtr(SWIG_MAYBE_PERL_OBJECT SV *sv, void *ptr, swig_type_info *t, int flags) { - if (ptr && (flags & SWIG_SHADOW)) { - SV *self; - SV *obj=newSV(0); - HV *hash=newHV(); - HV *stash; - sv_setref_pv(obj, (char *) t->name, ptr); - stash=SvSTASH(SvRV(obj)); - if (flags & SWIG_OWNER) { - HV *hv; - GV *gv=*(GV**)hv_fetch(stash, "OWNER", 5, TRUE); - if (!isGV(gv)) - gv_init(gv, stash, "OWNER", 5, FALSE); - hv=GvHVn(gv); - hv_store_ent(hv, obj, newSViv(1), 0); - } - sv_magic((SV *)hash, (SV *)obj, 'P', Nullch, 0); - SvREFCNT_dec(obj); - self=newRV_noinc((SV *)hash); - sv_setsv(sv, self); - SvREFCNT_dec((SV *)self); - sv_bless(sv, stash); - } - else { - sv_setref_pv(sv, (char *) t->name, ptr); - } -} - -static SWIGINLINE SV * -SWIG_Perl_NewPointerObj(SWIG_MAYBE_PERL_OBJECT void *ptr, swig_type_info *t, int flags) { - SV *result = sv_newmortal(); - SWIG_MakePtr(result, ptr, t, flags); - return result; -} - -static void - SWIG_Perl_MakePackedObj(SWIG_MAYBE_PERL_OBJECT SV *sv, void *ptr, int sz, swig_type_info *type) { - char result[1024]; - char *r = result; - if ((2*sz + 1 + strlen(type->name)) > 1000) return; - *(r++) = '_'; - r = SWIG_PackData(r,ptr,sz); - strcpy(r,type->name); - sv_setpv(sv, result); -} - -/* Convert a packed value value */ -static int -SWIG_Perl_ConvertPacked(SWIG_MAYBE_PERL_OBJECT SV *obj, void *ptr, int sz, swig_type_info *ty, int flags) { - swig_type_info *tc; - char *c = 0; - - if ((!obj) || (!SvOK(obj))) return -1; - c = SvPV(obj, PL_na); - /* Pointer values must start with leading underscore */ - if (*c != '_') return -1; - c++; - c = SWIG_UnpackData(c,ptr,sz); - if (ty) { - tc = SWIG_TypeCheck(c,ty); - if (!tc) return -1; - } - return 0; -} - -static SWIGINLINE void -SWIG_Perl_SetError(SWIG_MAYBE_PERL_OBJECT const char *error) { - if (error) sv_setpv(perl_get_sv("@", TRUE), error); -} - -static SWIGINLINE void -SWIG_Perl_SetErrorSV(SWIG_MAYBE_PERL_OBJECT SV *error) { - if (error) sv_setsv(perl_get_sv("@", TRUE), error); -} - -static void -SWIG_Perl_SetErrorf(const char *fmt, ...) { - va_list args; - va_start(args, fmt); - sv_vsetpvfn(perl_get_sv("@", TRUE), fmt, strlen(fmt), &args, Null(SV**), 0, Null(bool*)); - va_end(args); -} - -/* Macros for low-level exception handling */ -#define SWIG_fail goto fail -#define SWIG_croak(x) { SWIG_SetError(x); goto fail; } -#define SWIG_croakSV(x) { SWIG_SetErrorSV(x); goto fail; } -/* most preprocessors do not support vararg macros :-( */ -/* #define SWIG_croakf(x...) { SWIG_SetErrorf(x); goto fail; } */ - - -typedef XS(SwigPerlWrapper); -typedef SwigPerlWrapper *SwigPerlWrapperPtr; - -/* Structure for command table */ -typedef struct { - const char *name; - SwigPerlWrapperPtr wrapper; -} swig_command_info; - -/* Information for constant table */ - -#define SWIG_INT 1 -#define SWIG_FLOAT 2 -#define SWIG_STRING 3 -#define SWIG_POINTER 4 -#define SWIG_BINARY 5 - -/* Constant information structure */ -typedef struct swig_constant_info { - int type; - const char *name; - long lvalue; - double dvalue; - void *pvalue; - swig_type_info **ptype; -} swig_constant_info; - -#ifdef __cplusplus -} -#endif - -/* Structure for variable table */ -typedef struct { - const char *name; - SwigMagicFunc set; - SwigMagicFunc get; - swig_type_info **type; -} swig_variable_info; - -/* Magic variable code */ -#ifndef PERL_OBJECT -#define swig_create_magic(s,a,b,c) _swig_create_magic(s,a,b,c) - #ifndef MULTIPLICITY - static void _swig_create_magic(SV *sv, char *name, int (*set)(SV *, MAGIC *), int (*get)(SV *,MAGIC *)) { - #else - static void _swig_create_magic(SV *sv, char *name, int (*set)(struct interpreter*, SV *, MAGIC *), int (*get)(struct interpreter*, SV *,MAGIC *)) { - #endif -#else -# define swig_create_magic(s,a,b,c) _swig_create_magic(pPerl,s,a,b,c) -static void _swig_create_magic(CPerlObj *pPerl, SV *sv, const char *name, int (CPerlObj::*set)(SV *, MAGIC *), int (CPerlObj::*get)(SV *, MAGIC *)) { -#endif - MAGIC *mg; - sv_magic(sv,sv,'U',(char *) name,strlen(name)); - mg = mg_find(sv,'U'); - mg->mg_virtual = (MGVTBL *) malloc(sizeof(MGVTBL)); - mg->mg_virtual->svt_get = (SwigMagicFuncHack) get; - mg->mg_virtual->svt_set = (SwigMagicFuncHack) set; - mg->mg_virtual->svt_len = 0; - mg->mg_virtual->svt_clear = 0; - mg->mg_virtual->svt_free = 0; -} - - - - - - -#ifdef do_open - #undef do_open -#endif -#ifdef do_close - #undef do_close -#endif -#ifdef scalar - #undef scalar -#endif -#ifdef list - #undef list -#endif -#ifdef apply - #undef apply -#endif -#ifdef convert - #undef convert -#endif -#ifdef Error - #undef Error -#endif -#ifdef form - #undef form -#endif -#ifdef vform - #undef vform -#endif -#ifdef LABEL - #undef LABEL -#endif -#ifdef METHOD - #undef METHOD -#endif -#ifdef Move - #undef Move -#endif -#ifdef yylex - #undef yylex -#endif -#ifdef yyparse - #undef yyparse -#endif -#ifdef yyerror - #undef yyerror -#endif -#ifdef invert - #undef invert -#endif -#ifdef ref - #undef ref -#endif -#ifdef ENTER - #undef ENTER -#endif - - -/* -------- TYPES TABLE (BEGIN) -------- */ - -#define SWIGTYPE_p_Inkscape__Extension__Script__Desktop swig_types[0] -#define SWIGTYPE_p_Inkscape__Extension__Script__Inkscape swig_types[1] -#define SWIGTYPE_p_Inkscape__Extension__Script__DialogManager swig_types[2] -#define SWIGTYPE_p_Inkscape__Extension__Script__Document swig_types[3] -static swig_type_info *swig_types[5]; - -/* -------- TYPES TABLE (END) -------- */ - -#define SWIG_init boot_inkscape_perl - -#define SWIG_name "inkscape_perlc::boot_inkscape_perl" -#define SWIG_prefix "inkscape_perlc::" - -#ifdef __cplusplus -extern "C" -#endif -#ifndef PERL_OBJECT -#ifndef MULTIPLICITY -SWIGEXPORT(void) SWIG_init (CV* cv); -#else -SWIGEXPORT(void) SWIG_init (pTHXo_ CV* cv); -#endif -#else -SWIGEXPORT(void) SWIG_init (CV *cv, CPerlObj *); -#endif - - -#include "InkscapeBinding.h" - - -static void xs_init _((pTHX)); -static PerlInterpreter *my_perl; - -int perl_eval(char *string) { - char *argv[2]; - argv[0] = string; - argv[1] = (char *) 0; - return perl_call_argv("eval",0,argv); -} - -extern "C" int -InkscapePerlParseBuf(char *startupCodeBuf, char *codeBuf) -{ - STRLEN n_a; - int exitstatus; - char *embedding[] = { "", "-e", "0" }; - - my_perl = perl_alloc(); - if (!my_perl) - return 0; - perl_construct( my_perl ); - - exitstatus = perl_parse( my_perl, xs_init, 3, - embedding, (char **) NULL ); - if (exitstatus) - return 0; - - /* Initialize all of the module variables */ - - exitstatus = perl_run( my_perl ); - - SV *retSV = eval_pv(startupCodeBuf, TRUE); - char *ret = SvPV(retSV, n_a); - //printf("## module ret:%s\n", ret); - - retSV = eval_pv("$inkscape = inkscape_perlc::getInkscape();\n", TRUE); - ret = SvPV(retSV, n_a); - //printf("## inkscape ret:%s\n", ret); - - retSV = eval_pv(codeBuf, TRUE); - ret = SvPV(retSV, n_a); - //printf("## code ret:%s\n", ret); - - perl_destruct( my_perl ); - perl_free( my_perl ); - - return 1; -} - -/* Register any extra external extensions */ - -/* Do not delete this line--writemain depends on it */ -/* EXTERN_C void boot_DynaLoader _((CV* cv)); */ - -static void -xs_init(pTHX) -{ -/* dXSUB_SYS; */ - char *file = __FILE__; - { - /* newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file); */ - newXS(SWIG_name, SWIG_init, file); -#ifdef SWIGMODINIT - SWIGMODINIT -#endif - } -} - - - -#ifdef PERL_OBJECT -#define MAGIC_CLASS _wrap_inkscape_perl_var:: -class _wrap_inkscape_perl_var : public CPerlObj { -public: -#else -#define MAGIC_CLASS -#endif -SWIGCLASS_STATIC int swig_magic_readonly(pTHX_ SV *sv, MAGIC *mg) { - MAGIC_PPERL - sv = sv; mg = mg; - croak("Value is read-only."); - return 0; -} - - -#ifdef PERL_OBJECT -}; -#endif - -#ifdef __cplusplus -extern "C" { -#endif -XS(_wrap_getInkscape) { - { - Inkscape::Extension::Script::Inkscape *result; - int argvi = 0; - dXSARGS; - - if ((items < 0) || (items > 0)) { - SWIG_croak("Usage: getInkscape();"); - } - result = (Inkscape::Extension::Script::Inkscape *)Inkscape::Extension::Script::getInkscape(); - - ST(argvi) = sv_newmortal(); - SWIG_MakePtr(ST(argvi++), (void *) result, SWIGTYPE_p_Inkscape__Extension__Script__Inkscape, SWIG_SHADOW|0); - XSRETURN(argvi); - fail: - ; - } - croak(Nullch); -} - - -XS(_wrap_delete_Inkscape) { - { - Inkscape::Extension::Script::Inkscape *arg1 = (Inkscape::Extension::Script::Inkscape *) 0 ; - int argvi = 0; - dXSARGS; - - if ((items < 1) || (items > 1)) { - SWIG_croak("Usage: delete_Inkscape(self);"); - } - { - if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_Inkscape__Extension__Script__Inkscape,0) < 0) { - SWIG_croak("Type error in argument 1 of delete_Inkscape. Expected _p_Inkscape__Extension__Script__Inkscape"); - } - } - delete arg1; - - - XSRETURN(argvi); - fail: - ; - } - croak(Nullch); -} - - -XS(_wrap_Inkscape_getDesktop) { - { - Inkscape::Extension::Script::Inkscape *arg1 = (Inkscape::Extension::Script::Inkscape *) 0 ; - Inkscape::Extension::Script::Desktop *result; - int argvi = 0; - dXSARGS; - - if ((items < 1) || (items > 1)) { - SWIG_croak("Usage: Inkscape_getDesktop(self);"); - } - { - if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_Inkscape__Extension__Script__Inkscape,0) < 0) { - SWIG_croak("Type error in argument 1 of Inkscape_getDesktop. Expected _p_Inkscape__Extension__Script__Inkscape"); - } - } - result = (Inkscape::Extension::Script::Desktop *)(arg1)->getDesktop(); - - ST(argvi) = sv_newmortal(); - SWIG_MakePtr(ST(argvi++), (void *) result, SWIGTYPE_p_Inkscape__Extension__Script__Desktop, SWIG_SHADOW|0); - XSRETURN(argvi); - fail: - ; - } - croak(Nullch); -} - - -XS(_wrap_Inkscape_getDialogManager) { - { - Inkscape::Extension::Script::Inkscape *arg1 = (Inkscape::Extension::Script::Inkscape *) 0 ; - Inkscape::Extension::Script::DialogManager *result; - int argvi = 0; - dXSARGS; - - if ((items < 1) || (items > 1)) { - SWIG_croak("Usage: Inkscape_getDialogManager(self);"); - } - { - if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_Inkscape__Extension__Script__Inkscape,0) < 0) { - SWIG_croak("Type error in argument 1 of Inkscape_getDialogManager. Expected _p_Inkscape__Extension__Script__Inkscape"); - } - } - result = (Inkscape::Extension::Script::DialogManager *)(arg1)->getDialogManager(); - - ST(argvi) = sv_newmortal(); - SWIG_MakePtr(ST(argvi++), (void *) result, SWIGTYPE_p_Inkscape__Extension__Script__DialogManager, SWIG_SHADOW|0); - XSRETURN(argvi); - fail: - ; - } - croak(Nullch); -} - - -XS(_wrap_delete_DialogManager) { - { - Inkscape::Extension::Script::DialogManager *arg1 = (Inkscape::Extension::Script::DialogManager *) 0 ; - int argvi = 0; - dXSARGS; - - if ((items < 1) || (items > 1)) { - SWIG_croak("Usage: delete_DialogManager(self);"); - } - { - if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_Inkscape__Extension__Script__DialogManager,0) < 0) { - SWIG_croak("Type error in argument 1 of delete_DialogManager. Expected _p_Inkscape__Extension__Script__DialogManager"); - } - } - delete arg1; - - - XSRETURN(argvi); - fail: - ; - } - croak(Nullch); -} - - -XS(_wrap_DialogManager_showAbout) { - { - Inkscape::Extension::Script::DialogManager *arg1 = (Inkscape::Extension::Script::DialogManager *) 0 ; - int argvi = 0; - dXSARGS; - - if ((items < 1) || (items > 1)) { - SWIG_croak("Usage: DialogManager_showAbout(self);"); - } - { - if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_Inkscape__Extension__Script__DialogManager,0) < 0) { - SWIG_croak("Type error in argument 1 of DialogManager_showAbout. Expected _p_Inkscape__Extension__Script__DialogManager"); - } - } - (arg1)->showAbout(); - - - XSRETURN(argvi); - fail: - ; - } - croak(Nullch); -} - - -XS(_wrap_delete_Desktop) { - { - Inkscape::Extension::Script::Desktop *arg1 = (Inkscape::Extension::Script::Desktop *) 0 ; - int argvi = 0; - dXSARGS; - - if ((items < 1) || (items > 1)) { - SWIG_croak("Usage: delete_Desktop(self);"); - } - { - if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_Inkscape__Extension__Script__Desktop,0) < 0) { - SWIG_croak("Type error in argument 1 of delete_Desktop. Expected _p_Inkscape__Extension__Script__Desktop"); - } - } - delete arg1; - - - XSRETURN(argvi); - fail: - ; - } - croak(Nullch); -} - - -XS(_wrap_Desktop_getDocument) { - { - Inkscape::Extension::Script::Desktop *arg1 = (Inkscape::Extension::Script::Desktop *) 0 ; - Inkscape::Extension::Script::Document *result; - int argvi = 0; - dXSARGS; - - if ((items < 1) || (items > 1)) { - SWIG_croak("Usage: Desktop_getDocument(self);"); - } - { - if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_Inkscape__Extension__Script__Desktop,0) < 0) { - SWIG_croak("Type error in argument 1 of Desktop_getDocument. Expected _p_Inkscape__Extension__Script__Desktop"); - } - } - result = (Inkscape::Extension::Script::Document *)(arg1)->getDocument(); - - ST(argvi) = sv_newmortal(); - SWIG_MakePtr(ST(argvi++), (void *) result, SWIGTYPE_p_Inkscape__Extension__Script__Document, SWIG_SHADOW|0); - XSRETURN(argvi); - fail: - ; - } - croak(Nullch); -} - - -XS(_wrap_delete_Document) { - { - Inkscape::Extension::Script::Document *arg1 = (Inkscape::Extension::Script::Document *) 0 ; - int argvi = 0; - dXSARGS; - - if ((items < 1) || (items > 1)) { - SWIG_croak("Usage: delete_Document(self);"); - } - { - if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_Inkscape__Extension__Script__Document,0) < 0) { - SWIG_croak("Type error in argument 1 of delete_Document. Expected _p_Inkscape__Extension__Script__Document"); - } - } - delete arg1; - - - XSRETURN(argvi); - fail: - ; - } - croak(Nullch); -} - - -XS(_wrap_Document_hello) { - { - Inkscape::Extension::Script::Document *arg1 = (Inkscape::Extension::Script::Document *) 0 ; - int argvi = 0; - dXSARGS; - - if ((items < 1) || (items > 1)) { - SWIG_croak("Usage: Document_hello(self);"); - } - { - if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_Inkscape__Extension__Script__Document,0) < 0) { - SWIG_croak("Type error in argument 1 of Document_hello. Expected _p_Inkscape__Extension__Script__Document"); - } - } - (arg1)->hello(); - - - XSRETURN(argvi); - fail: - ; - } - croak(Nullch); -} - - - -/* -------- TYPE CONVERSION AND EQUIVALENCE RULES (BEGIN) -------- */ - -static swig_type_info _swigt__p_Inkscape__Extension__Script__Desktop[] = {{"inkscape_perl::Desktop", 0, "Inkscape::Extension::Script::Desktop *", 0, 0, 0, 0},{"inkscape_perl::Desktop", 0, 0, 0, 0, 0, 0},{0, 0, 0, 0, 0, 0, 0}}; -static swig_type_info _swigt__p_Inkscape__Extension__Script__Inkscape[] = {{"inkscape_perl::Inkscape", 0, "Inkscape::Extension::Script::Inkscape *", 0, 0, 0, 0},{"inkscape_perl::Inkscape", 0, 0, 0, 0, 0, 0},{0, 0, 0, 0, 0, 0, 0}}; -static swig_type_info _swigt__p_Inkscape__Extension__Script__DialogManager[] = {{"inkscape_perl::DialogManager", 0, "Inkscape::Extension::Script::DialogManager *", 0, 0, 0, 0},{"inkscape_perl::DialogManager", 0, 0, 0, 0, 0, 0},{0, 0, 0, 0, 0, 0, 0}}; -static swig_type_info _swigt__p_Inkscape__Extension__Script__Document[] = {{"inkscape_perl::Document", 0, "Inkscape::Extension::Script::Document *", 0, 0, 0, 0},{"inkscape_perl::Document", 0, 0, 0, 0, 0, 0},{0, 0, 0, 0, 0, 0, 0}}; - -static swig_type_info *swig_types_initial[] = { -_swigt__p_Inkscape__Extension__Script__Desktop, -_swigt__p_Inkscape__Extension__Script__Inkscape, -_swigt__p_Inkscape__Extension__Script__DialogManager, -_swigt__p_Inkscape__Extension__Script__Document, -0 -}; - - -/* -------- TYPE CONVERSION AND EQUIVALENCE RULES (END) -------- */ - -static swig_constant_info swig_constants[] = { -{0,0,0,0,0,0} -}; -#ifdef __cplusplus -} -#endif -static swig_variable_info swig_variables[] = { -{0,0,0,0} -}; -static swig_command_info swig_commands[] = { -{"inkscape_perlc::getInkscape", _wrap_getInkscape}, -{"inkscape_perlc::delete_Inkscape", _wrap_delete_Inkscape}, -{"inkscape_perlc::Inkscape_getDesktop", _wrap_Inkscape_getDesktop}, -{"inkscape_perlc::Inkscape_getDialogManager", _wrap_Inkscape_getDialogManager}, -{"inkscape_perlc::delete_DialogManager", _wrap_delete_DialogManager}, -{"inkscape_perlc::DialogManager_showAbout", _wrap_DialogManager_showAbout}, -{"inkscape_perlc::delete_Desktop", _wrap_delete_Desktop}, -{"inkscape_perlc::Desktop_getDocument", _wrap_Desktop_getDocument}, -{"inkscape_perlc::delete_Document", _wrap_delete_Document}, -{"inkscape_perlc::Document_hello", _wrap_Document_hello}, -{0,0} -}; - -#ifdef __cplusplus -extern "C" -#endif - -XS(SWIG_init) { - dXSARGS; - int i; - static int _init = 0; - if (!_init) { - SWIG_Perl_LookupTypePointer(); - for (i = 0; swig_types_initial[i]; i++) { - swig_types[i] = SWIG_TypeRegister(swig_types_initial[i]); - } - _init = 1; - } - - /* Install commands */ - for (i = 0; swig_commands[i].name; i++) { - newXS((char*) swig_commands[i].name,swig_commands[i].wrapper, (char*)__FILE__); - } - - /* Install variables */ - for (i = 0; swig_variables[i].name; i++) { - SV *sv; - sv = perl_get_sv((char*) swig_variables[i].name, TRUE | 0x2); - if (swig_variables[i].type) { - SWIG_MakePtr(sv,(void *)1, *swig_variables[i].type,0); - } else { - sv_setiv(sv,(IV) 0); - } - swig_create_magic(sv, (char *) swig_variables[i].name, swig_variables[i].set, swig_variables[i].get); - } - - /* Install constant */ - for (i = 0; swig_constants[i].type; i++) { - SV *sv; - sv = perl_get_sv((char*)swig_constants[i].name, TRUE | 0x2); - switch(swig_constants[i].type) { - case SWIG_INT: - sv_setiv(sv, (IV) swig_constants[i].lvalue); - break; - case SWIG_FLOAT: - sv_setnv(sv, (double) swig_constants[i].dvalue); - break; - case SWIG_STRING: - sv_setpv(sv, (char *) swig_constants[i].pvalue); - break; - case SWIG_POINTER: - SWIG_MakePtr(sv, swig_constants[i].pvalue, *(swig_constants[i].ptype),0); - break; - case SWIG_BINARY: - SWIG_MakePackedObj(sv, swig_constants[i].pvalue, swig_constants[i].lvalue, *(swig_constants[i].ptype)); - break; - default: - break; - } - SvREADONLY_on(sv); - } - - SWIG_TypeClientData(SWIGTYPE_p_Inkscape__Extension__Script__Inkscape, (void*) "inkscape_perl::Inkscape"); - SWIG_TypeClientData(SWIGTYPE_p_Inkscape__Extension__Script__DialogManager, (void*) "inkscape_perl::DialogManager"); - SWIG_TypeClientData(SWIGTYPE_p_Inkscape__Extension__Script__Desktop, (void*) "inkscape_perl::Desktop"); - SWIG_TypeClientData(SWIGTYPE_p_Inkscape__Extension__Script__Document, (void*) "inkscape_perl::Document"); - ST(0) = &PL_sv_yes; - XSRETURN(1); -} - diff --git a/src/extension/script/quotefile.pl b/src/extension/script/quotefile.pl deleted file mode 100644 index 9eb769a25..000000000 --- a/src/extension/script/quotefile.pl +++ /dev/null @@ -1,82 +0,0 @@ -#!/usr/bin/perl -############################################################################ -# -# Quote all of the lines of a text file, so that it can be loaded -# into C/C++ -# -############################################################################ - -# -# main - top level code -# - - -if ( $#ARGV != 1 ) { # parse command line args - print "usage: perl quotefile.pl infile outfile\n\n"; - exit 1; -} - -$inName = $ARGV[0]; -$outName = $ARGV[1]; - -print "#######################################################\n"; -print "## Quoting $inName to $outName\n"; -print "#######################################################\n"; - -&doQuoteFile(); #Do your magic! - -print "#######################################################\n"; -print "## DONE\n"; -print "#######################################################\n"; - -exit 0; - - - -############################################################################ -# -# -# -# -############################################################################ -sub doQuoteFile -{ - my $line; #current line from input file - my $datestr; #Current date - local(*INFILE); - local(*OUTFILE); - - $datestr = gmtime(); - - if ( -r $inName ) - { - open INFILE, $inName or - die "$inName: $!"; - open OUTFILE, ">$outName" or - die "$outName: $!"; - print OUTFILE "\n"; - print OUTFILE "/* ###################################################\n"; - print OUTFILE "## This file generated by quotefile.pl from\n"; - print OUTFILE "## $inName on $datestr\n"; - print OUTFILE "## DO NOT EDIT\n"; - print OUTFILE "################################################### */\n"; - print OUTFILE "\n"; - print OUTFILE "static char *inkscape_module_script =\n"; - while () - { - $line = $_; - #Escape existing quotes - $line =~ s/\"/\\"/g; - #Add outer quotes - $line =~ s/^/\"/; - $line =~ s/$/\\n\"/; - - print OUTFILE $line - } - close INFILE; - print OUTFILE "\"\";\n"; - close OUTFILE; - } - -} - diff --git a/src/extension/script/runme.py b/src/extension/script/runme.py deleted file mode 100644 index 706676064..000000000 --- a/src/extension/script/runme.py +++ /dev/null @@ -1,8 +0,0 @@ - -import inkscape_py - -inkscape = inkscape_py.getInkscape() -desktop = inkscape.getDesktop() -document = desktop.getDocument() -document.hello() - diff --git a/src/extension/script/wrap_swig_module.sh b/src/extension/script/wrap_swig_module.sh deleted file mode 100644 index 8c6236f2d..000000000 --- a/src/extension/script/wrap_swig_module.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/sh - -inf=$1 -outf=$2 -datestr=`date` - -echo "" > ${outf} -echo "/* ###################################################" >> ${outf} -echo "## This file generated by wrap_swig_module.sh from" >> ${outf} -echo "## ${inf} on ${datestr}" >> ${outf} -echo "## DO NOT EDIT" >> ${outf} -echo "################################################### */" >> ${outf} -echo "" >> ${outf} - -echo "static char *inkscape_module_script =" >> ${outf} -echo "\"\n\"" >> ${outf} - -cat ${inf} | \ -sed -e 's/\"/\\"/g' -e 's/^/\"/g' -e 's/$/\\n\"/g' >> ${outf} - -echo "\"\n\";" >> ${outf} - - - - - -