]> www.infradead.org Git - users/dhowells/kafs-utils.git/commitdiff
rxgen: Always check type of objects in a bulk list when encoding arguments
authorDavid Howells <dhowells@redhat.com>
Tue, 13 May 2014 20:24:30 +0000 (21:24 +0100)
committerDavid Howells <dhowells@redhat.com>
Tue, 13 May 2014 20:24:49 +0000 (21:24 +0100)
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>
rxgen/emit_py_types.pm

index 6da15c4f48fb470c25d6c62f9924f12f8e6626d8..09fa3f1fd65ae47372009c883894ce0d00f895a3 100644 (file)
@@ -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;