• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2023 Huawei Technologies Co., Ltd
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #ifndef MINDSPORE_PI_JIT_PYDEF_H
17 #define MINDSPORE_PI_JIT_PYDEF_H
18 
19 #define PY_SSIZE_T_CLEAN
20 #include <Python.h>
21 #include "pybind11/pybind11.h"
22 #include "pipeline/jit/pi/utils/opcode_declare.h"
23 
24 #if (PY_MAJOR_VERSION == 3) && (PY_MINOR_VERSION < 9)
25 
26 #define Py_IS_TYPE(ob, type) Py_TYPE(ob) == type
27 
28 extern "C" {
29 typedef PyObject *(*_PyFrameEvalFunction)(PyFrameObject *, int);
30 void _PyInterpreterState_SetEvalFrameFunc(PyInterpreterState *state, _PyFrameEvalFunction eval_frame_function);
31 _PyFrameEvalFunction _PyInterpreterState_GetEvalFrameFunc(PyInterpreterState *state);
32 }
33 
_PyEval_EvalFrameDefault(PyThreadState * state,PyFrameObject * f,int exc)34 inline PyObject *_PyEval_EvalFrameDefault(PyThreadState *state, PyFrameObject *f, int exc) {
35   return _PyEval_EvalFrameDefault(f, exc);
36 }
37 
PyObject_Vectorcall(PyObject * func,PyObject * const * stack,Py_ssize_t nargs,PyObject * kwnames)38 inline PyObject *PyObject_Vectorcall(PyObject *func, PyObject *const *stack, Py_ssize_t nargs, PyObject *kwnames) {
39 #if PY_MINOR_VERSION == 7
40   return _PyObject_FastCallKeywords(func, stack, nargs, kwnames);
41 #else
42   return _PyObject_Vectorcall(func, stack, nargs, kwnames);
43 #endif
44 }
45 #endif
46 
GetCodeLineTable(PyCodeObject * co)47 inline auto GetCodeLineTable(PyCodeObject *co) {
48 #if (PY_MAJOR_VERSION == 3) && (PY_MINOR_VERSION < 10)
49   return co->co_lnotab;
50 #else
51   return co->co_linetable;
52 #endif
53 }
54 
GetCodePositionOnlyArgCount(PyCodeObject * co)55 inline auto GetCodePositionOnlyArgCount(PyCodeObject *co) {
56 #if (PY_MAJOR_VERSION == 3) && (PY_MINOR_VERSION > 7)
57   return co->co_posonlyargcount;
58 #else
59   return 0;
60 #endif
61 }
62 
63 #endif
64