Author: Armin Rigo <ar...@tunes.org>
Branch: cffi-1.0
Changeset: r1693:3ac82266ea94
Date: 2015-04-11 09:32 +0200
http://bitbucket.org/cffi/cffi/changeset/3ac82266ea94/

Log:    Copy some tests from creflect

diff --git a/new/parse_c_type.c b/new/parse_c_type.c
--- a/new/parse_c_type.c
+++ b/new/parse_c_type.c
@@ -1,6 +1,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <assert.h>
+#include <errno.h>
 #include "parse_c_type.h"
 
 
@@ -324,10 +325,13 @@
             if (tok->kind != TOK_INTEGER)
                 return parse_error(tok, "expected a positive integer 
constant");
 
+            errno = 0;
             if (sizeof(length) > sizeof(unsigned long))
                 length = strtoull(tok->p, NULL, 10);
             else
                 length = strtoul(tok->p, NULL, 10);
+            if (errno == ERANGE)
+                return parse_error(tok, "number too large");
             next_token(tok);
 
             write_ds(tok, _CFFI_OP(_CFFI_OP_ARRAY, 0));
diff --git a/new/test_parse_c_type.py b/new/test_parse_c_type.py
--- a/new/test_parse_c_type.py
+++ b/new/test_parse_c_type.py
@@ -188,6 +188,34 @@
 
 def test_error():
     parse_error("short short int", "'short' after another 'short' or 'long'", 
6)
+    parse_error("long long long", "'long long long' is too long", 10)
+    parse_error("short long", "'long' after 'short'", 6)
+    parse_error("signed unsigned int", "multiple 'signed' or 'unsigned'", 7)
+    parse_error("unsigned signed int", "multiple 'signed' or 'unsigned'", 9)
+    parse_error("long char", "invalid combination of types", 5)
+    parse_error("short char", "invalid combination of types", 6)
+    parse_error("signed void", "invalid combination of types", 7)
+    parse_error("unsigned struct", "invalid combination of types", 9)
+    #
+    parse_error("", "identifier expected", 0)
+    parse_error("]", "identifier expected", 0)
+    parse_error("*", "identifier expected", 0)
+    parse_error("int ]**", "unexpected symbol", 4)
+    parse_error("char char", "unexpected symbol", 5)
+    parse_error("int(int]", "expected ')'", 7)
+    parse_error("int(*]", "expected ')'", 5)
+    parse_error("int(]", "identifier expected", 4)
+    parse_error("int[?]", "expected a positive integer constant", 4)
+    parse_error("int[24)", "expected ']'", 6)
+    parse_error("struct", "struct or union name expected", 6)
+    parse_error("struct 24", "struct or union name expected", 7)
+    parse_error("int[5](*)", "unexpected symbol", 6)
+    parse_error("int a(*)", "identifier expected", 6)
+    parse_error("int[123456789012345678901234567890]", "number too large", 4)
+
+def test_complexity_limit():
+    parse_error("int" + "[]" * 2500, "internal type complexity limit reached",
+                202)
 
 def test_struct():
     for i in range(len(struct_names)):
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to