diff options
author | m32 <grzegorz.makarewicz@gmail.com> | 2021-07-21 14:47:44 +0300 |
---|---|---|
committer | m32 <grzegorz.makarewicz@gmail.com> | 2021-07-21 14:47:44 +0300 |
commit | 4a264c695d7e2ed4f8591cc797e2eb344903c551 (patch) | |
tree | d0d977ba15b01bf66fd54644531cbf2ca2d0819b /python | |
parent | 6f99097eb8b8983e3aa136676dc03068d60d940b (diff) |
automatically generated cffi module, which is able to catch errors of structures from plugin.hpp during compilation
Diffstat (limited to 'python')
-rw-r--r-- | python/CMakeLists.txt | 9 | ||||
-rw-r--r-- | python/configs/plug/far2l/plugin.hpp | 23 | ||||
-rw-r--r-- | python/src/python.cpp | 10 | ||||
-rwxr-xr-x | python/src/pythongen.py | 52 |
4 files changed, 79 insertions, 15 deletions
diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 6b2ba830..4a353dd9 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -2,7 +2,8 @@ project(python) set(SOURCES -src/python.cpp +src/python.cpp +_pyfar.cpp ) find_package(PythonLibs 3.0) @@ -11,7 +12,7 @@ add_library (python MODULE ${SOURCES}) target_link_libraries(python utils far2l ${PYTHON_LIBRARIES}) -target_compile_definitions(python PRIVATE -DWINPORT_DIRECT -DUNICODE -DFAR_DONT_USE_INTERNALS -DPYTHON_LIBRARY="${PYTHON_LIBRARY}") +target_compile_definitions(python PRIVATE -DWINPORT_DIRECT -DUNICODE -DFAR_USE_INTERNALS -DPROCPLUGINMACROFUNC -DPYTHON_LIBRARY="${PYTHON_LIBRARY}") target_include_directories(python PRIVATE .) target_include_directories(python PRIVATE ../far2l) @@ -36,3 +37,7 @@ add_custom_command(TARGET python PRE_BUILD COMMAND ${PYTHON3} -m venv --system-site-packages ${CMAKE_CURRENT_SOURCE_DIR}/configs/plug/python COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/configs/plug/python/bin/python -m pip install cffi debugpy ) + +add_custom_command(OUTPUT _pyfar.cpp + COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/configs/plug/python/bin/python ${CMAKE_CURRENT_SOURCE_DIR}/src/pythongen.py ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} +) diff --git a/python/configs/plug/far2l/plugin.hpp b/python/configs/plug/far2l/plugin.hpp index b291f976..fb417527 100644 --- a/python/configs/plug/far2l/plugin.hpp +++ b/python/configs/plug/far2l/plugin.hpp @@ -10,8 +10,6 @@ typedef struct _INPUT_RECORD INPUT_RECORD; typedef struct _CHAR_INFO CHAR_INFO; -#define CP_UNICODE 1200 -#define CP_REVERSEBOM 1201 #define CP_AUTODETECT -1 enum FARMESSAGEFLAGS @@ -659,9 +657,9 @@ struct CmdLineSelect int SelEnd; }; -#define PANEL_NONE -1 -#define PANEL_ACTIVE -1 -#define PANEL_PASSIVE -2 +//#define PANEL_NONE -1 +//#define PANEL_ACTIVE -1 +//#define PANEL_PASSIVE -2 enum FILE_CONTROL_COMMANDS { @@ -1021,7 +1019,6 @@ enum FARKEYSEQUENCEFLAGS { KSFLAGS_DISABLEOUTPUT = 0x00000001, KSFLAGS_NOSENDKEYSTOPLUGINS = 0x00000002, - KSFLAGS_REG_MULTI_SZ = 0x00100000, KSFLAGS_SILENTCHECK = 0x00000001, }; @@ -1276,7 +1273,8 @@ struct ViewerMode int Wrap; int WordWrap; int Hex; - DWORD Reserved[4]; + int Processed; + DWORD Reserved[3]; }; struct ViewerInfo @@ -1332,9 +1330,9 @@ enum SYNCHRO_EVENTS SE_COMMONSYNCHRO =0, }; -#define EEREDRAW_ALL 0 -#define EEREDRAW_CHANGE 1 -#define EEREDRAW_LINE 2 +//#define EEREDRAW_ALL 0 +//#define EEREDRAW_CHANGE 1 +//#define EEREDRAW_LINE 2 enum EDITOR_CONTROL_COMMANDS { @@ -1739,7 +1737,8 @@ typedef struct FarStandardFunctions FARSTDSNPRINTF snprintf; // </C&C++> - DWORD_PTR Reserved[8]; + DWORD_PTR Reserved[7]; + const WCHAR * BoxSymbols; // indexed via BOX_DEF_SYMBOLS FARSTDLOCALISLOWER LIsLower; FARSTDLOCALISUPPER LIsUpper; @@ -1779,7 +1778,7 @@ typedef struct FarStandardFunctions FARSTDMKLINK MkLink; FARCONVERTPATH ConvertPath; FARGETREPARSEPOINTINFO GetReparsePointInfo; - FARGETCURRENTDIRECTORY GetCurrentDirectory; +// FARGETCURRENTDIRECTORY GetCurrentDirectory; } FARSTANDARDFUNCTIONS; struct PluginStartupInfo diff --git a/python/src/python.cpp b/python/src/python.cpp index aad445bf..cb415edb 100644 --- a/python/src/python.cpp +++ b/python/src/python.cpp @@ -3,11 +3,17 @@ #include <string> #include <dlfcn.h> +#include <Python.h> + +#include "plugin.hpp" +#include "farcolor.hpp" +#include "farkeys.hpp" #include "../../etc/plugs.h" #include "python.hpp" -#include <Python.h> +PyMODINIT_FUNC PyInit__pyfar(void); + std::wstring gPluginPath; PyObject *pyPluginModule = NULL; @@ -142,6 +148,8 @@ XPORT(void, SetStartupInfo)(const struct PluginStartupInfo *Info) Py_Initialize(); PyEval_InitThreads(); + PyInit__pyfar(); + std::string pp( gPluginPath.begin(), gPluginPath.end() );; std::string syspath = "import sys"; syspath += "\nsys.path.insert(1, '" + pp + "')"; diff --git a/python/src/pythongen.py b/python/src/pythongen.py new file mode 100755 index 00000000..0382483e --- /dev/null +++ b/python/src/pythongen.py @@ -0,0 +1,52 @@ +#!/usr/bin/env vpython3 +import sys +import os +import cffi + +source = sys.argv[1] +target = os.path.join(sys.argv[2], "_pyfar.cpp") + +far2l = os.path.join(source, '..') +far2lp = os.path.join(source, 'configs', 'plug', 'far2l') +ffi = cffi.FFI() + +xpre = """ +//#define FAR_DONT_USE_INTERNALS +#define FAR_USE_INTERNALS +#define PROCPLUGINMACROFUNC 1 + +#define UNICODE +#define WINPORT_DIRECT +#define WINPORT_REGISTRY +//#define WXUSINGDLL +#define _FILE_OFFSET_BITS 64 +//#define __WXGTK__ + +""" + +ffi.set_source("_pyfar", # name of the output C extension + #xpre + +""" +#include "../../etc/plugs.h" +#include "plugin.hpp" +#include "farcolor.hpp" +#include "farkeys.hpp" +""", + include_dirs=[ + os.path.join(far2l), + os.path.join(far2l, 'far2l', 'Include'), + os.path.join(far2l, 'WinPort'), + ], +) +for fname in ("farwin.h", "farcolor.hpp", "farkeys.hpp", "plugin.hpp"): + fqname = os.path.join(far2lp, fname) + data = open(fqname, "rt", encoding="utf-8").read() + ffi.cdef(data, packed=True) + +if 0: + ffi.compile( + verbose=True, + call_c_compiler=False + ) +else: + ffi.emit_c_code(target) |