]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virQEMUBuildCommandLineJSONArrayBitmap: Open code bitmap conversion
authorPeter Krempa <pkrempa@redhat.com>
Thu, 8 Apr 2021 11:35:33 +0000 (13:35 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 12 Apr 2021 12:59:29 +0000 (14:59 +0200)
Add a simpler algorithm converting the JSON array to bitmap so that
virJSONValueGetArrayAsBitmap can be removed in next step.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
src/util/virqemu.c

index a1f57dea661ca2386e15d9d7a1fda7a26cabe012..4d432651eed63b24b447276599b38d169720016b 100644 (file)
@@ -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)