From fe2854db79827a6afecad8399fa789210bfcaf74 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Wed, 31 May 2017 17:47:38 -0700 Subject: [PATCH] Python: Reduce boilerplate in builder --- src/platform/python/_builder.h | 3 +++ src/platform/python/_builder.py | 17 ++++------------- src/platform/python/log.h | 2 +- src/platform/python/vfs-py.h | 22 +++++++++------------- 4 files changed, 17 insertions(+), 27 deletions(-) diff --git a/src/platform/python/_builder.h b/src/platform/python/_builder.h index 58a214d93..c2ef3fe78 100644 --- a/src/platform/python/_builder.h +++ b/src/platform/python/_builder.h @@ -29,8 +29,11 @@ void free(void*); #include #include + +#define PYEXPORT extern "Python+C" #include "platform/python/vfs-py.h" #include "platform/python/log.h" +#undef PYEXPORT #ifdef USE_PNG #include diff --git a/src/platform/python/_builder.py b/src/platform/python/_builder.py index 94babdb55..3603e991e 100644 --- a/src/platform/python/_builder.py +++ b/src/platform/python/_builder.py @@ -32,19 +32,10 @@ ffi.set_source("mgba._pylib", """ #include #include -struct VFile* VFileFromPython(void* fileobj); - -struct VFilePy { - struct VFile d; - void* fileobj; -}; - -struct mLogger* mLoggerPythonCreate(void* pyobj); - -struct mLoggerPy { - struct mLogger d; - void* pyobj; -}; +#define PYEXPORT +#include "platform/python/log.h" +#include "platform/python/vfs-py.h" +#undef PYEXPORT """, include_dirs=[incdir, srcdir], extra_compile_args=cppflags, libraries=["mgba"], diff --git a/src/platform/python/log.h b/src/platform/python/log.h index f29dba8bb..26ec70253 100644 --- a/src/platform/python/log.h +++ b/src/platform/python/log.h @@ -12,4 +12,4 @@ struct mLoggerPy { struct mLogger* mLoggerPythonCreate(void* pyobj); -extern "Python+C" void _pyLog(void* logger, int category, enum mLogLevel level, const char* message); +PYEXPORT void _pyLog(void* logger, int category, enum mLogLevel level, const char* message); diff --git a/src/platform/python/vfs-py.h b/src/platform/python/vfs-py.h index 2842d4812..6cc56dc4c 100644 --- a/src/platform/python/vfs-py.h +++ b/src/platform/python/vfs-py.h @@ -13,16 +13,12 @@ struct VFilePy { struct VFile* VFileFromPython(void* fileobj); -extern "Python+C" { - -bool _vfpClose(struct VFile* vf); -off_t _vfpSeek(struct VFile* vf, off_t offset, int whence); -ssize_t _vfpRead(struct VFile* vf, void* buffer, size_t size); -ssize_t _vfpWrite(struct VFile* vf, const void* buffer, size_t size); -void* _vfpMap(struct VFile* vf, size_t size, int flags); -void _vfpUnmap(struct VFile* vf, void* memory, size_t size); -void _vfpTruncate(struct VFile* vf, size_t size); -ssize_t _vfpSize(struct VFile* vf); -bool _vfpSync(struct VFile* vf, const void* buffer, size_t size); - -} +PYEXPORT bool _vfpClose(struct VFile* vf); +PYEXPORT off_t _vfpSeek(struct VFile* vf, off_t offset, int whence); +PYEXPORT ssize_t _vfpRead(struct VFile* vf, void* buffer, size_t size); +PYEXPORT ssize_t _vfpWrite(struct VFile* vf, const void* buffer, size_t size); +PYEXPORT void* _vfpMap(struct VFile* vf, size_t size, int flags); +PYEXPORT void _vfpUnmap(struct VFile* vf, void* memory, size_t size); +PYEXPORT void _vfpTruncate(struct VFile* vf, size_t size); +PYEXPORT ssize_t _vfpSize(struct VFile* vf); +PYEXPORT bool _vfpSync(struct VFile* vf, const void* buffer, size_t size);