From 7a369100f38b6f342bbfe4300288fea92e214e35 Mon Sep 17 00:00:00 2001 From: scawful Date: Thu, 8 Aug 2024 22:55:17 -0400 Subject: [PATCH] remove CPython extension loading, todo for boost.python --- src/ext/CMakeLists.txt | 5 +++-- src/ext/extension.cc | 36 +----------------------------------- 2 files changed, 4 insertions(+), 37 deletions(-) diff --git a/src/ext/CMakeLists.txt b/src/ext/CMakeLists.txt index 109f0db3..7ea54090 100644 --- a/src/ext/CMakeLists.txt +++ b/src/ext/CMakeLists.txt @@ -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 diff --git a/src/ext/extension.cc b/src/ext/extension.cc index a66831e0..bc59b18c 100644 --- a/src/ext/extension.cc +++ b/src/ext/extension.cc @@ -1,6 +1,5 @@ #include "extension.h" -#include #include #include @@ -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(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() {