Blame SOURCES/0001-Bug-1591493-add-support-for-array-item-deletion.patch

b58af2
From 51cf76acb55aa933212c9ac78176835e1b12c7e6 Mon Sep 17 00:00:00 2001
b58af2
From: Noriko Hosoi <nhosoi@momo7.localdomain>
b58af2
Date: Fri, 25 May 2018 11:09:46 -0700
b58af2
Subject: [PATCH] Bug 1591493 - add support for array item deletion
b58af2
b58af2
Adding "void fjson_object_array_del_idx(struct fjson_object *jso, int idx)",
b58af2
which deletes the idx-th element in the array type object.
b58af2
b58af2
(cherry picked from commit e32df78fc68a4ae881681b5f845967edd6b86004 -- https://github.com/rsyslog/libfastjson)
b58af2
---
b58af2
 arraylist.c   | 16 ++++++++++++++++
b58af2
 arraylist.h   |  3 +++
b58af2
 json_object.c |  8 ++++++++
b58af2
 json_object.h |  3 +++
b58af2
 4 files changed, 30 insertions(+)
b58af2
b58af2
diff --git a/arraylist.c b/arraylist.c
b58af2
index 210b5c5..fc8dfe1 100644
b58af2
--- a/arraylist.c
b58af2
+++ b/arraylist.c
b58af2
@@ -87,6 +87,22 @@ array_list_add(struct array_list *arr, void *data)
b58af2
 	return array_list_put_idx(arr, arr->length, data);
b58af2
 }
b58af2
 
b58af2
+/*
b58af2
+ * Deleting the idx-th element in the array_list.
b58af2
+ */
b58af2
+void
b58af2
+array_list_del_idx(struct array_list *const arr, const int idx)
b58af2
+{
b58af2
+	if (idx < 0 || idx >= arr->length) {
b58af2
+		return;
b58af2
+	}
b58af2
+	if(arr->array[idx]) arr->free_fn(arr->array[idx]);
b58af2
+	if (--arr->length > idx) {
b58af2
+		memmove(arr->array + idx, arr->array + idx + 1, (arr->length - idx) * sizeof(void *));
b58af2
+	}
b58af2
+	return;
b58af2
+}
b58af2
+
b58af2
 /* work around wrong compiler message: GCC and clang do
b58af2
  * not handle sort_fn correctly if -Werror is given.
b58af2
  */
b58af2
diff --git a/arraylist.h b/arraylist.h
b58af2
index 4b0f9e8..54ddad4 100644
b58af2
--- a/arraylist.h
b58af2
+++ b/arraylist.h
b58af2
@@ -41,6 +41,9 @@ array_list_put_idx(struct array_list *al, int i, void *data);
b58af2
 extern int
b58af2
 array_list_add(struct array_list *al, void *data);
b58af2
 
b58af2
+extern void
b58af2
+array_list_del_idx(struct array_list *const arr, const int idx);
b58af2
+
b58af2
 extern int
b58af2
 array_list_length(struct array_list *al);
b58af2
 
b58af2
diff --git a/json_object.c b/json_object.c
b58af2
index 56e8df6..42e516f 100644
b58af2
--- a/json_object.c
b58af2
+++ b/json_object.c
b58af2
@@ -1053,6 +1053,14 @@ struct fjson_object* fjson_object_array_get_idx(struct fjson_object *jso,
b58af2
 	return (struct fjson_object*)array_list_get_idx(jso->o.c_array, idx);
b58af2
 }
b58af2
 
b58af2
+/*
b58af2
+ * Deleting the idx-th element in the array type object.
b58af2
+ */
b58af2
+void fjson_object_array_del_idx(struct fjson_object *jso, int idx)
b58af2
+{
b58af2
+	array_list_del_idx(jso->o.c_array, idx);
b58af2
+}
b58af2
+
b58af2
 int fjson_object_get_member_count(struct fjson_object *jso)
b58af2
 {
b58af2
 	return jso->o.c_obj.nelem;
b58af2
diff --git a/json_object.h b/json_object.h
b58af2
index 55ee177..80a2075 100644
b58af2
--- a/json_object.h
b58af2
+++ b/json_object.h
b58af2
@@ -469,6 +469,8 @@ extern int fjson_object_array_put_idx(struct fjson_object *obj, int idx,
b58af2
 extern struct fjson_object* fjson_object_array_get_idx(struct fjson_object *obj,
b58af2
 						     int idx);
b58af2
 
b58af2
+extern void fjson_object_array_del_idx(struct fjson_object *jso, int idx);
b58af2
+
b58af2
 /* fjson_bool type methods */
b58af2
 
b58af2
 /** Create a new empty fjson_object of type fjson_type_boolean
b58af2
@@ -720,6 +722,7 @@ typedef struct fjson_tokener fjson_tokener;
b58af2
 #define json_object_get_int64 fjson_object_get_int64
b58af2
 #define json_object_get_string_len fjson_object_get_string_len
b58af2
 #define json_object_get_member_count fjson_object_get_member_count
b58af2
+#define json_object_array_del_idx fjson_object_array_del_idx
b58af2
 
b58af2
 
b58af2
 #endif
b58af2
-- 
b58af2
2.14.4
b58af2