[Libguestfs] [PATCH] python: Fix bug in code generator

Matteo Cafasso noxdafox at gmail.com
Fri Apr 1 15:59:39 UTC 2016


When a struct containing FChar fields is defined
in generator/structs.ml, the Python code generator will generate
code referencing a dirent struct instead of the correct one
thus breaking at compile time.

This bug was left unnoticed because the dirent struct is the only
one using FChar fields. Yet it prevents any other struct
from using such fields.

Signed-off-by: Matteo Cafasso <noxdafox at gmail.com>
---
 generator/python.ml | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/generator/python.ml b/generator/python.ml
index 9663fb4..9d9dc4a 100644
--- a/generator/python.ml
+++ b/generator/python.ml
@@ -225,10 +225,12 @@ put_table (char * const * const argv)
         | name, FChar ->
             pr "#ifdef HAVE_PYSTRING_ASSTRING\n";
             pr "  PyDict_SetItemString (dict, \"%s\",\n" name;
-            pr "                        PyString_FromStringAndSize (&dirent->%s, 1));\n" name;
+            pr "                        PyString_FromStringAndSize (&%s->%s, 1));\n"
+              typ name;
             pr "#else\n";
             pr "  PyDict_SetItemString (dict, \"%s\",\n" name;
-            pr "                        PyUnicode_FromStringAndSize (&dirent->%s, 1));\n" name;
+            pr "                        PyUnicode_FromStringAndSize (&%s->%s, 1));\n"
+              typ name;
             pr "#endif\n"
       ) cols;
       pr "  return dict;\n";
-- 
2.8.0.rc3




More information about the Libguestfs mailing list