changeset 165:1b025870f242

debugging dynamic gtk2 load and gtk_init crash
author Frank Benoit <benoit@tionex.de>
date Sat, 16 Feb 2008 03:13:04 +0100
parents fb5cc45e0be6
children 38afe5c8e5b7
files dwt/internal/c/gtk.d dwt/internal/c/gtk_unix_print_2_0.d dwt/internal/gtk/OS.d dwt/widgets/Display.d
diffstat 4 files changed, 96 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/dwt/internal/c/gtk.d	Sat Feb 16 00:21:07 2008 +0100
+++ b/dwt/internal/c/gtk.d	Sat Feb 16 03:13:04 2008 +0100
@@ -1,4 +1,4 @@
-/******************************************************************************
+/******************************************************************************
     Based on the generated files from the BCD tool
     modified by: Frank Benoit <keinfarbton@googlemail.com>
 ******************************************************************************/
@@ -10,6 +10,61 @@
 public import dwt.internal.c.gdk;
 public import dwt.internal.c.glib_object;
 
+
+version=DYNLINK;
+
+version(DYNLINK){
+
+
+extern (C) int gtk_init_check(int *, char * * *);
+extern (C) char * gtk_set_locale();
+extern (C) extern uint gtk_interface_age;
+extern (C) extern uint gtk_binary_age;
+extern (C) extern uint gtk_micro_version;
+extern (C) extern uint gtk_minor_version;
+extern (C) extern uint gtk_major_version;
+
+
+    import tango.sys.SharedLib : SharedLib;
+    import tango.util.log.Trace;
+    struct Symbol{
+        char[] name;
+        void** symbol;
+    }
+}
+
+void loadLib(){
+    version(DYNLINK){
+        char[] libname = "libgtk-x11-2.0.so";
+
+        SharedLib lib = SharedLib.load( libname );
+        if( lib is null ){
+            lib = SharedLib.load( libname ~ ".0" );
+        }
+        return;
+        int loaded;
+        if ( lib !is null ) {
+            foreach( s; symbols_gtk ){
+                if( loaded >= 0 ) break;
+                try{
+                    *s.symbol = lib.getSymbol( s.name.ptr );
+                }
+                catch(Exception e){}
+                if( *s.symbol is null ){
+                    Trace.formatln( "{}: Symbol '{}' not found", libname, s.name );
+                }
+                else{
+                    loaded++;
+                }
+            }
+        } else {
+            Trace.formatln( "Could not load the library {}", libname );
+        }
+
+    }
+}
+
+
 extern(C):
 align(4):
 
@@ -7213,20 +7268,20 @@
 extern (C) void function(_GdkEvent *)gtk_main_do_event;
 extern (C) int function()gtk_events_pending;
 extern (C) void * function()gtk_get_default_language;
-extern (C) char * function()gtk_set_locale;
+//extern (C) char * function()gtk_set_locale;
 extern (C) void function()gtk_disable_setlocale;
 extern (C) void function(int)gtk_exit;
 extern (C) void * function(int)gtk_get_option_group;
 extern (C) int function(int *, char * * *, char *, _GOptionEntry *, char *, _GError * *)gtk_init_with_args;
-extern (C) int function(int *, char * * *)gtk_init_check;
+//extern (C) int function(int *, char * * *)gtk_init_check;
 extern (C) void function(int *, char * * *)gtk_init;
 extern (C) int function(int *, char * * *)gtk_parse_args;
 extern (C) char * function(uint, uint, uint)gtk_check_version;
-extern (C) extern uint* gtk_interface_age;
-extern (C) extern uint* gtk_binary_age;
-extern (C) extern uint* gtk_micro_version;
-extern (C) extern uint* gtk_minor_version;
-extern (C) extern uint* gtk_major_version;
+// extern (C) uint* gtk_interface_age;
+// extern (C) uint* gtk_binary_age;
+// extern (C) uint* gtk_micro_version;
+// extern (C) uint* gtk_minor_version;
+// extern (C) uint* gtk_major_version;
 extern (C) void function(aGtkList *)gtk_list_end_drag_selection;
 extern (C) void function(aGtkList *)gtk_list_undo_selection;
 extern (C) void function(aGtkList *, aGtkWidget *)gtk_list_toggle_row;
