FreeCAD

Форк
0
/
IndirectPythonInterface.cxx 
563 строки · 23.5 Кб
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
static int _IsInstance( PyObject *op, PyTypeObject *type )
43
{
44
    return PyObject_IsInstance( op, reinterpret_cast<PyObject *>( type ) );
45
}
46

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; }
53
#endif
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; }
59
#endif
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; }
71
#endif
72
#if PY_MAJOR_VERSION >= 3
73
PYCXX_EXPORT bool _Bytes_Check( PyObject *op )       { return _IsInstance( op, _Bytes_Type() ) > 0; }
74
#endif
75

76
#if defined(PY_WIN32_DELAYLOAD_PYTHON_DLL)
77

78
# if defined(MS_WINDOWS)
79
#  include <windows.h>
80

81

82
static HMODULE python_dll;
83

84
#  define PYCXX_STANDARD_EXCEPTION( eclass, bclass ) \
85
    static PyObject *ptr_Exc_##eclass = NULL;
86

87
#  if PY_MAJOR_VERSION == 2
88
#   include "CXX/Python2/cxx_standard_exceptions.hxx"
89
#  else
90
#   include "CXX/Python3/cxx_standard_exceptions.hxx"
91
#  endif
92

93
#  undef PYCXX_STANDARD_EXCEPTION
94

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;
101
#  endif
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;
107
#  endif
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;
119
#  endif
120
#  if PY_MAJOR_VERSION >= 3
121
static PyTypeObject *ptr__Bytes_Type = NULL;
122
#  endif
123

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;
131
#    endif
132

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;
136
#      else
137
static char **ptr__Py_PackageContext = NULL;
138
#      endif
139
#    endif
140
#  endif
141

142
#  ifdef Py_REF_DEBUG
143
int *ptr_Py_RefTotal;
144
#  endif
145

146

147
//--------------------------------------------------------------------------------
148
class GetAddressException
149
{
150
public:
151
    GetAddressException( const char *_name )
152
        : name( _name )
153
    {}
154
    virtual ~GetAddressException() {}
155
    const char *name;
156
};
157

158

159
//--------------------------------------------------------------------------------
160
static PyObject *GetPyObjectPointer_As_PyObjectPointer( const char *name )
161
{
162
    FARPROC addr = GetProcAddress( python_dll, name );
163
    if( addr == NULL )
164
        throw GetAddressException( name );
165

166
    return *(PyObject **)addr;
167
}
168

169
static PyObject *GetPyObject_As_PyObjectPointer( const char *name )
170
{
171
    FARPROC addr = GetProcAddress( python_dll, name );
172
    if( addr == NULL )
173
        throw GetAddressException( name );
174

175
    return (PyObject *)addr;
176
}
177

178
static PyTypeObject *GetPyTypeObjectPointer_As_PyTypeObjectPointer( const char *name )
179
{
180
    FARPROC addr = GetProcAddress( python_dll, name );
181
    if( addr == NULL )
182
        throw GetAddressException( name );
183

184
    return *(PyTypeObject **)addr;
185
}
186

187
static PyTypeObject *GetPyTypeObject_As_PyTypeObjectPointer( const char *name )
188
{
189
    FARPROC addr = GetProcAddress( python_dll, name );
190
    if( addr == NULL )
191
        throw GetAddressException( name );
192

193
    return (PyTypeObject *)addr;
194
}
195

196
static int *GetInt_as_IntPointer( const char *name )
197
{
198
    FARPROC addr = GetProcAddress( python_dll, name );
199
    if( addr == NULL )
200
        throw GetAddressException( name );
201

202
    return (int *)addr;
203
}
204

205
static char **GetCharPointer_as_CharPointerPointer( const char *name )
206
{
207
    FARPROC addr = GetProcAddress( python_dll, name );
208
    if( addr == NULL )
209
        throw GetAddressException( name );
210

211
    return (char **)addr;
212
}
213

214
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 7
215
static char **GetConstCharPointer_as_ConstCharPointerPointer( const char *name )
216
{
217
    FARPROC addr = GetProcAddress( python_dll, name );
218
    if( addr == NULL )
219
        throw GetAddressException( name );
220

221
    return (const char **)addr;
222
}
223
#endif
224

225

226
#  ifdef _DEBUG
227
static const char python_dll_name_format[] = "PYTHON%1.1d%1.1d_D.DLL";
228
#  else
229
static const char python_dll_name_format[] = "PYTHON%1.1d%1.1d.DLL";
230
#  endif
231

