[vlc-commits] python: Use a forward declaration for structs

Olivier Aubert git at videolan.org
Sun Jan 10 11:55:48 UTC 2021


vlc/python | branch: master | Olivier Aubert <contact at olivieraubert.net> | Sun Jan 10 12:24:26 2021 +0100| [3595fc41a31356b022801bed3da2c23463841939] | committer: Olivier Aubert

python: Use a forward declaration for structs

> http://git.videolan.org/gitweb.cgi/vlc/python.git/?a=commit;h=3595fc41a31356b022801bed3da2c23463841939
---

 generator/generate.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/generator/generate.py b/generator/generate.py
index 1e6f85c..b369393 100755
--- a/generator/generate.py
+++ b/generator/generate.py
@@ -1250,10 +1250,13 @@ class _Enum(ctypes.c_uint):
             # (for tricky ones) in override.py
             if cls in self.overrides.codes:
                 continue
+            # We use a forward declaration here to allow for self-referencing structures - cf
+            # https://docs.python.org/3/library/ctypes.html#ctypes.Structure._fields_
             self.output("""class %s(ctypes.Structure):
     '''%s
     '''
-    _fields_ = (""" % (cls, e.epydocs() or _NA_))
+    pass
+%s._fields_ = (""" % (cls, e.epydocs() or _NA_, cls))
 
             for v in e.fields:
                 self.output("        ('%s', %s)," % (v.name, self.class4(v.type)))



More information about the vlc-commits mailing list