[PATCH] python: Fix bug in code generator
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@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
On Fri, Apr 01, 2016 at 06:59:39PM +0300, Matteo Cafasso wrote:
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@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";
Oops. Thanks - I've pushed this. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-builder quickly builds VMs from scratch http://libguestfs.org/virt-builder.1.html
participants (2)
-
Matteo Cafasso -
Richard W.M. Jones