From nobody Fri Dec 19 21:49:40 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1587477049; cv=none; d=zohomail.com; s=zohoarc; b=X6EPkPaqfmJYpE+9CEP/9S1VMHDZoXh2SAfABXMHaC0z/9GXbMnteF7gHpH46bMX8P5usVuabvlboFOuP5HZOIcM7zHenqaCMgmKy7cXj32xQ+m8javr8hocdxJp/1LvzvXa1iHS1q4/g8C/t+gD2HBWSXVDoTi/br8171fjnWU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587477049; h=Content-Type:Content-Transfer-Encoding:Cc: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=Fz4vYSgB+C2QlF4WGnRfv3LKLlmZ40EIUlBGLnaFi9c=; b=kJSQfoAR6hWNvFN+CF7h/ojNa1Yr9kKkfTxIQg0SCPOjbN4cqqv2AoFeVZ+S1Z8v7huIRIWtuD7MMgirzbYvzPXxAcvV66xh7RFaWixVeNjLtecze3f9Fsbv9WodoLuW3WbkemBildmBE9u0p9pbvPjE4k0xriypuPdWcp+34vk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1587477049216321.3468379622458; Tue, 21 Apr 2020 06:50:49 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-215-CNNg2_zbMYyc99ziDhO7KQ-1; Tue, 21 Apr 2020 09:50:45 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D5040107B27E; Tue, 21 Apr 2020 13:50:39 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AE9815DA87; Tue, 21 Apr 2020 13:50:39 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 63614941B2; Tue, 21 Apr 2020 13:50:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 03LDoLVb003368 for ; Tue, 21 Apr 2020 09:50:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id F3DB92026E1C; Tue, 21 Apr 2020 13:50:20 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EF7992024517 for ; Tue, 21 Apr 2020 13:50:20 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C383F1019E14 for ; Tue, 21 Apr 2020 13:50:20 +0000 (UTC) Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-351-NuVsao1oODmNawZADhPnsA-1; Tue, 21 Apr 2020 09:50:18 -0400 Received: by mail-wm1-f66.google.com with SMTP id z6so3776589wml.2 for ; Tue, 21 Apr 2020 06:50:18 -0700 (PDT) Received: from localhost.localdomain (public-gprs377075.centertel.pl. [37.47.104.52]) by smtp.gmail.com with ESMTPSA id q10sm3981826wrv.95.2020.04.21.06.50.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Apr 2020 06:50:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587477047; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=Fz4vYSgB+C2QlF4WGnRfv3LKLlmZ40EIUlBGLnaFi9c=; b=VjwGd8zzj4Bg1lkOcMeKY4z0GSv2U1B8g064qCP1kf7yIV+dJcxIscida/PPzsRPhCF5Lx /FoJgKn/4dPM3XkySOm6+rA8GwQLJmIwl2QBXCOvEssA9ooS5lUNiKrLIoWVWOFWe0Z4O6 EmlPiPSgHofa9ivxd8iLOK6WwikGL5M= X-MC-Unique: CNNg2_zbMYyc99ziDhO7KQ-1 X-MC-Unique: NuVsao1oODmNawZADhPnsA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cXhCkeloVxO8IeSIdL0w6xNOMVQR9Wpxq+CkRA92kHI=; b=s/OAHsrc8/dtbX9ePKPvzctgIsj0J9jftht0xt3W1HyHxBONVmK0QeUuOlp33zbi40 oE4eWBXXIXXeRDtSZSt72siTQi7fUze+geNQ1KroDNl6V0Xk2cpSa7TCR7wc5qwoVvpT 14E974lfOboXjEP0SLzRqVcp5Cwpwf8/kxJxZzxAGDDJwRQe+VwFPuxGwLc7yFXHQkX8 P99DhxniG+SLEHiv8N7PxYtYX6XCO+pGx6WI6YY2vjRd6EML4lpGHeIdZ2NvYNNwyUOH WqTUUMpdm+6Zp++3gGvWnFyaBW93eqRUED2JRuTFxCGRrcA43WpqsoD9iJArIeggvLNH SJxA== X-Gm-Message-State: AGi0PuZ0ULYLFjxpnMzobwgFkDzEvuTxDbRcNxNrp5/GSU6aerbJVzcm Jx+tynsfN1Di1oeRbW5l/Pq5CnPZX6Q= X-Google-Smtp-Source: APiQypLC/lpxwpLIbO55PVnpmWJ0TmIwy1H3k0glE7b7frPFZP59xKq8skqkWO02r5K0LVKgS4PGDQ== X-Received: by 2002:a1c:148:: with SMTP id 69mr5175777wmb.181.1587477016781; Tue, 21 Apr 2020 06:50:16 -0700 (PDT) From: Rafael Fonseca To: libvir-list@redhat.com Subject: [PATCH v2 14/40] rpc: gendispatch: prepare for GObject conversion Date: Tue, 21 Apr 2020 15:48:55 +0200 Message-Id: <20200421134921.3717019-15-r4f4rfs@gmail.com> In-Reply-To: <20200421134921.3717019-1-r4f4rfs@gmail.com> References: <20200421134921.3717019-1-r4f4rfs@gmail.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 03LDoLVb003368 X-loop: libvir-list@redhat.com Cc: Rafael Fonseca X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" As we slowly convert virObject to GObject, prepare gendispatch.pl to choose the right unref implementation for each object type. Once a type has been converted, just add it to the `gobject_impl` hash. Note though that types explicitly declared should be changed directly where they are used. Signed-off-by: Rafael Fonseca --- src/rpc/gendispatch.pl | 66 +++++++++++++++++++++++++++++++----------- 1 file changed, 49 insertions(+), 17 deletions(-) diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl index 0b2ae59910..bc32246618 100755 --- a/src/rpc/gendispatch.pl +++ b/src/rpc/gendispatch.pl @@ -193,6 +193,22 @@ sub get_conn_method { return "remoteGetHypervisorConn"; } =20 +my %gobject_impl =3D ( +); + +sub use_gobject { + (my $typename =3D shift) =3D~ s/Ptr$//; + return exists($gobject_impl{$typename}); +} + +sub get_unref_method { + my $type =3D shift; + if (use_gobject($type)) { + return "g_object_unref"; + } + return "virObjectUnref"; +} + # Read the input file (usually remote_protocol.x) and form an # opinion about the name, args and return type of each RPC. my ($name, $ProcName, $id, $flags, %calls, @calls, %opts); @@ -584,6 +600,7 @@ elsif ($mode eq "server") { next } elsif ($args_member =3D~ m/^remote_nonnull_(domain|netwo= rk|network_port|storage_pool|storage_vol|interface|secret|nwfilter|nwfilter= _binding) (\S+);/) { my $type_name =3D name_to_TypeName($1); + my $unref_impl =3D get_unref_method("vir${type_name}"); =20 push(@vars_list, "vir${type_name}Ptr $2 =3D NULL"); push(@getters_list, @@ -591,9 +608,11 @@ elsif ($mode eq "server") { " goto cleanup;\n"); push(@args_list, "$2"); push(@free_list, - " virObjectUnref($2);"); + " if ($2)\n" . + " $unref_impl($2);"); } elsif ($args_member =3D~ m/^remote_nonnull_domain_(check= point|snapshot) (\S+);$/) { my $type_name =3D name_to_TypeName($1); + my $unref_impl =3D get_unref_method("virDomain${type_n= ame}"); =20 push(@vars_list, "virDomainPtr dom =3D NULL"); push(@vars_list, "virDomain${type_name}Ptr ${1} =3D NU= LL"); @@ -605,7 +624,8 @@ elsif ($mode eq "server") { " goto cleanup;\n"); push(@args_list, "$1"); push(@free_list, - " virObjectUnref($1);\n" . + " if ($1)\n" . + " $unref_impl($1);\n" . " virObjectUnref(dom);"); } elsif ($args_member =3D~ m/^(?:(?:admin|remote)_string|r= emote_uuid) (\S+)<\S+>;/) { push(@args_list, $conn_var) if !@args_list; @@ -686,6 +706,7 @@ elsif ($mode eq "server") { } } elsif ($args_member =3D~ m/^admin_nonnull_(server) (\S+)= ;/) { my $type_name =3D name_to_TypeName($1); + my $unref_impl =3D get_unref_method("virNet${type_name= }"); =20 push(@vars_list, "virNet${type_name}Ptr $2 =3D NULL"); push(@getters_list, @@ -693,9 +714,11 @@ elsif ($mode eq "server") { " goto cleanup;\n"); push(@args_list, "$2"); push(@free_list, - " virObjectUnref($2);"); + " if ($2)\n" . + " $unref_impl($2);"); } elsif ($args_member =3D~ m/^admin_nonnull_(client) (\S+)= ;/) { my $type_name =3D name_to_TypeName($1); + my $unref_impl =3D get_unref_method("virNetServer${typ= e_name}"); =20 push(@vars_list, "virNetServerPtr srv =3D NULL"); push(@vars_list, "virNetServer${type_name}Ptr $2 =3D N= ULL"); @@ -706,7 +729,9 @@ elsif ($mode eq "server") { " if (!($2 =3D get_nonnull_$1(srv, args->$2)))= \n" . " goto cleanup;\n"); push(@args_list, "$2"); - push(@free_list, " virObjectUnref($2);"); + push(@free_list, + " if ($2)\n" . + " $unref_impl($2);"); push(@free_list, " virObjectUnref(srv);"); } elsif ($args_member =3D~ m/^(\/)?\*/) { # ignore comments @@ -815,10 +840,12 @@ elsif ($mode eq "server") { $single_ret_var =3D undef; $single_ret_by_ref =3D 1; } else { + my $unref_impl =3D get_unref_method("vir${type_nam= e}"); push(@vars_list, "vir${type_name}Ptr $2 =3D NULL"); push(@ret_list, "make_nonnull_$1(&ret->$2, $2);\n"= ); push(@free_list, - " virObjectUnref($2);"); + " if ($2)\n" . + " $unref_impl($2);"); $single_ret_var =3D $2; $single_ret_by_ref =3D 0; $single_ret_check =3D " =3D=3D NULL"; @@ -929,18 +956,22 @@ elsif ($mode eq "server") { die "opaque array without insert@ annotation: = $ret_member"; } elsif ($ret_member =3D~ m/^admin_nonnull_(server|client)= (\S+);/) { my $type_name =3D name_to_TypeName($1); + my $unref_impl; =20 if ($1 eq "client") { + $unref_impl =3D get_unref_method("virNetServer${ty= pe_name}"); push(@vars_list, "virNetServer${type_name}Ptr $2 = =3D NULL"); push(@ret_list, "make_nonnull_$1(&ret->$2, $2);\n"= ); push(@ret_list, "make_nonnull_server(&ret->$2.srv,= srv);\n"); } else { + $unref_impl =3D get_unref_method("virNet${type_nam= e}"); push(@vars_list, "virNet${type_name}Ptr $2 =3D NUL= L"); push(@ret_list, "make_nonnull_$1(&ret->$2, $2);"); } =20 push(@free_list, - " virObjectUnref($2);"); + " if ($2)\n" . + " $unref_impl($2);"); $single_ret_var =3D $2; $single_ret_by_ref =3D 0; $single_ret_check =3D " =3D=3D NULL"; @@ -1245,11 +1276,12 @@ elsif ($mode eq "server") { } =20 if ($modern_ret_as_list) { - print " if (result) {\n"; - print " for (i =3D 0; i < nresults; i++)\n"; - print " virObjectUnref(result[i]);\n"; - print " }\n"; - print " VIR_FREE(result);\n"; + if (use_gobject($modern_ret_struct_name)) { + print " virGObjectListFreeCount"; + } else { + print " virObjectListFreeCount"; + } + print "(result, nresults);\n"; } =20 print " return rv;\n"; @@ -2003,12 +2035,12 @@ elsif ($mode eq "client") { print " }\n"; } if ($modern_ret_as_list) { - print " if (tmp_results) {\n"; - print " for (i =3D 0; i < ret.$single_ret_list_name= .${single_ret_list_name}_len; i++)\n"; - print " virObjectUnref(tmp_results[i]);\n"; - print " VIR_FREE(tmp_results);\n"; - print " }\n"; - print "\n"; + if (use_gobject($modern_ret_var_type)) { + print " virGObjectListFreeCount"; + } else { + print " virObjectListFreeCount"; + } + print "(tmp_results, ret.$single_ret_list_name.${single_re= t_list_name}_len);\n"; } print " xdr_free((xdrproc_t)xdr_$call->{ret}, (char *)&ret)= ;\n"; } --=20 2.25.3