diff options
| author | Armin Rigo <arigo@tunes.org> | 2016-12-07 18:16:37 +0100 |
|---|---|---|
| committer | Armin Rigo <arigo@tunes.org> | 2016-12-07 18:16:37 +0100 |
| commit | 9eb3ea70ac59e3823f7ab628a4796512e2e66f47 (patch) | |
| tree | f8e74b6c95df8e60b0bb36b45c16ad73ff7d4d3f /doc/source/embedding.rst | |
| parent | b203432d6b3907fc080a7eabae6d93f3e08d4d9f (diff) | |
| download | cffi-9eb3ea70ac59e3823f7ab628a4796512e2e66f47.tar.gz | |
Windows fixes in the example
Diffstat (limited to 'doc/source/embedding.rst')
| -rw-r--r-- | doc/source/embedding.rst | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/doc/source/embedding.rst b/doc/source/embedding.rst index c6ec289..1eab5e3 100644 --- a/doc/source/embedding.rst +++ b/doc/source/embedding.rst @@ -47,6 +47,20 @@ here this slightly expanded example: typedef struct { int x, y; } point_t; extern int do_stuff(point_t *); +.. code-block:: c + + /* file plugin.h, Windows-friendly version */ + typedef struct { int x, y; } point_t; + + /* When including this file from ffibuilder.set_source(), + this macro is defined to __declspec(dllexport). When + including this file directly from your C program, we + define it to __declspec(dllimport) instead. */ + #ifndef CFFI_DLLEXPORT + # define CFFI_DLLEXPORT __declspec(dllimport) + #endif + CFFI_DLLEXPORT int do_stuff(point_t *); + .. code-block:: python # file plugin_build.py @@ -54,7 +68,11 @@ here this slightly expanded example: ffibuilder = cffi.FFI() with open('plugin.h') as f: - ffibuilder.embedding_api(f.read()) + # read plugin.h and pass it to embedding_api(), manually + # removing the '#' directives and the CFFI_DLLEXPORT + data = ''.join([line for line in f if not line.startswith('#')]) + data = data.replace('CFFI_DLLEXPORT', '') + ffibuilder.embedding_api(data) ffibuilder.set_source("my_plugin", r''' #include "plugin.h" |
