mirror of
				https://github.com/pocketpy/pocketpy
				synced 2025-10-31 08:50:17 +00:00 
			
		
		
		
	* lazy cpp_function and capsule. * remove retv. * remove type_map. * remove object pool from initialize. * support dynamic library. * remove vector_bool. * remove unused header. * fix export name. * fix test name. * some fix * some fix * ... --------- Co-authored-by: blueloveTH <blueloveth@foxmail.com>
		
			
				
	
	
		
			44 lines
		
	
	
		
			982 B
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			44 lines
		
	
	
		
			982 B
		
	
	
	
		
			C++
		
	
	
	
	
	
| #pragma once
 | |
| 
 | |
| #include "internal/class.h"
 | |
| 
 | |
| namespace pkbind {
 | |
| 
 | |
| namespace literals {
 | |
| inline arg operator""_a (const char* c, size_t) { return arg(c); }
 | |
| }  // namespace literals
 | |
| 
 | |
| inline bool initialized = false;
 | |
| 
 | |
| /// initialize the vm.
 | |
| inline void initialize(int object_pool_size = 1024) {
 | |
|     if(!initialized) { py_initialize(); }
 | |
|     action::initialize();
 | |
|     initialized = true;
 | |
| }
 | |
| 
 | |
| /// finalize the vm.
 | |
| inline void finalize(bool test = false) {
 | |
|     if(!initialized) { return; }
 | |
|     object_pool::finalize();
 | |
|     type::m_type_map.clear();
 | |
|     capsule::tp_capsule.reset();
 | |
|     cpp_function::tp_function_record.reset();
 | |
|     if(test) {
 | |
|         py_resetvm();
 | |
|     } else {
 | |
|         py_finalize();
 | |
|     }
 | |
| }
 | |
| 
 | |
| /// a RAII class to initialize and finalize python interpreter
 | |
| class scoped_interpreter {
 | |
| public:
 | |
|     scoped_interpreter(int object_pool_size = 1024) { initialize(object_pool_size); }
 | |
| 
 | |
|     ~scoped_interpreter() { finalize(); }
 | |
| };
 | |
| 
 | |
| }  // namespace pkbind
 | |
| 
 | |
| namespace pybind11 = pkbind; |