232
//--------------------------------------------------------------------------------
233
bool InitialisePythonIndirectInterface()
234
{
235
    char python_dll_name[sizeof(python_dll_name_format)];
236

237
    _snprintf( python_dll_name, sizeof(python_dll_name_format) / sizeof(char) - 1, python_dll_name_format, PY_MAJOR_VERSION, PY_MINOR_VERSION );
238

239
    python_dll = LoadLibraryA( python_dll_name );
240
    if( python_dll == NULL )
241
        return false;
242

243
    try
244
    {
245
#  ifdef Py_REF_DEBUG
246
    ptr_Py_RefTotal             = GetInt_as_IntPointer( "_Py_RefTotal" );
247
#  endif
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" );
255
#    endif
256

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" );
260
#       else
261
    ptr__Py_PackageContext      = GetCharPointer_as_CharPointerPointer( "_Py_PackageContext" );
262
#       endif
263
#     endif
264
#  endif
265

266
#  define PYCXX_STANDARD_EXCEPTION( eclass, bclass )
267
    ptr_Exc_#eclass = GetPyTypeObject_As_PyTypeObjectPointer( "PyExc_" #eclass );
268

269
#  if PY_MAJOR_VERSION == 2
270
#   include "CXX/Python2/cxx_standard_exceptions.hxx"
271
#  else
272
#   include "CXX/Python3/cxx_standard_exceptions.hxx"
273
#  endif
274

275
#  undef PYCXX_STANDARD_EXCEPTION
276

277
    ptr__PyNone                 = GetPyObject_As_PyObjectPointer( "_Py_NoneStruct" );
278

279
#  if PY_MAJOR_VERSION == 2
280
    ptr__PyFalse                = GetPyObject_As_PyObjectPointer( "_Py_ZeroStruct" );
281
#  else
282
    ptr__PyFalse                = GetPyObject_As_PyObjectPointer( "_Py_FalseStruct" );
283
#  endif
284
    ptr__PyTrue                 = GetPyObject_As_PyObjectPointer( "_Py_TrueStruct" );
285

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" );
292
#  endif
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" );
298
#  endif
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" );
310
#  endif
311
#  if PY_MAJOR_VERSION >= 3
312
    ptr__Bytes_Type             = GetPyTypeObject_As_PyTypeObjectPointer( "PyBytes_Type" );
313
#  endif
314
    }
315
    catch( GetAddressException &e )
316
    {
317
        OutputDebugStringA( python_dll_name );
318
        OutputDebugStringA( " does not contain symbol " );
319
        OutputDebugStringA( e.name );
320
        OutputDebugStringA( "\n" );
321

322
        return false;
323
    }
324

325
    return true;
326
}
327

328
//
329
//    Wrap variables as function calls
330
//
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; }
352
#  endif
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; }
358
#  ifdef MS_WINDOWS
359
PYCXX_EXPORT PyObject *_Exc_WindowsError()           { return ptr__Exc_WindowsError; }
360
#  endif
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; }
366

367
//
368
//    wrap items in Object.h
369
//
370
PYCXX_EXPORT PyObject *_None()                       { return ptr__PyNone; }
371

372
PYCXX_EXPORT PyObject *_False()                      { return ptr__PyFalse; }
373
PYCXX_EXPORT PyObject *_True()                       { return ptr__PyTrue; }
374

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; }
381
#  endif
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; }
387
#  endif
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; }
399
#  endif
400
#  if PY_MAJOR_VERSION >= 3
401
PYCXX_EXPORT PyTypeObject *_Bytes_Type()             { return ptr__Bytes_Type; }
402
#  endif
403

404
//
405
//    wrap the Python Flag variables
406
//
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; }
414
#    endif
415
#  endif
416

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; }
420
#    else
421
PYCXX_EXPORT char *__Py_PackageContext()             { return *ptr__Py_PackageContext; }
422
#    endif
423
#  endif
424

425
#  if 0
426
#   define Py_INCREF(op) (                         \
427
    _Py_INC_REFTOTAL  _Py_REF_DEBUG_COMMA       \
428
    ((PyObject*)(op))->ob_refcnt++)
429

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)                    \
434
    else                                        \
435
        _Py_Dealloc((PyObject *)(op))
436
#  endif
437

438
void _XINCREF( PyObject *op )
439
{
440
    // This function must match the contents of Py_XINCREF(op)
441
    if( op == NULL )
442
        return;
443

444
#  ifdef Py_REF_DEBUG
445
    (*ptr_Py_RefTotal)++;
446
#  endif
447
    (op)->ob_refcnt++;
448

449
}
450

451
void _XDECREF( PyObject *op )
452
{
453
    // This function must match the contents of Py_XDECREF(op);
454
    if( op == NULL )
455
        return;
456

457
#  ifdef Py_REF_DEBUG
458
    (*ptr_Py_RefTotal)--;
459
#  endif
460

461
    if (--(op)->ob_refcnt == 0)
462
        _Py_Dealloc((PyObject *)(op));
463
}
464

465

466
# else
467
#  error "Can only delay load under Win32"
468
# endif
469

470
#else
471

472
//================================================================================
473
//
474
//    Map onto Macros
475
//
476
//================================================================================
477

478
//
479
//    Wrap variables as function calls
480
//
481
# define PYCXX_STANDARD_EXCEPTION( eclass, bclass ) \
482
    PYCXX_EXPORT PyObject *_Exc_##eclass() { return ::PyExc_##eclass; }
483

484
# if PY_MAJOR_VERSION == 2
485
#  include "CXX/Python2/cxx_standard_exceptions.hxx"
486
# else
487
#  include "CXX/Python3/cxx_standard_exceptions.hxx"
488
# endif
489

490
# undef PYCXX_STANDARD_EXCEPTION
491

492
//
493
//    wrap items in Object.h
494
//
495
PYCXX_EXPORT PyObject *_None()                       { return &::_Py_NoneStruct; }
496

497
PYCXX_EXPORT PyObject *_False()                      { return Py_False; }
498
PYCXX_EXPORT PyObject *_True()                       { return Py_True; }
499

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; }
506
# endif
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; }
512
# endif
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; }
524
# endif
525
# if PY_MAJOR_VERSION >= 3
526
PYCXX_EXPORT PyTypeObject *_Bytes_Type()             { return &PyBytes_Type; }
527
# endif
528

529
//
530
//    wrap flags
531
//
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; }
539
#    endif
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; }
543
#   else
544
PYCXX_EXPORT char *__Py_PackageContext()             { return _Py_PackageContext; }
545
#   endif
546
#  endif
547
# endif
548

549
//
550
//    Needed to keep the abstractions for delayload interface
551
//
552
void _XINCREF( PyObject *op )
553
{
554
    Py_XINCREF( op );
555
}
556

557
void _XDECREF( PyObject *op )
558
{
559
    Py_XDECREF( op );
560
}
561

562
#endif
563
}
564

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.