[pypy-commit] creflect default: Kill a feature, with comments for why

arigo noreply at buildbot.pypy.org
Sat Nov 29 16:11:30 CET 2014


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r120:315cd9372b22
Date: 2014-11-29 16:06 +0100
http://bitbucket.org/cffi/creflect/changeset/315cd9372b22/

Log:	Kill a feature, with comments for why

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
@@ -175,7 +175,7 @@
     return result;
 }
 
-static crx_type_t *parse_complete(crxp_token_t *tok, int is_func_arg);
+static crx_type_t *parse_complete(crxp_token_t *tok);
 
 static void parse_sequel(crxp_token_t *tok, intptr_t ds_end)
 {
@@ -232,7 +232,7 @@
                         next_token(tok);
                         break;
                     }
-                    crx_type_t *t1 = parse_complete(tok, 1);
+                    crx_type_t *t1 = parse_complete(tok);
                     intptr_t *ds_type = alloc_ds(tok, 1);
                     if (ds_type == NULL)
                         return;
@@ -301,7 +301,7 @@
 }
 
 static crx_type_t *fetch_delay_slots(crxp_token_t *tok, crx_type_t *t1,
-                                     intptr_t *delay_slot, int is_func_arg)
+                                     intptr_t *delay_slot)
 {
     if (tok->kind == TOK_ERROR)
         return NULL;
@@ -324,11 +324,6 @@
         case TOK_OPEN_BRACKET:   /* array */
             {
                 uintptr_t length = (uintptr_t)*delay_slot++;
-                if (is_func_arg && *delay_slot == TOK_END) {
-                    /* function argument: replace an array with a ptr */
-                    t1 = tok->cb->get_pointer_type(tok->cb, t1);
-                    break;
-                }
                 if (length != (uintptr_t)-1)
                     t1 = tok->cb->get_array_type(tok->cb, t1, length);
                 else
@@ -347,10 +342,6 @@
                 else
                     t1 = tok->cb->get_function_type(tok->cb, t1, argtypes,
                                                     nbargs, NULL);
-                if (is_func_arg && *delay_slot == TOK_END) {
-                    /* function argument: replace a func with a ptr-to-func */
-                    t1 = tok->cb->get_pointer_type(tok->cb, t1);
-                }
                 break;
             }
         default:
@@ -359,7 +350,7 @@
     }
 }
 
-static crx_type_t *parse_complete(crxp_token_t *tok, int is_func_arg)
+static crx_type_t *parse_complete(crxp_token_t *tok)
 {
     crx_type_t *t1;
     int is_const = (tok->kind == TOK_CONST);
@@ -512,7 +503,7 @@
 
     intptr_t *orig = tok->delay_slots;
     parse_sequel(tok, TOK_END);
-    return fetch_delay_slots(tok, t1, orig, is_func_arg);
+    return fetch_delay_slots(tok, t1, orig);
 }
 
 const char *creflect_decl_parser(crx_builder_t *cb, const char *input,
@@ -525,7 +516,7 @@
     token.size = 0;
     token.delay_slots = token.all_delay_slots;
     next_token(&token);
-    *result = parse_complete(&token, 0);
+    *result = parse_complete(&token);
 
     if (token.kind == TOK_END)
         return NULL;
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
@@ -79,8 +79,11 @@
     parse("foo_t", "foo_t")
     parse("foo_t*", "PTR foo_t")
     parse("int(int, ...)", "FUNC( int -> ... -> int )")
-    parse("int(int[])", "FUNC( PTR int -> int )")
-    parse("int(long(char))", "FUNC( PTR FUNC( char -> long ) -> int )")
+    # The following should be interpreted like 'int(int *)', but it is not
+    # the job of c_decl_parser to change it -- it can't if the array type
+    # is typedef'ed.  Same for 'int(long(char))' => 'int(long(*)(char))'.
+    parse("int(int[])", "FUNC( ARRAY[] int -> int )")
+    parse("int(long(char))", "FUNC( FUNC( char -> long ) -> int )")
     parse("_Bool", "_Bool")
     parse("float", "float")
     parse("double", "double")
@@ -90,7 +93,7 @@
     parse("void *", "PTR void")
     parse("int a", "int")
     parse("int *abc", "PTR int")
-    parse("int myfunc(int a[])", "FUNC( PTR int -> int )")
+    parse("int myfunc(int a[])", "FUNC( ARRAY[] int -> int )")
     parse("abcd efgh", "abcd")    # 'efgh' is the variable name, ignored
 
 def test_c_decl_error():


More information about the pypy-commit mailing list