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