diff options
Diffstat (limited to 'libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMainThread.c')
-rw-r--r-- | libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMainThread.c | 81 |
1 files changed, 57 insertions, 24 deletions
diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMainThread.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMainThread.c index a9da539f223..99107a1282c 100644 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMainThread.c +++ b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMainThread.c @@ -63,12 +63,10 @@ jmethodID postWindowEventID; JNIEnv *gdk_env; -#ifdef PORTABLE_NATIVE_SYNC -JavaVM *gdk_vm; -#endif - GtkWindowGroup *global_gtk_window_group; +static void init_glib_threads(JNIEnv *, jint); + double dpi_conversion_factor; static void init_dpi_conversion_factor (); @@ -78,10 +76,17 @@ static void dpi_changed_cb (GtkSettings *settings, /* * Call gtk_init. It is very important that this happen before any other * gtk calls. + * + * The portableNativeSync argument may have the values: + * 1 if the Java property gnu.classpath.awt.gtk.portable.native.sync + * is set to "true". + * 0 if it is set to "false" + * -1 if unset. */ JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkMainThread_gtkInit (JNIEnv *env, jclass clazz) +Java_gnu_java_awt_peer_gtk_GtkMainThread_gtkInit (JNIEnv *env, jclass clazz, + jint portableNativeSync) { int argc = 1; char **argv; @@ -91,23 +96,22 @@ Java_gnu_java_awt_peer_gtk_GtkMainThread_gtkInit (JNIEnv *env, jclass clazz) gtkmenuitempeer, gtktextcomponentpeer, window; NSA_INIT (env, clazz); + gdk_env = env; /* GTK requires a program's argc and argv variables, and requires that they - be valid. */ - - argv = (char **) malloc (sizeof (char *) * 2); - argv[0] = ""; + be valid. Set it up. */ + argv = (char **) g_malloc (sizeof (char *) * 2); + argv[0] = (char *) g_malloc(1); +#if 1 + strcpy(argv[0], ""); +#else /* The following is a more efficient alternative, but less intuitively + * expresses what we are trying to do. This code is only run once, so + * I'm going for intuitive. */ + argv[0][0] = '\0'; +#endif argv[1] = NULL; - /* until we have JDK 1.2 JNI, assume we have a VM with threads that - match what GLIB was compiled for */ -#ifdef PORTABLE_NATIVE_SYNC - (*env)->GetJavaVM( env, &gdk_vm ); - g_thread_init ( &g_thread_jni_functions ); - printf("called gthread init\n"); -#else - g_thread_init ( NULL ); -#endif + init_glib_threads(env, portableNativeSync); /* From GDK 2.0 onwards we have to explicitly call gdk_threads_init */ gdk_threads_init(); @@ -122,21 +126,19 @@ Java_gnu_java_awt_peer_gtk_GtkMainThread_gtkInit (JNIEnv *env, jclass clazz) we're shutting down. */ atexit (gdk_threads_enter); - gdk_env = env; gdk_event_handler_set ((GdkEventFunc)awt_event_handler, NULL, NULL); if ((homedir = getenv ("HOME"))) { - rcpath = (char *) malloc (strlen (homedir) + strlen (RC_FILE) + 2); + rcpath = (char *) g_malloc (strlen (homedir) + strlen (RC_FILE) + 2); sprintf (rcpath, "%s/%s", homedir, RC_FILE); } gtk_rc_parse ((rcpath) ? rcpath : RC_FILE); - if (rcpath) - free (rcpath); - - free (argv); + g_free (rcpath); + g_free (argv[0]); + g_free (argv); /* setup cached IDs for posting GTK events to Java */ /* gtkgenericpeer = (*env)->FindClass (env, */ @@ -204,6 +206,37 @@ Java_gnu_java_awt_peer_gtk_GtkMainThread_gtkInit (JNIEnv *env, jclass clazz) init_dpi_conversion_factor (); } + +/** Initialize GLIB's threads properly, based on the value of the + gnu.classpath.awt.gtk.portable.native.sync Java system property. If + that's unset, use the PORTABLE_NATIVE_SYNC config.h macro. (TODO: + In some release following 0.10, that config.h macro will go away.) + */ +static void +init_glib_threads(JNIEnv *env, jint portableNativeSync) +{ + if (portableNativeSync < 0) + { +#ifdef PORTABLE_NATIVE_SYNC /* Default value, if not set by the Java system + property */ + portableNativeSync = 1; +#else + portableNativeSync = 0; +#endif + } + + (*env)->GetJavaVM( env, &the_vm ); + if (portableNativeSync) + g_thread_init ( &portable_native_sync_jni_functions ); + else + g_thread_init ( NULL ); + + /* Debugging progress message; uncomment if needed: */ + /* printf("called gthread init\n"); */ +} + + + /* * Run gtk_main and block. */ |