Author: Ronan Lamy <[email protected]>
Branch: rffi-parser-2
Changeset: r89218:66787841431b
Date: 2016-12-23 12:51 +0100
http://bitbucket.org/pypy/pypy/changeset/66787841431b/

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
@@ -682,6 +682,12 @@
         self._Config = type(
             'Config', (object,), {'_compilation_info_': eci})
         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
@@ -749,12 +755,11 @@
 
 def parse_source(source, includes=None, eci=None):
     ctx = Parser()
+    src = ParsedSource(source, ctx, eci=eci)
     if includes is not None:
         for header in includes:
-            ctx.include(header.ctx)
-
+            src.include(header)
     ctx.parse(source)
-    src = ParsedSource(source, ctx, eci=eci)
     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
@@ -53,13 +53,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
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to