From: Peter Krempa Date: Thu, 8 Apr 2021 11:35:33 +0000 (+0200) Subject: virQEMUBuildCommandLineJSONArrayBitmap: Open code bitmap conversion X-Git-Tag: v7.3.0-rc1~317 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fd8eeff117d2e1fa0edaf895f99f5320686dd81a;p=thirdparty%2Flibvirt.git virQEMUBuildCommandLineJSONArrayBitmap: Open code bitmap conversion 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 --- 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 = -1; ssize_t end; - g_autoptr(virBitmap) bitmap = NULL; + g_autoptr(virBitmap) bitmap = virBitmapNew(0); + size_t i; - if (virJSONValueGetArrayAsBitmap(array, &bitmap) < 0) - return -1; + for (i = 0; i < virJSONValueArraySize(array); i++) { + virJSONValue *member = virJSONValueArrayGet(array, i); + unsigned long long value; + + if (virJSONValueGetNumberUlong(member, &value) < 0) + return -1; + + if (virBitmapSetBitExpand(bitmap, value) < 0) + return -1; + } while ((pos = virBitmapNextSetBit(bitmap, pos)) > -1) { if ((end = virBitmapNextClearBit(bitmap, pos)) < 0)