SST  12.0.1
StructuralSimulationToolkit
pymacros.h
1 // -*- c++ -*-
2 
3 // Copyright 2009-2022 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-2022, 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_MODEL_PYTHON_PYMACROS_H
15 #define SST_CORE_MODEL_PYTHON_PYMACROS_H
16 
17 #include "sst/core/warnmacros.h"
18 
19 DISABLE_WARN_DEPRECATED_REGISTER
20 #include <Python.h>
21 REENABLE_WARNING
22 
23 #if PY_MAJOR_VERSION >= 3
24 #define SST_PY_OBJ_HEAD PyVarObject_HEAD_INIT(nullptr, 0)
25 #define SST_ConvertToPythonLong(x) PyLong_FromLong(x)
26 #define SST_ConvertToPythonBool(x) PyBool_FromLong(x)
27 #define SST_ConvertToCppLong(x) PyLong_AsLong(x)
28 #define SST_ConvertToPythonString(x) PyUnicode_FromString(x)
29 #define SST_ConvertToCppString(x) PyUnicode_AsUTF8(x)
30 #define SST_TP_FINALIZE nullptr,
31 #define SST_TP_VECTORCALL_OFFSET 0,
32 #define SST_TP_PRINT
33 #define SST_TP_COMPARE(x)
34 #define SST_TP_RICH_COMPARE(x) x,
35 #define SST_TP_AS_SYNC nullptr,
36 #define SST_PY_INIT_MODULE(name, methods, moddef) PyModule_Create(&moddef)
37 #if PY_MINOR_VERSION == 8
38 #define SST_TP_PRINT_DEP nullptr,
39 //#define SST_TP_PRINT_DEP DISABLE_WARN_DEPRECATED_DECLARATION nullptr, REENABLE_WARNING
40 #else
41 #define SST_TP_PRINT_DEP
42 #endif
43 #if PY_MINOR_VERSION >= 8
44 #define SST_TP_VECTORCALL nullptr,
45 #else
46 #define SST_TP_VECTORCALL
47 #endif
48 
49 // Number protocol macros
50 #define SST_NB_DIVIDE(x)
51 #define SST_NB_COERCE
52 #define SST_NB_INTLONG(x) x,
53 #define SST_NB_RESERVED nullptr,
54 #define SST_NB_OCT
55 #define SST_NB_HEX
56 #define SST_NB_INPLACE_DIVIDE(x)
57 #define SST_NB_MATRIX_MULTIPLY nullptr,
58 #define SST_NB_INPLACE_MATRIX_MULTIPLY nullptr,
59 
60 #else
61 
62 #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
63 #define SST_PY_OBJ_HEAD PyVarObject_HEAD_INIT(nullptr, 0)
64 #define SST_ConvertToPythonLong(x) PyInt_FromLong(x)
65 #define SST_ConvertToPythonBool(x) PyBool_FromLong(x)
66 #define SST_ConvertToCppLong(x) PyInt_AsLong(x)
67 #define SST_ConvertToPythonString(x) PyString_FromString(x)
68 #define SST_ConvertToCppString(x) PyString_AsString(x)
69 #define SST_TP_FINALIZE
70 #define SST_TP_VECTORCALL_OFFSET
71 #define SST_TP_PRINT nullptr,
72 #define SST_TP_COMPARE(x) x,
73 #define SST_TP_RICH_COMPARE(x) nullptr,
74 #define SST_TP_AS_SYNC
75 #define SST_TP_VECTORCALL
76 #define SST_TP_PRINT_DEP
77 #define SST_PY_INIT_MODULE(name, methods, moddef) Py_InitModule(name, methods)
78 
79 // Number protocol macros
80 #define SST_NB_DIVIDE(x) x,
81 #define SST_NB_COERCE nullptr,
82 #define SST_NB_INTLONG(x) x, x,
83 #define SST_NB_RESERVED
84 #define SST_NB_OCT nullptr,
85 #define SST_NB_HEX nullptr,
86 #define SST_NB_INPLACE_DIVIDE(x) x,
87 #define SST_NB_MATRIX_MULTIPLY
88 #define SST_NB_INPLACE_MATRIX_MULTIPLY
89 #endif
90 
91 #endif // SST_CORE_MODEL_PYTHON_PYMACROS_H