Matteo Cafasso
2016-Apr-01 15:59 UTC
[Libguestfs] [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 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
Richard W.M. Jones
2016-Apr-01 16:15 UTC
[Libguestfs] [PATCH] python: Fix bug in code generator
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 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";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
Apparently Analagous Threads
- [PATCH] python: Fix bug in code generator
- [PATCH v2] python: add simple wrappers for PyObject<->string functions
- [PATCH] python: check return value of Python APIs
- [Bug #1406906] [PATCH] python: fix segmentation fault when setting non UTF-8 strings
- [PATCH] python: add simple wrappers for PyObject<->string functions