pybind11.h 982 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #pragma once
  2. #include "internal/class.h"
  3. namespace pkbind {
  4. namespace literals {
  5. inline arg operator""_a (const char* c, size_t) { return arg(c); }
  6. } // namespace literals
  7. inline bool initialized = false;
  8. /// initialize the vm.
  9. inline void initialize(int object_pool_size = 1024) {
  10. if(!initialized) { py_initialize(); }
  11. action::initialize();
  12. initialized = true;
  13. }
  14. /// finalize the vm.
  15. inline void finalize(bool test = false) {
  16. if(!initialized) { return; }
  17. object_pool::finalize();
  18. type::m_type_map.clear();
  19. capsule::tp_capsule.reset();
  20. cpp_function::tp_function_record.reset();
  21. if(test) {
  22. py_resetvm();
  23. } else {
  24. py_finalize();
  25. }
  26. }
  27. /// a RAII class to initialize and finalize python interpreter
  28. class scoped_interpreter {
  29. public:
  30. scoped_interpreter(int object_pool_size = 1024) { initialize(object_pool_size); }
  31. ~scoped_interpreter() { finalize(); }
  32. };
  33. } // namespace pkbind
  34. namespace pybind11 = pkbind;