1
//-----------------------------------------------------------------------------
3
// Copyright (c) 1998 - 2007, The Regents of the University of California
4
// Produced at the Lawrence Livermore National Laboratory
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
#include "CXX/IndirectPythonInterface.hxx"
42
static int _IsInstance( PyObject *op, PyTypeObject *type )
44
return PyObject_IsInstance( op, reinterpret_cast<PyObject *>( type ) );
47
PYCXX_EXPORT bool _CFunction_Check( PyObject *op ) { return _IsInstance( op, _CFunction_Type() ) > 0; }
48
PYCXX_EXPORT bool _Complex_Check( PyObject *op ) { return _IsInstance( op, _Complex_Type() ) > 0; }
49
PYCXX_EXPORT bool _Dict_Check( PyObject *op ) { return _IsInstance( op, _Dict_Type() ) > 0; }
50
PYCXX_EXPORT bool _Float_Check( PyObject *op ) { return _IsInstance( op, _Float_Type() ) > 0; }
51
#if PY_MAJOR_VERSION == 2 || !defined( Py_LIMITED_API )
52
PYCXX_EXPORT bool _Function_Check( PyObject *op ) { return _IsInstance( op, _Function_Type() ) > 0; }
54
PYCXX_EXPORT bool _Boolean_Check( PyObject *op ) { return _IsInstance( op, _Bool_Type() ) > 0; }
55
PYCXX_EXPORT bool _List_Check( PyObject *op ) { return _IsInstance( op, _List_Type() ) > 0; }
56
PYCXX_EXPORT bool _Long_Check( PyObject *op ) { return _IsInstance( op, _Long_Type() ) > 0; }
57
#if PY_MAJOR_VERSION == 2 || !defined( Py_LIMITED_API )
58
PYCXX_EXPORT bool _Method_Check( PyObject *op ) { return _IsInstance( op, _Method_Type() ) > 0; }
60
PYCXX_EXPORT bool _Module_Check( PyObject *op ) { return _IsInstance( op, _Module_Type() ) > 0; }
61
PYCXX_EXPORT bool _Range_Check( PyObject *op ) { return _IsInstance( op, _Range_Type() ) > 0; }
62
PYCXX_EXPORT bool _Slice_Check( PyObject *op ) { return _IsInstance( op, _Slice_Type() ) > 0; }
63
PYCXX_EXPORT bool _TraceBack_Check( PyObject *op ) { return _IsInstance( op, _TraceBack_Type() ) > 0; }
64
PYCXX_EXPORT bool _Tuple_Check( PyObject *op ) { return _IsInstance( op, _Tuple_Type() ) > 0; }
65
PYCXX_EXPORT bool _Type_Check( PyObject *op ) { return _IsInstance( op, _Type_Type() ) > 0; }
66
PYCXX_EXPORT bool _Unicode_Check( PyObject *op ) { return _IsInstance( op, _Unicode_Type() ) > 0; }
67
#if PY_MAJOR_VERSION == 2
68
PYCXX_EXPORT bool _String_Check( PyObject *op ) { return _IsInstance( op, _String_Type() ) > 0; }
69
PYCXX_EXPORT bool _Int_Check( PyObject *op ) { return _IsInstance( op, _Int_Type() ) > 0; }
70
PYCXX_EXPORT bool _CObject_Check( PyObject *op ) { return _IsInstance( op, _CObject_Type() ) > 0; }
72
#if PY_MAJOR_VERSION >= 3
73
PYCXX_EXPORT bool _Bytes_Check( PyObject *op ) { return _IsInstance( op, _Bytes_Type() ) > 0; }
76
#if defined(PY_WIN32_DELAYLOAD_PYTHON_DLL)
78
# if defined(MS_WINDOWS)
82
static HMODULE python_dll;
84
# define PYCXX_STANDARD_EXCEPTION( eclass, bclass ) \
85
static PyObject *ptr_Exc_##eclass = NULL;
87
# if PY_MAJOR_VERSION == 2
88
# include "CXX/Python2/cxx_standard_exceptions.hxx"
90
# include "CXX/Python3/cxx_standard_exceptions.hxx"
93
# undef PYCXX_STANDARD_EXCEPTION
95
static PyTypeObject *ptr__CFunction_Type = NULL;
96
static PyTypeObject *ptr__Complex_Type = NULL;
97
static PyTypeObject *ptr__Dict_Type = NULL;
98
static PyTypeObject *ptr__Float_Type = NULL;
99
# if PY_MAJOR_VERSION == 2 || !defined( Py_LIMITED_API )
100
static PyTypeObject *ptr__Function_Type = NULL;
102
static PyTypeObject *ptr__Bool_Type = NULL;
103
static PyTypeObject *ptr__List_Type = NULL;
104
static PyTypeObject *ptr__Long_Type = NULL;
105
# if PY_MAJOR_VERSION == 2 || !defined( Py_LIMITED_API )
106
static PyTypeObject *ptr__Method_Type = NULL;
108
static PyTypeObject *ptr__Module_Type = NULL;
109
static PyTypeObject *ptr__Range_Type = NULL;
110
static PyTypeObject *ptr__Slice_Type = NULL;
111
static PyTypeObject *ptr__TraceBack_Type = NULL;
112
static PyTypeObject *ptr__Tuple_Type = NULL;
113
static PyTypeObject *ptr__Type_Type = NULL;
114
static PyTypeObject *ptr__Unicode_Type = NULL;
115
# if PY_MAJOR_VERSION == 2
116
static PyTypeObject *ptr__Int_Type = NULL;
117
static PyTypeObject *ptr__String_Type = NULL;
118
static PyTypeObject *ptr__CObject_Type = NULL;
120
# if PY_MAJOR_VERSION >= 3
121
static PyTypeObject *ptr__Bytes_Type = NULL;
124
# if PY_MAJOR_VERSION == 2 || !defined( Py_LIMITED_API )
125
# if PY_MAJOR_VERSION == 2 || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION <= 11)
126
static int *ptr_Py_DebugFlag = NULL;
127
static int *ptr_Py_InteractiveFlag = NULL;
128
static int *ptr_Py_OptimizeFlag = NULL;
129
static int *ptr_Py_NoSiteFlag = NULL;
130
static int *ptr_Py_VerboseFlag = NULL;
133
# if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION <= 11
134
# if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 7
135
static const char **ptr__Py_PackageContext = NULL;
137
static char **ptr__Py_PackageContext = NULL;
147
//--------------------------------------------------------------------------------
148
class GetAddressException
151
GetAddressException( const char *_name )
154
virtual ~GetAddressException() {}
159
//--------------------------------------------------------------------------------
160
static PyObject *GetPyObjectPointer_As_PyObjectPointer( const char *name )
162
FARPROC addr = GetProcAddress( python_dll, name );
164
throw GetAddressException( name );
166
return *(PyObject **)addr;
169
static PyObject *GetPyObject_As_PyObjectPointer( const char *name )
171
FARPROC addr = GetProcAddress( python_dll, name );
173
throw GetAddressException( name );
175
return (PyObject *)addr;
178
static PyTypeObject *GetPyTypeObjectPointer_As_PyTypeObjectPointer( const char *name )
180
FARPROC addr = GetProcAddress( python_dll, name );
182
throw GetAddressException( name );
184
return *(PyTypeObject **)addr;
187
static PyTypeObject *GetPyTypeObject_As_PyTypeObjectPointer( const char *name )
189
FARPROC addr = GetProcAddress( python_dll, name );
191
throw GetAddressException( name );
193
return (PyTypeObject *)addr;
196
static int *GetInt_as_IntPointer( const char *name )
198
FARPROC addr = GetProcAddress( python_dll, name );
200
throw GetAddressException( name );
205
static char **GetCharPointer_as_CharPointerPointer( const char *name )
207
FARPROC addr = GetProcAddress( python_dll, name );
209
throw GetAddressException( name );
211
return (char **)addr;
214
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 7
215
static char **GetConstCharPointer_as_ConstCharPointerPointer( const char *name )
217
FARPROC addr = GetProcAddress( python_dll, name );
219
throw GetAddressException( name );
221
return (const char **)addr;
227
static const char python_dll_name_format[] = "PYTHON%1.1d%1.1d_D.DLL";
229
static const char python_dll_name_format[] = "PYTHON%1.1d%1.1d.DLL";
232
//--------------------------------------------------------------------------------
233
bool InitialisePythonIndirectInterface()
235
char python_dll_name[sizeof(python_dll_name_format)];
237
_snprintf( python_dll_name, sizeof(python_dll_name_format) / sizeof(char) - 1, python_dll_name_format, PY_MAJOR_VERSION, PY_MINOR_VERSION );
239
python_dll = LoadLibraryA( python_dll_name );
240
if( python_dll == NULL )
246
ptr_Py_RefTotal = GetInt_as_IntPointer( "_Py_RefTotal" );
248
# if PY_MAJOR_VERSION == 2 || !defined( Py_LIMITED_API )
249
# if PY_MAJOR_VERSION == 2 || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION <= 11)
250
ptr_Py_DebugFlag = GetInt_as_IntPointer( "Py_DebugFlag" );
251
ptr_Py_InteractiveFlag = GetInt_as_IntPointer( "Py_InteractiveFlag" );
252
ptr_Py_OptimizeFlag = GetInt_as_IntPointer( "Py_OptimizeFlag" );
253
ptr_Py_NoSiteFlag = GetInt_as_IntPointer( "Py_NoSiteFlag" );
254
ptr_Py_VerboseFlag = GetInt_as_IntPointer( "Py_VerboseFlag" );
257
# if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION <= 11
258
# if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 7
259
ptr__Py_PackageContext = GetConstCharPointer_as_ConstCharPointerPointer( "_Py_PackageContext" );
261
ptr__Py_PackageContext = GetCharPointer_as_CharPointerPointer( "_Py_PackageContext" );
266
# define PYCXX_STANDARD_EXCEPTION( eclass, bclass )
267
ptr_Exc_#eclass = GetPyTypeObject_As_PyTypeObjectPointer( "PyExc_" #eclass );
269
# if PY_MAJOR_VERSION == 2
270
# include "CXX/Python2/cxx_standard_exceptions.hxx"
272
# include "CXX/Python3/cxx_standard_exceptions.hxx"
275
# undef PYCXX_STANDARD_EXCEPTION
277
ptr__PyNone = GetPyObject_As_PyObjectPointer( "_Py_NoneStruct" );
279
# if PY_MAJOR_VERSION == 2
280
ptr__PyFalse = GetPyObject_As_PyObjectPointer( "_Py_ZeroStruct" );
282
ptr__PyFalse = GetPyObject_As_PyObjectPointer( "_Py_FalseStruct" );
284
ptr__PyTrue = GetPyObject_As_PyObjectPointer( "_Py_TrueStruct" );
286
ptr__CFunction_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyCFunction_Type" );
287
ptr__Complex_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyComplex_Type" );
288
ptr__Dict_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyDict_Type" );
289
ptr__Float_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyFloat_Type" );
290
# if PY_MAJOR_VERSION == 2 || !defined( Py_LIMITED_API )
291
ptr__Function_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyFunction_Type" );
293
ptr__Bool_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyBool_Type" );
294
ptr__List_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyList_Type" );
295
ptr__Long_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyLong_Type" );
296
# if PY_MAJOR_VERSION == 2 || !defined( Py_LIMITED_API )
297
ptr__Method_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyMethod_Type" );
299
ptr__Module_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyModule_Type" );
300
ptr__Range_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyRange_Type" );
301
ptr__Slice_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PySlice_Type" );
302
ptr__TraceBack_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyTraceBack_Type" );
303
ptr__Tuple_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyTuple_Type" );
304
ptr__Type_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyType_Type" );
305
ptr__Unicode_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyUnicode_Type" );
306
# if PY_MAJOR_VERSION == 2
307
ptr__String_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyString_Type" );
308
ptr__Int_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyInt_Type" );
309
ptr__CObject_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyCObject_Type" );
311
# if PY_MAJOR_VERSION >= 3
312
ptr__Bytes_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyBytes_Type" );
315
catch( GetAddressException &e )
317
OutputDebugStringA( python_dll_name );
318
OutputDebugStringA( " does not contain symbol " );
319
OutputDebugStringA( e.name );
320
OutputDebugStringA( "\n" );
329
// Wrap variables as function calls
331
PYCXX_EXPORT PyObject *_Exc_ArithmeticError() { return ptr__Exc_ArithmeticError; }
332
PYCXX_EXPORT PyObject *_Exc_AssertionError() { return ptr__Exc_AssertionError; }
333
PYCXX_EXPORT PyObject *_Exc_AttributeError() { return ptr__Exc_AttributeError; }
334
PYCXX_EXPORT PyObject *_Exc_EnvironmentError() { return ptr__Exc_EnvironmentError; }
335
PYCXX_EXPORT PyObject *_Exc_EOFError() { return ptr__Exc_EOFError; }
336
PYCXX_EXPORT PyObject *_Exc_Exception() { return ptr__Exc_Exception; }
337
PYCXX_EXPORT PyObject *_Exc_FloatingPointError() { return ptr__Exc_FloatingPointError; }
338
PYCXX_EXPORT PyObject *_Exc_ImportError() { return ptr__Exc_ImportError; }
339
PYCXX_EXPORT PyObject *_Exc_IndexError() { return ptr__Exc_IndexError; }
340
PYCXX_EXPORT PyObject *_Exc_IOError() { return ptr__Exc_IOError; }
341
PYCXX_EXPORT PyObject *_Exc_KeyboardInterrupt() { return ptr__Exc_KeyboardInterrupt; }
342
PYCXX_EXPORT PyObject *_Exc_KeyError() { return ptr__Exc_KeyError; }
343
PYCXX_EXPORT PyObject *_Exc_LookupError() { return ptr__Exc_LookupError; }
344
PYCXX_EXPORT PyObject *_Exc_MemoryError() { return ptr__Exc_MemoryError; }
345
PYCXX_EXPORT PyObject *_Exc_NameError() { return ptr__Exc_NameError; }
346
PYCXX_EXPORT PyObject *_Exc_NotImplementedError() { return ptr__Exc_NotImplementedError; }
347
PYCXX_EXPORT PyObject *_Exc_OSError() { return ptr__Exc_OSError; }
348
PYCXX_EXPORT PyObject *_Exc_OverflowError() { return ptr__Exc_OverflowError; }
349
PYCXX_EXPORT PyObject *_Exc_RuntimeError() { return ptr__Exc_RuntimeError; }
350
# if PY_MAJOR_VERSION == 2
351
PYCXX_EXPORT PyObject *_Exc_StandardError() { return ptr__Exc_StandardError; }
353
PYCXX_EXPORT PyObject *_Exc_SyntaxError() { return ptr__Exc_SyntaxError; }
354
PYCXX_EXPORT PyObject *_Exc_SystemError() { return ptr__Exc_SystemError; }
355
PYCXX_EXPORT PyObject *_Exc_SystemExit() { return ptr__Exc_SystemExit; }
356
PYCXX_EXPORT PyObject *_Exc_TypeError() { return ptr__Exc_TypeError; }
357
PYCXX_EXPORT PyObject *_Exc_ValueError() { return ptr__Exc_ValueError; }
359
PYCXX_EXPORT PyObject *_Exc_WindowsError() { return ptr__Exc_WindowsError; }
361
PYCXX_EXPORT PyObject *_Exc_ZeroDivisionError() { return ptr__Exc_ZeroDivisionError; }
362
PYCXX_EXPORT PyObject *_Exc_IndentationError() { return ptr__Exc_IndentationError; }
363
PYCXX_EXPORT PyObject *_Exc_TabError() { return ptr__Exc_TabError; }
364
PYCXX_EXPORT PyObject *_Exc_UnboundLocalError() { return ptr__Exc_UnboundLocalError; }
365
PYCXX_EXPORT PyObject *_Exc_UnicodeError() { return ptr__Exc_UnicodeError; }
368
// wrap items in Object.h
370
PYCXX_EXPORT PyObject *_None() { return ptr__PyNone; }
372
PYCXX_EXPORT PyObject *_False() { return ptr__PyFalse; }
373
PYCXX_EXPORT PyObject *_True() { return ptr__PyTrue; }
375
PYCXX_EXPORT PyTypeObject *_CFunction_Type() { return ptr__CFunction_Type; }
376
PYCXX_EXPORT PyTypeObject *_Complex_Type() { return ptr__Complex_Type; }
377
PYCXX_EXPORT PyTypeObject *_Dict_Type() { return ptr__Dict_Type; }
378
PYCXX_EXPORT PyTypeObject *_Float_Type() { return ptr__Float_Type; }
379
# if PY_MAJOR_VERSION == 2 || !defined( Py_LIMITED_API )
380
PYCXX_EXPORT PyTypeObject *_Function_Type() { return ptr__Function_Type; }
382
PYCXX_EXPORT PyTypeObject *_Bool_Type() { return ptr__Bool_Type; }
383
PYCXX_EXPORT PyTypeObject *_List_Type() { return ptr__List_Type; }
384
PYCXX_EXPORT PyTypeObject *_Long_Type() { return ptr__Long_Type; }
385
# if PY_MAJOR_VERSION == 2 || !defined( Py_LIMITED_API )
386
PYCXX_EXPORT PyTypeObject *_Method_Type() { return ptr__Method_Type; }
388
PYCXX_EXPORT PyTypeObject *_Module_Type() { return ptr__Module_Type; }
389
PYCXX_EXPORT PyTypeObject *_Range_Type() { return ptr__Range_Type; }
390
PYCXX_EXPORT PyTypeObject *_Slice_Type() { return ptr__Slice_Type; }
391
PYCXX_EXPORT PyTypeObject *_TraceBack_Type() { return ptr__TraceBack_Type; }
392
PYCXX_EXPORT PyTypeObject *_Tuple_Type() { return ptr__Tuple_Type; }
393
PYCXX_EXPORT PyTypeObject *_Type_Type() { return ptr__Type_Type; }
394
PYCXX_EXPORT PyTypeObject *_Unicode_Type() { return ptr__Unicode_Type; }
395
# if PY_MAJOR_VERSION == 2
396
PYCXX_EXPORT PyTypeObject *_String_Type() { return ptr__String_Type; }
397
PYCXX_EXPORT PyTypeObject *_Int_Type() { return ptr__Int_Type; }
398
PYCXX_EXPORT PyTypeObject *_CObject_Type() { return ptr__CObject_Type; }
400
# if PY_MAJOR_VERSION >= 3
401
PYCXX_EXPORT PyTypeObject *_Bytes_Type() { return ptr__Bytes_Type; }
405
// wrap the Python Flag variables
407
# if PY_MAJOR_VERSION == 2 || !defined( Py_LIMITED_API )
408
# if PY_MAJOR_VERSION == 2 || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION <= 11)
409
PYCXX_EXPORT int &_Py_DebugFlag() { return *ptr_Py_DebugFlag; }
410
PYCXX_EXPORT int &_Py_InteractiveFlag() { return *ptr_Py_InteractiveFlag; }
411
PYCXX_EXPORT int &_Py_OptimizeFlag() { return *ptr_Py_OptimizeFlag; }
412
PYCXX_EXPORT int &_Py_NoSiteFlag() { return *ptr_Py_NoSiteFlag; }
413
PYCXX_EXPORT int &_Py_VerboseFlag() { return *ptr_Py_VerboseFlag; }
417
# if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION <= 11
418
# if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 7
419
PYCXX_EXPORT const char *__Py_PackageContext() { return *ptr__Py_PackageContext; }
421
PYCXX_EXPORT char *__Py_PackageContext() { return *ptr__Py_PackageContext; }
426
# define Py_INCREF(op) ( \
427
_Py_INC_REFTOTAL _Py_REF_DEBUG_COMMA \
428
((PyObject*)(op))->ob_refcnt++)
430
# define Py_DECREF(op) \
431
if (_Py_DEC_REFTOTAL _Py_REF_DEBUG_COMMA \
432
--((PyObject*)(op))->ob_refcnt != 0) \
433
_Py_CHECK_REFCNT(op) \
435
_Py_Dealloc((PyObject *)(op))
438
void _XINCREF( PyObject *op )
440
// This function must match the contents of Py_XINCREF(op)
445
(*ptr_Py_RefTotal)++;
451
void _XDECREF( PyObject *op )
453
// This function must match the contents of Py_XDECREF(op);
458
(*ptr_Py_RefTotal)--;
461
if (--(op)->ob_refcnt == 0)
462
_Py_Dealloc((PyObject *)(op));
467
# error "Can only delay load under Win32"
472
//================================================================================
476
//================================================================================
479
// Wrap variables as function calls
481
# define PYCXX_STANDARD_EXCEPTION( eclass, bclass ) \
482
PYCXX_EXPORT PyObject *_Exc_##eclass() { return ::PyExc_##eclass; }
484
# if PY_MAJOR_VERSION == 2
485
# include "CXX/Python2/cxx_standard_exceptions.hxx"
487
# include "CXX/Python3/cxx_standard_exceptions.hxx"
490
# undef PYCXX_STANDARD_EXCEPTION
493
// wrap items in Object.h
495
PYCXX_EXPORT PyObject *_None() { return &::_Py_NoneStruct; }
497
PYCXX_EXPORT PyObject *_False() { return Py_False; }
498
PYCXX_EXPORT PyObject *_True() { return Py_True; }
500
PYCXX_EXPORT PyTypeObject *_CFunction_Type() { return &PyCFunction_Type; }
501
PYCXX_EXPORT PyTypeObject *_Complex_Type() { return &PyComplex_Type; }
502
PYCXX_EXPORT PyTypeObject *_Dict_Type() { return &PyDict_Type; }
503
PYCXX_EXPORT PyTypeObject *_Float_Type() { return &PyFloat_Type; }
504
# if PY_MAJOR_VERSION == 2 || !defined( Py_LIMITED_API )
505
PYCXX_EXPORT PyTypeObject *_Function_Type() { return &PyFunction_Type; }
507
PYCXX_EXPORT PyTypeObject *_Bool_Type() { return &PyBool_Type; }
508
PYCXX_EXPORT PyTypeObject *_List_Type() { return &PyList_Type; }
509
PYCXX_EXPORT PyTypeObject *_Long_Type() { return &PyLong_Type; }
510
# if PY_MAJOR_VERSION == 2 || !defined( Py_LIMITED_API )
511
PYCXX_EXPORT PyTypeObject *_Method_Type() { return &PyMethod_Type; }
513
PYCXX_EXPORT PyTypeObject *_Module_Type() { return &PyModule_Type; }
514
PYCXX_EXPORT PyTypeObject *_Range_Type() { return &PyRange_Type; }
515
PYCXX_EXPORT PyTypeObject *_Slice_Type() { return &PySlice_Type; }
516
PYCXX_EXPORT PyTypeObject *_TraceBack_Type() { return &PyTraceBack_Type; }
517
PYCXX_EXPORT PyTypeObject *_Tuple_Type() { return &PyTuple_Type; }
518
PYCXX_EXPORT PyTypeObject *_Type_Type() { return &PyType_Type; }
519
PYCXX_EXPORT PyTypeObject *_Unicode_Type() { return &PyUnicode_Type; }
520
# if PY_MAJOR_VERSION == 2
521
PYCXX_EXPORT PyTypeObject *_String_Type() { return &PyString_Type; }
522
PYCXX_EXPORT PyTypeObject *_Int_Type() { return &PyInt_Type; }
523
PYCXX_EXPORT PyTypeObject *_CObject_Type() { return &PyCObject_Type; }
525
# if PY_MAJOR_VERSION >= 3
526
PYCXX_EXPORT PyTypeObject *_Bytes_Type() { return &PyBytes_Type; }
532
# if PY_MAJOR_VERSION == 2 || !defined( Py_LIMITED_API )
533
# if PY_MAJOR_VERSION == 2 || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION <= 11)
534
PYCXX_EXPORT int &_Py_DebugFlag() { return Py_DebugFlag; }
535
PYCXX_EXPORT int &_Py_InteractiveFlag() { return Py_InteractiveFlag; }
536
PYCXX_EXPORT int &_Py_OptimizeFlag() { return Py_OptimizeFlag; }
537
PYCXX_EXPORT int &_Py_NoSiteFlag() { return Py_NoSiteFlag; }
538
PYCXX_EXPORT int &_Py_VerboseFlag() { return Py_VerboseFlag; }
540
# if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION <= 11
541
# if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 7
542
PYCXX_EXPORT const char *__Py_PackageContext() { return _Py_PackageContext; }
544
PYCXX_EXPORT char *__Py_PackageContext() { return _Py_PackageContext; }
550
// Needed to keep the abstractions for delayload interface
552
void _XINCREF( PyObject *op )
557
void _XDECREF( PyObject *op )