[gjs] context: Only call JS_SetCStringsAreUTF8() once



commit 9148ed0d8a8dafffbc564bfbf387239d96007fc5
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Thu Jan 3 22:44:08 2013 -0500

    context: Only call JS_SetCStringsAreUTF8() once
    
    The JS engine mandates that this is called once, and before
    the first runtime is constructed. This is enforced by an
    assertion that's turned on in debug builds.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=691108

 gjs/context.c |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)
---
diff --git a/gjs/context.c b/gjs/context.c
index 3ebfc97..8894de6 100644
--- a/gjs/context.c
+++ b/gjs/context.c
@@ -523,6 +523,17 @@ static JSLocaleCallbacks gjs_locale_callbacks =
     gjs_locale_to_unicode
 };
 
+static void
+set_c_strings_are_utf8_if_needed (void)
+{
+    static gsize init = 0;
+    if (g_once_init_enter (&init)) {
+        gsize one = 1;
+        JS_SetCStringsAreUTF8();
+        g_once_init_leave (&init, &one);
+    }
+}
+
 static GObject*
 gjs_context_constructor (GType                  type,
                          guint                  n_construct_properties,
@@ -537,9 +548,10 @@ gjs_context_constructor (GType                  type,
                                                                          n_construct_properties,
                                                                          construct_params);
 
+    set_c_strings_are_utf8_if_needed ();
+
     js_context = GJS_CONTEXT(object);
 
-    JS_SetCStringsAreUTF8();
     js_context->runtime = JS_NewRuntime(32*1024*1024 /* max bytes */);
     if (js_context->runtime == NULL)
         gjs_fatal("Failed to create javascript runtime");



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