Author: Armin Rigo <[email protected]>
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')
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit