[pypy-commit] creflect default: check for char more precisely

arigo noreply at buildbot.pypy.org
Tue Nov 18 19:53:05 CET 2014


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r87:0338c76d71e5
Date: 2014-11-18 19:53 +0100
http://bitbucket.org/cffi/creflect/changeset/0338c76d71e5/

Log:	check for char more precisely

diff --git a/creflect/model.py b/creflect/model.py
--- a/creflect/model.py
+++ b/creflect/model.py
@@ -110,6 +110,12 @@
             if self.is_integer_type():
                 expr = 'CRX_INT_TYPE(cb, %s, "%s")' % (star_p1, self.name)
             elif self.is_char_type():
+                errmsg = "numeric type '%s' is not a char" % (
+                    inspect.get_comment_type(0, False),)
+                block.writeline("if (sizeof(%s) != 1) {" % (star_p1,))
+                block.writeline('    cb->error(cb, "%s");' % (errmsg,))
+                block.writeline("    return;")
+                block.writeline("}")
                 expr = 'cb->get_char_type(cb)'
             elif self.is_float_type():
                 xxx
diff --git a/test/codegen/003e.c b/test/codegen/003e.c
--- a/test/codegen/003e.c
+++ b/test/codegen/003e.c
@@ -11,6 +11,10 @@
         p1 = (void *)b;
         (void)(*p1 << 1);  /* check that 'num_t' is an integer type */
         *p1 = -1;  /* check that 'num_t' is not declared 'const' */
+        if (sizeof(*p1) != 1) {
+            cb->error(cb, "numeric type 'num_t' is not a char");
+            return;
+        }
         t1 = cb->get_char_type(cb);
         cb->define_type(cb, "num_t", t1);
 #expect TYPEDEF num_t = char


More information about the pypy-commit mailing list