You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

python_compatibility.h 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * python_compatibility.h -- macros for Python 2/3 compatibility
  3. *
  4. * This file is Copyright (c) 2016 by the GPSD project
  5. * SPDX-License-Identifier: BSD-2-clause
  6. *
  7. * Definitions based on examples in "Supporting Python 3 - The Book Site"
  8. * http://python3porting.com/cextensions.html
  9. */
  10. #ifndef _PYTHON_COMPATIBILITY_H_
  11. #define _PYTHON_COMPATIBILITY_H_
  12. #include <Python.h>
  13. #if PY_MAJOR_VERSION >= 3
  14. #define GPSD_PY_MODULE_INIT(name) PyMODINIT_FUNC PyInit_##name(void)
  15. #define GPSD_PY_MODULE_DEF(mod, name, doc, methods) \
  16. static struct PyModuleDef moduledef = { \
  17. PyModuleDef_HEAD_INIT, name, doc, -1, methods, }; \
  18. mod = PyModule_Create(&moduledef);
  19. #define GPSD_PY_MODULE_ERROR_VAL NULL
  20. #define GPSD_PY_MODULE_SUCCESS_VAL(val) val
  21. #define GPSD_PY_BYTE_FORMAT "y#"
  22. #else /* !Python 3 */
  23. #define GPSD_PY_MODULE_INIT(name) PyMODINIT_FUNC init##name(void)
  24. #define GPSD_PY_MODULE_DEF(mod, name, doc, methods) \
  25. mod = Py_InitModule3(name, methods, doc);
  26. #define GPSD_PY_MODULE_ERROR_VAL
  27. #define GPSD_PY_MODULE_SUCCESS_VAL(val)
  28. #define GPSD_PY_BYTE_FORMAT "s#"
  29. #endif /* !Python 3 */
  30. #endif /* _PYTHON_COMPATIBILITY_H_ */