util: json: Make function to free JSON values in virHash universal

Move the helper that frees JSON entries put into hash tables into the
JSON module so that it does not have to be reimplemented.
This commit is contained in:
Peter Krempa 2017-03-16 10:19:32 +01:00
parent 0feebab2c4
commit 86e51d68f9
4 changed files with 11 additions and 9 deletions

View File

@ -1835,6 +1835,7 @@ virJSONValueGetNumberLong;
virJSONValueGetNumberUint;
virJSONValueGetNumberUlong;
virJSONValueGetString;
virJSONValueHashFree;
virJSONValueIsArray;
virJSONValueIsNull;
virJSONValueNewArray;

View File

@ -7488,14 +7488,6 @@ qemuMonitorJSONFillQMPSchema(size_t pos ATTRIBUTE_UNUSED,
}
static void
qemuMonitorJSONFreeSchemaEntry(void *opaque,
const void *name ATTRIBUTE_UNUSED)
{
virJSONValueFree(opaque);
}
virHashTablePtr
qemuMonitorJSONQueryQMPSchema(qemuMonitorPtr mon)
{
@ -7516,7 +7508,7 @@ qemuMonitorJSONQueryQMPSchema(qemuMonitorPtr mon)
arr = virJSONValueObjectGet(reply, "return");
if (!(schema = virHashCreate(512, qemuMonitorJSONFreeSchemaEntry)))
if (!(schema = virHashCreate(512, virJSONValueHashFree)))
goto cleanup;
if (virJSONValueArrayForeachSteal(arr, qemuMonitorJSONFillQMPSchema,

View File

@ -376,6 +376,14 @@ virJSONValueFree(virJSONValuePtr value)
}
void
virJSONValueHashFree(void *opaque,
const void *name ATTRIBUTE_UNUSED)
{
virJSONValueFree(opaque);
}
virJSONValuePtr
virJSONValueNewString(const char *data)
{

View File

@ -81,6 +81,7 @@ struct _virJSONValue {
};
void virJSONValueFree(virJSONValuePtr value);
void virJSONValueHashFree(void *opaque, const void *name);
int virJSONValueObjectCreate(virJSONValuePtr *obj, ...)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_SENTINEL;