Commits

Armin Rigo committed 2a2a1ac

Forgot to check this in.

Comments (0)

Files changed (1)

pypy/rpython/lltypesystem/ll2ctypes.py

             fields.append((fieldname, cls))
         CStruct._fields_ = fields
 
-    class CStruct(ctypes.Structure):
+    if S._hints.get('union', False):
+        base = ctypes.Union
+    else:
+        base = ctypes.Structure
+
+    class CStruct(base):
         # no _fields_: filled later by builder()
 
         def _malloc(cls, n=None):
 _int2obj = {}
 _callback_exc_info = None
 _opaque_objs = [None]
+_opaque_objs_seen = {}
 
 def get_rtyper():
     llinterp = LLInterpreter.current_interpreter
             # otherwise it came from integer and we want a c_void_p with
             # the same value
             if getattr(container, 'llopaque', None):
-                no = len(_opaque_objs)
-                _opaque_objs.append(container)
+                try:
+                    no = _opaque_objs_seen[container]
+                except KeyError:
+                    no = len(_opaque_objs)
+                    _opaque_objs.append(container)
+                    _opaque_objs_seen[container] = no
                 return no * 2 + 1
         else:
             container = llobj._obj