Author: Armin Rigo <[email protected]>
Branch:
Changeset: r2827:adbbfbe13351
Date: 2016-12-07 18:16 +0100
http://bitbucket.org/cffi/cffi/changeset/adbbfbe13351/
Log: Windows fixes in the example
diff --git a/doc/source/embedding.rst b/doc/source/embedding.rst
--- a/doc/source/embedding.rst
+++ b/doc/source/embedding.rst
@@ -47,6 +47,20 @@
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 @@
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"
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit