This will eliminate the need to call xdr_free to clear
pointers from data structures.
Signed-off-by: Daniel P. Berrangé <berrange(a)redhat.com>
---
build-aux/syntax-check.mk | 2 +-
scripts/rpcgen/main.py | 4 +
scripts/rpcgen/rpcgen/generator.py | 64 +++++++++--
scripts/rpcgen/tests/demo.c | 144 +++++++++++++++++++++++++
scripts/rpcgen/tests/demo.h | 48 +++++++++
scripts/rpcgen/tests/test_demo.c | 91 ++++++++--------
scripts/rpcgen/tests/test_generator.py | 7 +-
7 files changed, 298 insertions(+), 62 deletions(-)
diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk
index 2599ba688f..317cf223e7 100644
--- a/build-aux/syntax-check.mk
+++ b/build-aux/syntax-check.mk
@@ -1464,7 +1464,7 @@ exclude_file_name_regexp--sc_prohibit_mixed_case_abbreviations = \
^src/(vbox/vbox_CAPI.*.h|esx/esx_vi.(c|h)|esx/esx_storage_backend_iscsi.c)$$
exclude_file_name_regexp--sc_prohibit_empty_first_line = \
- ^tests/vmwareverdata/fusion-5.0.3.txt$$
+ ^tests/vmwareverdata/fusion-5.0.3.txt|scripts/rpcgen/tests/demo\.c$$
exclude_file_name_regexp--sc_prohibit_useless_translation = \
^tests/virpolkittest.c
diff --git a/scripts/rpcgen/main.py b/scripts/rpcgen/main.py
index bf4ef38ede..d50f08c180 100755
--- a/scripts/rpcgen/main.py
+++ b/scripts/rpcgen/main.py
@@ -8,6 +8,7 @@ import sys
from rpcgen.parser import XDRParser
from rpcgen.generator import (
XDRTypeDeclarationGenerator,
+ XDRTypeImplementationGenerator,
XDRMarshallDeclarationGenerator,
XDRMarshallImplementationGenerator,
)
@@ -59,6 +60,7 @@ def main():
if args.mode == "header":
print("/* This file is auto-generated from %s */\n" % args.input,
file=outfp)
print("#include <rpc/rpc.h>", file=outfp)
+ print('#include "internal.h"', file=outfp)
for h in args.header:
print('#include "%s"' % h, file=outfp)
print("", file=outfp)
@@ -75,6 +77,8 @@ def main():
for h in args.header:
print('#include "%s"' % h, file=outfp)
print("", file=outfp)
+ generator = XDRTypeImplementationGenerator(spec)
+ print(generator.visit(), file=outfp)
generator = XDRMarshallImplementationGenerator(spec)
print(generator.visit(), file=outfp)
elif args.mode == "repr":
diff --git a/scripts/rpcgen/rpcgen/generator.py b/scripts/rpcgen/rpcgen/generator.py
index 110cd12c5e..c0f1e03ec4 100644
--- a/scripts/rpcgen/rpcgen/generator.py
+++ b/scripts/rpcgen/rpcgen/generator.py
@@ -28,24 +28,42 @@ class XDRTypeDeclarationGenerator(XDRVisitor):
) + "%stypedef enum %s %s;\n" % (indent, obj.name, obj.name)
return code
- def visit_definition_struct(self, obj, indent, context):
- code = "%sstruct %s %s;\n" % (
+ def generate_cleanup(self, name, indent):
+ code = "%svoid xdr_%s_clear(%s *objp);\n" % (
indent,
- obj.name,
- self.visit_object(obj.body, indent),
- ) + "%stypedef struct %s %s;\n" % (indent, obj.name, obj.name)
+ name,
+ name,
+ ) + "%sG_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(%s, xdr_%s_clear);\n" % (
+ indent,
+ name,
+ name,
+ )
+ return code
+
+ def visit_definition_struct(self, obj, indent, context):
+ code = (
+ "%sstruct %s %s;\n"
+ % (indent, obj.name, self.visit_object(obj.body, indent))
+ + "%stypedef struct %s %s;\n" % (indent, obj.name, obj.name)
+ + self.generate_cleanup(obj.name, indent)
+ )
return code
def visit_definition_union(self, obj, indent, context):
- code = "%sstruct %s %s;\n" % (
- indent,
- obj.name,
- self.visit_object(obj.body, indent, obj.name),
- ) + "%stypedef struct %s %s;\n" % (indent, obj.name, obj.name)
+ code = (
+ "%sstruct %s %s;\n"
+ % (indent, obj.name, self.visit_object(obj.body, indent, obj.name))
+ + "%stypedef struct %s %s;\n" % (indent, obj.name, obj.name)
+ + self.generate_cleanup(obj.name, indent)
+ )
return code
def visit_definition_typedef(self, obj, indent, context):
- return "%stypedef %s;\n" % (indent, self.visit_object(obj.decl,
indent))
+ code = "%stypedef %s;\n" % (
+ indent,
+ self.visit_object(obj.decl, indent),
+ ) + self.generate_cleanup(obj.decl.identifier, indent)
+ return code
def visit_declaration_scalar(self, obj, indent, context):
return "%s %s" % (self.visit_object(obj.typ, indent), obj.identifier)
@@ -167,6 +185,30 @@ class XDRTypeDeclarationGenerator(XDRVisitor):
return code
+class XDRTypeImplementationGenerator(XDRVisitor):
+ def visit_definition_enum(self, obj, indent, context):
+ pass
+
+ def generate_cleanup(self, name, indent):
+ code = (
+ "\n"
+ + "%svoid xdr_%s_clear(%s *objp)\n" % (indent, name, name)
+ + "%s{\n" % indent
+ + "%s xdr_free((xdrproc_t)xdr_%s, (char *)objp);\n" % (indent,
name)
+ + "%s}\n" % indent
+ )
+ return code
+
+ def visit_definition_union(self, obj, indent, context):
+ return self.generate_cleanup(obj.name, indent)
+
+ def visit_definition_struct(self, obj, indent, context):
+ return self.generate_cleanup(obj.name, indent)
+
+ def visit_definition_typedef(self, obj, indent, context):
+ return self.generate_cleanup(obj.decl.identifier, indent)
+
+
class XDRMarshallDeclarationGenerator(XDRVisitor):
def visit_definition_enum(self, obj, indent, context):
return "%sextern bool_t xdr_%s(XDR *, %s*);\n" % (indent, obj.name,
obj.name)
diff --git a/scripts/rpcgen/tests/demo.c b/scripts/rpcgen/tests/demo.c
index a261b4fe22..d57547d5eb 100644
--- a/scripts/rpcgen/tests/demo.c
+++ b/scripts/rpcgen/tests/demo.c
@@ -1,3 +1,147 @@
+
+void xdr_TestStruct_clear(TestStruct *objp)
+{
+ xdr_free((xdrproc_t)xdr_TestStruct, (char *)objp);
+}
+
+
+void xdr_TestUnion_clear(TestUnion *objp)
+{
+ xdr_free((xdrproc_t)xdr_TestUnion, (char *)objp);
+}
+
+
+void xdr_TestUnionVoidDefault_clear(TestUnionVoidDefault *objp)
+{
+ xdr_free((xdrproc_t)xdr_TestUnionVoidDefault, (char *)objp);
+}
+
+
+void xdr_TestUnionNoDefault_clear(TestUnionNoDefault *objp)
+{
+ xdr_free((xdrproc_t)xdr_TestUnionNoDefault, (char *)objp);
+}
+
+
+void xdr_TestIntScalar_clear(TestIntScalar *objp)
+{
+ xdr_free((xdrproc_t)xdr_TestIntScalar, (char *)objp);
+}
+
+
+void xdr_TestIntPointer_clear(TestIntPointer *objp)
+{
+ xdr_free((xdrproc_t)xdr_TestIntPointer, (char *)objp);
+}
+
+
+void xdr_TestIntFixedArray_clear(TestIntFixedArray *objp)
+{
+ xdr_free((xdrproc_t)xdr_TestIntFixedArray, (char *)objp);
+}
+
+
+void xdr_TestIntVariableArray_clear(TestIntVariableArray *objp)
+{
+ xdr_free((xdrproc_t)xdr_TestIntVariableArray, (char *)objp);
+}
+
+
+void xdr_TestStringVariableArray_clear(TestStringVariableArray *objp)
+{
+ xdr_free((xdrproc_t)xdr_TestStringVariableArray, (char *)objp);
+}
+
+
+void xdr_TestOpaqueFixedArray_clear(TestOpaqueFixedArray *objp)
+{
+ xdr_free((xdrproc_t)xdr_TestOpaqueFixedArray, (char *)objp);
+}
+
+
+void xdr_TestOpaqueVariableArray_clear(TestOpaqueVariableArray *objp)
+{
+ xdr_free((xdrproc_t)xdr_TestOpaqueVariableArray, (char *)objp);
+}
+
+
+void xdr_TestEnumScalar_clear(TestEnumScalar *objp)
+{
+ xdr_free((xdrproc_t)xdr_TestEnumScalar, (char *)objp);
+}
+
+
+void xdr_TestEnumPointer_clear(TestEnumPointer *objp)
+{
+ xdr_free((xdrproc_t)xdr_TestEnumPointer, (char *)objp);
+}
+
+
+void xdr_TestEnumFixedArray_clear(TestEnumFixedArray *objp)
+{
+ xdr_free((xdrproc_t)xdr_TestEnumFixedArray, (char *)objp);
+}
+
+
+void xdr_TestEnumVariableArray_clear(TestEnumVariableArray *objp)
+{
+ xdr_free((xdrproc_t)xdr_TestEnumVariableArray, (char *)objp);
+}
+
+
+void xdr_TestStructScalar_clear(TestStructScalar *objp)
+{
+ xdr_free((xdrproc_t)xdr_TestStructScalar, (char *)objp);
+}
+
+
+void xdr_TestStructPointer_clear(TestStructPointer *objp)
+{
+ xdr_free((xdrproc_t)xdr_TestStructPointer, (char *)objp);
+}
+
+
+void xdr_TestStructFixedArray_clear(TestStructFixedArray *objp)
+{
+ xdr_free((xdrproc_t)xdr_TestStructFixedArray, (char *)objp);
+}
+
+
+void xdr_TestStructVariableArray_clear(TestStructVariableArray *objp)
+{
+ xdr_free((xdrproc_t)xdr_TestStructVariableArray, (char *)objp);
+}
+
+
+void xdr_TestUnionScalar_clear(TestUnionScalar *objp)
+{
+ xdr_free((xdrproc_t)xdr_TestUnionScalar, (char *)objp);
+}
+
+
+void xdr_TestUnionPointer_clear(TestUnionPointer *objp)
+{
+ xdr_free((xdrproc_t)xdr_TestUnionPointer, (char *)objp);
+}
+
+
+void xdr_TestUnionFixedArray_clear(TestUnionFixedArray *objp)
+{
+ xdr_free((xdrproc_t)xdr_TestUnionFixedArray, (char *)objp);
+}
+
+
+void xdr_TestUnionVariableArray_clear(TestUnionVariableArray *objp)
+{
+ xdr_free((xdrproc_t)xdr_TestUnionVariableArray, (char *)objp);
+}
+
+
+void xdr_TestStructAllTypes_clear(TestStructAllTypes *objp)
+{
+ xdr_free((xdrproc_t)xdr_TestStructAllTypes, (char *)objp);
+}
+
bool_t
xdr_TestEnum(XDR *xdrs, TestEnum *objp)
{
diff --git a/scripts/rpcgen/tests/demo.h b/scripts/rpcgen/tests/demo.h
index 6fac61e7e9..36bcb40916 100644
--- a/scripts/rpcgen/tests/demo.h
+++ b/scripts/rpcgen/tests/demo.h
@@ -9,6 +9,8 @@ struct TestStruct {
char c2;
};
typedef struct TestStruct TestStruct;
+void xdr_TestStruct_clear(TestStruct *objp);
+G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TestStruct, xdr_TestStruct_clear);
struct TestUnion {
int type;
@@ -19,6 +21,8 @@ struct TestUnion {
} TestUnion_u;
};
typedef struct TestUnion TestUnion;
+void xdr_TestUnion_clear(TestUnion *objp);
+G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TestUnion, xdr_TestUnion_clear);
struct TestUnionVoidDefault {
int type;
@@ -28,6 +32,8 @@ struct TestUnionVoidDefault {
} TestUnionVoidDefault_u;
};
typedef struct TestUnionVoidDefault TestUnionVoidDefault;
+void xdr_TestUnionVoidDefault_clear(TestUnionVoidDefault *objp);
+G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TestUnionVoidDefault, xdr_TestUnionVoidDefault_clear);
struct TestUnionNoDefault {
int type;
@@ -37,59 +43,99 @@ struct TestUnionNoDefault {
} TestUnionNoDefault_u;
};
typedef struct TestUnionNoDefault TestUnionNoDefault;
+void xdr_TestUnionNoDefault_clear(TestUnionNoDefault *objp);
+G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TestUnionNoDefault, xdr_TestUnionNoDefault_clear);
typedef int TestIntScalar;
+void xdr_TestIntScalar_clear(TestIntScalar *objp);
+G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TestIntScalar, xdr_TestIntScalar_clear);
typedef int *TestIntPointer;
+void xdr_TestIntPointer_clear(TestIntPointer *objp);
+G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TestIntPointer, xdr_TestIntPointer_clear);
typedef int TestIntFixedArray[3];
+void xdr_TestIntFixedArray_clear(TestIntFixedArray *objp);
+G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TestIntFixedArray, xdr_TestIntFixedArray_clear);
typedef struct {
u_int TestIntVariableArray_len;
int *TestIntVariableArray_val;
} TestIntVariableArray;
+void xdr_TestIntVariableArray_clear(TestIntVariableArray *objp);
+G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TestIntVariableArray, xdr_TestIntVariableArray_clear);
typedef char *TestStringVariableArray;
+void xdr_TestStringVariableArray_clear(TestStringVariableArray *objp);
+G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TestStringVariableArray,
xdr_TestStringVariableArray_clear);
typedef char TestOpaqueFixedArray[9];
+void xdr_TestOpaqueFixedArray_clear(TestOpaqueFixedArray *objp);
+G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TestOpaqueFixedArray, xdr_TestOpaqueFixedArray_clear);
typedef struct {
u_int TestOpaqueVariableArray_len;
char *TestOpaqueVariableArray_val;
} TestOpaqueVariableArray;
+void xdr_TestOpaqueVariableArray_clear(TestOpaqueVariableArray *objp);
+G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TestOpaqueVariableArray,
xdr_TestOpaqueVariableArray_clear);
typedef TestEnum TestEnumScalar;
+void xdr_TestEnumScalar_clear(TestEnumScalar *objp);
+G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TestEnumScalar, xdr_TestEnumScalar_clear);
typedef TestEnum *TestEnumPointer;
+void xdr_TestEnumPointer_clear(TestEnumPointer *objp);
+G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TestEnumPointer, xdr_TestEnumPointer_clear);
typedef TestEnum TestEnumFixedArray[13];
+void xdr_TestEnumFixedArray_clear(TestEnumFixedArray *objp);
+G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TestEnumFixedArray, xdr_TestEnumFixedArray_clear);
typedef struct {
u_int TestEnumVariableArray_len;
TestEnum *TestEnumVariableArray_val;
} TestEnumVariableArray;
+void xdr_TestEnumVariableArray_clear(TestEnumVariableArray *objp);
+G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TestEnumVariableArray,
xdr_TestEnumVariableArray_clear);
typedef TestStruct TestStructScalar;
+void xdr_TestStructScalar_clear(TestStructScalar *objp);
+G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TestStructScalar, xdr_TestStructScalar_clear);
typedef TestStruct *TestStructPointer;
+void xdr_TestStructPointer_clear(TestStructPointer *objp);
+G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TestStructPointer, xdr_TestStructPointer_clear);
typedef TestStruct TestStructFixedArray[17];
+void xdr_TestStructFixedArray_clear(TestStructFixedArray *objp);
+G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TestStructFixedArray, xdr_TestStructFixedArray_clear);
typedef struct {
u_int TestStructVariableArray_len;
TestStruct *TestStructVariableArray_val;
} TestStructVariableArray;
+void xdr_TestStructVariableArray_clear(TestStructVariableArray *objp);
+G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TestStructVariableArray,
xdr_TestStructVariableArray_clear);
typedef TestUnion TestUnionScalar;
+void xdr_TestUnionScalar_clear(TestUnionScalar *objp);
+G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TestUnionScalar, xdr_TestUnionScalar_clear);
typedef TestUnion *TestUnionPointer;
+void xdr_TestUnionPointer_clear(TestUnionPointer *objp);
+G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TestUnionPointer, xdr_TestUnionPointer_clear);
typedef TestUnion TestUnionFixedArray[21];
+void xdr_TestUnionFixedArray_clear(TestUnionFixedArray *objp);
+G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TestUnionFixedArray, xdr_TestUnionFixedArray_clear);
typedef struct {
u_int TestUnionVariableArray_len;
TestUnion *TestUnionVariableArray_val;
} TestUnionVariableArray;
+void xdr_TestUnionVariableArray_clear(TestUnionVariableArray *objp);
+G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TestUnionVariableArray,
xdr_TestUnionVariableArray_clear);
#define TestConstDec 25
@@ -164,6 +210,8 @@ struct TestStructAllTypes {
TestUnionVariableArray tuva;
};
typedef struct TestStructAllTypes TestStructAllTypes;
+void xdr_TestStructAllTypes_clear(TestStructAllTypes *objp);
+G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TestStructAllTypes, xdr_TestStructAllTypes_clear);
extern bool_t xdr_TestEnum(XDR *, TestEnum*);
diff --git a/scripts/rpcgen/tests/test_demo.c b/scripts/rpcgen/tests/test_demo.c
index 54f48e5637..cfb4cbe146 100644
--- a/scripts/rpcgen/tests/test_demo.c
+++ b/scripts/rpcgen/tests/test_demo.c
@@ -72,13 +72,6 @@ static void test_xdr(xdrproc_t proc, void *vorig, void *vnew, const
char *testna
g_assert_cmpint(memcmp(buf, expected, actlen), ==, 0);
xdr_destroy(&xdr);
- /* Step 4: free mem from the new object only; the orig
- * was on the stack so leave untouched */
- xdrmem_create(&xdr, buf, buflen, XDR_FREE);
-
- ret = !!proc(&xdr, vnew);
- g_assert_cmpint(ret, ==, true);
-
cleanup:
xdr_destroy(&xdr);
}
@@ -96,7 +89,7 @@ static void test_struct(void)
TestStruct vorig = {
.c1 = 'a', .c2 = 'b',
};
- TestStruct vnew = {0};
+ g_auto(TestStruct) vnew = {0};
test_xdr((xdrproc_t)xdr_TestStruct, &vorig, &vnew, "struct",
false);
}
@@ -106,7 +99,7 @@ static void test_union_case(void)
TestUnion vorig = {
.type = 20, .TestUnion_u = { .i1 = 1729 },
};
- TestUnion vnew = {0};
+ g_auto(TestUnion) vnew = {0};
test_xdr((xdrproc_t)xdr_TestUnion, &vorig, &vnew, "union_case",
false);
}
@@ -116,7 +109,7 @@ static void test_union_default(void)
TestUnion vorig = {
.type = 87539319, .TestUnion_u = { .i3 = 1729 },
};
- TestUnion vnew = {0};
+ g_auto(TestUnion) vnew = {0};
test_xdr((xdrproc_t)xdr_TestUnion, &vorig, &vnew, "union_default",
false);
}
@@ -126,7 +119,7 @@ static void test_union_void_default_case(void)
TestUnionVoidDefault vorig = {
.type = 21, .TestUnionVoidDefault_u = { .i1 = 1729 },
};
- TestUnionVoidDefault vnew = {0};
+ g_auto(TestUnionVoidDefault) vnew = {0};
test_xdr((xdrproc_t)xdr_TestUnionVoidDefault, &vorig, &vnew,
"union_void_default_case", false);
}
@@ -136,7 +129,7 @@ static void test_union_void_default_default(void)
TestUnionVoidDefault vorig = {
.type = 87539319
};
- TestUnionVoidDefault vnew = {0};
+ g_auto(TestUnionVoidDefault) vnew = {0};
test_xdr((xdrproc_t)xdr_TestUnionVoidDefault, &vorig, &vnew,
"union_void_default_default", false);
}
@@ -146,7 +139,7 @@ static void test_union_no_default_case(void)
TestUnionNoDefault vorig = {
.type = 22, .TestUnionNoDefault_u = { .i1 = 1729 },
};
- TestUnionNoDefault vnew = {0};
+ g_auto(TestUnionNoDefault) vnew = {0};
test_xdr((xdrproc_t)xdr_TestUnionNoDefault, &vorig, &vnew,
"union_no_default_case", false);
}
@@ -156,7 +149,7 @@ static void test_union_no_default_default(void)
TestUnionNoDefault vorig = {
.type = 87539319,
};
- TestUnionNoDefault vnew = {0};
+ g_auto(TestUnionNoDefault) vnew = {0};
test_xdr((xdrproc_t)xdr_TestUnionNoDefault, &vorig, &vnew,
"union_no_default_default", true);
}
@@ -164,7 +157,7 @@ static void test_union_no_default_default(void)
static void test_int_scalar(void)
{
TestIntScalar vorig = 1729;
- TestIntScalar vnew = 0;
+ g_auto(TestIntScalar) vnew = 0;
test_xdr((xdrproc_t)xdr_TestIntScalar, &vorig, &vnew, "int_scalar",
false);
}
@@ -173,7 +166,7 @@ static void test_int_pointer_set(void)
{
int vorigp = 1729;
TestIntPointer vorig = &vorigp;
- TestIntPointer vnew = NULL;
+ g_auto(TestIntPointer) vnew = NULL;
test_xdr((xdrproc_t)xdr_TestIntPointer, &vorig, &vnew,
"int_pointer_set", false);
}
@@ -181,7 +174,7 @@ static void test_int_pointer_set(void)
static void test_int_pointer_null(void)
{
TestIntPointer vorig = NULL;
- TestIntPointer vnew = NULL;
+ g_auto(TestIntPointer) vnew = NULL;
test_xdr((xdrproc_t)xdr_TestIntPointer, &vorig, &vnew,
"int_pointer_null", false);
}
@@ -189,7 +182,7 @@ static void test_int_pointer_null(void)
static void test_int_fixed_array(void)
{
TestIntFixedArray vorig = { 1729, 0, 87539319 };
- TestIntFixedArray vnew = {0};
+ g_auto(TestIntFixedArray) vnew = {0};
test_xdr((xdrproc_t)xdr_TestIntFixedArray,
vorig, vnew, "int_fixed_array", false);
@@ -201,7 +194,7 @@ static void test_int_variable_array_set(void)
.TestIntVariableArray_len = 3,
.TestIntVariableArray_val = (int[]) { 1729, 0, 87539319 }
};
- TestIntVariableArray vnew = {0};
+ g_auto(TestIntVariableArray) vnew = {0};
test_xdr((xdrproc_t)xdr_TestIntVariableArray,
&vorig, &vnew, "int_variable_array_set", false);
@@ -213,7 +206,7 @@ static void test_int_variable_array_overflow(void)
.TestIntVariableArray_len = 6,
.TestIntVariableArray_val = (int[]) { 1729, 0, 87539319, 0, 1729 }
};
- TestIntVariableArray vnew = {0};
+ g_auto(TestIntVariableArray) vnew = {0};
test_xdr((xdrproc_t)xdr_TestIntVariableArray,
&vorig, &vnew, "int_variable_array_overflow", true);
@@ -225,7 +218,7 @@ static void test_int_variable_array_empty(void)
.TestIntVariableArray_len = 0,
.TestIntVariableArray_val = (int[]) {0},
};
- TestIntVariableArray vnew = {0};
+ g_auto(TestIntVariableArray) vnew = {0};
test_xdr((xdrproc_t)xdr_TestIntVariableArray,
&vorig, &vnew, "int_variable_array_empty", false);
@@ -234,7 +227,7 @@ static void test_int_variable_array_empty(void)
static void test_string_variable_array_set(void)
{
TestStringVariableArray vorig = (TestStringVariableArray) "taxis";
- TestStringVariableArray vnew = NULL;
+ g_auto(TestStringVariableArray) vnew = NULL;
test_xdr((xdrproc_t)xdr_TestStringVariableArray,
&vorig, &vnew, "string_variable_array_set", false);
@@ -243,7 +236,7 @@ static void test_string_variable_array_set(void)
static void test_string_variable_array_empty(void)
{
TestStringVariableArray vorig = (TestStringVariableArray)"";
- TestStringVariableArray vnew = NULL;
+ g_auto(TestStringVariableArray) vnew = NULL;
test_xdr((xdrproc_t)xdr_TestStringVariableArray,
&vorig, &vnew, "string_variable_array_empty", false);
@@ -252,7 +245,7 @@ static void test_string_variable_array_empty(void)
static void test_opaque_fixed_array(void)
{
TestOpaqueFixedArray vorig = { 0xca, 0xfe, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, 0x78
};
- TestOpaqueFixedArray vnew = {0};
+ g_auto(TestOpaqueFixedArray) vnew = {0};
test_xdr((xdrproc_t)xdr_TestOpaqueFixedArray, vorig, vnew,
"opaque_fixed_array", false);
}
@@ -263,7 +256,7 @@ static void test_opaque_variable_array_set(void)
.TestOpaqueVariableArray_len = 3,
.TestOpaqueVariableArray_val = (char[]) { 0xca, 0xfe, 0x12 },
};
- TestOpaqueVariableArray vnew = {0};
+ g_auto(TestOpaqueVariableArray) vnew = {0};
test_xdr((xdrproc_t)xdr_TestOpaqueVariableArray,
&vorig, &vnew, "opaque_variable_array_set", false);
@@ -278,7 +271,7 @@ static void test_opaque_variable_array_overflow(void)
0xca, 0xfe, 0x12, 0xca, 0xfe, 0x12,
},
};
- TestOpaqueVariableArray vnew = {0};
+ g_auto(TestOpaqueVariableArray) vnew = {0};
test_xdr((xdrproc_t)xdr_TestOpaqueVariableArray,
&vorig, &vnew, "opaque_variable_array_overflow", true);
@@ -290,7 +283,7 @@ static void test_opaque_variable_array_empty(void)
.TestOpaqueVariableArray_len = 0,
.TestOpaqueVariableArray_val = (char[]) {0},
};
- TestOpaqueVariableArray vnew = {0};
+ g_auto(TestOpaqueVariableArray) vnew = {0};
test_xdr((xdrproc_t)xdr_TestOpaqueVariableArray,
&vorig, &vnew, "opaque_variable_array_empty", false);
@@ -299,7 +292,7 @@ static void test_opaque_variable_array_empty(void)
static void test_enum_scalar(void)
{
TestEnumScalar vorig = TEST_ENUM_TWO;
- TestEnumScalar vnew = 0;
+ g_auto(TestEnumScalar) vnew = 0;
test_xdr((xdrproc_t)xdr_TestEnumScalar,
&vorig, &vnew, "enum_scalar", false);
@@ -309,7 +302,7 @@ static void test_enum_pointer_set(void)
{
TestEnum vorigp = TEST_ENUM_TWO;
TestEnumPointer vorig = &vorigp;
- TestEnumPointer vnew = NULL;
+ g_auto(TestEnumPointer) vnew = NULL;
test_xdr((xdrproc_t)xdr_TestEnumPointer,
&vorig, &vnew, "enum_pointer_set", false);
@@ -318,7 +311,7 @@ static void test_enum_pointer_set(void)
static void test_enum_pointer_null(void)
{
TestEnumPointer vorig = NULL;
- TestEnumPointer vnew = NULL;
+ g_auto(TestEnumPointer) vnew = NULL;
test_xdr((xdrproc_t)xdr_TestEnumPointer,
&vorig, &vnew, "enum_pointer_null", false);
@@ -331,7 +324,7 @@ static void test_enum_fixed_array(void)
TEST_ENUM_ONE, TEST_ENUM_TWO, TEST_ENUM_ONE, TEST_ENUM_TWO,
TEST_ENUM_ONE, TEST_ENUM_TWO, TEST_ENUM_ONE
};
- TestEnumFixedArray vnew = {0};
+ g_auto(TestEnumFixedArray) vnew = {0};
test_xdr((xdrproc_t)xdr_TestEnumFixedArray, vorig, vnew,
"enum_fixed_array", false);
}
@@ -344,7 +337,7 @@ static void test_enum_variable_array_set(void)
TEST_ENUM_ONE, TEST_ENUM_TWO, TEST_ENUM_ONE,
},
};
- TestEnumVariableArray vnew = {0};
+ g_auto(TestEnumVariableArray) vnew = {0};
test_xdr((xdrproc_t)xdr_TestEnumVariableArray,
&vorig, &vnew, "enum_variable_array_set", false);
@@ -361,7 +354,7 @@ static void test_enum_variable_array_overflow(void)
TEST_ENUM_ONE, TEST_ENUM_TWO, TEST_ENUM_ONE, TEST_ENUM_TWO,
}
};
- TestEnumVariableArray vnew = {0};
+ g_auto(TestEnumVariableArray) vnew = {0};
test_xdr((xdrproc_t)xdr_TestEnumVariableArray,
&vorig, &vnew, "enum_variable_array_overflow", true);
@@ -373,7 +366,7 @@ static void test_enum_variable_array_empty(void)
.TestEnumVariableArray_len = 0,
.TestEnumVariableArray_val = (TestEnum[]) {0},
};
- TestEnumVariableArray vnew = {0};
+ g_auto(TestEnumVariableArray) vnew = {0};
test_xdr((xdrproc_t)xdr_TestEnumVariableArray,
&vorig, &vnew, "enum_variable_array_empty", false);
@@ -385,7 +378,7 @@ static void test_enum_variable_array_empty(void)
static void test_struct_scalar(void)
{
TestStructScalar vorig = TEST_STRUCT_INIT;
- TestStructScalar vnew = {0};
+ g_auto(TestStructScalar) vnew = {0};
test_xdr((xdrproc_t)xdr_TestStructScalar,
&vorig, &vnew, "struct_scalar", false);
@@ -395,7 +388,7 @@ static void test_struct_pointer_set(void)
{
TestStruct vorigp = TEST_STRUCT_INIT;
TestStructPointer vorig = &vorigp;
- TestStructPointer vnew = NULL;
+ g_auto(TestStructPointer) vnew = NULL;
test_xdr((xdrproc_t)xdr_TestStructPointer,
&vorig, &vnew, "struct_pointer_set", false);
@@ -404,7 +397,7 @@ static void test_struct_pointer_set(void)
static void test_struct_pointer_null(void)
{
TestStructPointer vorig = NULL;
- TestStructPointer vnew = NULL;
+ g_auto(TestStructPointer) vnew = NULL;
test_xdr((xdrproc_t)xdr_TestStructPointer,
&vorig, &vnew, "struct_pointer_null", false);
@@ -419,7 +412,7 @@ static void test_struct_fixed_array(void)
TEST_STRUCT_INIT_ALT, TEST_STRUCT_INIT_ALT, TEST_STRUCT_INIT, TEST_STRUCT_INIT,
TEST_STRUCT_INIT_ALT
};
- TestStructFixedArray vnew = {0};
+ g_auto(TestStructFixedArray) vnew = {0};
test_xdr((xdrproc_t)xdr_TestStructFixedArray, vorig, vnew,
"struct_fixed_array", false);
}
@@ -432,7 +425,7 @@ static void test_struct_variable_array_set(void)
TEST_STRUCT_INIT, TEST_STRUCT_INIT_ALT, TEST_STRUCT_INIT_ALT,
},
};
- TestStructVariableArray vnew = {0};
+ g_auto(TestStructVariableArray) vnew = {0};
test_xdr((xdrproc_t)xdr_TestStructVariableArray,
&vorig, &vnew, "struct_variable_array_set", false);
@@ -450,7 +443,7 @@ static void test_struct_variable_array_overflow(void)
TEST_STRUCT_INIT, TEST_STRUCT_INIT, TEST_STRUCT_INIT, TEST_STRUCT_INIT,
}
};
- TestStructVariableArray vnew = {0};
+ g_auto(TestStructVariableArray) vnew = {0};
test_xdr((xdrproc_t)xdr_TestStructVariableArray,
&vorig, &vnew, "struct_variable_array_overflow", true);
@@ -462,7 +455,7 @@ static void test_struct_variable_array_empty(void)
.TestStructVariableArray_len = 0,
.TestStructVariableArray_val = (TestStruct[]) {},
};
- TestStructVariableArray vnew = {0};
+ g_auto(TestStructVariableArray) vnew = {0};
test_xdr((xdrproc_t)xdr_TestStructVariableArray,
&vorig, &vnew, "struct_variable_array_empty", false);
@@ -474,7 +467,7 @@ static void test_struct_variable_array_empty(void)
static void test_union_scalar(void)
{
TestUnionScalar vorig = TEST_UNION_INIT;
- TestUnionScalar vnew = {0};
+ g_auto(TestUnionScalar) vnew = {0};
test_xdr((xdrproc_t)xdr_TestUnionScalar,
&vorig, &vnew, "union_scalar", false);
@@ -484,7 +477,7 @@ static void test_union_pointer_set(void)
{
TestUnion vorigp = TEST_UNION_INIT;
TestUnionPointer vorig = &vorigp;
- TestUnionPointer vnew = NULL;
+ g_auto(TestUnionPointer) vnew = NULL;
test_xdr((xdrproc_t)xdr_TestUnionPointer,
&vorig, &vnew, "union_pointer_set", false);
@@ -493,7 +486,7 @@ static void test_union_pointer_set(void)
static void test_union_pointer_null(void)
{
TestUnionPointer vorig = NULL;
- TestUnionPointer vnew = NULL;
+ g_auto(TestUnionPointer) vnew = NULL;
test_xdr((xdrproc_t)xdr_TestUnionPointer,
&vorig, &vnew, "union_pointer_null", false);
@@ -508,7 +501,7 @@ static void test_union_fixed_array(void)
TEST_UNION_INIT_ALT, TEST_UNION_INIT_ALT, TEST_UNION_INIT, TEST_UNION_INIT,
TEST_UNION_INIT_ALT
};
- TestUnionFixedArray vnew = {0};
+ g_auto(TestUnionFixedArray) vnew = {0};
test_xdr((xdrproc_t)xdr_TestUnionFixedArray, vorig, vnew,
"union_fixed_array", false);
}
@@ -521,7 +514,7 @@ static void test_union_variable_array_set(void)
TEST_UNION_INIT, TEST_UNION_INIT_ALT, TEST_UNION_INIT_ALT,
},
};
- TestUnionVariableArray vnew = {0};
+ g_auto(TestUnionVariableArray) vnew = {0};
test_xdr((xdrproc_t)xdr_TestUnionVariableArray,
&vorig, &vnew, "union_variable_array_set", false);
@@ -540,7 +533,7 @@ static void test_union_variable_array_overflow(void)
TEST_UNION_INIT, TEST_UNION_INIT, TEST_UNION_INIT, TEST_UNION_INIT,
}
};
- TestUnionVariableArray vnew = {0};
+ g_auto(TestUnionVariableArray) vnew = {0};
test_xdr((xdrproc_t)xdr_TestUnionVariableArray,
&vorig, &vnew, "union_variable_array_overflow", true);
@@ -552,7 +545,7 @@ static void test_union_variable_array_empty(void)
.TestUnionVariableArray_len = 0,
.TestUnionVariableArray_val = (TestUnion[]) {},
};
- TestUnionVariableArray vnew = {0};
+ g_auto(TestUnionVariableArray) vnew = {0};
test_xdr((xdrproc_t)xdr_TestUnionVariableArray,
&vorig, &vnew, "union_variable_array_empty", false);
@@ -720,7 +713,7 @@ static void test_struct_all_types(void)
},
},
};
- TestStructAllTypes vnew = {0};
+ g_auto(TestStructAllTypes) vnew = {0};
test_xdr((xdrproc_t)xdr_TestStructAllTypes,
&vorig, &vnew, "test_struct_all_types", false);
diff --git a/scripts/rpcgen/tests/test_generator.py
b/scripts/rpcgen/tests/test_generator.py
index bc7660a6fc..6660810f41 100644
--- a/scripts/rpcgen/tests/test_generator.py
+++ b/scripts/rpcgen/tests/test_generator.py
@@ -6,6 +6,7 @@ from pathlib import Path
from rpcgen.parser import XDRParser
from rpcgen.generator import (
XDRTypeDeclarationGenerator,
+ XDRTypeImplementationGenerator,
XDRMarshallDeclarationGenerator,
XDRMarshallImplementationGenerator,
)
@@ -42,7 +43,11 @@ def test_generate_source():
parser = XDRParser(fp)
spec = parser.parse()
- got = XDRMarshallImplementationGenerator(spec).visit()
+ got = (
+ XDRTypeImplementationGenerator(spec).visit()
+ + "\n"
+ + XDRMarshallImplementationGenerator(spec).visit()
+ )
with h.open("r") as fp:
want = fp.read()
--
2.39.1