mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-19 19:10: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>
40 lines
1016 B
C
40 lines
1016 B
C
#include "pocketpy/pocketpy.h"
|
|
|
|
#if PK_IS_DESKTOP_PLATFORM
|
|
|
|
#ifdef _WIN32
|
|
void* LoadLibraryA(const char*);
|
|
void* GetProcAddress(void*, const char*);
|
|
#else
|
|
#include <dlfcn.h>
|
|
#endif
|
|
|
|
typedef bool (*py_module_initialize_t)() PY_RAISE PY_RETURN;
|
|
|
|
int load_module_from_dll_desktop_only(const char* path) PY_RAISE PY_RETURN {
|
|
const char* f_init_name = "py_module_initialize";
|
|
#ifdef _WIN32
|
|
void* dll = LoadLibraryA(path);
|
|
if(dll == NULL) return 0;
|
|
py_module_initialize_t f_init = (py_module_initialize_t)GetProcAddress(dll, f_init_name);
|
|
#else
|
|
void* dll = dlopen(path, RTLD_LAZY);
|
|
if(dll == NULL) return 0;
|
|
py_module_initialize_t f_init = (py_module_initialize_t)dlsym(dll, f_init_name);
|
|
#endif
|
|
if(f_init == NULL) {
|
|
RuntimeError("%s() not found in '%s'", f_init_name, path);
|
|
return -1;
|
|
}
|
|
bool success = f_init();
|
|
if(!success) return -1;
|
|
return 1;
|
|
}
|
|
|
|
#else
|
|
|
|
int load_module_from_dll_desktop_only(const char* path) PY_RAISE PY_RETURN {
|
|
return 0;
|
|
}
|
|
|
|
#endif |