~launchpad-committers/ubuntu/lucid/pysvn/launchpad-ppa

« back to all changes in this revision

Viewing changes to Import/pycxx-5.4.0/Src/IndirectPythonInterface.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2007-02-18 14:30:49 UTC
  • Revision ID: james.westby@ubuntu.com-20070218143049-m3wxtj3m79xqo0by
Tags: 1.5.1-0ubuntu1
New upstream version; bug fix release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//-----------------------------------------------------------------------------
 
2
//
 
3
// Copyright (c) 1998 - 2007, The Regents of the University of California
 
4
// Produced at the Lawrence Livermore National Laboratory
 
5
// All rights reserved.
 
6
//
 
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.
 
10
//
 
11
// Redistribution  and  use  in  source  and  binary  forms,  with  or  without
 
12
// modification, are permitted provided that the following conditions are met:
 
13
//
 
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.
 
22
//
 
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
 
34
// DAMAGE.
 
35
//
 
36
//-----------------------------------------------------------------------------
 
37
 
 
38
#include "CXX/IndirectPythonInterface.hxx"
 
39
 
 
40
namespace Py
 
41
{
 
42
bool _Buffer_Check( PyObject *op ) { return (op)->ob_type == _Buffer_Type(); }
 
43
bool _CFunction_Check( PyObject *op ) { return (op)->ob_type == _CFunction_Type(); }
 
44
bool _Class_Check( PyObject *op ) { return (op)->ob_type == _Class_Type(); }
 
45
bool _CObject_Check( PyObject *op ) { return (op)->ob_type == _CObject_Type(); }
 
46
bool _Complex_Check( PyObject *op ) { return (op)->ob_type == _Complex_Type(); }
 
47
bool _Dict_Check( PyObject *op ) { return (op)->ob_type == _Dict_Type(); }
 
48
bool _File_Check( PyObject *op ) { return (op)->ob_type == _File_Type(); }
 
49
bool _Float_Check( PyObject *op ) { return (op)->ob_type == _Float_Type(); }
 
50
bool _Function_Check( PyObject *op ) { return (op)->ob_type == _Function_Type(); }
 
51
bool _Instance_Check( PyObject *op ) { return (op)->ob_type == _Instance_Type(); }
 
52
bool _Int_Check( PyObject *op ) { return (op)->ob_type == _Int_Type(); }
 
53
bool _List_Check( PyObject *o ) { return o->ob_type == _List_Type(); }
 
54
bool _Long_Check( PyObject *op ) { return (op)->ob_type == _Long_Type(); }
 
55
bool _Method_Check( PyObject *op ) { return (op)->ob_type == _Method_Type(); }
 
56
bool _Module_Check( PyObject *op ) { return (op)->ob_type == _Module_Type(); }
 
57
bool _Range_Check( PyObject *op ) { return (op)->ob_type == _Range_Type(); }
 
58
bool _Slice_Check( PyObject *op ) { return (op)->ob_type == _Slice_Type(); }
 
59
bool _String_Check( PyObject *o ) { return o->ob_type == _String_Type(); }
 
60
bool _TraceBack_Check( PyObject *v ) { return (v)->ob_type == _TraceBack_Type(); }
 
61
bool _Tuple_Check( PyObject *op ) { return (op)->ob_type == _Tuple_Type(); }
 
62
bool _Type_Check( PyObject *op ) { return (op)->ob_type == _Type_Type(); }
 
63
 
 
64
#if PY_MAJOR_VERSION >= 2
 
65
bool _Unicode_Check( PyObject *op ) { return (op)->ob_type == _Unicode_Type(); }
 
66
#endif
 
67
 
 
68
 
 
69
 
 
70
#if defined(PY_WIN32_DELAYLOAD_PYTHON_DLL)
 
71
 
 
72
#if defined(MS_WINDOWS)
 
73
#include <windows.h>
 
74
 
 
75
 
 
76
static HMODULE python_dll;
 
77
 
 
78
static PyObject *ptr__Exc_ArithmeticError = NULL;
 
79
static PyObject *ptr__Exc_AssertionError = NULL;
 
80
static PyObject *ptr__Exc_AttributeError = NULL;
 
81
static PyObject *ptr__Exc_EnvironmentError = NULL;
 
82
static PyObject *ptr__Exc_EOFError = NULL;
 
83
static PyObject *ptr__Exc_Exception = NULL;
 
84
static PyObject *ptr__Exc_FloatingPointError = NULL;
 
85
static PyObject *ptr__Exc_ImportError = NULL;
 
86
static PyObject *ptr__Exc_IndexError = NULL;
 
87
static PyObject *ptr__Exc_IOError = NULL;
 
88
static PyObject *ptr__Exc_KeyboardInterrupt = NULL;
 
89
static PyObject *ptr__Exc_KeyError = NULL;
 
90
static PyObject *ptr__Exc_LookupError = NULL;
 
91
static PyObject *ptr__Exc_MemoryError = NULL;
 
92
static PyObject *ptr__Exc_MemoryErrorInst = NULL;
 
93
static PyObject *ptr__Exc_NameError = NULL;
 
94
static PyObject *ptr__Exc_NotImplementedError = NULL;
 
95
static PyObject *ptr__Exc_OSError = NULL;
 
96
static PyObject *ptr__Exc_OverflowError = NULL;
 
97
static PyObject *ptr__Exc_RuntimeError = NULL;
 
98
static PyObject *ptr__Exc_StandardError = NULL;
 
99
static PyObject *ptr__Exc_SyntaxError = NULL;
 
100
static PyObject *ptr__Exc_SystemError = NULL;
 
101
static PyObject *ptr__Exc_SystemExit = NULL;
 
102
static PyObject *ptr__Exc_TypeError = NULL;
 
103
static PyObject *ptr__Exc_ValueError = NULL;
 
104
static PyObject *ptr__Exc_ZeroDivisionError = NULL;
 
105
 
 
106
#ifdef MS_WINDOWS
 
107
static PyObject *ptr__Exc_WindowsError = NULL;
 
108
#endif
 
109
 
 
110
#if PY_MAJOR_VERSION >= 2
 
111
static PyObject *ptr__Exc_IndentationError = NULL;
 
112
static PyObject *ptr__Exc_TabError = NULL;
 
113
static PyObject *ptr__Exc_UnboundLocalError = NULL;
 
114
static PyObject *ptr__Exc_UnicodeError = NULL;
 
115
#endif
 
116
 
 
117
static PyObject *ptr__PyNone = NULL;
 
118
 
 
119
static PyTypeObject *ptr__Buffer_Type = NULL;
 
120
static PyTypeObject *ptr__CFunction_Type = NULL;
 
121
static PyTypeObject *ptr__Class_Type = NULL;
 
122
static PyTypeObject *ptr__CObject_Type = NULL;
 
123
static PyTypeObject *ptr__Complex_Type = NULL;
 
124
static PyTypeObject *ptr__Dict_Type = NULL;
 
125
static PyTypeObject *ptr__File_Type = NULL;
 
126
static PyTypeObject *ptr__Float_Type = NULL;
 
127
static PyTypeObject *ptr__Function_Type = NULL;
 
128
static PyTypeObject *ptr__Instance_Type = NULL;
 
129
static PyTypeObject *ptr__Int_Type = NULL;
 
130
static PyTypeObject *ptr__List_Type = NULL;
 
131
static PyTypeObject *ptr__Long_Type = NULL;
 
132
static PyTypeObject *ptr__Method_Type = NULL;
 
133
static PyTypeObject *ptr__Module_Type = NULL;
 
134
static PyTypeObject *ptr__Range_Type = NULL;
 
135
static PyTypeObject *ptr__Slice_Type = NULL;
 
136
static PyTypeObject *ptr__String_Type = NULL;
 
137
static PyTypeObject *ptr__TraceBack_Type = NULL;
 
138
static PyTypeObject *ptr__Tuple_Type = NULL;
 
139
static PyTypeObject *ptr__Type_Type = NULL;
 
140
 
 
141
#if PY_MAJOR_VERSION >= 2
 
142
static PyTypeObject *ptr__Unicode_Type = NULL;
 
143
#endif
 
144
 
 
145
static int *ptr_Py_DebugFlag = NULL;
 
146
static int *ptr_Py_InteractiveFlag = NULL;
 
147
static int *ptr_Py_OptimizeFlag = NULL;
 
148
static int *ptr_Py_NoSiteFlag = NULL;
 
149
static int *ptr_Py_TabcheckFlag = NULL;
 
150
static int *ptr_Py_VerboseFlag = NULL;
 
151
 
 
152
#if PY_MAJOR_VERSION >= 2
 
153
static int *ptr_Py_UnicodeFlag = NULL;
 
154
#endif
 
155
 
 
156
static char **ptr__Py_PackageContext = NULL;
 
157
 
 
158
#ifdef Py_REF_DEBUG
 
159
int *ptr_Py_RefTotal;
 
160
#endif
 
161
 
 
162
 
 
163
//--------------------------------------------------------------------------------
 
164
class GetAddressException
 
165
{
 
166
public:
 
167
    GetAddressException( const char *_name )
 
168
        : name( _name )
 
169
    {}
 
170
    virtual ~GetAddressException() {}
 
171
    const char *name;
 
172
};
 
173
 
 
174
 
 
175
//--------------------------------------------------------------------------------
 
176
static PyObject *GetPyObjectPointer_As_PyObjectPointer( const char *name )
 
177
{
 
178
    FARPROC addr = GetProcAddress( python_dll, name );
 
179
    if( addr == NULL )
 
180
        throw GetAddressException( name );
 
181
 
 
182
    return *(PyObject **)addr;
 
183
}
 
184
 
 
185
static PyObject *GetPyObject_As_PyObjectPointer( const char *name )
 
186
{
 
187
    FARPROC addr = GetProcAddress( python_dll, name );
 
188
    if( addr == NULL )
 
189
        throw GetAddressException( name );
 
190
 
 
191
    return (PyObject *)addr;
 
192
}
 
193
 
 
194
static PyTypeObject *GetPyTypeObjectPointer_As_PyTypeObjectPointer( const char *name )
 
195
{
 
196
    FARPROC addr = GetProcAddress( python_dll, name );
 
197
    if( addr == NULL )
 
198
        throw GetAddressException( name );
 
199
 
 
200
    return *(PyTypeObject **)addr;
 
201
}
 
202
 
 
203
static PyTypeObject *GetPyTypeObject_As_PyTypeObjectPointer( const char *name )
 
204
{
 
205
    FARPROC addr = GetProcAddress( python_dll, name );
 
206
    if( addr == NULL )
 
207
        throw GetAddressException( name );
 
208
 
 
209
    return (PyTypeObject *)addr;
 
210
}
 
211
 
 
212
static int *GetInt_as_IntPointer( const char *name )
 
213
{
 
214
    FARPROC addr = GetProcAddress( python_dll, name );
 
215
    if( addr == NULL )
 
216
        throw GetAddressException( name );
 
217
 
 
218
    return (int *)addr;
 
219
}
 
220
 
 
221
static char **GetCharPointer_as_CharPointerPointer( const char *name )
 
222
{
 
223
    FARPROC addr = GetProcAddress( python_dll, name );
 
224
    if( addr == NULL )
 
225
        throw GetAddressException( name );
 
226
 
 
227
    return (char **)addr;
 
228
}
 
229
 
 
230
 
 
231
#ifdef _DEBUG
 
232
static const char python_dll_name_format[] = "PYTHON%1.1d%1.1d_D.DLL";
 
233
#else
 
234
static const char python_dll_name_format[] = "PYTHON%1.1d%1.1d.DLL";
 
235
#endif
 
236
 
 
237
//--------------------------------------------------------------------------------
 
238
bool InitialisePythonIndirectInterface()
 
239
{
 
240
    char python_dll_name[sizeof(python_dll_name_format)];
 
241
 
 
242
    sprintf( python_dll_name, python_dll_name_format, PY_MAJOR_VERSION, PY_MINOR_VERSION );
 
243
 
 
244
    python_dll = LoadLibrary( python_dll_name );
 
245
    if( python_dll == NULL )
 
246
        return false;
 
247
 
 
248
    try
 
249
{
 
250
#ifdef Py_REF_DEBUG
 
251
    ptr_Py_RefTotal            = GetInt_as_IntPointer( "_Py_RefTotal" );
 
252
#endif
 
253
    ptr_Py_DebugFlag        = GetInt_as_IntPointer( "Py_DebugFlag" );
 
254
    ptr_Py_InteractiveFlag        = GetInt_as_IntPointer( "Py_InteractiveFlag" );
 
255
    ptr_Py_OptimizeFlag        = GetInt_as_IntPointer( "Py_OptimizeFlag" );
 
256
    ptr_Py_NoSiteFlag        = GetInt_as_IntPointer( "Py_NoSiteFlag" );
 
257
    ptr_Py_TabcheckFlag        = GetInt_as_IntPointer( "Py_TabcheckFlag" );
 
258
    ptr_Py_VerboseFlag        = GetInt_as_IntPointer( "Py_VerboseFlag" );
 
259
#if PY_MAJOR_VERSION >= 2
 
260
    ptr_Py_UnicodeFlag        = GetInt_as_IntPointer( "Py_UnicodeFlag" );
 
261
#endif
 
262
    ptr__Py_PackageContext        = GetCharPointer_as_CharPointerPointer( "_Py_PackageContext" );
 
263
 
 
264
    ptr__Exc_ArithmeticError    = GetPyObjectPointer_As_PyObjectPointer( "PyExc_ArithmeticError" );
 
265
    ptr__Exc_AssertionError        = GetPyObjectPointer_As_PyObjectPointer( "PyExc_AssertionError" );
 
266
    ptr__Exc_AttributeError        = GetPyObjectPointer_As_PyObjectPointer( "PyExc_AttributeError" );
 
267
    ptr__Exc_EnvironmentError    = GetPyObjectPointer_As_PyObjectPointer( "PyExc_EnvironmentError" );
 
268
    ptr__Exc_EOFError        = GetPyObjectPointer_As_PyObjectPointer( "PyExc_EOFError" );
 
269
    ptr__Exc_Exception        = GetPyObjectPointer_As_PyObjectPointer( "PyExc_Exception" );
 
270
    ptr__Exc_FloatingPointError    = GetPyObjectPointer_As_PyObjectPointer( "PyExc_FloatingPointError" );
 
271
    ptr__Exc_ImportError        = GetPyObjectPointer_As_PyObjectPointer( "PyExc_ImportError" );
 
272
    ptr__Exc_IndexError        = GetPyObjectPointer_As_PyObjectPointer( "PyExc_IndexError" );
 
273
    ptr__Exc_IOError        = GetPyObjectPointer_As_PyObjectPointer( "PyExc_IOError" );
 
274
    ptr__Exc_KeyboardInterrupt    = GetPyObjectPointer_As_PyObjectPointer( "PyExc_KeyboardInterrupt" );
 
275
    ptr__Exc_KeyError        = GetPyObjectPointer_As_PyObjectPointer( "PyExc_KeyError" );
 
276
    ptr__Exc_LookupError        = GetPyObjectPointer_As_PyObjectPointer( "PyExc_LookupError" );
 
277
    ptr__Exc_MemoryError        = GetPyObjectPointer_As_PyObjectPointer( "PyExc_MemoryError" );
 
278
    ptr__Exc_MemoryErrorInst    = GetPyObjectPointer_As_PyObjectPointer( "PyExc_MemoryErrorInst" );
 
279
    ptr__Exc_NameError        = GetPyObjectPointer_As_PyObjectPointer( "PyExc_NameError" );
 
280
    ptr__Exc_NotImplementedError    = GetPyObjectPointer_As_PyObjectPointer( "PyExc_NotImplementedError" );
 
281
    ptr__Exc_OSError        = GetPyObjectPointer_As_PyObjectPointer( "PyExc_OSError" );
 
282
    ptr__Exc_OverflowError        = GetPyObjectPointer_As_PyObjectPointer( "PyExc_OverflowError" );
 
283
    ptr__Exc_RuntimeError        = GetPyObjectPointer_As_PyObjectPointer( "PyExc_RuntimeError" );
 
284
    ptr__Exc_StandardError        = GetPyObjectPointer_As_PyObjectPointer( "PyExc_StandardError" );
 
285
    ptr__Exc_SyntaxError        = GetPyObjectPointer_As_PyObjectPointer( "PyExc_SyntaxError" );
 
286
    ptr__Exc_SystemError        = GetPyObjectPointer_As_PyObjectPointer( "PyExc_SystemError" );
 
287
    ptr__Exc_SystemExit        = GetPyObjectPointer_As_PyObjectPointer( "PyExc_SystemExit" );
 
288
    ptr__Exc_TypeError        = GetPyObjectPointer_As_PyObjectPointer( "PyExc_TypeError" );
 
289
    ptr__Exc_ValueError        = GetPyObjectPointer_As_PyObjectPointer( "PyExc_ValueError" );
 
290
#ifdef MS_WINDOWS
 
291
    ptr__Exc_WindowsError        = GetPyObjectPointer_As_PyObjectPointer( "PyExc_WindowsError" );
 
292
#endif
 
293
    ptr__Exc_ZeroDivisionError    = GetPyObjectPointer_As_PyObjectPointer( "PyExc_ZeroDivisionError" );
 
294
 
 
295
#if PY_MAJOR_VERSION >= 2
 
296
    ptr__Exc_IndentationError    = GetPyObjectPointer_As_PyObjectPointer( "PyExc_IndentationError" );
 
297
    ptr__Exc_TabError        = GetPyObjectPointer_As_PyObjectPointer( "PyExc_TabError" );
 
298
    ptr__Exc_UnboundLocalError    = GetPyObjectPointer_As_PyObjectPointer( "PyExc_UnboundLocalError" );
 
299
    ptr__Exc_UnicodeError        = GetPyObjectPointer_As_PyObjectPointer( "PyExc_UnicodeError" );
 
300
#endif
 
301
    ptr__PyNone            = GetPyObject_As_PyObjectPointer( "_Py_NoneStruct" );
 
302
 
 
303
    ptr__Buffer_Type        = GetPyTypeObject_As_PyTypeObjectPointer( "PyBuffer_Type" );
 
304
    ptr__CFunction_Type        = GetPyTypeObject_As_PyTypeObjectPointer( "PyCFunction_Type" );
 
305
    ptr__Class_Type            = GetPyTypeObject_As_PyTypeObjectPointer( "PyClass_Type" );
 
306
    ptr__CObject_Type        = GetPyTypeObject_As_PyTypeObjectPointer( "PyCObject_Type" );
 
307
    ptr__Complex_Type        = GetPyTypeObject_As_PyTypeObjectPointer( "PyComplex_Type" );
 
308
    ptr__Dict_Type            = GetPyTypeObject_As_PyTypeObjectPointer( "PyDict_Type" );
 
309
    ptr__File_Type            = GetPyTypeObject_As_PyTypeObjectPointer( "PyFile_Type" );
 
310
    ptr__Float_Type            = GetPyTypeObject_As_PyTypeObjectPointer( "PyFloat_Type" );
 
311
    ptr__Function_Type        = GetPyTypeObject_As_PyTypeObjectPointer( "PyFunction_Type" );
 
312
    ptr__Instance_Type        = GetPyTypeObject_As_PyTypeObjectPointer( "PyInstance_Type" );
 
313
    ptr__Int_Type            = GetPyTypeObject_As_PyTypeObjectPointer( "PyInt_Type" );
 
314
    ptr__List_Type            = GetPyTypeObject_As_PyTypeObjectPointer( "PyList_Type" );
 
315
    ptr__Long_Type            = GetPyTypeObject_As_PyTypeObjectPointer( "PyLong_Type" );
 
316
    ptr__Method_Type        = GetPyTypeObject_As_PyTypeObjectPointer( "PyMethod_Type" );
 
317
    ptr__Module_Type        = GetPyTypeObject_As_PyTypeObjectPointer( "PyModule_Type" );
 
318
    ptr__Range_Type            = GetPyTypeObject_As_PyTypeObjectPointer( "PyRange_Type" );
 
319
    ptr__Slice_Type            = GetPyTypeObject_As_PyTypeObjectPointer( "PySlice_Type" );
 
320
    ptr__String_Type        = GetPyTypeObject_As_PyTypeObjectPointer( "PyString_Type" );
 
321
    ptr__TraceBack_Type        = GetPyTypeObject_As_PyTypeObjectPointer( "PyTraceBack_Type" );
 
322
    ptr__Tuple_Type            = GetPyTypeObject_As_PyTypeObjectPointer( "PyTuple_Type" );
 
323
    ptr__Type_Type            = GetPyTypeObject_As_PyTypeObjectPointer( "PyType_Type" );
 
324
 
 
325
#if PY_MAJOR_VERSION >= 2
 
326
    ptr__Unicode_Type        = GetPyTypeObject_As_PyTypeObjectPointer( "PyUnicode_Type" );
 
327
#endif
 
328
}
 
329
    catch( GetAddressException &e )
 
330
    {
 
331
        OutputDebugString( python_dll_name );
 
332
        OutputDebugString( " does not contain symbol ");
 
333
        OutputDebugString( e.name );
 
334
        OutputDebugString( "\n" );
 
335
 
 
336
        return false;
 
337
    }
 
338
 
 
339
    return true;
 
340
}
 
341
 
 
342
//
 
343
//    Wrap variables as function calls
 
344
//
 
345
PyObject * _Exc_ArithmeticError(){ return ptr__Exc_ArithmeticError; }
 
346
PyObject * _Exc_AssertionError(){ return ptr__Exc_AssertionError; }
 
347
PyObject * _Exc_AttributeError(){ return ptr__Exc_AttributeError; }
 
348
PyObject * _Exc_EnvironmentError(){ return ptr__Exc_EnvironmentError; }
 
349
PyObject * _Exc_EOFError()    { return ptr__Exc_EOFError; }
 
350
PyObject * _Exc_Exception()    { return ptr__Exc_Exception; }
 
351
PyObject * _Exc_FloatingPointError(){ return ptr__Exc_FloatingPointError; }
 
352
PyObject * _Exc_ImportError()    { return ptr__Exc_ImportError; }
 
353
PyObject * _Exc_IndexError()    { return ptr__Exc_IndexError; }
 
354
PyObject * _Exc_IOError()    { return ptr__Exc_IOError; }
 
355
PyObject * _Exc_KeyboardInterrupt(){ return ptr__Exc_KeyboardInterrupt; }
 
356
PyObject * _Exc_KeyError()    { return ptr__Exc_KeyError; }
 
357
PyObject * _Exc_LookupError()    { return ptr__Exc_LookupError; }
 
358
PyObject * _Exc_MemoryError()    { return ptr__Exc_MemoryError; }
 
359
PyObject * _Exc_MemoryErrorInst(){ return ptr__Exc_MemoryErrorInst; }
 
360
PyObject * _Exc_NameError()    { return ptr__Exc_NameError; }
 
361
PyObject * _Exc_NotImplementedError(){ return ptr__Exc_NotImplementedError; }
 
362
PyObject * _Exc_OSError()    { return ptr__Exc_OSError; }
 
363
PyObject * _Exc_OverflowError()    { return ptr__Exc_OverflowError; }
 
364
PyObject * _Exc_RuntimeError()    { return ptr__Exc_RuntimeError; }
 
365
PyObject * _Exc_StandardError()    { return ptr__Exc_StandardError; }
 
366
PyObject * _Exc_SyntaxError()    { return ptr__Exc_SyntaxError; }
 
367
PyObject * _Exc_SystemError()    { return ptr__Exc_SystemError; }
 
368
PyObject * _Exc_SystemExit()    { return ptr__Exc_SystemExit; }
 
369
PyObject * _Exc_TypeError()    { return ptr__Exc_TypeError; }
 
370
PyObject * _Exc_ValueError()    { return ptr__Exc_ValueError; }
 
371
#ifdef MS_WINDOWS
 
372
PyObject * _Exc_WindowsError()    { return ptr__Exc_WindowsError; }
 
373
#endif
 
374
PyObject * _Exc_ZeroDivisionError(){ return ptr__Exc_ZeroDivisionError; }
 
375
 
 
376
#if PY_MAJOR_VERSION >= 2
 
377
PyObject * _Exc_IndentationError(){ return ptr__Exc_IndentationError; }
 
378
PyObject * _Exc_TabError()    { return ptr__Exc_TabError; }
 
379
PyObject * _Exc_UnboundLocalError(){ return ptr__Exc_UnboundLocalError; }
 
380
PyObject * _Exc_UnicodeError()    { return ptr__Exc_UnicodeError; }
 
381
#endif
 
382
 
 
383
//
 
384
//    wrap items in Object.h
 
385
//
 
386
PyObject * _None() { return ptr__PyNone; }
 
387
 
 
388
 
 
389
PyTypeObject * _Buffer_Type()    { return ptr__Buffer_Type; }
 
390
PyTypeObject * _CFunction_Type(){ return ptr__CFunction_Type; }
 
391
PyTypeObject * _Class_Type()    { return ptr__Class_Type; }
 
392
PyTypeObject * _CObject_Type()    { return ptr__CObject_Type; }
 
393
PyTypeObject * _Complex_Type()    { return ptr__Complex_Type; }
 
394
PyTypeObject * _Dict_Type()    { return ptr__Dict_Type; }
 
395
PyTypeObject * _File_Type()    { return ptr__File_Type; }
 
396
PyTypeObject * _Float_Type()    { return ptr__Float_Type; }
 
397
PyTypeObject * _Function_Type()    { return ptr__Function_Type; }
 
398
PyTypeObject * _Instance_Type()    { return ptr__Instance_Type; }
 
399
PyTypeObject * _Int_Type()    { return ptr__Int_Type; }
 
400
PyTypeObject * _List_Type()    { return ptr__List_Type; }
 
401
PyTypeObject * _Long_Type()    { return ptr__Long_Type; }
 
402
PyTypeObject * _Method_Type()    { return ptr__Method_Type; }
 
403
PyTypeObject * _Module_Type()    { return ptr__Module_Type; }
 
404
PyTypeObject * _Range_Type()    { return ptr__Range_Type; }
 
405
PyTypeObject * _Slice_Type()    { return ptr__Slice_Type; }
 
406
PyTypeObject * _String_Type()    { return ptr__String_Type; }
 
407
PyTypeObject * _TraceBack_Type(){ return ptr__TraceBack_Type; }
 
408
PyTypeObject * _Tuple_Type()    { return ptr__Tuple_Type; }
 
409
PyTypeObject * _Type_Type()    { return ptr__Type_Type; }
 
410
 
 
411
#if PY_MAJOR_VERSION >= 2
 
412
PyTypeObject * _Unicode_Type()    { return ptr__Unicode_Type; }
 
413
#endif
 
414
 
 
415
char *__Py_PackageContext()    { return *ptr__Py_PackageContext; }
 
416
 
 
417
 
 
418
//
 
419
//    wrap the Python Flag variables
 
420
//
 
421
int &_Py_DebugFlag() { return *ptr_Py_DebugFlag; }
 
422
int &_Py_InteractiveFlag() { return *ptr_Py_InteractiveFlag; }
 
423
int &_Py_OptimizeFlag() { return *ptr_Py_OptimizeFlag; }
 
424
int &_Py_NoSiteFlag() { return *ptr_Py_NoSiteFlag; }
 
425
int &_Py_TabcheckFlag() { return *ptr_Py_TabcheckFlag; }
 
426
int &_Py_VerboseFlag() { return *ptr_Py_VerboseFlag; }
 
427
#if PY_MAJOR_VERSION >= 2
 
428
int &_Py_UnicodeFlag() { return *ptr_Py_UnicodeFlag; }
 
429
#endif
 
430
 
 
431
void _XINCREF( PyObject *op )
 
432
{
 
433
    // This function must match the contents of Py_XINCREF(op)
 
434
    if( op == NULL )
 
435
        return;
 
436
 
 
437
#ifdef Py_REF_DEBUG
 
438
    (*ptr_Py_RefTotal)++;
 
439
#endif
 
440
    (op)->ob_refcnt++;
 
441
 
 
442
}
 
443
 
 
444
void _XDECREF( PyObject *op )
 
445
{
 
446
    // This function must match the contents of Py_XDECREF(op);
 
447
    if( op == NULL )
 
448
        return;
 
449
 
 
450
#ifdef Py_REF_DEBUG
 
451
    (*ptr_Py_RefTotal)--;
 
452
#endif
 
453
 
 
454
    if (--(op)->ob_refcnt == 0)
 
455
        _Py_Dealloc((PyObject *)(op));
 
456
}
 
457
 
 
458
 
 
459
#else
 
460
#error "Can only delay load under Win32"
 
461
#endif
 
462
 
 
463
#else
 
464
 
 
465
//
 
466
//    Duplicated these declarations from rangeobject.h which is missing the
 
467
//    extern "C". This has been reported as a bug upto and include 2.1
 
468
//
 
469
extern "C" DL_IMPORT(PyTypeObject) PyRange_Type;
 
470
extern "C" DL_IMPORT(PyObject *) PyRange_New(long, long, long, int);
 
471
 
 
472
 
 
473
//================================================================================
 
474
//
 
475
//    Map onto Macros
 
476
//
 
477
//================================================================================
 
478
 
 
479
//
 
480
//    Wrap variables as function calls
 
481
//
 
482
 
 
483
PyObject * _Exc_ArithmeticError() { return ::PyExc_ArithmeticError; }
 
484
PyObject * _Exc_AssertionError() { return ::PyExc_AssertionError; }
 
485
PyObject * _Exc_AttributeError() { return ::PyExc_AttributeError; }
 
486
PyObject * _Exc_EnvironmentError() { return ::PyExc_EnvironmentError; }
 
487
PyObject * _Exc_EOFError() { return ::PyExc_EOFError; }
 
488
PyObject * _Exc_Exception() { return ::PyExc_Exception; }
 
489
PyObject * _Exc_FloatingPointError() { return ::PyExc_FloatingPointError; }
 
490
PyObject * _Exc_ImportError() { return ::PyExc_ImportError; }
 
491
PyObject * _Exc_IndexError() { return ::PyExc_IndexError; }
 
492
PyObject * _Exc_IOError() { return ::PyExc_IOError; }
 
493
PyObject * _Exc_KeyboardInterrupt() { return ::PyExc_KeyboardInterrupt; }
 
494
PyObject * _Exc_KeyError() { return ::PyExc_KeyError; }
 
495
PyObject * _Exc_LookupError() { return ::PyExc_LookupError; }
 
496
PyObject * _Exc_MemoryError() { return ::PyExc_MemoryError; }
 
497
PyObject * _Exc_MemoryErrorInst() { return ::PyExc_MemoryErrorInst; }
 
498
PyObject * _Exc_NameError() { return ::PyExc_NameError; }
 
499
PyObject * _Exc_NotImplementedError() { return ::PyExc_NotImplementedError; }
 
500
PyObject * _Exc_OSError() { return ::PyExc_OSError; }
 
501
PyObject * _Exc_OverflowError() { return ::PyExc_OverflowError; }
 
502
PyObject * _Exc_RuntimeError() { return ::PyExc_RuntimeError; }
 
503
PyObject * _Exc_StandardError() { return ::PyExc_StandardError; }
 
504
PyObject * _Exc_SyntaxError() { return ::PyExc_SyntaxError; }
 
505
PyObject * _Exc_SystemError() { return ::PyExc_SystemError; }
 
506
PyObject * _Exc_SystemExit() { return ::PyExc_SystemExit; }
 
507
PyObject * _Exc_TypeError() { return ::PyExc_TypeError; }
 
508
PyObject * _Exc_ValueError() { return ::PyExc_ValueError; }
 
509
PyObject * _Exc_ZeroDivisionError() { return ::PyExc_ZeroDivisionError; }
 
510
 
 
511
#ifdef MS_WINDOWS
 
512
PyObject * _Exc_WindowsError() { return ::PyExc_WindowsError; }
 
513
#endif
 
514
 
 
515
 
 
516
#if PY_MAJOR_VERSION >= 2
 
517
PyObject * _Exc_IndentationError() { return ::PyExc_IndentationError; }
 
518
PyObject * _Exc_TabError() { return ::PyExc_TabError; }
 
519
PyObject * _Exc_UnboundLocalError() { return ::PyExc_UnboundLocalError; }
 
520
PyObject * _Exc_UnicodeError() { return ::PyExc_UnicodeError; }
 
521
#endif
 
522
 
 
523
 
 
524
//
 
525
//    wrap items in Object.h
 
526
//
 
527
PyObject * _None() { return &::_Py_NoneStruct; }
 
528
 
 
529
PyTypeObject * _Buffer_Type() { return &PyBuffer_Type; }
 
530
PyTypeObject * _CFunction_Type() { return &PyCFunction_Type; }
 
531
PyTypeObject * _Class_Type() { return &PyClass_Type; }
 
532
PyTypeObject * _CObject_Type() { return &PyCObject_Type; }
 
533
PyTypeObject * _Complex_Type() { return &PyComplex_Type; }
 
534
PyTypeObject * _Dict_Type() { return &PyDict_Type; }
 
535
PyTypeObject * _File_Type() { return &PyFile_Type; }
 
536
PyTypeObject * _Float_Type() { return &PyFloat_Type; }
 
537
PyTypeObject * _Function_Type() { return &PyFunction_Type; }
 
538
PyTypeObject * _Instance_Type() { return &PyInstance_Type; }
 
539
PyTypeObject * _Int_Type() { return &PyInt_Type; }
 
540
PyTypeObject * _List_Type() { return &PyList_Type; }
 
541
PyTypeObject * _Long_Type() { return &PyLong_Type; }
 
542
PyTypeObject * _Method_Type() { return &PyMethod_Type; }
 
543
PyTypeObject * _Module_Type() { return &PyModule_Type; }
 
544
PyTypeObject * _Range_Type() { return &PyRange_Type; }
 
545
PyTypeObject * _Slice_Type() { return &PySlice_Type; }
 
546
PyTypeObject * _String_Type() { return &PyString_Type; }
 
547
PyTypeObject * _TraceBack_Type() { return &PyTraceBack_Type; }
 
548
PyTypeObject * _Tuple_Type() { return &PyTuple_Type; }
 
549
PyTypeObject * _Type_Type() { return &PyType_Type; }
 
550
 
 
551
#if PY_MAJOR_VERSION >= 2
 
552
PyTypeObject * _Unicode_Type() { return &PyUnicode_Type; }
 
553
#endif
 
554
 
 
555
//
 
556
//    wrap flags
 
557
//
 
558
int &_Py_DebugFlag()    { return Py_DebugFlag; }
 
559
int &_Py_InteractiveFlag(){ return Py_InteractiveFlag; }
 
560
int &_Py_OptimizeFlag()    { return Py_OptimizeFlag; }
 
561
int &_Py_NoSiteFlag()    { return Py_NoSiteFlag; }
 
562
int &_Py_TabcheckFlag()    { return Py_TabcheckFlag; }
 
563
int &_Py_VerboseFlag()    { return Py_VerboseFlag; }
 
564
#if PY_MAJOR_VERSION >= 2
 
565
int &_Py_UnicodeFlag()    { return Py_UnicodeFlag; }
 
566
#endif
 
567
char *__Py_PackageContext(){ return _Py_PackageContext; }
 
568
 
 
569
//
 
570
//    Needed to keep the abstactions for delayload interface
 
571
//
 
572
void _XINCREF( PyObject *op )
 
573
{
 
574
    Py_XINCREF(op);
 
575
}
 
576
 
 
577
void _XDECREF( PyObject *op )
 
578
{
 
579
    Py_XDECREF(op);
 
580
}
 
581
 
 
582
#endif
 
583
}