summaryrefslogtreecommitdiff
path: root/docs/src
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2022-02-24 18:43:05 +0100
committerStefan Behnel <stefan_ml@behnel.de>2022-02-24 18:43:05 +0100
commit10621a0525ba58a87a31d9a2045732806eaf9fa0 (patch)
tree9b764ed13d18801e9032fbdbeb756f6fc0d98837 /docs/src
parentbc43abf7bd2618543770d37597a527541795eb6b (diff)
downloadcython-10621a0525ba58a87a31d9a2045732806eaf9fa0.tar.gz
docs: Add an example on how to use verbatim C code to work around version specific struct fields.
See https://github.com/cython/cython/issues/4310
Diffstat (limited to 'docs/src')
-rw-r--r--docs/src/userguide/external_C_code.rst5
1 files changed, 5 insertions, 0 deletions
diff --git a/docs/src/userguide/external_C_code.rst b/docs/src/userguide/external_C_code.rst
index 75ad3fb2f..86bdf8313 100644
--- a/docs/src/userguide/external_C_code.rst
+++ b/docs/src/userguide/external_C_code.rst
@@ -400,6 +400,11 @@ It is also possible to combine a header file and verbatim C code::
In this case, the C code ``#undef int`` is put right after
``#include "badheader.h"`` in the C code generated by Cython.
+Verbatim C code can also be used for version specific adaptations, e.g. when
+a struct field was added to a library but is not available in older versions:
+
+.. literalinclude:: ../../examples/userguide/external_C_code/struct_field_adaptation.pyx
+
Note that the string is parsed like any other docstring in Python.
If you require character escapes to be passed into the C code file,
use a raw docstring, i.e. ``r""" ... """``.