SST  10.1.0
StructuralSimulationToolkit
pymacros.h
1 // -*- c++ -*-
2 
3 // Copyright 2009-2020 NTESS. Under the terms
4 // of Contract DE-NA0003525 with NTESS, the U.S.
5 // Government retains certain rights in this software.
6 //
7 // Copyright (c) 2009-2020, NTESS
8 // All rights reserved.
9 //
10 // This file is part of the SST software package. For license
11 // information, see the LICENSE file in the top level directory of the
12 // distribution.
13 
14 #ifndef sst_core_python_macros_h
15 #define sst_core_python_macros_h
16 
17 #include "sst/core/warnmacros.h"
18 
19 #if PY_MAJOR_VERSION >= 3
20  #define SST_PY_OBJ_HEAD PyVarObject_HEAD_INIT(nullptr, 0)
21  #define SST_ConvertToPythonLong(x) PyLong_FromLong(x)
22  #define SST_ConvertToCppLong(x) PyLong_AsLong(x)
23  #define SST_ConvertToPythonString(x) PyUnicode_FromString(x)
24  #define SST_ConvertToCppString(x) PyUnicode_AsUTF8(x)
25  #define SST_TP_FINALIZE nullptr,
26  #define SST_TP_VECTORCALL_OFFSET 0,
27  #define SST_TP_PRINT
28  #define SST_TP_COMPARE(x)
29  #define SST_TP_RICH_COMPARE(x) x,
30  #define SST_TP_AS_SYNC nullptr,
31  #define SST_PY_INIT_MODULE(name, methods, moddef) PyModule_Create(&moddef)
32  #if PY_MINOR_VERSION >= 8
33  #define SST_TP_VECTORCALL nullptr,
34  #define SST_TP_PRINT_DEP nullptr,
35 //#define SST_TP_PRINT_DEP DISABLE_WARN_DEPRECATED_DECLARATION nullptr, REENABLE_WARNING
36 #else
37  #define SST_TP_VECTORCALL
38  #define SST_TP_PRINT_DEP
39  #endif
40 
41 // Number protocol macros
42  #define SST_NB_DIVIDE(x)
43  #define SST_NB_COERCE
44  #define SST_NB_INTLONG(x) x,
45  #define SST_NB_RESERVED nullptr,
46  #define SST_NB_OCT
47  #define SST_NB_HEX
48  #define SST_NB_INPLACE_DIVIDE(x)
49  #define SST_NB_MATRIX_MULTIPLY nullptr,
50  #define SST_NB_INPLACE_MATRIX_MULTIPLY nullptr,
51 
52 #else
53 
54  #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
55  #define SST_PY_OBJ_HEAD PyVarObject_HEAD_INIT(nullptr, 0)
56  #define SST_ConvertToPythonLong(x) PyInt_FromLong(x)
57  #define SST_ConvertToCppLong(x) PyInt_AsLong(x)
58  #define SST_ConvertToPythonString(x) PyString_FromString(x)
59  #define SST_ConvertToCppString(x) PyString_AsString(x)
60  #define SST_TP_FINALIZE
61  #define SST_TP_VECTORCALL_OFFSET
62  #define SST_TP_PRINT nullptr,
63  #define SST_TP_COMPARE(x) x,
64  #define SST_TP_RICH_COMPARE(x) nullptr,
65  #define SST_TP_AS_SYNC
66  #define SST_TP_VECTORCALL
67  #define SST_TP_PRINT_DEP
68  #define SST_PY_INIT_MODULE(name, methods, moddef) Py_InitModule(name, methods)
69 
70 // Number protocol macros
71  #define SST_NB_DIVIDE(x) x,
72  #define SST_NB_COERCE nullptr,
73  #define SST_NB_INTLONG(x) x, x,
74  #define SST_NB_RESERVED
75  #define SST_NB_OCT nullptr,
76  #define SST_NB_HEX nullptr,
77  #define SST_NB_INPLACE_DIVIDE(x) x,
78  #define SST_NB_MATRIX_MULTIPLY
79  #define SST_NB_INPLACE_MATRIX_MULTIPLY
80 #endif
81 
82 #endif