[gjs/wip/ptomato/mozjs38: 12/28] keep-alive: Remove custom hash table handling



commit 5368760f485f0057e586e49f2846afb15b0c3b5d
Author: Philip Chimento <philip endlessm com>
Date:   Tue Jan 24 13:52:12 2017 -0800

    keep-alive: Remove custom hash table handling
    
    The gjs_g_hash_table_steal_one() function was probably written before
    GHashTableIter was in the API. We can replace it by GHashTableIter and
    remove the custom API.
    
    For some reason, the custom API was causing the keep-alive finalizer to
    crash under SpiderMonkey 38.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=776966

 gi/keep-alive.cpp |    9 +++++----
 util/glib.cpp     |   49 ++-----------------------------------------------
 util/glib.h       |    3 ---
 3 files changed, 7 insertions(+), 54 deletions(-)
---
diff --git a/gi/keep-alive.cpp b/gi/keep-alive.cpp
index 488a771..6ae0255 100644
--- a/gi/keep-alive.cpp
+++ b/gi/keep-alive.cpp
@@ -87,7 +87,6 @@ keep_alive_finalize(JSFreeOp *fop,
 {
     KeepAlive *priv;
     void *key;
-    void *value;
 
     priv = (KeepAlive *) JS_GetPrivate(obj);
 
@@ -99,9 +98,11 @@ keep_alive_finalize(JSFreeOp *fop,
 
     priv->inside_finalize = true;
 
-    while (gjs_g_hash_table_steal_one(priv->children,
-                                      &key, &value)) {
-        Child *child = (Child *) value;
+    GHashTableIter iter;
+    g_hash_table_iter_init(&iter, priv->children);
+    while (g_hash_table_iter_next(&iter, &key, NULL)) {
+        g_hash_table_iter_steal(&iter);
+        Child *child = static_cast<Child *>(key);
         if (child->notify)
             (* child->notify) (child->child, child->data);
 
diff --git a/util/glib.cpp b/util/glib.cpp
index f084e7f..c33f3e6 100644
--- a/util/glib.cpp
+++ b/util/glib.cpp
@@ -21,54 +21,9 @@
  * IN THE SOFTWARE.
  */
 
-#include <string.h>
+#include <glib.h>
 
-#include "glib.h"
-
-#include <config.h>
-
-typedef struct {
-    void *key;
-    void *value;
-} StoreOneData;
-
-static gboolean
-get_first_one_predicate(void  *key,
-                        void  *value,
-                        void  *data)
-{
-    StoreOneData *sod = (StoreOneData *) data;
-
-    sod->key = key;
-    sod->value = value;
-
-    /* found it! */
-    return true;
-}
-
-bool
-gjs_g_hash_table_steal_one(GHashTable *hash,
-                           void      **key_p,
-                           void      **value_p)
-{
-    StoreOneData sod;
-
-    sod.key = NULL;
-    sod.value = NULL;
-    g_hash_table_find(hash, get_first_one_predicate, &sod);
-
-    if (sod.key == NULL)
-        return false;
-
-    if (key_p)
-        *key_p = sod.key;
-    if (value_p)
-        *value_p = sod.value;
-
-    g_hash_table_steal(hash, sod.key);
-
-    return sod.value != NULL;
-}
+#include "util/glib.h"
 
 /** gjs_g_strv_concat:
  *
diff --git a/util/glib.h b/util/glib.h
index 393cc8a..7522034 100644
--- a/util/glib.h
+++ b/util/glib.h
@@ -28,9 +28,6 @@
 
 G_BEGIN_DECLS
 
-bool     gjs_g_hash_table_steal_one  (GHashTable  *hash,
-                                      void       **key_p,
-                                      void       **value_p);
 char**   gjs_g_strv_concat           (char      ***strv_array,
                                       int          len);
 


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