[PATCHv3 13/17] test: use VIR_(APPEND|DELETE)_ELEMENT for qemuMonitorTest list

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 tests/qemumonitortestutils.c | 23 +++--------------------
 1 file changed, 3 insertions(+), 20 deletions(-)

diff --git a/tests/qemumonitortestutils.c b/tests/qemumonitortestutils.c
index b55d867..8dc62e4 100644
--- a/tests/qemumonitortestutils.c
+++ b/tests/qemumonitortestutils.c
@@ -135,15 +135,7 @@ static int qemuMonitorTestProcessCommandJSON(qemuMonitorTestPtr test,
         ret = qemuMonitorTestAddReponse(test,
                                         test->items[0]->response);
         qemuMonitorTestItemFree(test->items[0]);
-        if (test->nitems == 1) {
-            VIR_FREE(test->items);
-            test->nitems = 0;
-        } else {
-            memmove(test->items,
-                    test->items + 1,
-                    sizeof(test->items[0]) * (test->nitems - 1));
-            VIR_SHRINK_N(test->items, test->nitems, 1);
-        }
+        VIR_DELETE_ELEMENT(test->items, 0, test->nitems);
     }
 
 cleanup:
@@ -178,15 +170,7 @@ static int qemuMonitorTestProcessCommandText(qemuMonitorTestPtr test,
         ret = qemuMonitorTestAddReponse(test,
                                         test->items[0]->response);
         qemuMonitorTestItemFree(test->items[0]);
-        if (test->nitems == 1) {
-            VIR_FREE(test->items);
-            test->nitems = 0;
-        } else {
-            memmove(test->items,
-                    test->items + 1,
-                    sizeof(test->items[0]) * (test->nitems - 1));
-            VIR_SHRINK_N(test->items, test->nitems, 1);
-        }
+        VIR_DELETE_ELEMENT(test->items, 0, test->nitems);
     }
 
 cleanup:
@@ -405,11 +389,10 @@ qemuMonitorTestAddItem(qemuMonitorTestPtr test,
         goto no_memory;
 
     virMutexLock(&test->lock);
-    if (VIR_EXPAND_N(test->items, test->nitems, 1) < 0) {
+    if (VIR_APPEND_ELEMENT(test->items, test->nitems, &item) < 0) {
         virMutexUnlock(&test->lock);
         goto no_memory;
     }
-    test->items[test->nitems - 1] = item;
 
     virMutexUnlock(&test->lock);
 
-- 
1.7.11.7

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]