remove CPython extension loading, todo for boost.python

This commit is contained in:
scawful
2024-08-08 22:55:17 -04:00
parent dece918957
commit 7a369100f3
2 changed files with 4 additions and 37 deletions

View File

@@ -8,12 +8,13 @@ target_include_directories(
lib/
app/
${CMAKE_SOURCE_DIR}/src/
/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/Headers
${Boost_INCLUDE_DIRS}
)
target_link_libraries(
yaze_ext PUBLIC
Python
${PYTHON_LIBRARIES}
Boost::python3
)
# C Sample

View File

@@ -1,6 +1,5 @@
#include "extension.h"
#include <Python.h>
#include <dlfcn.h>
#include <iostream>
@@ -41,40 +40,7 @@ void yaze_load_c_extension(const char* extension_path) {
}
void yaze_load_py_extension(const char* script_path) {
Py_Initialize();
FILE* fp = fopen(script_path, "r");
if (fp) {
PyRun_SimpleFile(fp, script_path);
fclose(fp);
} else {
std::cerr << "Cannot open Python script: " << script_path << std::endl;
return;
}
PyObject* pModule = PyImport_AddModule("__main__");
PyObject* pFunc = PyObject_GetAttrString(pModule, "get_yaze_extension");
if (pFunc && PyCallable_Check(pFunc)) {
PyObject* pExtension = PyObject_CallObject(pFunc, nullptr);
if (pExtension) {
extension =
reinterpret_cast<yaze_extension*>(PyLong_AsVoidPtr(pExtension));
if (extension && extension->initialize) {
extension->initialize();
}
} else {
std::cerr << "Failed to get extension from Python script." << std::endl;
}
Py_XDECREF(pExtension);
} else {
std::cerr
<< "Python function 'get_yaze_extension' not found or not callable."
<< std::endl;
}
Py_XDECREF(pFunc);
Py_Finalize();
// TODO: Use Boost.Python to load Python extensions
}
void yaze_cleanup_extension() {