[pypy-commit] creflect default: incomplete arrays

arigo noreply at buildbot.pypy.org
Sat Nov 29 10:09:12 CET 2014


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r108:a18484dc4bd9
Date: 2014-11-29 09:58 +0100
http://bitbucket.org/cffi/creflect/changeset/a18484dc4bd9/

Log:	incomplete arrays

diff --git a/creflect/src/c_decl_parser.c b/creflect/src/c_decl_parser.c
--- a/creflect/src/c_decl_parser.c
+++ b/creflect/src/c_decl_parser.c
@@ -216,16 +216,18 @@
         goto next_right_part;
 
     case TOK_OPEN_BRACKET:
+    {
+        uintptr_t length = (uintptr_t)-1;
         next_token(tok);
-        assert(tok->kind == TOK_INTEGER);  // XXX
+        if (tok->kind != TOK_CLOSE_BRACKET) {
+            assert(tok->kind == TOK_INTEGER);  // XXX
 
-        uintptr_t length;
-        if (sizeof(uintptr_t) > sizeof(unsigned long))
-            length = strtoull(tok->p, NULL, 10);
-        else
-            length = strtoul(tok->p, NULL, 10);
-        next_token(tok);
-
+            if (sizeof(uintptr_t) > sizeof(unsigned long))
+                length = strtoull(tok->p, NULL, 10);
+            else
+                length = strtoul(tok->p, NULL, 10);
+            next_token(tok);
+        }
         assert(tok->kind == TOK_CLOSE_BRACKET);  // XXX
         next_token(tok);
 
@@ -235,7 +237,7 @@
         ds[2] = *jump_slot;
         *jump_slot = -(ds - tok->all_delay_slots);
         goto next_right_part;
-
+    }
     default:
         break;
     }
@@ -260,7 +262,10 @@
             case TOK_OPEN_BRACKET:   /* array */
             {
                 uintptr_t length = (uintptr_t)*delay_slot++;
-                t1 = tok->cb->get_array_type(tok->cb, t1, length);
+                if (length != (uintptr_t)-1)
+                    t1 = tok->cb->get_array_type(tok->cb, t1, length);
+                else
+                    t1 = tok->cb->get_incomplete_array_type(tok->cb, t1);
                 break;
             }
             case TOK_OPEN_PAREN:   /* function */
diff --git a/test/test_c_decl_parser.py b/test/test_c_decl_parser.py
--- a/test/test_c_decl_parser.py
+++ b/test/test_c_decl_parser.py
@@ -74,8 +74,9 @@
     parse("signed char", "signed char")
     parse("unsigned char", "unsigned char")
     parse("char(*(*)(long))(int)","PTR FUNC( long -> PTR FUNC( int -> char ) )")
+    parse("int[]", "ARRAY[] int")
     import py; py.test.skip("in-progress")
-    parse("foo_t[]")
+    parse("foo_t")
     parse("int(int, ...)")
     parse("int(int[])")
     parse("int(long(char))")


More information about the pypy-commit mailing list