[pypy-commit] cffi cpy-extension: Non-full enums, starting

arigo noreply at buildbot.pypy.org
Thu Jun 14 10:41:03 CEST 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: cpy-extension
Changeset: r321:c7e2c4eef785
Date: 2012-06-14 10:40 +0200
http://bitbucket.org/cffi/cffi/changeset/c7e2c4eef785/

Log:	Non-full enums, starting

diff --git a/cffi/cparser.py b/cffi/cparser.py
--- a/cffi/cparser.py
+++ b/cffi/cparser.py
@@ -1,7 +1,8 @@
 
 from . import api, model
-import pycparser, weakref
+import pycparser, weakref, re
 
+_r_partial_enum = re.compile(r"\.\.\.\s*\}")
 _parser_cache = None
 
 def _get_parser():
@@ -10,6 +11,14 @@
         _parser_cache = pycparser.CParser()
     return _parser_cache
 
+def _preprocess(csource):
+    matches = list(_r_partial_enum.finditer(csource))
+    for number, match in enumerate(reversed(matches)):
+        p = match.start()
+        assert csource[p:p+3] == '...'
+        csource = '%s__dotdotdot%d__%s' % (csource[:p], number, csource[p+3:])
+    return csource.replace('...', '__dotdotdot__')
+
 class Parser(object):
     def __init__(self):
         self._declarations = {}
@@ -26,7 +35,7 @@
             if name.startswith('typedef '):
                 csourcelines.append('typedef int %s;' % (name[8:],))
         csourcelines.append('typedef int __dotdotdot__;')
-        csourcelines.append(csource.replace('...', '__dotdotdot__'))
+        csourcelines.append(_preprocess(csource))
         csource = '\n'.join(csourcelines)
         ast = _get_parser().parse(csource)
         return ast
diff --git a/testing/test_verify.py b/testing/test_verify.py
--- a/testing/test_verify.py
+++ b/testing/test_verify.py
@@ -271,3 +271,9 @@
         lib = ffi.verify("#define AA %s\n" % vstr)
         assert lib.AA == value
         assert type(lib.AA) is type(int(lib.AA))
+
+def test_nonfull_enum():
+    ffi = FFI()
+    ffi.cdef("enum ee { EE1, EE2, EE3, ... \n \t };")
+    py.test.skip("in-progress")
+    py.test.raises(VerificationMissing, ffi.cast, 'enum ee', 'EE2')


More information about the pypy-commit mailing list