17db96d56Sopenharmony_ci 27db96d56Sopenharmony_ci#ifndef Py_MODSUPPORT_H 37db96d56Sopenharmony_ci#define Py_MODSUPPORT_H 47db96d56Sopenharmony_ci#ifdef __cplusplus 57db96d56Sopenharmony_ciextern "C" { 67db96d56Sopenharmony_ci#endif 77db96d56Sopenharmony_ci 87db96d56Sopenharmony_ci/* Module support interface */ 97db96d56Sopenharmony_ci 107db96d56Sopenharmony_ci#include <stdarg.h> // va_list 117db96d56Sopenharmony_ci 127db96d56Sopenharmony_ci/* If PY_SSIZE_T_CLEAN is defined, each functions treats #-specifier 137db96d56Sopenharmony_ci to mean Py_ssize_t */ 147db96d56Sopenharmony_ci#ifdef PY_SSIZE_T_CLEAN 157db96d56Sopenharmony_ci#define PyArg_Parse _PyArg_Parse_SizeT 167db96d56Sopenharmony_ci#define PyArg_ParseTuple _PyArg_ParseTuple_SizeT 177db96d56Sopenharmony_ci#define PyArg_ParseTupleAndKeywords _PyArg_ParseTupleAndKeywords_SizeT 187db96d56Sopenharmony_ci#define PyArg_VaParse _PyArg_VaParse_SizeT 197db96d56Sopenharmony_ci#define PyArg_VaParseTupleAndKeywords _PyArg_VaParseTupleAndKeywords_SizeT 207db96d56Sopenharmony_ci#define Py_BuildValue _Py_BuildValue_SizeT 217db96d56Sopenharmony_ci#define Py_VaBuildValue _Py_VaBuildValue_SizeT 227db96d56Sopenharmony_ci#endif 237db96d56Sopenharmony_ci 247db96d56Sopenharmony_ci/* Due to a glitch in 3.2, the _SizeT versions weren't exported from the DLL. */ 257db96d56Sopenharmony_ci#if !defined(PY_SSIZE_T_CLEAN) || !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000 267db96d56Sopenharmony_ciPyAPI_FUNC(int) PyArg_Parse(PyObject *, const char *, ...); 277db96d56Sopenharmony_ciPyAPI_FUNC(int) PyArg_ParseTuple(PyObject *, const char *, ...); 287db96d56Sopenharmony_ciPyAPI_FUNC(int) PyArg_ParseTupleAndKeywords(PyObject *, PyObject *, 297db96d56Sopenharmony_ci const char *, char **, ...); 307db96d56Sopenharmony_ciPyAPI_FUNC(int) PyArg_VaParse(PyObject *, const char *, va_list); 317db96d56Sopenharmony_ciPyAPI_FUNC(int) PyArg_VaParseTupleAndKeywords(PyObject *, PyObject *, 327db96d56Sopenharmony_ci const char *, char **, va_list); 337db96d56Sopenharmony_ci#endif 347db96d56Sopenharmony_ciPyAPI_FUNC(int) PyArg_ValidateKeywordArguments(PyObject *); 357db96d56Sopenharmony_ciPyAPI_FUNC(int) PyArg_UnpackTuple(PyObject *, const char *, Py_ssize_t, Py_ssize_t, ...); 367db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) Py_BuildValue(const char *, ...); 377db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) _Py_BuildValue_SizeT(const char *, ...); 387db96d56Sopenharmony_ci 397db96d56Sopenharmony_ci 407db96d56Sopenharmony_ci#define ANY_VARARGS(n) (n == PY_SSIZE_T_MAX) 417db96d56Sopenharmony_ci 427db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) Py_VaBuildValue(const char *, va_list); 437db96d56Sopenharmony_ci 447db96d56Sopenharmony_ci// Add an attribute with name 'name' and value 'obj' to the module 'mod. 457db96d56Sopenharmony_ci// On success, return 0 on success. 467db96d56Sopenharmony_ci// On error, raise an exception and return -1. 477db96d56Sopenharmony_ciPyAPI_FUNC(int) PyModule_AddObjectRef(PyObject *mod, const char *name, PyObject *value); 487db96d56Sopenharmony_ci 497db96d56Sopenharmony_ci// Similar to PyModule_AddObjectRef() but steal a reference to 'obj' 507db96d56Sopenharmony_ci// (Py_DECREF(obj)) on success (if it returns 0). 517db96d56Sopenharmony_ciPyAPI_FUNC(int) PyModule_AddObject(PyObject *mod, const char *, PyObject *value); 527db96d56Sopenharmony_ci 537db96d56Sopenharmony_ciPyAPI_FUNC(int) PyModule_AddIntConstant(PyObject *, const char *, long); 547db96d56Sopenharmony_ciPyAPI_FUNC(int) PyModule_AddStringConstant(PyObject *, const char *, const char *); 557db96d56Sopenharmony_ci 567db96d56Sopenharmony_ci#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03090000 577db96d56Sopenharmony_ci/* New in 3.9 */ 587db96d56Sopenharmony_ciPyAPI_FUNC(int) PyModule_AddType(PyObject *module, PyTypeObject *type); 597db96d56Sopenharmony_ci#endif /* Py_LIMITED_API */ 607db96d56Sopenharmony_ci 617db96d56Sopenharmony_ci#define PyModule_AddIntMacro(m, c) PyModule_AddIntConstant(m, #c, c) 627db96d56Sopenharmony_ci#define PyModule_AddStringMacro(m, c) PyModule_AddStringConstant(m, #c, c) 637db96d56Sopenharmony_ci 647db96d56Sopenharmony_ci#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000 657db96d56Sopenharmony_ci/* New in 3.5 */ 667db96d56Sopenharmony_ciPyAPI_FUNC(int) PyModule_SetDocString(PyObject *, const char *); 677db96d56Sopenharmony_ciPyAPI_FUNC(int) PyModule_AddFunctions(PyObject *, PyMethodDef *); 687db96d56Sopenharmony_ciPyAPI_FUNC(int) PyModule_ExecDef(PyObject *module, PyModuleDef *def); 697db96d56Sopenharmony_ci#endif 707db96d56Sopenharmony_ci 717db96d56Sopenharmony_ci#define Py_CLEANUP_SUPPORTED 0x20000 727db96d56Sopenharmony_ci 737db96d56Sopenharmony_ci#define PYTHON_API_VERSION 1013 747db96d56Sopenharmony_ci#define PYTHON_API_STRING "1013" 757db96d56Sopenharmony_ci/* The API version is maintained (independently from the Python version) 767db96d56Sopenharmony_ci so we can detect mismatches between the interpreter and dynamically 777db96d56Sopenharmony_ci loaded modules. These are diagnosed by an error message but 787db96d56Sopenharmony_ci the module is still loaded (because the mismatch can only be tested 797db96d56Sopenharmony_ci after loading the module). The error message is intended to 807db96d56Sopenharmony_ci explain the core dump a few seconds later. 817db96d56Sopenharmony_ci 827db96d56Sopenharmony_ci The symbol PYTHON_API_STRING defines the same value as a string 837db96d56Sopenharmony_ci literal. *** PLEASE MAKE SURE THE DEFINITIONS MATCH. *** 847db96d56Sopenharmony_ci 857db96d56Sopenharmony_ci Please add a line or two to the top of this log for each API 867db96d56Sopenharmony_ci version change: 877db96d56Sopenharmony_ci 887db96d56Sopenharmony_ci 22-Feb-2006 MvL 1013 PEP 353 - long indices for sequence lengths 897db96d56Sopenharmony_ci 907db96d56Sopenharmony_ci 19-Aug-2002 GvR 1012 Changes to string object struct for 917db96d56Sopenharmony_ci interning changes, saving 3 bytes. 927db96d56Sopenharmony_ci 937db96d56Sopenharmony_ci 17-Jul-2001 GvR 1011 Descr-branch, just to be on the safe side 947db96d56Sopenharmony_ci 957db96d56Sopenharmony_ci 25-Jan-2001 FLD 1010 Parameters added to PyCode_New() and 967db96d56Sopenharmony_ci PyFrame_New(); Python 2.1a2 977db96d56Sopenharmony_ci 987db96d56Sopenharmony_ci 14-Mar-2000 GvR 1009 Unicode API added 997db96d56Sopenharmony_ci 1007db96d56Sopenharmony_ci 3-Jan-1999 GvR 1007 Decided to change back! (Don't reuse 1008!) 1017db96d56Sopenharmony_ci 1027db96d56Sopenharmony_ci 3-Dec-1998 GvR 1008 Python 1.5.2b1 1037db96d56Sopenharmony_ci 1047db96d56Sopenharmony_ci 18-Jan-1997 GvR 1007 string interning and other speedups 1057db96d56Sopenharmony_ci 1067db96d56Sopenharmony_ci 11-Oct-1996 GvR renamed Py_Ellipses to Py_Ellipsis :-( 1077db96d56Sopenharmony_ci 1087db96d56Sopenharmony_ci 30-Jul-1996 GvR Slice and ellipses syntax added 1097db96d56Sopenharmony_ci 1107db96d56Sopenharmony_ci 23-Jul-1996 GvR For 1.4 -- better safe than sorry this time :-) 1117db96d56Sopenharmony_ci 1127db96d56Sopenharmony_ci 7-Nov-1995 GvR Keyword arguments (should've been done at 1.3 :-( ) 1137db96d56Sopenharmony_ci 1147db96d56Sopenharmony_ci 10-Jan-1995 GvR Renamed globals to new naming scheme 1157db96d56Sopenharmony_ci 1167db96d56Sopenharmony_ci 9-Jan-1995 GvR Initial version (incompatible with older API) 1177db96d56Sopenharmony_ci*/ 1187db96d56Sopenharmony_ci 1197db96d56Sopenharmony_ci/* The PYTHON_ABI_VERSION is introduced in PEP 384. For the lifetime of 1207db96d56Sopenharmony_ci Python 3, it will stay at the value of 3; changes to the limited API 1217db96d56Sopenharmony_ci must be performed in a strictly backwards-compatible manner. */ 1227db96d56Sopenharmony_ci#define PYTHON_ABI_VERSION 3 1237db96d56Sopenharmony_ci#define PYTHON_ABI_STRING "3" 1247db96d56Sopenharmony_ci 1257db96d56Sopenharmony_ci#ifdef Py_TRACE_REFS 1267db96d56Sopenharmony_ci /* When we are tracing reference counts, rename module creation functions so 1277db96d56Sopenharmony_ci modules compiled with incompatible settings will generate a 1287db96d56Sopenharmony_ci link-time error. */ 1297db96d56Sopenharmony_ci #define PyModule_Create2 PyModule_Create2TraceRefs 1307db96d56Sopenharmony_ci #define PyModule_FromDefAndSpec2 PyModule_FromDefAndSpec2TraceRefs 1317db96d56Sopenharmony_ci#endif 1327db96d56Sopenharmony_ci 1337db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyModule_Create2(PyModuleDef*, int apiver); 1347db96d56Sopenharmony_ci 1357db96d56Sopenharmony_ci#ifdef Py_LIMITED_API 1367db96d56Sopenharmony_ci#define PyModule_Create(module) \ 1377db96d56Sopenharmony_ci PyModule_Create2(module, PYTHON_ABI_VERSION) 1387db96d56Sopenharmony_ci#else 1397db96d56Sopenharmony_ci#define PyModule_Create(module) \ 1407db96d56Sopenharmony_ci PyModule_Create2(module, PYTHON_API_VERSION) 1417db96d56Sopenharmony_ci#endif 1427db96d56Sopenharmony_ci 1437db96d56Sopenharmony_ci#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000 1447db96d56Sopenharmony_ci/* New in 3.5 */ 1457db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyModule_FromDefAndSpec2(PyModuleDef *def, 1467db96d56Sopenharmony_ci PyObject *spec, 1477db96d56Sopenharmony_ci int module_api_version); 1487db96d56Sopenharmony_ci 1497db96d56Sopenharmony_ci#ifdef Py_LIMITED_API 1507db96d56Sopenharmony_ci#define PyModule_FromDefAndSpec(module, spec) \ 1517db96d56Sopenharmony_ci PyModule_FromDefAndSpec2(module, spec, PYTHON_ABI_VERSION) 1527db96d56Sopenharmony_ci#else 1537db96d56Sopenharmony_ci#define PyModule_FromDefAndSpec(module, spec) \ 1547db96d56Sopenharmony_ci PyModule_FromDefAndSpec2(module, spec, PYTHON_API_VERSION) 1557db96d56Sopenharmony_ci#endif /* Py_LIMITED_API */ 1567db96d56Sopenharmony_ci 1577db96d56Sopenharmony_ci#endif /* New in 3.5 */ 1587db96d56Sopenharmony_ci 1597db96d56Sopenharmony_ci#ifndef Py_LIMITED_API 1607db96d56Sopenharmony_ci# define Py_CPYTHON_MODSUPPORT_H 1617db96d56Sopenharmony_ci# include "cpython/modsupport.h" 1627db96d56Sopenharmony_ci# undef Py_CPYTHON_MODSUPPORT_H 1637db96d56Sopenharmony_ci#endif 1647db96d56Sopenharmony_ci 1657db96d56Sopenharmony_ci#ifdef __cplusplus 1667db96d56Sopenharmony_ci} 1677db96d56Sopenharmony_ci#endif 1687db96d56Sopenharmony_ci#endif /* !Py_MODSUPPORT_H */ 169