[pypy-commit] pypy rffi-parser: Refactor includes

rlamy pypy.commits at gmail.com
Sun Dec 18 10:45:45 EST 2016


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: rffi-parser
Changeset: r89147:1237824b7174
Date: 2016-12-18 15:31 +0000
http://bitbucket.org/pypy/pypy/changeset/1237824b7174/

Log:	Refactor includes

diff --git a/pypy/module/cpyext/cparser.py b/pypy/module/cpyext/cparser.py
--- a/pypy/module/cpyext/cparser.py
+++ b/pypy/module/cpyext/cparser.py
@@ -686,6 +686,12 @@
         self._Config = type('Config', (object,), {})
         self._Config._compilation_info_ = CConfig._compilation_info_
         self._TYPES = {}
+        self.includes = []
+
+    def include(self, other):
+        self.ctx.include(other.ctx)
+        self.structs.update(other.structs)
+        self.includes.append(other)
 
     def add_typedef(self, name, obj):
         assert name not in self.definitions
@@ -757,12 +763,11 @@
 
 def parse_source(source, includes=None):
     ctx = Parser()
+    src = ParsedSource(source, ctx)
     if includes is not None:
         for header in includes:
-            ctx.include(header.ctx)
-
+            src.include(header)
     ctx.parse(source)
-    src = ParsedSource(source, ctx)
     for name, (obj, quals) in ctx._declarations.iteritems():
         if obj in ctx._included_declarations:
             continue
diff --git a/pypy/module/cpyext/test/test_cparser.py b/pypy/module/cpyext/test/test_cparser.py
--- a/pypy/module/cpyext/test/test_cparser.py
+++ b/pypy/module/cpyext/test/test_cparser.py
@@ -47,13 +47,19 @@
     #define PyObject_HEAD  \
         Py_ssize_t ob_refcnt;        \
         Py_ssize_t ob_pypy_link;     \
+
+    typedef struct {
+        char *name;
+    } Type;
     """
     hdr1 = parse_source(cdef1)
     cdef2 = """
     typedef struct {
         PyObject_HEAD
         Py_ssize_t ob_foo;
+        Type *type;
     } Object;
     """
     hdr2 = parse_source(cdef2, includes=[hdr1])
     assert 'Object' in hdr2.definitions
+    assert 'Type' not in hdr2.definitions


More information about the pypy-commit mailing list