1 //-----------------------------------------------------------------------------
3 // Copyright (c) 1998 - 2007, The Regents of the University of California
4 // Produced at the Lawrence Livermore National Laboratory
5 // All rights reserved.
7 // This file is part of PyCXX. For details,see http://cxx.sourceforge.net/. The
8 // full copyright notice is contained in the file COPYRIGHT located at the root
9 // of the PyCXX distribution.
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are met:
14 // - Redistributions of source code must retain the above copyright notice,
15 // this list of conditions and the disclaimer below.
16 // - Redistributions in binary form must reproduce the above copyright notice,
17 // this list of conditions and the disclaimer (as noted below) in the
18 // documentation and/or materials provided with the distribution.
19 // - Neither the name of the UC/LLNL nor the names of its contributors may be
20 // used to endorse or promote products derived from this software without
21 // specific prior written permission.
23 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 // ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OF THE UNIVERSITY OF
27 // CALIFORNIA, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR
28 // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
36 //-----------------------------------------------------------------------------
38 #ifndef __CXX_Extensions__h
39 #define __CXX_Extensions__h
43 // disable warning C4786: symbol greater than 255 character,
45 #pragma warning( disable: 4786 )
48 #include "CXX/WrapPython.h"
49 #include "CXX/Version.hxx"
50 #include "CXX/Python3/Config.hxx"
51 #include "CXX/Python3/CxxDebug.hxx"
52 #include "CXX/Python3/Objects.hxx"
54 extern "C" { extern PyObject py_object_initializer
; }
59 // ----------------------------------------------------------------------
63 class ExtensionModuleBase
;
65 // Make an Exception Type for use in raising custom exceptions
66 class ExtensionExceptionType
: public Object
69 ExtensionExceptionType();
70 virtual ~ExtensionExceptionType();
72 // call init to create the type
73 void init( ExtensionModuleBase
&module
, const std::string
&name
, ExtensionExceptionType
&parent
);
74 void init( ExtensionModuleBase
&module
, const std::string
&name
);
81 virtual ~MethodTable();
83 void add( const char *method_name
, PyCFunction f
, const char *doc
="", int flag
=1 );
87 std::vector
<PyMethodDef
> t
; // accumulator of PyMethodDef's
88 PyMethodDef
*mt
; // Actual method table produced when full
90 static PyMethodDef
method( const char* method_name
, PyCFunction f
, int flags
=1, const char* doc
="" );
94 // prevent the compiler generating these unwanted functions
96 MethodTable( const MethodTable
&m
); //unimplemented
97 void operator=( const MethodTable
&m
); //unimplemented
99 }; // end class MethodTable
101 // Note: Python calls noargs as varargs buts args==NULL
102 extern "C" typedef PyObject
*(*method_noargs_call_handler_t
)( PyObject
*_self
, PyObject
* );
103 extern "C" typedef PyObject
*(*method_varargs_call_handler_t
)( PyObject
*_self
, PyObject
*_args
);
104 extern "C" typedef PyObject
*(*method_keyword_call_handler_t
)( PyObject
*_self
, PyObject
*_args
, PyObject
*_dict
);
107 class MethodDefExt
: public PyMethodDef
110 typedef Object (T::*method_noargs_function_t
)();
111 typedef Object (T::*method_varargs_function_t
)( const Tuple
&args
);
112 typedef Object (T::*method_keyword_function_t
)( const Tuple
&args
, const Dict
&kws
);
118 method_noargs_function_t _function
,
119 method_noargs_call_handler_t _handler
,
123 ext_meth_def
.ml_name
= const_cast<char *>( _name
);
124 ext_meth_def
.ml_meth
= reinterpret_cast<method_varargs_call_handler_t
>( _handler
);
125 ext_meth_def
.ml_flags
= METH_NOARGS
;
126 ext_meth_def
.ml_doc
= const_cast<char *>( _doc
);
128 ext_noargs_function
= _function
;
129 ext_varargs_function
= NULL
;
130 ext_keyword_function
= NULL
;
137 method_varargs_function_t _function
,
138 method_varargs_call_handler_t _handler
,
142 ext_meth_def
.ml_name
= const_cast<char *>( _name
);
143 ext_meth_def
.ml_meth
= reinterpret_cast<method_varargs_call_handler_t
>( _handler
);
144 ext_meth_def
.ml_flags
= METH_VARARGS
;
145 ext_meth_def
.ml_doc
= const_cast<char *>( _doc
);
147 ext_noargs_function
= NULL
;
148 ext_varargs_function
= _function
;
149 ext_keyword_function
= NULL
;
156 method_keyword_function_t _function
,
157 method_keyword_call_handler_t _handler
,
161 ext_meth_def
.ml_name
= const_cast<char *>( _name
);
162 ext_meth_def
.ml_meth
= reinterpret_cast<method_varargs_call_handler_t
>( _handler
);
163 ext_meth_def
.ml_flags
= METH_VARARGS
|METH_KEYWORDS
;
164 ext_meth_def
.ml_doc
= const_cast<char *>( _doc
);
166 ext_noargs_function
= NULL
;
167 ext_varargs_function
= NULL
;
168 ext_keyword_function
= _function
;
174 PyMethodDef ext_meth_def
;
175 method_noargs_function_t ext_noargs_function
;
176 method_varargs_function_t ext_varargs_function
;
177 method_keyword_function_t ext_keyword_function
;
182 #include "CXX/Python3/ExtensionModule.hxx"
183 #include "CXX/Python3/PythonType.hxx"
184 #include "CXX/Python3/ExtensionTypeBase.hxx"
185 #include "CXX/Python3/ExtensionOldType.hxx"
186 #include "CXX/Python3/ExtensionType.hxx"
188 // End of CXX_Extensions.h