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

Laine Stump laine at laine.org
Fri Dec 7 18:16:47 UTC 2012


---
 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




More information about the libvir-list mailing list