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

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