Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r68:a9431fb05c50
Date: 2014-11-18 16:02 +0100
http://bitbucket.org/cffi/creflect/changeset/a9431fb05c50/

Log:    Global arrays

diff --git a/creflect/model.py b/creflect/model.py
--- a/creflect/model.py
+++ b/creflect/model.py
@@ -300,8 +300,12 @@
             brackets = '&[/*...*/]'
         else:
             brackets = '&[%d]' % length
+        if ' &' in self.item.c_name_with_marker:
+            replace_from = ' &'
+        else:
+            replace_from = '&'
         self.c_name_with_marker = (
-            self.item.c_name_with_marker.replace('&', brackets))
+            self.item.c_name_with_marker.replace(replace_from, brackets))
 
     def inspect_type(self, block, inspect):
         # this class overrides inspect_type() instead of
@@ -321,9 +325,21 @@
                 block.writeline("}")
             inspect.levels.append('[]')
             inspect.after_star_p1_assignment.append(after)
+        elif isinstance(inspect, VarInspector):
+            declitem = self.item.get_c_name("(*p1)")
+            block.writeline("%s[] = &%s;  /* check that '%s' is of type '%s'"
+                            " */" % (declitem, inspect.varname,
+                                     inspect.varname, self.get_c_name()))
+            block.writeline("(void)p1;")
+            star_p1 = inspect.varname
+        else:
+            star_p1 = None
         t1 = self.item.inspect_type(block, inspect)
-        expr = 'cb->get_array_type(cb, %s, sizeof(%s) / sizeof(*%s))' % (
-            t1, star_p1, star_p1)
+        if star_p1 is not None:
+            expr = 'cb->get_array_type(cb, %s, sizeof(%s) / sizeof(*%s))' % (
+                t1, star_p1, star_p1)
+        else:
+            expr = 'cb->get_incomplete_array_type(cb, %s)' % (t1,)
         return block.write_crx_type_var(expr)
 
 
diff --git a/test/codegen/glob-002.c b/test/codegen/glob-002.c
--- a/test/codegen/glob-002.c
+++ b/test/codegen/glob-002.c
@@ -4,12 +4,13 @@
 
 void testglob_002(crx_builder_t *cb)
 {
-    crx_type *t1, *t2;
+    crx_type_t *t1, *t2;
     {
         char (*p1)[] = &someglob;  /* check that 'someglob' is of type 
'char[]' */
         (void)p1;
         t1 = cb->get_char_type(cb);
         t2 = cb->get_array_type(cb, t1, sizeof(someglob) / sizeof(*someglob));
         cb->define_var(cb, "someglob", t2, &someglob);
+#expect VAR someglob: ARRAY[100] char
     }
 }
diff --git a/test/codegen/glob-002b.c b/test/codegen/glob-002b.c
new file mode 100644
--- /dev/null
+++ b/test/codegen/glob-002b.c
@@ -0,0 +1,18 @@
+int someglob[100];
+
+// XXX can be improved to correct the size of the integer type
+
+# ____________________________________________________________
+
+void testglob_002b(crx_builder_t *cb)
+{
+    crx_type_t *t1, *t2;
+    {
+        int (*p1)[] = &someglob;  /* check that 'someglob' is of type 'int[]' 
*/
+        (void)p1;
+        t1 = cb->get_signed_type(cb, sizeof(int), "int");
+        t2 = cb->get_array_type(cb, t1, sizeof(someglob) / sizeof(*someglob));
+        cb->define_var(cb, "someglob", t2, &someglob);
+#expect VAR someglob: ARRAY[100] int
+    }
+}
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to