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

[libvirt] [PATCH v3 2/7] virjson: Resolve const correctness



Plenty of our virJSON*() APIs don't modify passed object. They
merely get a value stored in it. Note this fact in their
definition and enforce const correctness.

Signed-off-by: Michal Privoznik <mprivozn redhat com>
---
 src/util/virjson.c | 58 +++++++++++++++++++++++++++---------------------------
 src/util/virjson.h | 54 +++++++++++++++++++++++++-------------------------
 2 files changed, 56 insertions(+), 56 deletions(-)

diff --git a/src/util/virjson.c b/src/util/virjson.c
index ae6362b..0a595b9 100644
--- a/src/util/virjson.c
+++ b/src/util/virjson.c
@@ -735,7 +735,7 @@ virJSONValueArrayAppend(virJSONValuePtr array,
 
 
 int
-virJSONValueObjectHasKey(virJSONValuePtr object,
+virJSONValueObjectHasKey(const virJSONValue *object,
                          const char *key)
 {
     size_t i;
@@ -753,7 +753,7 @@ virJSONValueObjectHasKey(virJSONValuePtr object,
 
 
 virJSONValuePtr
-virJSONValueObjectGet(virJSONValuePtr object,
+virJSONValueObjectGet(const virJSONValue *object,
                       const char *key)
 {
     size_t i;
@@ -773,7 +773,7 @@ virJSONValueObjectGet(virJSONValuePtr object,
 /* Return the value associated with KEY within OBJECT, but return NULL
  * if the key is missing or if value is not the correct TYPE.  */
 virJSONValuePtr
-virJSONValueObjectGetByType(virJSONValuePtr object,
+virJSONValueObjectGetByType(const virJSONValue *object,
                             const char *key,
                             virJSONType type)
 {
@@ -786,7 +786,7 @@ virJSONValueObjectGetByType(virJSONValuePtr object,
 
 
 int
-virJSONValueObjectKeysNumber(virJSONValuePtr object)
+virJSONValueObjectKeysNumber(const virJSONValue *object)
 {
     if (object->type != VIR_JSON_TYPE_OBJECT)
         return -1;
@@ -796,7 +796,7 @@ virJSONValueObjectKeysNumber(virJSONValuePtr object)
 
 
 const char *
-virJSONValueObjectGetKey(virJSONValuePtr object,
+virJSONValueObjectGetKey(const virJSONValue *object,
                          unsigned int n)
 {
     if (object->type != VIR_JSON_TYPE_OBJECT)
@@ -844,7 +844,7 @@ virJSONValueObjectRemoveKey(virJSONValuePtr object,
 
 
 virJSONValuePtr
-virJSONValueObjectGetValue(virJSONValuePtr object,
+virJSONValueObjectGetValue(const virJSONValue *object,
                            unsigned int n)
 {
     if (object->type != VIR_JSON_TYPE_OBJECT)
@@ -858,7 +858,7 @@ virJSONValueObjectGetValue(virJSONValuePtr object,
 
 
 bool
-virJSONValueIsArray(virJSONValuePtr array)
+virJSONValueIsArray(const virJSONValue *array)
 {
     return array->type == VIR_JSON_TYPE_ARRAY;
 }
@@ -875,7 +875,7 @@ virJSONValueArraySize(const virJSONValue *array)
 
 
 virJSONValuePtr
-virJSONValueArrayGet(virJSONValuePtr array,
+virJSONValueArrayGet(const virJSONValue *array,
                      unsigned int element)
 {
     if (array->type != VIR_JSON_TYPE_ARRAY)
@@ -911,7 +911,7 @@ virJSONValueArraySteal(virJSONValuePtr array,
 
 
 const char *
-virJSONValueGetString(virJSONValuePtr string)
+virJSONValueGetString(const virJSONValue *string)
 {
     if (string->type != VIR_JSON_TYPE_STRING)
         return NULL;
@@ -921,7 +921,7 @@ virJSONValueGetString(virJSONValuePtr string)
 
 
 int
-virJSONValueGetNumberInt(virJSONValuePtr number,
+virJSONValueGetNumberInt(const virJSONValue *number,
                          int *value)
 {
     if (number->type != VIR_JSON_TYPE_NUMBER)
@@ -932,7 +932,7 @@ virJSONValueGetNumberInt(virJSONValuePtr number,
 
 
 int
-virJSONValueGetNumberUint(virJSONValuePtr number,
+virJSONValueGetNumberUint(const virJSONValue *number,
                           unsigned int *value)
 {
     if (number->type != VIR_JSON_TYPE_NUMBER)
@@ -943,7 +943,7 @@ virJSONValueGetNumberUint(virJSONValuePtr number,
 
 
 int
-virJSONValueGetNumberLong(virJSONValuePtr number,
+virJSONValueGetNumberLong(const virJSONValue *number,
                           long long *value)
 {
     if (number->type != VIR_JSON_TYPE_NUMBER)
@@ -954,7 +954,7 @@ virJSONValueGetNumberLong(virJSONValuePtr number,
 
 
 int
-virJSONValueGetNumberUlong(virJSONValuePtr number,
+virJSONValueGetNumberUlong(const virJSONValue *number,
                            unsigned long long *value)
 {
     if (number->type != VIR_JSON_TYPE_NUMBER)
@@ -965,7 +965,7 @@ virJSONValueGetNumberUlong(virJSONValuePtr number,
 
 
 int
-virJSONValueGetNumberDouble(virJSONValuePtr number,
+virJSONValueGetNumberDouble(const virJSONValue *number,
                             double *value)
 {
     if (number->type != VIR_JSON_TYPE_NUMBER)
@@ -976,7 +976,7 @@ virJSONValueGetNumberDouble(virJSONValuePtr number,
 
 
 int
-virJSONValueGetBoolean(virJSONValuePtr val,
+virJSONValueGetBoolean(const virJSONValue *val,
                        bool *value)
 {
     if (val->type != VIR_JSON_TYPE_BOOLEAN)
@@ -1077,14 +1077,14 @@ virJSONValueNewArrayFromBitmap(virBitmapPtr bitmap)
 
 
 bool
-virJSONValueIsNull(virJSONValuePtr val)
+virJSONValueIsNull(const virJSONValue *val)
 {
     return val->type == VIR_JSON_TYPE_NULL;
 }
 
 
 const char *
-virJSONValueObjectGetString(virJSONValuePtr object,
+virJSONValueObjectGetString(const virJSONValue *object,
                             const char *key)
 {
     virJSONValuePtr val = virJSONValueObjectGet(object, key);
@@ -1097,7 +1097,7 @@ virJSONValueObjectGetString(virJSONValuePtr object,
 
 
 int
-virJSONValueObjectGetNumberInt(virJSONValuePtr object,
+virJSONValueObjectGetNumberInt(const virJSONValue *object,
                                const char *key,
                                int *value)
 {
@@ -1111,7 +1111,7 @@ virJSONValueObjectGetNumberInt(virJSONValuePtr object,
 
 
 int
-virJSONValueObjectGetNumberUint(virJSONValuePtr object,
+virJSONValueObjectGetNumberUint(const virJSONValue *object,
                                 const char *key,
                                 unsigned int *value)
 {
@@ -1125,7 +1125,7 @@ virJSONValueObjectGetNumberUint(virJSONValuePtr object,
 
 
 int
-virJSONValueObjectGetNumberLong(virJSONValuePtr object,
+virJSONValueObjectGetNumberLong(const virJSONValue *object,
                                 const char *key,
                                 long long *value)
 {
@@ -1139,7 +1139,7 @@ virJSONValueObjectGetNumberLong(virJSONValuePtr object,
 
 
 int
-virJSONValueObjectGetNumberUlong(virJSONValuePtr object,
+virJSONValueObjectGetNumberUlong(const virJSONValue *object,
                                  const char *key,
                                  unsigned long long *value)
 {
@@ -1153,7 +1153,7 @@ virJSONValueObjectGetNumberUlong(virJSONValuePtr object,
 
 
 int
-virJSONValueObjectGetNumberDouble(virJSONValuePtr object,
+virJSONValueObjectGetNumberDouble(const virJSONValue *object,
                                   const char *key,
                                   double *value)
 {
@@ -1167,7 +1167,7 @@ virJSONValueObjectGetNumberDouble(virJSONValuePtr object,
 
 
 int
-virJSONValueObjectGetBoolean(virJSONValuePtr object,
+virJSONValueObjectGetBoolean(const virJSONValue *object,
                              const char *key,
                              bool *value)
 {
@@ -1195,7 +1195,7 @@ virJSONValueObjectGetArray(virJSONValuePtr object, const char *key)
 
 
 int
-virJSONValueObjectIsNull(virJSONValuePtr object,
+virJSONValueObjectIsNull(const virJSONValue *object,
                          const char *key)
 {
     virJSONValuePtr val = virJSONValueObjectGet(object, key);
@@ -1220,7 +1220,7 @@ virJSONValueObjectIsNull(virJSONValuePtr object,
  * during iteration and -1 on generic errors.
  */
 int
-virJSONValueObjectForeachKeyValue(virJSONValuePtr object,
+virJSONValueObjectForeachKeyValue(const virJSONValue *object,
                                   virJSONValueObjectIteratorFunc cb,
                                   void *opaque)
 {
@@ -1241,7 +1241,7 @@ virJSONValueObjectForeachKeyValue(virJSONValuePtr object,
 
 
 virJSONValuePtr
-virJSONValueCopy(virJSONValuePtr in)
+virJSONValueCopy(const virJSONValue *in)
 {
     size_t i;
     virJSONValuePtr out = NULL;
@@ -1683,7 +1683,7 @@ virJSONValueFromString(const char *jsonstring)
 
 
 static int
-virJSONValueToStringOne(virJSONValuePtr object,
+virJSONValueToStringOne(const virJSONValue *object,
                         yajl_gen g)
 {
     size_t i;
@@ -1748,7 +1748,7 @@ virJSONValueToStringOne(virJSONValuePtr object,
 
 
 char *
-virJSONValueToString(virJSONValuePtr object,
+virJSONValueToString(const virJSONValue *object,
                      bool pretty)
 {
     yajl_gen g;
@@ -1809,7 +1809,7 @@ virJSONValueFromString(const char *jsonstring ATTRIBUTE_UNUSED)
 
 
 char *
-virJSONValueToString(virJSONValuePtr object ATTRIBUTE_UNUSED,
+virJSONValueToString(const virJSONValue *object ATTRIBUTE_UNUSED,
                      bool pretty ATTRIBUTE_UNUSED)
 {
     virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
diff --git a/src/util/virjson.h b/src/util/virjson.h
index 66ed48a..133e976 100644
--- a/src/util/virjson.h
+++ b/src/util/virjson.h
@@ -108,43 +108,43 @@ virJSONValuePtr virJSONValueNewArrayFromBitmap(virBitmapPtr bitmap);
 int virJSONValueObjectAppend(virJSONValuePtr object, const char *key, virJSONValuePtr value);
 int virJSONValueArrayAppend(virJSONValuePtr object, virJSONValuePtr value);
 
-int virJSONValueObjectHasKey(virJSONValuePtr object, const char *key);
-virJSONValuePtr virJSONValueObjectGet(virJSONValuePtr object, const char *key);
-virJSONValuePtr virJSONValueObjectGetByType(virJSONValuePtr object,
+int virJSONValueObjectHasKey(const virJSONValue *object, const char *key);
+virJSONValuePtr virJSONValueObjectGet(const virJSONValue *object, const char *key);
+virJSONValuePtr virJSONValueObjectGetByType(const virJSONValue *object,
                                             const char *key, virJSONType type);
 
-bool virJSONValueIsArray(virJSONValuePtr array);
+bool virJSONValueIsArray(const virJSONValue *array);
 ssize_t virJSONValueArraySize(const virJSONValue *array);
-virJSONValuePtr virJSONValueArrayGet(virJSONValuePtr object, unsigned int element);
+virJSONValuePtr virJSONValueArrayGet(const virJSONValue *object, unsigned int element);
 virJSONValuePtr virJSONValueArraySteal(virJSONValuePtr object, unsigned int element);
 
-int virJSONValueObjectKeysNumber(virJSONValuePtr object);
-const char *virJSONValueObjectGetKey(virJSONValuePtr object, unsigned int n);
-virJSONValuePtr virJSONValueObjectGetValue(virJSONValuePtr object, unsigned int n);
+int virJSONValueObjectKeysNumber(const virJSONValue *object);
+const char *virJSONValueObjectGetKey(const virJSONValue *object, unsigned int n);
+virJSONValuePtr virJSONValueObjectGetValue(const virJSONValue *object, unsigned int n);
 
-const char *virJSONValueGetString(virJSONValuePtr object);
-int virJSONValueGetNumberInt(virJSONValuePtr object, int *value);
-int virJSONValueGetNumberUint(virJSONValuePtr object, unsigned int *value);
-int virJSONValueGetNumberLong(virJSONValuePtr object, long long *value);
-int virJSONValueGetNumberUlong(virJSONValuePtr object, unsigned long long *value);
-int virJSONValueGetNumberDouble(virJSONValuePtr object, double *value);
-int virJSONValueGetBoolean(virJSONValuePtr object, bool *value);
+const char *virJSONValueGetString(const virJSONValue *object);
+int virJSONValueGetNumberInt(const virJSONValue *object, int *value);
+int virJSONValueGetNumberUint(const virJSONValue *object, unsigned int *value);
+int virJSONValueGetNumberLong(const virJSONValue *object, long long *value);
+int virJSONValueGetNumberUlong(const virJSONValue *object, unsigned long long *value);
+int virJSONValueGetNumberDouble(const virJSONValue *object, double *value);
+int virJSONValueGetBoolean(const virJSONValue *object, bool *value);
 int virJSONValueGetArrayAsBitmap(const virJSONValue *val, virBitmapPtr *bitmap)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
-bool virJSONValueIsNull(virJSONValuePtr object);
+bool virJSONValueIsNull(const virJSONValue *object);
 virJSONValuePtr virJSONValueObjectGetObject(virJSONValuePtr object,
                                             const char *key);
 virJSONValuePtr virJSONValueObjectGetArray(virJSONValuePtr object,
                                            const char *key);
 
-const char *virJSONValueObjectGetString(virJSONValuePtr object, const char *key);
-int virJSONValueObjectGetNumberInt(virJSONValuePtr object, const char *key, int *value);
-int virJSONValueObjectGetNumberUint(virJSONValuePtr object, const char *key, unsigned int *value);
-int virJSONValueObjectGetNumberLong(virJSONValuePtr object, const char *key, long long *value);
-int virJSONValueObjectGetNumberUlong(virJSONValuePtr object, const char *key, unsigned long long *value);
-int virJSONValueObjectGetNumberDouble(virJSONValuePtr object, const char *key, double *value);
-int virJSONValueObjectGetBoolean(virJSONValuePtr object, const char *key, bool *value);
-int virJSONValueObjectIsNull(virJSONValuePtr object, const char *key);
+const char *virJSONValueObjectGetString(const virJSONValue *object, const char *key);
+int virJSONValueObjectGetNumberInt(const virJSONValue *object, const char *key, int *value);
+int virJSONValueObjectGetNumberUint(const virJSONValue *object, const char *key, unsigned int *value);
+int virJSONValueObjectGetNumberLong(const virJSONValue *object, const char *key, long long *value);
+int virJSONValueObjectGetNumberUlong(const virJSONValue *object, const char *key, unsigned long long *value);
+int virJSONValueObjectGetNumberDouble(const virJSONValue *object, const char *key, double *value);
+int virJSONValueObjectGetBoolean(const virJSONValue *object, const char *key, bool *value);
+int virJSONValueObjectIsNull(const virJSONValue *object, const char *key);
 
 int virJSONValueObjectAppendString(virJSONValuePtr object, const char *key, const char *value);
 int virJSONValueObjectAppendNumberInt(virJSONValuePtr object, const char *key, int number);
@@ -160,17 +160,17 @@ int virJSONValueObjectRemoveKey(virJSONValuePtr object, const char *key,
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
 
 virJSONValuePtr virJSONValueFromString(const char *jsonstring);
-char *virJSONValueToString(virJSONValuePtr object,
+char *virJSONValueToString(const virJSONValue *object,
                            bool pretty);
 
 typedef int (*virJSONValueObjectIteratorFunc)(const char *key,
                                               const virJSONValue *value,
                                               void *opaque);
 
-int virJSONValueObjectForeachKeyValue(virJSONValuePtr object,
+int virJSONValueObjectForeachKeyValue(const virJSONValue *object,
                                       virJSONValueObjectIteratorFunc cb,
                                       void *opaque);
 
-virJSONValuePtr virJSONValueCopy(virJSONValuePtr in);
+virJSONValuePtr virJSONValueCopy(const virJSONValue *in);
 
 #endif /* __VIR_JSON_H_ */
-- 
2.4.10


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