Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r2809:2234672774e3
Date: 2016-11-11 07:36 +0100
http://bitbucket.org/cffi/cffi/changeset/2234672774e3/

Log:    Update the docs to the style r"""...C source..."""

diff --git a/doc/source/cdef.rst b/doc/source/cdef.rst
--- a/doc/source/cdef.rst
+++ b/doc/source/cdef.rst
@@ -58,7 +58,7 @@
     import cffi
 
     ffibuilder = cffi.FFI()
-    ffibuilder.set_source("package._foo", "real C code")   # <=
+    ffibuilder.set_source("package._foo", r"""real C code""")   # <=
     ffibuilder.cdef("C-like declarations with '...'")
 
     if __name__ == "__main__":
@@ -345,7 +345,9 @@
 module to generate.  In this mode, no C compiler is called.
 
 In **API mode,** the ``c_header_source`` argument is a string that
-will be pasted into the .c file generated.  This piece of C code
+will be pasted into the .c file generated.  Typically, it is specified as
+``r""" ...multiple lines of C code... """`` (the ``r`` prefix allows these
+lines to contain a literal ``\n``, for example).  This piece of C code
 typically contains some ``#include``, but may also contain more,
 like definitions for custom "wrapper" C functions.  The goal is that
 the .c file can be generated like this::
@@ -387,7 +389,7 @@
 
 .. code-block:: python
 
-    ffibuilder.set_source("mymodule", '''
+    ffibuilder.set_source("mymodule", r'''
     extern "C" {
         int somefunc(int somearg) { return real_cpp_func(somearg); }
     }
@@ -851,7 +853,7 @@
     import cffi
 
     ffi = cffi.FFI()
-    C_HEADER_SRC = '''
+    C_HEADER_SRC = r'''
         #include "somelib.h"
     '''
     C_KEYWORDS = dict(libraries=['somelib'])
diff --git a/doc/source/embedding.rst b/doc/source/embedding.rst
--- a/doc/source/embedding.rst
+++ b/doc/source/embedding.rst
@@ -56,7 +56,7 @@
     with open('plugin.h') as f:
         ffibuilder.embedding_api(f.read())
 
-    ffibuilder.set_source("my_plugin", '''
+    ffibuilder.set_source("my_plugin", r'''
         #include "plugin.h"
     ''')
 
@@ -211,7 +211,9 @@
   As in the example above, you can also use the same ``foo.h`` from
   ``ffibuilder.set_source()``::
 
-      ffibuilder.set_source('module_name', '#include "foo.h"')
+      ffibuilder.set_source('module_name', r'''
+          #include "foo.h"
+      ''')
 
 
 .. __: using.html#working
@@ -404,7 +406,7 @@
         extern "Python" int mycb(int);
     """)
 
-    ffibuilder.set_source("my_plugin", """
+    ffibuilder.set_source("my_plugin", r"""
 
         static int mycb(int);   /* the callback: forward declaration, to make
                                    it accessible from the C code that follows 
*/
diff --git a/doc/source/overview.rst b/doc/source/overview.rst
--- a/doc/source/overview.rst
+++ b/doc/source/overview.rst
@@ -72,7 +72,7 @@
     ffibuilder = FFI()
 
     ffibuilder.set_source("_example",
-        """ // passed to the real C compiler
+       r""" // passed to the real C compiler
             #include <sys/types.h>
             #include <pwd.h>
         """,
@@ -195,7 +195,7 @@
     ffibuilder.cdef("int foo(int *, int *, int);")
 
     ffibuilder.set_source("_example",
-    """
+    r"""
         static int foo(int *buffer_in, int *buffer_out, int x)
         {
             /* some algorithm that is seriously faster in C than in Python */
diff --git a/doc/source/using.rst b/doc/source/using.rst
--- a/doc/source/using.rst
+++ b/doc/source/using.rst
@@ -479,7 +479,7 @@
 
         void library_function(int(*callback)(int, int));
     """)
-    ffibuilder.set_source("_my_example", """
+    ffibuilder.set_source("_my_example", r"""
         #include <some_library.h>
     """)
 
@@ -546,7 +546,7 @@
 
         extern "Python" void my_event_callback(event_t *, void *);
     """)
-    ffibuilder.set_source("_demo_cffi", """
+    ffibuilder.set_source("_demo_cffi", r"""
         #include <the_event_library.h>
     """)
 
@@ -613,7 +613,7 @@
 
 ::
 
-    ffibuilder.set_source("_demo_cffi", """
+    ffibuilder.set_source("_demo_cffi", r"""
         #include <the_event_library.h>
 
         static void my_event_callback(widget_t *, event_t *);
@@ -629,7 +629,7 @@
         extern "Python" int f(int);
         int my_algo(int);
     """)
-    ffibuilder.set_source("_example_cffi", """
+    ffibuilder.set_source("_example_cffi", r"""
         static int f(int);   /* the forward declaration */
 
         static int my_algo(int n) {
@@ -673,7 +673,7 @@
     ffibuilder.cdef("""
         extern "Python+C" int f(int);      /* not static */
     """)
-    ffibuilder.set_source("_example_cffi", """
+    ffibuilder.set_source("_example_cffi", r"""
         /* the forward declaration, setting a gcc attribute
            (this line could also be in some .h file, to be included
            both here and in the other C files of the project) */
@@ -834,7 +834,7 @@
         int (*python_callback)(int how_many, int *values);
         void *const c_callback;   /* pass this const ptr to C routines */
     """)
-    ffibuilder.set_source("_example", """
+    ffibuilder.set_source("_example", r"""
         #include <stdarg.h>
         #include <alloca.h>
         static int (*python_callback)(int how_many, int *values);
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to