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

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