[pypy-commit] cffi default: Tweaks

arigo noreply at buildbot.pypy.org
Mon Jul 23 09:40:12 CEST 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r677:93ce0020f4de
Date: 2012-07-23 09:39 +0200
http://bitbucket.org/cffi/cffi/changeset/93ce0020f4de/

Log:	Tweaks

diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -816,20 +816,23 @@
             expected = "cdata pointer";
             goto cannot_convert;
         }
-        expected = "compatible pointer";
         ctinit = ((CDataObject *)init)->c_type;
         if (!(ctinit->ct_flags & (CT_POINTER|CT_FUNCTIONPTR))) {
             if (ctinit->ct_flags & CT_ARRAY)
                 ctinit = (CTypeDescrObject *)ctinit->ct_stuff;
-            else
+            else {
+                expected = "pointer or array";
                 goto cannot_convert;
+            }
         }
         if (ctinit != ct) {
             if ((ct->ct_flags & CT_CAST_ANYTHING) ||
                 (ctinit->ct_flags & CT_CAST_ANYTHING))
                 ;   /* accept void* or char* as either source or target */
-            else
+            else {
+                expected = "pointer to same type";
                 goto cannot_convert;
+            }
         }
         ptrdata = ((CDataObject *)init)->c_data;
 
diff --git a/doc/source/index.rst b/doc/source/index.rst
--- a/doc/source/index.rst
+++ b/doc/source/index.rst
@@ -632,7 +632,8 @@
       int main_like(int argv, char *argv[]);
    """)
 
-Now, everything is simple, except, how do we create ``char**`` argument here?
+Now, everything is simple, except, how do we create the ``char**`` argument
+here?
 The first idea:
 
 .. code-block:: python
@@ -640,22 +641,25 @@
    argv = ffi.new("char *[]", ["arg0", "arg1"])
 
 Does not work, because the initializer receives python ``str`` instead of
-``char*``. Now, the following would work:
+``char*``. Now, the following would almost work:
 
 .. code-block:: python
 
-   argv = ffi.new("char *[]", [ffi.new("char[]", "xyz")])
+   argv = ffi.new("char *[]", [ffi.new("char[]", "arg0"),
+                               ffi.new("char[]", "arg1")])
 
-However, the "xyz" string will not be automatically kept alive. Instead
-we need to make sure that the list is stored somewhere for long enough.
+However, the two ``char[]`` objects will not be automatically kept alive.
+To keep them alive, one solution is to make sure that the list is stored
+somewhere for long enough.
 For example:
 
 .. code-block:: python
 
-   argv_keepalive = [ffi.new("char[]", "xyz")]
+   argv_keepalive = [ffi.new("char[]", "arg0"),
+                     ffi.new("char[]", "arg1")]
    argv = ffi.new("char *[]", argv_keepalive)
 
-would work.
+will work.
 
 Function calls
 --------------
@@ -817,7 +821,7 @@
 ``ffi.offsetof("C struct type", "fieldname")``: return the offset within
 the struct of the given field.  Corresponds to ``offsetof()`` in C.
 
-``ffi.getcname("C type" or <ctype>, ["extra"])``: return the string
+``ffi.getcname("C type" or <ctype>, extra="")``: return the string
 representation of the given C type.  If non-empty, the "extra" string is
 appended (or inserted at the right place in more complicated cases); it
 can be the name of a variable to declare, or an extra part of the type


More information about the pypy-commit mailing list