After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 710964 - Add g_hash_table_get_key_array()
Add g_hash_table_get_key_array()
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2013-10-27 15:35 UTC by Allison Karlitskaya (desrt)
Modified: 2013-10-27 16:29 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Add g_hash_table_get_key_array() (2.89 KB, patch)
2013-10-27 15:35 UTC, Allison Karlitskaya (desrt)
reviewed Details | Review
Add g_hash_table_get_keys_as_array() (3.21 KB, patch)
2013-10-27 16:25 UTC, Allison Karlitskaya (desrt)
committed Details | Review
tests: test g_hash_table_get_keys_as_array() (1.67 KB, patch)
2013-10-27 16:25 UTC, Allison Karlitskaya (desrt)
committed Details | Review

Description Allison Karlitskaya (desrt) 2013-10-27 15:35:08 UTC
After finding myself writing code to do this manually for the second
time in as many days (and having lots of memories of times past), I
think we could use this API.
Comment 1 Allison Karlitskaya (desrt) 2013-10-27 15:35:10 UTC
Created attachment 258222 [details] [review]
Add g_hash_table_get_key_array()

Returns a %NULL-terminated array of the keys of a hashtable.

In the case that the hash table has strings for keys, this is actually a
gchar**.
Comment 2 Lars Karlitski 2013-10-27 16:16:32 UTC
Review of attachment 258222 [details] [review]:

Looks good to me.

::: glib/ghash.c
@@ +1660,3 @@
+ * value of this function can be conveniently cast to (gchar **).
+ *
+ * Returns: a %NULL-terminated array containing each key from the table.

transfer-full, or a comment on how to free it

::: glib/ghash.h
@@ +122,3 @@
+GLIB_AVAILABLE_IN_2_40
+gpointer *  g_hash_table_get_key_array     (GHashTable     *hash_table,
+                                            guint          *length);

I'd prefer get_keys_as_array(). Fits better with get_keys().
Comment 3 Allison Karlitskaya (desrt) 2013-10-27 16:25:32 UTC
Created attachment 258226 [details] [review]
Add g_hash_table_get_keys_as_array()

Returns a %NULL-terminated array of the keys of a hashtable.

In the case that the hash table has strings for keys, this is actually a
gchar**.
Comment 4 Allison Karlitskaya (desrt) 2013-10-27 16:25:36 UTC
Created attachment 258227 [details] [review]
tests: test g_hash_table_get_keys_as_array()
Comment 5 Lars Karlitski 2013-10-27 16:27:10 UTC
Review of attachment 258226 [details] [review]:

Great, thanks.

::: docs/reference/glib/glib-sections.txt
@@ +2297,3 @@
 g_hash_table_get_keys
 g_hash_table_get_values
+g_hash_table_get_key_array

Change this as well please
Comment 6 Lars Karlitski 2013-10-27 16:28:52 UTC
Review of attachment 258227 [details] [review]:

Ok.
Comment 7 Allison Karlitskaya (desrt) 2013-10-27 16:29:53 UTC
Attachment 258226 [details] pushed as 2880767 - Add g_hash_table_get_keys_as_array()
Attachment 258227 [details] pushed as ba31037 - tests: test g_hash_table_get_keys_as_array()