@@ -9650,7 +9705,7 @@
 extern (C) uint function()gtk_accel_group_get_type;
 
 
-Symbol[] symbols = [
+Symbol[] symbols_gtk = [
     { "gtk_vseparator_new",  cast(void**)& gtk_vseparator_new},
     { "gtk_vseparator_get_type",  cast(void**)& gtk_vseparator_get_type},
     { "gtk_vscale_new_with_range",  cast(void**)& gtk_vscale_new_with_range},
@@ -10621,20 +10676,20 @@
     { "gtk_main_do_event",  cast(void**)& gtk_main_do_event},
     { "gtk_events_pending",  cast(void**)& gtk_events_pending},
     { "gtk_get_default_language",  cast(void**)& gtk_get_default_language},
-    { "gtk_set_locale",  cast(void**)& gtk_set_locale},
+    //{ "gtk_set_locale",  cast(void**)& gtk_set_locale},
     { "gtk_disable_setlocale",  cast(void**)& gtk_disable_setlocale},
     { "gtk_exit",  cast(void**)& gtk_exit},
     { "gtk_get_option_group",  cast(void**)& gtk_get_option_group},
     { "gtk_init_with_args",  cast(void**)& gtk_init_with_args},
-    { "gtk_init_check",  cast(void**)& gtk_init_check},
+    //{ "gtk_init_check",  cast(void**)& gtk_init_check},
     { "gtk_init",  cast(void**)& gtk_init},
     { "gtk_parse_args",  cast(void**)& gtk_parse_args},
     { "gtk_check_version",  cast(void**)& gtk_check_version},
-    { "gtk_interface_age",  cast(void**)& gtk_interface_age},
-    { "gtk_binary_age",  cast(void**)& gtk_binary_age},
-    { "gtk_micro_version",  cast(void**)& gtk_micro_version},
-    { "gtk_minor_version",  cast(void**)& gtk_minor_version},
-    { "gtk_major_version",  cast(void**)& gtk_major_version},
+//     { "gtk_interface_age",  cast(void**)& gtk_interface_age},
+//     { "gtk_binary_age",  cast(void**)& gtk_binary_age},
+//     { "gtk_micro_version",  cast(void**)& gtk_micro_version},
+//     { "gtk_minor_version",  cast(void**)& gtk_minor_version},
+//     { "gtk_major_version",  cast(void**)& gtk_major_version},
     { "gtk_list_end_drag_selection",  cast(void**)& gtk_list_end_drag_selection},
     { "gtk_list_undo_selection",  cast(void**)& gtk_list_undo_selection},
     { "gtk_list_toggle_row",  cast(void**)& gtk_list_toggle_row},
@@ -12567,7 +12622,7 @@
     { "_gtk_container_focus_sort",  cast(void**)& _gtk_container_focus_sort},
     { "_gtk_container_dequeue_resize_handler",  cast(void**)& _gtk_container_dequeue_resize_handler},
     { "_gtk_container_child_composite_name",  cast(void**)& _gtk_container_child_composite_name},
-    { "_gtk_container_clear_resize_widgets",  cast(void**)& _gtk_container_clear_resize_widgets},
+//    { "_gtk_container_clear_resize_widgets",  cast(void**)& _gtk_container_clear_resize_widgets},
     { "_gtk_container_queue_resize",  cast(void**)& _gtk_container_queue_resize},
     { "gtk_container_forall",  cast(void**)& gtk_container_forall},
     { "gtk_container_child_get_property",  cast(void**)& gtk_container_child_get_property},
--- a/dwt/internal/c/gtk_unix_print_2_0.d	Sat Feb 16 00:21:07 2008 +0100
+++ b/dwt/internal/c/gtk_unix_print_2_0.d	Sat Feb 16 03:13:04 2008 +0100
@@ -26,8 +26,11 @@
 
         if ( lib !is null ) {
             foreach( inout s; symbols ){
-                *s.symbol = lib.getSymbol( s.name.ptr );
-                if( s.symbol is null ){
+                try{
+                    *s.symbol = lib.getSymbol( s.name.ptr );
+                }
+                catch(Exception e){}
+                if( *s.symbol is null ){
                     Trace.formatln( "{}: Symbol '{}' not found", libname, s.name );
                 }
             }
--- a/dwt/internal/gtk/OS.d	Sat Feb 16 00:21:07 2008 +0100
+++ b/dwt/internal/gtk/OS.d	Sat Feb 16 03:13:04 2008 +0100
@@ -21,6 +21,7 @@
 import tango.core.Traits;
 import tango.stdc.locale;
 import tango.stdc.posix.stdlib : realpath;
+import tango.util.log.Trace;
 
 import  dwt.internal.c.gtk,
         dwt.internal.c.gdk,
@@ -35,6 +36,8 @@
         dwt.internal.c.Xrender,
         dwt.internal.c.glib_object;
 
+//version=GTK_DYN_LINK;
+
 public alias dwt.internal.c.glib_object.GPollFD GPollFD;
 public alias dwt.internal.c.glib_object.GClosure GClosure;
 public alias dwt.internal.c.glib_object.GList GList;
@@ -602,6 +605,7 @@
     alias ParameterTupleOf!(cFunc) P;
     alias ReturnTypeOf!(cFunc) R;
     mixin("public static R " ~ NameOfFunc!(cFunc) ~ "( P p ){
+        Trace.formatln( \"OS." ~ NameOfFunc!(cFunc) ~ "()\" );
         lock.lock();
         scope(exit) lock.unlock();
         return cFunc(p);
@@ -625,14 +629,16 @@
     return (major << 16) + (minor << 8) + micro;
 }
 private int GTK_VERSION(){
-    return buildVERSION(gtk_major_version, gtk_minor_version, gtk_micro_version);
+    version( GTK_DYN_LINK ) return buildVERSION(*gtk_major_version, *gtk_minor_version, *gtk_micro_version);
+    else                    return buildVERSION( gtk_major_version,  gtk_minor_version,  gtk_micro_version);
 }
 
 public class OS : Platform {
 
     static this(){
+        dwt.internal.c.gtk.loadLib();
         if (OS.GTK_VERSION >= OS.buildVERSION (2, 10, 0)){
-            dwt.internal.c.gtk_unix_print_2_0.loadLib();
+//            dwt.internal.c.gtk_unix_print_2_0.loadLib();
         }
     }
 
@@ -1146,13 +1152,16 @@
 public static const int PictOpOver = 3;
 
     public static int gtk_major_version(){
-        return .gtk_major_version;
+        version(GTK_DYN_LINK) return *.gtk_minor_version;
+        else                  return .gtk_minor_version;
     }
     public static int gtk_minor_version(){
-        return .gtk_minor_version;
+        version(GTK_DYN_LINK) return *.gtk_minor_version;
+        else                  return .gtk_minor_version;
     }
     public static int gtk_micro_version(){
-        return .gtk_micro_version;
+        version(GTK_DYN_LINK) return *.gtk_micro_version;
+        else                  return .gtk_micro_version;
     }
     mixin ForwardGtkOsCFunc!(localeconv_decimal_point);
     mixin ForwardGtkOsCFunc!(realpath);
--- a/dwt/widgets/Display.d	Sat Feb 16 00:21:07 2008 +0100
+++ b/dwt/widgets/Display.d	Sat Feb 16 03:13:04 2008 +0100
@@ -899,13 +899,18 @@
     if (!OS.g_thread_supported ()) {
         OS.g_thread_init (null);
     }
+Stdout.formatln ("*** Display: {}", __LINE__ );
     OS.gtk_set_locale();
     int cnt = 2;
     char*[] args = [ "name".ptr, "--sync".ptr, null ];
     char** a = args.ptr;
+Stdout.formatln ("*** Display: {}", __LINE__ );
     if (!OS.gtk_init_check (&cnt, &a )) {
+    //if (!OS.gtk_init_check (null, null )) {
+Stdout.formatln ("*** Display: {}", __LINE__ );
         DWT.error (DWT.ERROR_NO_HANDLES, null, " [gtk_init_check() failed]");
     }
+Stdout.formatln ("*** Display: {}", __LINE__ );
     assert( cnt is 1 );
     if (OS.GDK_WINDOWING_X11 ()) xDisplay = cast(void*) OS.GDK_DISPLAY ();