From nobody Thu Dec 18 23:01:57 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1678293614; cv=none; d=zohomail.com; s=zohoarc; b=jVuyh65fEtbEMTHjMr2gCf2jFZQqybz1HUiJL7CFDPzZE0nIqArywaMuwCIFlpFWgvDnUoObk7rk+24i66DHIrKPi/Tb+1XeIXC0NmtiOmQhZT7NdW9Jlb8Y/ZKzlo6nG5baVaFUM9PpXoJECiLyt6O2z8zVErcNbmRlbC3q94k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678293614; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=eiKZo++NdPDhiiHGyPgYZvR8g8tzeI6JHVHhg1m9T+4=; b=I4D5AYufyq1Y1Iw5wj/BlsjeNZK4L+nSjLaEXf/fD5uNA0xMzwVeB6Rukbu9cGuV9Qc0yCcaRVrFaoeEWsMdKGkt4lBmWRlKOeEw27fbP5P2YzXqZS8X325cXHPHR3TAdRkNVh9eyf9SMWjwbOBHcT9pLu23Rbl6JL4esOvf/vc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1678293614357690.8949985266769; Wed, 8 Mar 2023 08:40:14 -0800 (PST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-199-IjYUzNyONByotOo9m_Jd9Q-1; Wed, 08 Mar 2023 11:39:39 -0500 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 02A5B87AA11; Wed, 8 Mar 2023 16:39:23 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id E2337492B04; Wed, 8 Mar 2023 16:39:22 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 04AB619472DC; Wed, 8 Mar 2023 16:39:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id ACA401946A41 for ; Wed, 8 Mar 2023 16:39:19 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id A2E1A112132D; Wed, 8 Mar 2023 16:39:19 +0000 (UTC) Received: from virtlab420.virt.lab.eng.bos.redhat.com (virtlab420.virt.lab.eng.bos.redhat.com [10.19.152.148]) by smtp.corp.redhat.com (Postfix) with ESMTP id 845521121314; Wed, 8 Mar 2023 16:39:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678293613; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=eiKZo++NdPDhiiHGyPgYZvR8g8tzeI6JHVHhg1m9T+4=; b=DNbdLNLFITyyWgTuMW3uDEfmft/22LHH9iWkHcVcvDRSa4GxYIECeQfFbJXAi3BuHaqgJg 8hiCU+rCwjZeAM1MZOnO/uD9Tiq64aOAtqDP6jiWwCbzwuQIFHd1aU5pog50ZWgbWIaTnQ ZCZfha0iTnE/6orypq12tOcMN4pfxZs= X-MC-Unique: IjYUzNyONByotOo9m_Jd9Q-1 X-Original-To: libvir-list@listman.corp.redhat.com From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [PATCH 12/16] rpcgen: add g_auto function support Date: Wed, 8 Mar 2023 11:39:09 -0500 Message-Id: <20230308163913.338952-13-berrange@redhat.com> In-Reply-To: <20230308163913.338952-1-berrange@redhat.com> References: <20230308163913.338952-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1678293614882100004 This will eliminate the need to call xdr_free to clear pointers from data structures. Signed-off-by: Daniel P. Berrang=C3=A9 --- 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_abbr= eviations =3D \ ^src/(vbox/vbox_CAPI.*.h|esx/esx_vi.(c|h)|esx/esx_storage_backend_iscsi.= c)$$ =20 exclude_file_name_regexp--sc_prohibit_empty_first_line =3D \ - ^tests/vmwareverdata/fusion-5.0.3.txt$$ + ^tests/vmwareverdata/fusion-5.0.3.txt|scripts/rpcgen/tests/demo\.c$$ =20 exclude_file_name_regexp--sc_prohibit_useless_translation =3D \ ^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 =3D=3D "header": print("/* This file is auto-generated from %s */\n" % args.input, = file=3Doutfp) print("#include ", file=3Doutfp) + print('#include "internal.h"', file=3Doutfp) for h in args.header: print('#include "%s"' % h, file=3Doutfp) print("", file=3Doutfp) @@ -75,6 +77,8 @@ def main(): for h in args.header: print('#include "%s"' % h, file=3Doutfp) print("", file=3Doutfp) + generator =3D XDRTypeImplementationGenerator(spec) + print(generator.visit(), file=3Doutfp) generator =3D XDRMarshallImplementationGenerator(spec) print(generator.visit(), file=3Doutfp) elif args.mode =3D=3D "repr": diff --git a/scripts/rpcgen/rpcgen/generator.py b/scripts/rpcgen/rpcgen/gen= erator.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 =20 - def visit_definition_struct(self, obj, indent, context): - code =3D "%sstruct %s %s;\n" % ( + def generate_cleanup(self, name, indent): + code =3D "%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 =3D ( + "%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 =20 def visit_definition_union(self, obj, indent, context): - code =3D "%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 =3D ( + "%sstruct %s %s;\n" + % (indent, obj.name, self.visit_object(obj.body, indent, obj.n= ame)) + + "%stypedef struct %s %s;\n" % (indent, obj.name, obj.name) + + self.generate_cleanup(obj.name, indent) + ) return code =20 def visit_definition_typedef(self, obj, indent, context): - return "%stypedef %s;\n" % (indent, self.visit_object(obj.decl, in= dent)) + code =3D "%stypedef %s;\n" % ( + indent, + self.visit_object(obj.decl, indent), + ) + self.generate_cleanup(obj.decl.identifier, indent) + return code =20 def visit_declaration_scalar(self, obj, indent, context): return "%s %s" % (self.visit_object(obj.typ, indent), obj.identifi= er) @@ -167,6 +185,30 @@ class XDRTypeDeclarationGenerator(XDRVisitor): return code =20 =20 +class XDRTypeImplementationGenerator(XDRVisitor): + def visit_definition_enum(self, obj, indent, context): + pass + + def generate_cleanup(self, name, indent): + code =3D ( + "\n" + + "%svoid xdr_%s_clear(%s *objp)\n" % (indent, name, name) + + "%s{\n" % indent + + "%s xdr_free((xdrproc_t)xdr_%s, (char *)objp);\n" % (inde= nt, 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.nam= e, 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); =20 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); =20 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_TestUnionVoidDe= fault_clear); =20 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_TestUnionNoDefaul= t_clear); =20 typedef int TestIntScalar; +void xdr_TestIntScalar_clear(TestIntScalar *objp); +G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TestIntScalar, xdr_TestIntScalar_clear); =20 typedef int *TestIntPointer; +void xdr_TestIntPointer_clear(TestIntPointer *objp); +G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TestIntPointer, xdr_TestIntPointer_clear); =20 typedef int TestIntFixedArray[3]; +void xdr_TestIntFixedArray_clear(TestIntFixedArray *objp); +G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TestIntFixedArray, xdr_TestIntFixedArray_= clear); =20 typedef struct { u_int TestIntVariableArray_len; int *TestIntVariableArray_val; } TestIntVariableArray; +void xdr_TestIntVariableArray_clear(TestIntVariableArray *objp); +G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TestIntVariableArray, xdr_TestIntVariable= Array_clear); =20 typedef char *TestStringVariableArray; +void xdr_TestStringVariableArray_clear(TestStringVariableArray *objp); +G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TestStringVariableArray, xdr_TestStringVa= riableArray_clear); =20 typedef char TestOpaqueFixedArray[9]; +void xdr_TestOpaqueFixedArray_clear(TestOpaqueFixedArray *objp); +G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TestOpaqueFixedArray, xdr_TestOpaqueFixed= Array_clear); =20 typedef struct { u_int TestOpaqueVariableArray_len; char *TestOpaqueVariableArray_val; } TestOpaqueVariableArray; +void xdr_TestOpaqueVariableArray_clear(TestOpaqueVariableArray *objp); +G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TestOpaqueVariableArray, xdr_TestOpaqueVa= riableArray_clear); =20 typedef TestEnum TestEnumScalar; +void xdr_TestEnumScalar_clear(TestEnumScalar *objp); +G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TestEnumScalar, xdr_TestEnumScalar_clear); =20 typedef TestEnum *TestEnumPointer; +void xdr_TestEnumPointer_clear(TestEnumPointer *objp); +G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TestEnumPointer, xdr_TestEnumPointer_clea= r); =20 typedef TestEnum TestEnumFixedArray[13]; +void xdr_TestEnumFixedArray_clear(TestEnumFixedArray *objp); +G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TestEnumFixedArray, xdr_TestEnumFixedArra= y_clear); =20 typedef struct { u_int TestEnumVariableArray_len; TestEnum *TestEnumVariableArray_val; } TestEnumVariableArray; +void xdr_TestEnumVariableArray_clear(TestEnumVariableArray *objp); +G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TestEnumVariableArray, xdr_TestEnumVariab= leArray_clear); =20 typedef TestStruct TestStructScalar; +void xdr_TestStructScalar_clear(TestStructScalar *objp); +G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TestStructScalar, xdr_TestStructScalar_cl= ear); =20 typedef TestStruct *TestStructPointer; +void xdr_TestStructPointer_clear(TestStructPointer *objp); +G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TestStructPointer, xdr_TestStructPointer_= clear); =20 typedef TestStruct TestStructFixedArray[17]; +void xdr_TestStructFixedArray_clear(TestStructFixedArray *objp); +G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TestStructFixedArray, xdr_TestStructFixed= Array_clear); =20 typedef struct { u_int TestStructVariableArray_len; TestStruct *TestStructVariableArray_val; } TestStructVariableArray; +void xdr_TestStructVariableArray_clear(TestStructVariableArray *objp); +G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TestStructVariableArray, xdr_TestStructVa= riableArray_clear); =20 typedef TestUnion TestUnionScalar; +void xdr_TestUnionScalar_clear(TestUnionScalar *objp); +G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TestUnionScalar, xdr_TestUnionScalar_clea= r); =20 typedef TestUnion *TestUnionPointer; +void xdr_TestUnionPointer_clear(TestUnionPointer *objp); +G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TestUnionPointer, xdr_TestUnionPointer_cl= ear); =20 typedef TestUnion TestUnionFixedArray[21]; +void xdr_TestUnionFixedArray_clear(TestUnionFixedArray *objp); +G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TestUnionFixedArray, xdr_TestUnionFixedAr= ray_clear); =20 typedef struct { u_int TestUnionVariableArray_len; TestUnion *TestUnionVariableArray_val; } TestUnionVariableArray; +void xdr_TestUnionVariableArray_clear(TestUnionVariableArray *objp); +G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TestUnionVariableArray, xdr_TestUnionVari= ableArray_clear); =20 #define TestConstDec 25 =20 @@ -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_TestStructAllType= s_clear); =20 extern bool_t xdr_TestEnum(XDR *, TestEnum*); =20 diff --git a/scripts/rpcgen/tests/test_demo.c b/scripts/rpcgen/tests/test_d= emo.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), =3D=3D, 0); xdr_destroy(&xdr); =20 - /* 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 =3D !!proc(&xdr, vnew); - g_assert_cmpint(ret, =3D=3D, true); - cleanup: xdr_destroy(&xdr); } @@ -96,7 +89,7 @@ static void test_struct(void) TestStruct vorig =3D { .c1 =3D 'a', .c2 =3D 'b', }; - TestStruct vnew =3D {0}; + g_auto(TestStruct) vnew =3D {0}; =20 test_xdr((xdrproc_t)xdr_TestStruct, &vorig, &vnew, "struct", false); } @@ -106,7 +99,7 @@ static void test_union_case(void) TestUnion vorig =3D { .type =3D 20, .TestUnion_u =3D { .i1 =3D 1729 }, }; - TestUnion vnew =3D {0}; + g_auto(TestUnion) vnew =3D {0}; =20 test_xdr((xdrproc_t)xdr_TestUnion, &vorig, &vnew, "union_case", false); } @@ -116,7 +109,7 @@ static void test_union_default(void) TestUnion vorig =3D { .type =3D 87539319, .TestUnion_u =3D { .i3 =3D 1729 }, }; - TestUnion vnew =3D {0}; + g_auto(TestUnion) vnew =3D {0}; =20 test_xdr((xdrproc_t)xdr_TestUnion, &vorig, &vnew, "union_default", fal= se); } @@ -126,7 +119,7 @@ static void test_union_void_default_case(void) TestUnionVoidDefault vorig =3D { .type =3D 21, .TestUnionVoidDefault_u =3D { .i1 =3D 1729 }, }; - TestUnionVoidDefault vnew =3D {0}; + g_auto(TestUnionVoidDefault) vnew =3D {0}; =20 test_xdr((xdrproc_t)xdr_TestUnionVoidDefault, &vorig, &vnew, "union_vo= id_default_case", false); } @@ -136,7 +129,7 @@ static void test_union_void_default_default(void) TestUnionVoidDefault vorig =3D { .type =3D 87539319 }; - TestUnionVoidDefault vnew =3D {0}; + g_auto(TestUnionVoidDefault) vnew =3D {0}; =20 test_xdr((xdrproc_t)xdr_TestUnionVoidDefault, &vorig, &vnew, "union_vo= id_default_default", false); } @@ -146,7 +139,7 @@ static void test_union_no_default_case(void) TestUnionNoDefault vorig =3D { .type =3D 22, .TestUnionNoDefault_u =3D { .i1 =3D 1729 }, }; - TestUnionNoDefault vnew =3D {0}; + g_auto(TestUnionNoDefault) vnew =3D {0}; =20 test_xdr((xdrproc_t)xdr_TestUnionNoDefault, &vorig, &vnew, "union_no_d= efault_case", false); } @@ -156,7 +149,7 @@ static void test_union_no_default_default(void) TestUnionNoDefault vorig =3D { .type =3D 87539319, }; - TestUnionNoDefault vnew =3D {0}; + g_auto(TestUnionNoDefault) vnew =3D {0}; =20 test_xdr((xdrproc_t)xdr_TestUnionNoDefault, &vorig, &vnew, "union_no_d= efault_default", true); } @@ -164,7 +157,7 @@ static void test_union_no_default_default(void) static void test_int_scalar(void) { TestIntScalar vorig =3D 1729; - TestIntScalar vnew =3D 0; + g_auto(TestIntScalar) vnew =3D 0; =20 test_xdr((xdrproc_t)xdr_TestIntScalar, &vorig, &vnew, "int_scalar", fa= lse); } @@ -173,7 +166,7 @@ static void test_int_pointer_set(void) { int vorigp =3D 1729; TestIntPointer vorig =3D &vorigp; - TestIntPointer vnew =3D NULL; + g_auto(TestIntPointer) vnew =3D NULL; =20 test_xdr((xdrproc_t)xdr_TestIntPointer, &vorig, &vnew, "int_pointer_se= t", false); } @@ -181,7 +174,7 @@ static void test_int_pointer_set(void) static void test_int_pointer_null(void) { TestIntPointer vorig =3D NULL; - TestIntPointer vnew =3D NULL; + g_auto(TestIntPointer) vnew =3D NULL; =20 test_xdr((xdrproc_t)xdr_TestIntPointer, &vorig, &vnew, "int_pointer_nu= ll", false); } @@ -189,7 +182,7 @@ static void test_int_pointer_null(void) static void test_int_fixed_array(void) { TestIntFixedArray vorig =3D { 1729, 0, 87539319 }; - TestIntFixedArray vnew =3D {0}; + g_auto(TestIntFixedArray) vnew =3D {0}; =20 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 =3D 3, .TestIntVariableArray_val =3D (int[]) { 1729, 0, 87539319 } }; - TestIntVariableArray vnew =3D {0}; + g_auto(TestIntVariableArray) vnew =3D {0}; =20 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 =3D 6, .TestIntVariableArray_val =3D (int[]) { 1729, 0, 87539319, 0, 1729= } }; - TestIntVariableArray vnew =3D {0}; + g_auto(TestIntVariableArray) vnew =3D {0}; =20 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 =3D 0, .TestIntVariableArray_val =3D (int[]) {0}, }; - TestIntVariableArray vnew =3D {0}; + g_auto(TestIntVariableArray) vnew =3D {0}; =20 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 =3D (TestStringVariableArray) "taxis"; - TestStringVariableArray vnew =3D NULL; + g_auto(TestStringVariableArray) vnew =3D NULL; =20 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 =3D (TestStringVariableArray)""; - TestStringVariableArray vnew =3D NULL; + g_auto(TestStringVariableArray) vnew =3D NULL; =20 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 =3D { 0xca, 0xfe, 0x12, 0x23, 0x34, 0x45, 0= x56, 0x67, 0x78 }; - TestOpaqueFixedArray vnew =3D {0}; + g_auto(TestOpaqueFixedArray) vnew =3D {0}; =20 test_xdr((xdrproc_t)xdr_TestOpaqueFixedArray, vorig, vnew, "opaque_fix= ed_array", false); } @@ -263,7 +256,7 @@ static void test_opaque_variable_array_set(void) .TestOpaqueVariableArray_len =3D 3, .TestOpaqueVariableArray_val =3D (char[]) { 0xca, 0xfe, 0x12 }, }; - TestOpaqueVariableArray vnew =3D {0}; + g_auto(TestOpaqueVariableArray) vnew =3D {0}; =20 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 =3D {0}; + g_auto(TestOpaqueVariableArray) vnew =3D {0}; =20 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 =3D 0, .TestOpaqueVariableArray_val =3D (char[]) {0}, }; - TestOpaqueVariableArray vnew =3D {0}; + g_auto(TestOpaqueVariableArray) vnew =3D {0}; =20 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 =3D TEST_ENUM_TWO; - TestEnumScalar vnew =3D 0; + g_auto(TestEnumScalar) vnew =3D 0; =20 test_xdr((xdrproc_t)xdr_TestEnumScalar, &vorig, &vnew, "enum_scalar", false); @@ -309,7 +302,7 @@ static void test_enum_pointer_set(void) { TestEnum vorigp =3D TEST_ENUM_TWO; TestEnumPointer vorig =3D &vorigp; - TestEnumPointer vnew =3D NULL; + g_auto(TestEnumPointer) vnew =3D NULL; =20 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 =3D NULL; - TestEnumPointer vnew =3D NULL; + g_auto(TestEnumPointer) vnew =3D NULL; =20 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 =3D {0}; + g_auto(TestEnumFixedArray) vnew =3D {0}; =20 test_xdr((xdrproc_t)xdr_TestEnumFixedArray, vorig, vnew, "enum_fixed_a= rray", false); } @@ -344,7 +337,7 @@ static void test_enum_variable_array_set(void) TEST_ENUM_ONE, TEST_ENUM_TWO, TEST_ENUM_ONE, }, }; - TestEnumVariableArray vnew =3D {0}; + g_auto(TestEnumVariableArray) vnew =3D {0}; =20 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 =3D {0}; + g_auto(TestEnumVariableArray) vnew =3D {0}; =20 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 =3D 0, .TestEnumVariableArray_val =3D (TestEnum[]) {0}, }; - TestEnumVariableArray vnew =3D {0}; + g_auto(TestEnumVariableArray) vnew =3D {0}; =20 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 =3D TEST_STRUCT_INIT; - TestStructScalar vnew =3D {0}; + g_auto(TestStructScalar) vnew =3D {0}; =20 test_xdr((xdrproc_t)xdr_TestStructScalar, &vorig, &vnew, "struct_scalar", false); @@ -395,7 +388,7 @@ static void test_struct_pointer_set(void) { TestStruct vorigp =3D TEST_STRUCT_INIT; TestStructPointer vorig =3D &vorigp; - TestStructPointer vnew =3D NULL; + g_auto(TestStructPointer) vnew =3D NULL; =20 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 =3D NULL; - TestStructPointer vnew =3D NULL; + g_auto(TestStructPointer) vnew =3D NULL; =20 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 =3D {0}; + g_auto(TestStructFixedArray) vnew =3D {0}; =20 test_xdr((xdrproc_t)xdr_TestStructFixedArray, vorig, vnew, "struct_fix= ed_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 =3D {0}; + g_auto(TestStructVariableArray) vnew =3D {0}; =20 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_STR= UCT_INIT, } }; - TestStructVariableArray vnew =3D {0}; + g_auto(TestStructVariableArray) vnew =3D {0}; =20 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 =3D 0, .TestStructVariableArray_val =3D (TestStruct[]) {}, }; - TestStructVariableArray vnew =3D {0}; + g_auto(TestStructVariableArray) vnew =3D {0}; =20 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 =3D TEST_UNION_INIT; - TestUnionScalar vnew =3D {0}; + g_auto(TestUnionScalar) vnew =3D {0}; =20 test_xdr((xdrproc_t)xdr_TestUnionScalar, &vorig, &vnew, "union_scalar", false); @@ -484,7 +477,7 @@ static void test_union_pointer_set(void) { TestUnion vorigp =3D TEST_UNION_INIT; TestUnionPointer vorig =3D &vorigp; - TestUnionPointer vnew =3D NULL; + g_auto(TestUnionPointer) vnew =3D NULL; =20 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 =3D NULL; - TestUnionPointer vnew =3D NULL; + g_auto(TestUnionPointer) vnew =3D NULL; =20 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_UN= ION_INIT, TEST_UNION_INIT_ALT }; - TestUnionFixedArray vnew =3D {0}; + g_auto(TestUnionFixedArray) vnew =3D {0}; =20 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 =3D {0}; + g_auto(TestUnionVariableArray) vnew =3D {0}; =20 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 =3D {0}; + g_auto(TestUnionVariableArray) vnew =3D {0}; =20 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 =3D 0, .TestUnionVariableArray_val =3D (TestUnion[]) {}, }; - TestUnionVariableArray vnew =3D {0}; + g_auto(TestUnionVariableArray) vnew =3D {0}; =20 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 =3D {0}; + g_auto(TestStructAllTypes) vnew =3D {0}; =20 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 =3D XDRParser(fp) spec =3D parser.parse() =20 - got =3D XDRMarshallImplementationGenerator(spec).visit() + got =3D ( + XDRTypeImplementationGenerator(spec).visit() + + "\n" + + XDRMarshallImplementationGenerator(spec).visit() + ) =20 with h.open("r") as fp: want =3D fp.read() --=20 2.39.1