all repos — mgba @ fe2854db79827a6afecad8399fa789210bfcaf74

mGBA Game Boy Advance Emulator

Python: Reduce boilerplate in builder
Vicki Pfau vi@endrift.com
Wed, 31 May 2017 17:47:38 -0700
commit

fe2854db79827a6afecad8399fa789210bfcaf74

parent

7b66a702cfe96f34ef2842b1c9c6f6826738be5e

M src/platform/python/_builder.hsrc/platform/python/_builder.h

@@ -29,8 +29,11 @@ #include "flags.h"

#include <mgba/core/core.h> #include <mgba/core/tile-cache.h> + +#define PYEXPORT extern "Python+C" #include "platform/python/vfs-py.h" #include "platform/python/log.h" +#undef PYEXPORT #ifdef USE_PNG #include <mgba-util/png-io.h>
M src/platform/python/_builder.pysrc/platform/python/_builder.py

@@ -32,19 +32,10 @@ #include <mgba/internal/gb/renderers/tile-cache.h>

#include <mgba-util/png-io.h> #include <mgba-util/vfs.h> -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"],
M src/platform/python/log.hsrc/platform/python/log.h

@@ -12,4 +12,4 @@ };

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);
M src/platform/python/vfs-py.hsrc/platform/python/vfs-py.h

@@ -13,16 +13,12 @@ };

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);