提交 6f989485 编写于 作者: O Osier Yang

util: Use new array management macros

Like commit 94a26c7e from Eric Blake, the old fuzzy code should
be replaced by the new array management macros now.

And the type of scsi->count should be changed into "size_t", and
thus virSCSIDeviceListCount should return size_t instead, similar
for vir{PCI,USB}DeviceListCount.
上级 85600933
...@@ -1752,7 +1752,7 @@ virPCIDeviceListGet(virPCIDeviceListPtr list, ...@@ -1752,7 +1752,7 @@ virPCIDeviceListGet(virPCIDeviceListPtr list,
return list->devs[idx]; return list->devs[idx];
} }
int size_t
virPCIDeviceListCount(virPCIDeviceListPtr list) virPCIDeviceListCount(virPCIDeviceListPtr list)
{ {
return list->count; return list->count;
......
...@@ -86,7 +86,7 @@ int virPCIDeviceListAdd(virPCIDeviceListPtr list, ...@@ -86,7 +86,7 @@ int virPCIDeviceListAdd(virPCIDeviceListPtr list,
int virPCIDeviceListAddCopy(virPCIDeviceListPtr list, virPCIDevicePtr dev); int virPCIDeviceListAddCopy(virPCIDeviceListPtr list, virPCIDevicePtr dev);
virPCIDevicePtr virPCIDeviceListGet(virPCIDeviceListPtr list, virPCIDevicePtr virPCIDeviceListGet(virPCIDeviceListPtr list,
int idx); int idx);
int virPCIDeviceListCount(virPCIDeviceListPtr list); size_t virPCIDeviceListCount(virPCIDeviceListPtr list);
virPCIDevicePtr virPCIDeviceListSteal(virPCIDeviceListPtr list, virPCIDevicePtr virPCIDeviceListSteal(virPCIDeviceListPtr list,
virPCIDevicePtr dev); virPCIDevicePtr dev);
virPCIDevicePtr virPCIDeviceListStealIndex(virPCIDeviceListPtr list, virPCIDevicePtr virPCIDeviceListStealIndex(virPCIDeviceListPtr list,
......
...@@ -62,7 +62,7 @@ struct _virSCSIDevice { ...@@ -62,7 +62,7 @@ struct _virSCSIDevice {
struct _virSCSIDeviceList { struct _virSCSIDeviceList {
virObjectLockable parent; virObjectLockable parent;
unsigned int count; size_t count;
virSCSIDevicePtr *devs; virSCSIDevicePtr *devs;
}; };
...@@ -356,12 +356,7 @@ virSCSIDeviceListAdd(virSCSIDeviceListPtr list, ...@@ -356,12 +356,7 @@ virSCSIDeviceListAdd(virSCSIDeviceListPtr list,
return -1; return -1;
} }
if (VIR_REALLOC_N(list->devs, list->count + 1) < 0) return VIR_APPEND_ELEMENT(list->devs, list->count, dev);
return -1;
list->devs[list->count++] = dev;
return 0;
} }
virSCSIDevicePtr virSCSIDevicePtr
...@@ -373,7 +368,7 @@ virSCSIDeviceListGet(virSCSIDeviceListPtr list, int idx) ...@@ -373,7 +368,7 @@ virSCSIDeviceListGet(virSCSIDeviceListPtr list, int idx)
return list->devs[idx]; return list->devs[idx];
} }
int size_t
virSCSIDeviceListCount(virSCSIDeviceListPtr list) virSCSIDeviceListCount(virSCSIDeviceListPtr list)
{ {
return list->count; return list->count;
...@@ -387,25 +382,15 @@ virSCSIDeviceListSteal(virSCSIDeviceListPtr list, ...@@ -387,25 +382,15 @@ virSCSIDeviceListSteal(virSCSIDeviceListPtr list,
size_t i; size_t i;
for (i = 0; i < list->count; i++) { for (i = 0; i < list->count; i++) {
if (list->devs[i]->adapter != dev->adapter || if (list->devs[i]->adapter == dev->adapter &&
list->devs[i]->bus != dev->bus || list->devs[i]->bus == dev->bus &&
list->devs[i]->target != dev->target || list->devs[i]->target == dev->target &&
list->devs[i]->unit != dev->unit) list->devs[i]->unit == dev->unit) {
continue;
ret = list->devs[i]; ret = list->devs[i];
VIR_DELETE_ELEMENT(list->devs, i, list->count);
if (i != list->count--)
memmove(&list->devs[i],
&list->devs[i+1],
sizeof(*list->devs) * (list->count - i));
if (VIR_REALLOC_N(list->devs, list->count) < 0) {
; /* not fatal */
}
break; break;
} }
}
return ret; return ret;
} }
......
...@@ -77,7 +77,7 @@ int virSCSIDeviceListAdd(virSCSIDeviceListPtr list, ...@@ -77,7 +77,7 @@ int virSCSIDeviceListAdd(virSCSIDeviceListPtr list,
virSCSIDevicePtr dev); virSCSIDevicePtr dev);
virSCSIDevicePtr virSCSIDeviceListGet(virSCSIDeviceListPtr list, virSCSIDevicePtr virSCSIDeviceListGet(virSCSIDeviceListPtr list,
int idx); int idx);
int virSCSIDeviceListCount(virSCSIDeviceListPtr list); size_t virSCSIDeviceListCount(virSCSIDeviceListPtr list);
virSCSIDevicePtr virSCSIDeviceListSteal(virSCSIDeviceListPtr list, virSCSIDevicePtr virSCSIDeviceListSteal(virSCSIDeviceListPtr list,
virSCSIDevicePtr dev); virSCSIDevicePtr dev);
void virSCSIDeviceListDel(virSCSIDeviceListPtr list, void virSCSIDeviceListDel(virSCSIDeviceListPtr list,
......
...@@ -464,7 +464,7 @@ virUSBDeviceListGet(virUSBDeviceListPtr list, ...@@ -464,7 +464,7 @@ virUSBDeviceListGet(virUSBDeviceListPtr list,
return list->devs[idx]; return list->devs[idx];
} }
int size_t
virUSBDeviceListCount(virUSBDeviceListPtr list) virUSBDeviceListCount(virUSBDeviceListPtr list)
{ {
return list->count; return list->count;
......
...@@ -86,7 +86,7 @@ int virUSBDeviceListAdd(virUSBDeviceListPtr list, ...@@ -86,7 +86,7 @@ int virUSBDeviceListAdd(virUSBDeviceListPtr list,
virUSBDevicePtr dev); virUSBDevicePtr dev);
virUSBDevicePtr virUSBDeviceListGet(virUSBDeviceListPtr list, virUSBDevicePtr virUSBDeviceListGet(virUSBDeviceListPtr list,
int idx); int idx);
int virUSBDeviceListCount(virUSBDeviceListPtr list); size_t virUSBDeviceListCount(virUSBDeviceListPtr list);
virUSBDevicePtr virUSBDeviceListSteal(virUSBDeviceListPtr list, virUSBDevicePtr virUSBDeviceListSteal(virUSBDeviceListPtr list,
virUSBDevicePtr dev); virUSBDevicePtr dev);
void virUSBDeviceListDel(virUSBDeviceListPtr list, void virUSBDeviceListDel(virUSBDeviceListPtr list,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册