Author: Ronan Lamy <[email protected]>
Branch: 
Changeset: r89798:299d09fc6636
Date: 2017-01-27 15:44 +0000
http://bitbucket.org/pypy/pypy/changeset/299d09fc6636/

Log:    Configure structs in the order in which they are typedef'd

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
@@ -1,4 +1,5 @@
 from collections import OrderedDict
+from itertools import izip
 from . import cmodel as model
 from .commontypes import COMMON_TYPES, resolve_common_type
 from .error import FFIError, CDefError
@@ -103,7 +104,7 @@
 class Parser(object):
 
     def __init__(self):
-        self._declarations = {}
+        self._declarations = OrderedDict()
         self._included_declarations = set()
         self._anonymous_counter = 0
         self._structnode2type = weakref.WeakKeyDictionary()
@@ -796,7 +797,7 @@
             return
         eci = self.build_eci()
         result = rffi_platform.configure_entries(list(self._config_entries), 
eci)
-        for entry, TYPE in zip(self._config_entries, result):
+        for entry, TYPE in izip(self._config_entries, result):
             # hack: prevent the source from being pasted into common_header.h
             del TYPE._hints['eci']
             self._config_entries[entry].become(TYPE)
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
@@ -142,6 +142,20 @@
     assert isinstance(Object, lltype.Struct)
     hash(Object)
 
+def test_nested_struct():
+    cdef = """
+    typedef struct {
+        int x;
+    } foo;
+    typedef struct {
+        foo y;
+    } bar;
+    """
+    cts = parse_source(cdef)
+    bar = cts.gettype('bar')
+    assert isinstance(bar, lltype.Struct)
+    hash(bar)  # bar is hashable
+
 def test_const():
     cdef = """
     typedef struct {
diff --git a/rpython/rtyper/tool/rffi_platform.py 
b/rpython/rtyper/tool/rffi_platform.py
--- a/rpython/rtyper/tool/rffi_platform.py
+++ b/rpython/rtyper/tool/rffi_platform.py
@@ -245,7 +245,8 @@
         resultinfo[entry] = info
 
     result = ConfigResult(eci, resultinfo)
-    return [result.get_entry_result(entry) for entry in entries]
+    for entry in entries:
+        yield result.get_entry_result(entry)
 
 # ____________________________________________________________
 
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to