registration.h 959 B

12345678910111213141516171819202122232425262728
  1. #pragma once
  2. #ifdef _DEBUG
  3. #undef _DEBUG
  4. #include <Python.h>
  5. #define _DEBUG
  6. #else
  7. #include <Python.h>
  8. #endif
  9. #define _CONCAT(A, B) A##B
  10. #define CONCAT(A, B) _CONCAT(A, B)
  11. #define _STRINGIFY(A) #A
  12. #define STRINGIFY(A) _STRINGIFY(A)
  13. // A version of the TORCH_LIBRARY macro that expands the NAME, i.e. so NAME
  14. // could be a macro instead of a literal token.
  15. #define TORCH_LIBRARY_EXPAND(NAME, MODULE) TORCH_LIBRARY(NAME, MODULE)
  16. // REGISTER_EXTENSION allows the shared library to be loaded and initialized
  17. // via python's import statement.
  18. #define REGISTER_EXTENSION(NAME) \
  19. PyMODINIT_FUNC CONCAT(PyInit_, NAME)() { \
  20. static struct PyModuleDef module = {PyModuleDef_HEAD_INIT, \
  21. STRINGIFY(NAME), nullptr, 0, nullptr}; \
  22. return PyModule_Create(&module); \
  23. }