hyperv: Accept const @value in hypervSetEmbeddedProperty()

The hypervSetEmbeddedProperty() function is used to update a
value for given property in a list of properties created by
hypervCreateEmbeddedParam(). The list is nothing fancy - it's a
virHashTable that has NULL as dataFree callback => the table does
not own the value. This is not that obvious since
hypervSetEmbeddedProperty() accepts a non-const pointer. This
fact makes it unnecessary hard to consume, e.g. if we wanted to
pass a stack allocated string.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Matt Coleman <matt@datto.com>
This commit is contained in:
Michal Privoznik 2020-10-19 11:55:10 +02:00
parent e257493441
commit b54b229e74
2 changed files with 21 additions and 4 deletions

View File

@ -351,10 +351,26 @@ hypervCreateEmbeddedParam(hypervPrivate *priv, hypervWmiClassInfoListPtr info)
return NULL;
}
/**
* hypervSetEmbeddedProperty:
* @table: hash table allocated earlier by hypervCreateEmbeddedParam()
* @name: name of the property
* @value: value of the property
*
* For given table of properties, set property of @name to @value.
* Please note, that the hash table does NOT become owner of the @value and
* thus caller must ensure the pointer validity.
*
* Returns: 0 on success,
* -1 otherwise.
*/
int
hypervSetEmbeddedProperty(virHashTablePtr table, const char *name, char *value)
hypervSetEmbeddedProperty(virHashTablePtr table,
const char *name,
const char *value)
{
return virHashUpdateEntry(table, name, value);
return virHashUpdateEntry(table, name, (void*) value);
}
/*

View File

@ -146,8 +146,9 @@ int hypervAddEprParam(hypervInvokeParamsListPtr params, const char *name,
virHashTablePtr hypervCreateEmbeddedParam(hypervPrivate *priv,
hypervWmiClassInfoListPtr info);
int hypervSetEmbeddedProperty(virHashTablePtr table, const char *name,
char *value);
int hypervSetEmbeddedProperty(virHashTablePtr table,
const char *name,
const char *value);
int hypervAddEmbeddedParam(hypervInvokeParamsListPtr params,
hypervPrivate *priv,