From nobody Thu May 2 08:08:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1617971579; cv=none; d=zohomail.com; s=zohoarc; b=eGRnHmIBwzjlMANCcGGhRQTZRzh3l+BpigbPyxrXVT7oTDt3nOUn5OS6JGvsCjlVppmXDDO55Z4uhQGhsrzLgSSoIeVSk5WmVL+5kPITr99le+LsBaUGTeUVEYX6kw6kXkKUx24MFY9UgGU4EpnWDwOUfr1xL60A248YcEPnZVE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617971579; 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=87hqDAnASlVoe9FNXDx9+PAsHqJm79tqim8CGIODQ6c=; b=lygrLl8jc/8ocNYJTNhrygHP2YUQaNutzml1k+Fb5fU7Nw4GtobrEyyYqk4SLnNV+r0yZRdXHwSc+DVsVHPdcxIW1CfmYhu2g/eBQB0E/EFXfdoe2Qea18P1J9wpP+ot8F451+YjveMkcXKQ7FbLBZdufwPYoy2gcRDiUfDMsd4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1617971579816612.5306023949609; Fri, 9 Apr 2021 05:32:59 -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-453-i99hNkh7Ob67AqrrimeRDw-1; Fri, 09 Apr 2021 08:32:56 -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 A36FE107ACC7; Fri, 9 Apr 2021 12:32:50 +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 7833D5DAA5; Fri, 9 Apr 2021 12:32:50 +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 B95F455345; Fri, 9 Apr 2021 12:32:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 139CWiKb006538 for ; Fri, 9 Apr 2021 08:32:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3576918400; Fri, 9 Apr 2021 12:32:44 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id 904A9627DC for ; Fri, 9 Apr 2021 12:32:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617971578; 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=87hqDAnASlVoe9FNXDx9+PAsHqJm79tqim8CGIODQ6c=; b=NI+c+qB5ISz0d9E1kZtuYQxgozbKEGrGWvMe5ai3GJhEHnksFDo3TWokC/zpcI6gJiTTlt GnvieOh7tuVxmrKRiigxIzJ7CjtWfsqNVAEQvv6eciR0Z6geI1Pp7JcD5WLs1Wt1TpIKr5 tbpheLXgGV2JqBR1qbQB6F1+u1fzBCk= X-MC-Unique: i99hNkh7Ob67AqrrimeRDw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 1/3] virQEMUBuildCommandLineJSONArrayBitmap: Open code bitmap conversion Date: Fri, 9 Apr 2021 14:32:35 +0200 Message-Id: <21f3d18a8803013cb9a8da2882cf512fd4370f52.1617971454.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com 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 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com 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" Add a simpler algorithm converting the JSON array to bitmap so that virJSONValueGetArrayAsBitmap can be removed in next step. Signed-off-by: Peter Krempa Reviewed-by: Pavel Hrdina --- src/util/virqemu.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/util/virqemu.c b/src/util/virqemu.c index a1f57dea66..4d432651ee 100644 --- a/src/util/virqemu.c +++ b/src/util/virqemu.c @@ -28,6 +28,7 @@ #include "virqemu.h" #include "virstring.h" #include "viralloc.h" +#include "virbitmap.h" #define VIR_FROM_THIS VIR_FROM_NONE @@ -59,10 +60,19 @@ virQEMUBuildCommandLineJSONArrayBitmap(const char *key, { ssize_t pos =3D -1; ssize_t end; - g_autoptr(virBitmap) bitmap =3D NULL; + g_autoptr(virBitmap) bitmap =3D virBitmapNew(0); + size_t i; - if (virJSONValueGetArrayAsBitmap(array, &bitmap) < 0) - return -1; + for (i =3D 0; i < virJSONValueArraySize(array); i++) { + virJSONValue *member =3D virJSONValueArrayGet(array, i); + unsigned long long value; + + if (virJSONValueGetNumberUlong(member, &value) < 0) + return -1; + + if (virBitmapSetBitExpand(bitmap, value) < 0) + return -1; + } while ((pos =3D virBitmapNextSetBit(bitmap, pos)) > -1) { if ((end =3D virBitmapNextClearBit(bitmap, pos)) < 0) --=20 2.30.2 From nobody Thu May 2 08:08:54 2024 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=1617971593; cv=none; d=zohomail.com; s=zohoarc; b=GmN4c+zIl/yVhdyoiLNCJALdUzoxG2e2HDArLeSSXeH3c6tWRwjdaPfCzYup8aV5wWY5cijFGss8kWmIFuJiumLiA1oP7hvyWLDHPcelO1ar2gwSfIIjWvWwu+t0Q6cjB5t+4mpNJcQqNmOCkLBDToB3PvpuszWVUuM4c83Whkw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617971593; 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=U/9in3J+MlBOHpyfJsiEWff2YPlGxLXX6vUfT7wM05I=; b=VRNT7jvIC3V634DiYZv3tb38mkAGL6dKqKKme2NBzk9ArIubPMHgeoUOQoHXwbYr/iJMXcr93WxXamxVagOHQt2JOwp/R3Vt1XI/c3NUOrMNCSCT192kz+miqPrdmVtFddV8v0GU6sXxNUmd1TwQ0w2vgr41Uhlc3oDdYvBvszg= 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) header.from= 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 1617971593677317.0543430211186; Fri, 9 Apr 2021 05:33:13 -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-400-lCioVYxSM5qYXmaOhGh1Ww-1; Fri, 09 Apr 2021 08:33:10 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C64A9817472; Fri, 9 Apr 2021 12:33:05 +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 9EE6C60C5F; Fri, 9 Apr 2021 12:33:05 +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 5B8D75534D; Fri, 9 Apr 2021 12:33:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 139CWjqg006548 for ; Fri, 9 Apr 2021 08:32:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3C03618400; Fri, 9 Apr 2021 12:32:45 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9FDDF627DC for ; Fri, 9 Apr 2021 12:32:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617971592; 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=U/9in3J+MlBOHpyfJsiEWff2YPlGxLXX6vUfT7wM05I=; b=NLJ1MTquRUMNNG2GzMgCSaxxP3YGuJyCBJqf8y7bC26zkq4foyNfU+YxcTiluYt1KEWKoj 3BgQW7oCRsiYTIEdC01JxqNrxnf2ZSWBA0Z1HXL7uHHvlJXLz+4oodDx1Oh72bENaxyZy4 qs95nH0KCgwuAlDpt4pOh7AZ433glB8= X-MC-Unique: lCioVYxSM5qYXmaOhGh1Ww-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 2/3] util: json: Remove virJSONValueGetArrayAsBitmap Date: Fri, 9 Apr 2021 14:32:36 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com 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.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com 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" The function is not used. Signed-off-by: Peter Krempa Reviewed-by: Pavel Hrdina --- src/libvirt_private.syms | 1 - src/util/virjson.c | 51 ---------------------------------------- src/util/virjson.h | 2 -- 3 files changed, 54 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index f36400b5f6..0801728a74 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2478,7 +2478,6 @@ virJSONValueArraySteal; virJSONValueCopy; virJSONValueFree; virJSONValueFromString; -virJSONValueGetArrayAsBitmap; virJSONValueGetBoolean; virJSONValueGetNumberDouble; virJSONValueGetNumberInt; diff --git a/src/util/virjson.c b/src/util/virjson.c index 82081db870..746386c619 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -1174,57 +1174,6 @@ virJSONValueGetBoolean(virJSONValuePtr val, } -/** - * virJSONValueGetArrayAsBitmap: - * @val: JSON array to convert to bitmap - * @bitmap: New bitmap is allocated filled and returned via this argument - * - * Attempts a conversion of a JSON array to a bitmap. The members of the a= rray - * must be non-negative integers for the conversion to succeed. This funct= ion - * does not report libvirt errors so that it can be used to probe that the - * array can be represented as a bitmap. - * - * Returns 0 on success and fills @bitmap; -1 on error and @bitmap is set= to - * NULL. - */ -int -virJSONValueGetArrayAsBitmap(const virJSONValue *val, - virBitmapPtr *bitmap) -{ - virJSONValuePtr elem; - size_t i; - g_autofree unsigned long long *elems =3D NULL; - unsigned long long maxelem =3D 0; - - *bitmap =3D NULL; - - if (val->type !=3D VIR_JSON_TYPE_ARRAY) - return -1; - - elems =3D g_new0(unsigned long long, val->data.array.nvalues); - - /* first pass converts array members to numbers and finds the maximum = */ - for (i =3D 0; i < val->data.array.nvalues; i++) { - elem =3D val->data.array.values[i]; - - if (elem->type !=3D VIR_JSON_TYPE_NUMBER || - virStrToLong_ullp(elem->data.number, NULL, 10, &elems[i]) < 0) - return -1; - - if (elems[i] > maxelem) - maxelem =3D elems[i]; - } - - *bitmap =3D virBitmapNew(maxelem + 1); - - /* second pass sets the correct bits in the map */ - for (i =3D 0; i < val->data.array.nvalues; i++) - ignore_value(virBitmapSetBit(*bitmap, elems[i])); - - return 0; -} - - virJSONValuePtr virJSONValueNewArrayFromBitmap(virBitmapPtr bitmap) { diff --git a/src/util/virjson.h b/src/util/virjson.h index c22bc1fb45..1f15b23233 100644 --- a/src/util/virjson.h +++ b/src/util/virjson.h @@ -107,8 +107,6 @@ int virJSONValueGetNumberLong(virJSONValuePtr object, l= ong long *value); int virJSONValueGetNumberUlong(virJSONValuePtr object, unsigned long long = *value); int virJSONValueGetNumberDouble(virJSONValuePtr object, double *value); int virJSONValueGetBoolean(virJSONValuePtr object, bool *value); -int virJSONValueGetArrayAsBitmap(const virJSONValue *val, virBitmapPtr *bi= tmap) - ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); bool virJSONValueIsNull(virJSONValuePtr object); virJSONValuePtr virJSONValueObjectGetObject(virJSONValuePtr object, const char *key); --=20 2.30.2 From nobody Thu May 2 08:08:54 2024 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=1617971578; cv=none; d=zohomail.com; s=zohoarc; b=dbKsntV8aVbzw4X9TON+jRvbeNbaRcgfqcIQJm5fjRPOWxXq4f6INz3UUJUjyRuuZM8SDIJghYBI64q01azX0qqVetNDd9UK/wxWcPDen5xffiMWOp/fLDk+9IkXlkm2jNLi2MaaQQOlat4+MOzZUKL5Aj3ur4QHhUSJebI01mE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617971578; 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=CYpQXILWclNZh4Nb6HihrsjIuAzCa6mTDemuzMZiK1E=; b=a3rOsRoeoS8kXFi8IfeW3LyXFok+GK20+ad5KAxdIUxfeEFtGib6JeR8G5iUuPtyCUdUK33P5nU3jDCL7oyiUR1xkzQgTxRlspdh0OctmDYts4Tn4fPe7ZmeNLNGONt4NAKrHdaMyE4hh7dxDbZOH0tpq4Mp85/zSfZkyzzcTW0= 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) header.from= 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 161797157855215.319807852458553; Fri, 9 Apr 2021 05:32:58 -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-450-8V7u8a_cMnOsBJH0jT0Brw-1; Fri, 09 Apr 2021 08:32:55 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 98EEF6D4E0; Fri, 9 Apr 2021 12:32:50 +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 85FFE5C1D5; Fri, 9 Apr 2021 12:32:49 +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 7F4B755348; Fri, 9 Apr 2021 12:32:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 139CWkSw006555 for ; Fri, 9 Apr 2021 08:32:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 450CE18400; Fri, 9 Apr 2021 12:32:46 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9BC79627DC for ; Fri, 9 Apr 2021 12:32:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617971577; 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=CYpQXILWclNZh4Nb6HihrsjIuAzCa6mTDemuzMZiK1E=; b=g1zt8MHrnsEVScMIIW7+G7gwz6gs/qRTxYdgz9ASZMo/nksf25czDMpRgblO4THYOWGRmY M9ZyS0lxYyriI6tnldAI95zlDOmYbePCMgWvh8Fnd1PFpzNX2VB/xWdw3mCx0uKZJe8yA1 3TDStCSyS+KstniplaETA0nVeDKV4gA= X-MC-Unique: 8V7u8a_cMnOsBJH0jT0Brw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 3/3] util: json: Remove virJSONValueNewArrayFromBitmap Date: Fri, 9 Apr 2021 14:32:37 +0200 Message-Id: <61e0bd90df1ceb83d377901e568632656273ca94.1617971454.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com 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.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com 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" The function is used only inside of the file. We can open-code it and remove it as it's not very useful. Signed-off-by: Peter Krempa Reviewed-by: Pavel Hrdina --- src/libvirt_private.syms | 1 - src/util/virjson.c | 32 +++++++++----------------------- src/util/virjson.h | 2 -- 3 files changed, 9 insertions(+), 26 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 0801728a74..fd2d4462a6 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2492,7 +2492,6 @@ virJSONValueIsArray; virJSONValueIsNull; virJSONValueIsObject; virJSONValueNewArray; -virJSONValueNewArrayFromBitmap; virJSONValueNewBoolean; virJSONValueNewNull; virJSONValueNewNumberDouble; diff --git a/src/util/virjson.c b/src/util/virjson.c index 746386c619..0eff467ec5 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -31,6 +31,7 @@ #include "virutil.h" #include "virbuffer.h" #include "virenum.h" +#include "virbitmap.h" #if WITH_YAJL # include @@ -304,7 +305,8 @@ virJSONValueObjectAddVArgs(virJSONValuePtr obj, case 'M': case 'm': { virBitmapPtr map =3D va_arg(args, virBitmapPtr); - g_autoptr(virJSONValue) jsonMap =3D NULL; + g_autoptr(virJSONValue) jsonMap =3D virJSONValueNewArray(); + ssize_t pos =3D -1; if (!map) { if (type =3D=3D 'M') @@ -316,8 +318,12 @@ virJSONValueObjectAddVArgs(virJSONValuePtr obj, return -1; } - if (!(jsonMap =3D virJSONValueNewArrayFromBitmap(map))) - return -1; + while ((pos =3D virBitmapNextSetBit(map, pos)) > -1) { + g_autoptr(virJSONValue) newelem =3D virJSONValueNewNumberL= ong(pos); + + if (virJSONValueArrayAppend(jsonMap, &newelem) < 0) + return -1; + } if ((rc =3D virJSONValueObjectAppend(obj, key, &jsonMap)) < 0) return -1; @@ -1174,26 +1180,6 @@ virJSONValueGetBoolean(virJSONValuePtr val, } -virJSONValuePtr -virJSONValueNewArrayFromBitmap(virBitmapPtr bitmap) -{ - g_autoptr(virJSONValue) ret =3D virJSONValueNewArray(); - ssize_t pos =3D -1; - - if (!bitmap) - return g_steal_pointer(&ret); - - while ((pos =3D virBitmapNextSetBit(bitmap, pos)) > -1) { - g_autoptr(virJSONValue) newelem =3D virJSONValueNewNumberLong(pos); - - if (virJSONValueArrayAppend(ret, &newelem) < 0) - return NULL; - } - - return g_steal_pointer(&ret); -} - - bool virJSONValueIsNull(virJSONValuePtr val) { diff --git a/src/util/virjson.h b/src/util/virjson.h index 1f15b23233..3197f81f86 100644 --- a/src/util/virjson.h +++ b/src/util/virjson.h @@ -23,7 +23,6 @@ #pragma once #include "internal.h" -#include "virbitmap.h" #include "virbuffer.h" #include @@ -67,7 +66,6 @@ virJSONValuePtr virJSONValueNewBoolean(int boolean); virJSONValuePtr virJSONValueNewNull(void); virJSONValuePtr virJSONValueNewArray(void); virJSONValuePtr virJSONValueNewObject(void); -virJSONValuePtr virJSONValueNewArrayFromBitmap(virBitmapPtr bitmap); int virJSONValueObjectAppend(virJSONValuePtr object, const char *key, --=20 2.30.2