[librest/wip/rishi/autocleanups: 2/7] rest-params: Add reference counting API to enable the use of g_autoptr




commit f10e36962c5d0c300db37971308c205423052d66
Author: Debarshi Ray <debarshir gnome org>
Date:   Wed Jun 2 16:54:40 2021 +0200

    rest-params: Add reference counting API to enable the use of g_autoptr
    
    The subsequent commit will use this reference counting API to define a
    cleanup function for RestParams using G_DEFINE_AUTOPTR_CLEANUP_FUNC.
    
    https://gitlab.gnome.org/GNOME/librest/-/merge_requests/5

 docs/reference/rest/rest-sections.txt |  2 ++
 rest/rest-params.c                    | 41 +++++++++++++++++++++++++++++++++++
 rest/rest-params.h                    |  3 +++
 3 files changed, 46 insertions(+)
---
diff --git a/docs/reference/rest/rest-sections.txt b/docs/reference/rest/rest-sections.txt
index ef4b3e3..9d1fead 100644
--- a/docs/reference/rest/rest-sections.txt
+++ b/docs/reference/rest/rest-sections.txt
@@ -198,6 +198,8 @@ rest_params_are_strings
 rest_params_as_string_hash_table
 rest_params_iter_init
 rest_params_iter_next
+rest_params_ref
+rest_params_unref
 </SECTION>
 
 <SECTION>
diff --git a/rest/rest-params.c b/rest/rest-params.c
index f246cc2..28efabd 100644
--- a/rest/rest-params.c
+++ b/rest/rest-params.c
@@ -241,3 +241,44 @@ rest_params_iter_next (RestParamsIter *iter, const char **name, RestParam **para
 
   return g_hash_table_iter_next ((GHashTableIter *)iter, (gpointer)name, (gpointer)param);
 }
+
+/**
+ * rest_params_ref:
+ * @params: a valid #RestParams
+ *
+ * Increase the reference count on @params.
+ *
+ * Returns: the #RestParams
+ *
+ * Since: 0.9.0
+ **/
+RestParams *
+rest_params_ref (RestParams *params)
+{
+  GHashTable *hash = (GHashTable *)params;
+
+  g_return_val_if_fail (params != NULL, NULL);
+
+  g_hash_table_ref (hash);
+
+  return params;
+}
+
+/**
+ * rest_params_unref:
+ * @params: a valid #RestParams
+ *
+ * Decrease the reference count on @params, destroying it if the
+ * reference count reaches 0.
+ *
+ * Since: 0.9.0
+ **/
+void
+rest_params_unref (RestParams *params)
+{
+  GHashTable *hash = (GHashTable *)params;
+
+  g_return_if_fail (params != NULL);
+
+  g_hash_table_unref (hash);
+}
diff --git a/rest/rest-params.h b/rest/rest-params.h
index caace9d..d35411b 100644
--- a/rest/rest-params.h
+++ b/rest/rest-params.h
@@ -48,6 +48,9 @@ GHashTable * rest_params_as_string_hash_table (RestParams *params);
 void rest_params_iter_init (RestParamsIter *iter, RestParams *params);
 gboolean rest_params_iter_next (RestParamsIter *iter, const char **name, RestParam **param);
 
+RestParams *rest_params_ref (RestParams *params);
+void rest_params_unref (RestParams *params);
+
 G_END_DECLS
 
 #endif /* _REST_PARAMS */


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