From: David Howells <dhowells@redhat.com> Date: Tue, 13 May 2014 20:24:30 +0000 (+0100) Subject: rxgen: Always check type of objects in a bulk list when encoding arguments X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=3dd5e7b82ffbbd7ec29a906cd58fecbe8b08061f;p=users%2Fdhowells%2Fkafs-utils.git rxgen: Always check type of objects in a bulk list when encoding arguments We should always check the type of the objects in a bulk list when we're encoding them as part of an argument (or result) list. Previously we only did this when we needed to fold things like arrays of ints into an object. Signed-off-by: David Howells <dhowells@redhat.com> --- diff --git a/rxgen/emit_py_types.pm b/rxgen/emit_py_types.pm index 6da15c4..09fa3f1 100644 --- a/rxgen/emit_py_types.pm +++ b/rxgen/emit_py_types.pm @@ -324,24 +324,25 @@ sub emit_py_type_wrapper($) { print PYOUT "\treturn obj;\n"; print PYOUT "}\n"; - # Emit a function to premarshal such a type. This folds the contents of - # the cached Python objects into their raw fields. + # Emit a function to premarshal such a type. This checks the Python object + # type and folds the contents of the cached Python objects into their raw + # fields. # - if ($#single_structs + $#arrays > -2) { - print PYHDR "extern int py_premarshal_", $struct->{type}, "(PyObject *);\n"; + print PYHDR "extern int py_premarshal_", $struct->{type}, "(PyObject *);\n"; - print PYOUT "\n"; - print PYOUT "int py_premarshal_", $struct->{type}, "(PyObject *_self)\n"; - print PYOUT "{\n"; - print PYOUT "\tstruct py_", $struct->{type}, " *self = (struct py_", $struct->{type}, " *)_self;\n"; + print PYOUT "\n"; + print PYOUT "int py_premarshal_", $struct->{type}, "(PyObject *_self)\n"; + print PYOUT "{\n"; + print PYOUT "\tstruct py_", $struct->{type}, " *self = (struct py_", $struct->{type}, " *)_self;\n"; - # Check that the type we've been given is the right one - print PYOUT "\n"; - print PYOUT "\tif (!PyObject_TypeCheck(self, &py_", $struct->{type}, "Type)) {\n"; - print PYOUT "\t\tPyErr_Format(PyExc_TypeError, \"Expected object of type ", $struct->{type}, "\");\n"; - print PYOUT "\t\treturn -1;\n"; - print PYOUT "\t}\n"; + # Check that the type we've been given is the right one + print PYOUT "\n"; + print PYOUT "\tif (!PyObject_TypeCheck(self, &py_", $struct->{type}, "Type)) {\n"; + print PYOUT "\t\tPyErr_Format(PyExc_TypeError, \"Expected object of type ", $struct->{type}, "\");\n"; + print PYOUT "\t\treturn -1;\n"; + print PYOUT "\t}\n"; + if ($#single_structs + $#arrays > -2) { print PYOUT "\n"; my $first = 1; foreach my $m (@single_structs, @arrays) { @@ -388,14 +389,10 @@ sub emit_py_type_wrapper($) { print PYOUT ")\n"; print PYOUT "\t\treturn -1;\n"; - print PYOUT "\treturn 0;\n"; - print PYOUT "}\n"; - } else { - print PYHDR "static inline int py_premarshal_", $struct->{type}, "(PyObject *_self)\n"; - print PYHDR "{\n"; - print PYHDR "\treturn 0;\n"; - print PYHDR "}\n"; } + + print PYOUT "\treturn 0;\n"; + print PYOUT "}\n"; } 1;