From b70abe38c18b0ad794f39cbecd9c80cb5ddd7f6a Mon Sep 17 00:00:00 2001 From: Tim Janik Date: Wed, 10 Jun 1998 07:32:52 +0000 Subject: [PATCH] prevent gdk_init() from segfaulting when invoked with (NULL, NULL); (this Wed Jun 10 06:25:17 1998 Tim Janik * gdk/gdk.c (gdk_init): prevent gdk_init() from segfaulting when invoked with (NULL, NULL); (this worked sometime ago). * gtk/gtktypeutils.h: * gtk/gtktypeutils.c: enum and flags type creation can now be done through gtk_type_register_enum() and gtk_type_register_flags(), which allow to specify the enum value arrays directly. the NULL terminated value arrays can be retrived through gtk_type_enum_get_values() and gtk_type_flags_get_values(); (gtk_type_children_types): new function to query derived types. --- ChangeLog | 4 ++++ ChangeLog.pre-2-0 | 4 ++++ ChangeLog.pre-2-10 | 4 ++++ ChangeLog.pre-2-2 | 4 ++++ ChangeLog.pre-2-4 | 4 ++++ ChangeLog.pre-2-6 | 4 ++++ ChangeLog.pre-2-8 | 4 ++++ gdk/gdk.c | 35 ++++++++++++++++++++++------------- gdk/x11/gdkmain-x11.c | 35 ++++++++++++++++++++++------------- gtk/gtkmain.c | 12 +++++------- gtk/gtktypeutils.c | 18 +++++++++++++++--- gtk/gtktypeutils.h | 1 + 12 files changed, 93 insertions(+), 36 deletions(-) diff --git a/ChangeLog b/ChangeLog index ccfee94940..140772a93d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,11 +1,15 @@ Wed Jun 10 06:25:17 1998 Tim Janik + * gdk/gdk.c (gdk_init): prevent gdk_init() from segfaulting when + invoked with (NULL, NULL); (this worked sometime ago). + * gtk/gtktypeutils.h: * gtk/gtktypeutils.c: enum and flags type creation can now be done through gtk_type_register_enum() and gtk_type_register_flags(), which allow to specify the enum value arrays directly. the NULL terminated value arrays can be retrived through gtk_type_enum_get_values() and gtk_type_flags_get_values(); + (gtk_type_children_types): new function to query derived types. 1998-06-09 Raja R Harinath diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index ccfee94940..140772a93d 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,11 +1,15 @@ Wed Jun 10 06:25:17 1998 Tim Janik + * gdk/gdk.c (gdk_init): prevent gdk_init() from segfaulting when + invoked with (NULL, NULL); (this worked sometime ago). + * gtk/gtktypeutils.h: * gtk/gtktypeutils.c: enum and flags type creation can now be done through gtk_type_register_enum() and gtk_type_register_flags(), which allow to specify the enum value arrays directly. the NULL terminated value arrays can be retrived through gtk_type_enum_get_values() and gtk_type_flags_get_values(); + (gtk_type_children_types): new function to query derived types. 1998-06-09 Raja R Harinath diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index ccfee94940..140772a93d 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,11 +1,15 @@ Wed Jun 10 06:25:17 1998 Tim Janik + * gdk/gdk.c (gdk_init): prevent gdk_init() from segfaulting when + invoked with (NULL, NULL); (this worked sometime ago). + * gtk/gtktypeutils.h: * gtk/gtktypeutils.c: enum and flags type creation can now be done through gtk_type_register_enum() and gtk_type_register_flags(), which allow to specify the enum value arrays directly. the NULL terminated value arrays can be retrived through gtk_type_enum_get_values() and gtk_type_flags_get_values(); + (gtk_type_children_types): new function to query derived types. 1998-06-09 Raja R Harinath diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index ccfee94940..140772a93d 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,11 +1,15 @@ Wed Jun 10 06:25:17 1998 Tim Janik + * gdk/gdk.c (gdk_init): prevent gdk_init() from segfaulting when + invoked with (NULL, NULL); (this worked sometime ago). + * gtk/gtktypeutils.h: * gtk/gtktypeutils.c: enum and flags type creation can now be done through gtk_type_register_enum() and gtk_type_register_flags(), which allow to specify the enum value arrays directly. the NULL terminated value arrays can be retrived through gtk_type_enum_get_values() and gtk_type_flags_get_values(); + (gtk_type_children_types): new function to query derived types. 1998-06-09 Raja R Harinath diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index ccfee94940..140772a93d 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,11 +1,15 @@ Wed Jun 10 06:25:17 1998 Tim Janik + * gdk/gdk.c (gdk_init): prevent gdk_init() from segfaulting when + invoked with (NULL, NULL); (this worked sometime ago). + * gtk/gtktypeutils.h: * gtk/gtktypeutils.c: enum and flags type creation can now be done through gtk_type_register_enum() and gtk_type_register_flags(), which allow to specify the enum value arrays directly. the NULL terminated value arrays can be retrived through gtk_type_enum_get_values() and gtk_type_flags_get_values(); + (gtk_type_children_types): new function to query derived types. 1998-06-09 Raja R Harinath diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index ccfee94940..140772a93d 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,11 +1,15 @@ Wed Jun 10 06:25:17 1998 Tim Janik + * gdk/gdk.c (gdk_init): prevent gdk_init() from segfaulting when + invoked with (NULL, NULL); (this worked sometime ago). + * gtk/gtktypeutils.h: * gtk/gtktypeutils.c: enum and flags type creation can now be done through gtk_type_register_enum() and gtk_type_register_flags(), which allow to specify the enum value arrays directly. the NULL terminated value arrays can be retrived through gtk_type_enum_get_values() and gtk_type_flags_get_values(); + (gtk_type_children_types): new function to query derived types. 1998-06-09 Raja R Harinath diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index ccfee94940..140772a93d 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,11 +1,15 @@ Wed Jun 10 06:25:17 1998 Tim Janik + * gdk/gdk.c (gdk_init): prevent gdk_init() from segfaulting when + invoked with (NULL, NULL); (this worked sometime ago). + * gtk/gtktypeutils.h: * gtk/gtktypeutils.c: enum and flags type creation can now be done through gtk_type_register_enum() and gtk_type_register_flags(), which allow to specify the enum value arrays directly. the NULL terminated value arrays can be retrived through gtk_type_enum_get_values() and gtk_type_flags_get_values(); + (gtk_type_children_types): new function to query derived types. 1998-06-09 Raja R Harinath diff --git a/gdk/gdk.c b/gdk/gdk.c index 6b5f4021f5..ab2604ed25 100644 --- a/gdk/gdk.c +++ b/gdk/gdk.c @@ -160,7 +160,7 @@ static void gdk_ic_cleanup (void); /* Private variable declarations */ -static int initialized = 0; /* 1 if the library is initialized, +static int gdk_initialized = 0; /* 1 if the library is initialized, * 0 otherwise. */ static int connection_number = 0; /* The file descriptor number of our @@ -268,13 +268,21 @@ gdk_init (int *argc, gint synchronize; gint i, j, k; XClassHint *class_hint; - gint argc_orig = *argc; - gchar **argv_orig; + gchar **argv_orig = NULL; + gint argc_orig = 0; - argv_orig = g_malloc ((argc_orig + 1) * sizeof (char*)); - for (i = 0; i < argc_orig; i++) - argv_orig[i] = g_strdup ((*argv)[i]); - argv_orig[argc_orig] = NULL; + if (gdk_initialized) + return; + + if (argc && argv) + { + argc_orig = *argc; + + argv_orig = g_malloc ((argc_orig + 1) * sizeof (char*)); + for (i = 0; i < argc_orig; i++) + argv_orig[i] = g_strdup ((*argv)[i]); + argv_orig[argc_orig] = NULL; + } X_GETTIMEOFDAY (&start); @@ -316,8 +324,6 @@ gdk_init (int *argc, gdk_progname = g_strdup (d + 1); else gdk_progname = g_strdup ((*argv)[0]); - GDK_NOTE (MISC, - g_print ("Gdk: progname: \"%s\"\n", gdk_progname)); } for (i = 1; i < *argc;) @@ -484,6 +490,8 @@ gdk_init (int *argc, gdk_progname = ""; } + GDK_NOTE (MISC, g_print ("Gdk: progname: \"%s\"\n", gdk_progname)); + gdk_display = XOpenDisplay (gdk_display_name); if (!gdk_display) { @@ -579,7 +587,7 @@ gdk_init (int *argc, gdk_im_open (NULL, NULL, NULL); #endif - initialized = 1; + gdk_initialized = 1; } /* @@ -3159,10 +3167,11 @@ gdk_exit_func (void) /* This is to avoid an infinite loop if a program segfaults in an atexit() handler (and yes, it does happen, especially if a program has trounced over memory too badly for even g_print to work) */ - if(in_gdk_exit_func == TRUE) return; + if (in_gdk_exit_func == TRUE) + return; in_gdk_exit_func = TRUE; - if (initialized) + if (gdk_initialized) { #ifdef USE_XIM /* cleanup IC */ @@ -3175,7 +3184,7 @@ gdk_exit_func (void) gdk_key_repeat_restore (); XCloseDisplay (gdk_display); - initialized = 0; + gdk_initialized = 0; } } diff --git a/gdk/x11/gdkmain-x11.c b/gdk/x11/gdkmain-x11.c index 6b5f4021f5..ab2604ed25 100644 --- a/gdk/x11/gdkmain-x11.c +++ b/gdk/x11/gdkmain-x11.c @@ -160,7 +160,7 @@ static void gdk_ic_cleanup (void); /* Private variable declarations */ -static int initialized = 0; /* 1 if the library is initialized, +static int gdk_initialized = 0; /* 1 if the library is initialized, * 0 otherwise. */ static int connection_number = 0; /* The file descriptor number of our @@ -268,13 +268,21 @@ gdk_init (int *argc, gint synchronize; gint i, j, k; XClassHint *class_hint; - gint argc_orig = *argc; - gchar **argv_orig; + gchar **argv_orig = NULL; + gint argc_orig = 0; - argv_orig = g_malloc ((argc_orig + 1) * sizeof (char*)); - for (i = 0; i < argc_orig; i++) - argv_orig[i] = g_strdup ((*argv)[i]); - argv_orig[argc_orig] = NULL; + if (gdk_initialized) + return; + + if (argc && argv) + { + argc_orig = *argc; + + argv_orig = g_malloc ((argc_orig + 1) * sizeof (char*)); + for (i = 0; i < argc_orig; i++) + argv_orig[i] = g_strdup ((*argv)[i]); + argv_orig[argc_orig] = NULL; + } X_GETTIMEOFDAY (&start); @@ -316,8 +324,6 @@ gdk_init (int *argc, gdk_progname = g_strdup (d + 1); else gdk_progname = g_strdup ((*argv)[0]); - GDK_NOTE (MISC, - g_print ("Gdk: progname: \"%s\"\n", gdk_progname)); } for (i = 1; i < *argc;) @@ -484,6 +490,8 @@ gdk_init (int *argc, gdk_progname = ""; } + GDK_NOTE (MISC, g_print ("Gdk: progname: \"%s\"\n", gdk_progname)); + gdk_display = XOpenDisplay (gdk_display_name); if (!gdk_display) { @@ -579,7 +587,7 @@ gdk_init (int *argc, gdk_im_open (NULL, NULL, NULL); #endif - initialized = 1; + gdk_initialized = 1; } /* @@ -3159,10 +3167,11 @@ gdk_exit_func (void) /* This is to avoid an infinite loop if a program segfaults in an atexit() handler (and yes, it does happen, especially if a program has trounced over memory too badly for even g_print to work) */ - if(in_gdk_exit_func == TRUE) return; + if (in_gdk_exit_func == TRUE) + return; in_gdk_exit_func = TRUE; - if (initialized) + if (gdk_initialized) { #ifdef USE_XIM /* cleanup IC */ @@ -3175,7 +3184,7 @@ gdk_exit_func (void) gdk_key_repeat_restore (); XCloseDisplay (gdk_display); - initialized = 0; + gdk_initialized = 0; } } diff --git a/gtk/gtkmain.c b/gtk/gtkmain.c index 02fb22ceb2..802ebce6af 100644 --- a/gtk/gtkmain.c +++ b/gtk/gtkmain.c @@ -140,7 +140,7 @@ const guint gtk_micro_version = GTK_MICRO_VERSION; static gboolean iteration_done = FALSE; static guint main_level = 0; -static gint initialized = FALSE; +static gint gtk_initialized = FALSE; static GdkEvent *next_event = NULL; static GList *current_events = NULL; @@ -231,12 +231,10 @@ void gtk_init (int *argc, char ***argv) { - static gboolean gtk_initialized = FALSE; gchar *current_locale; if (gtk_initialized) return; - gtk_initialized = TRUE; if (0) { @@ -331,7 +329,7 @@ gtk_init (int *argc, /* Check if there is a good chance the mb functions will handle things * correctly - set if either mblen("\xc0", MB_CUR_MAX) == 1 in the - * C locale, or were using X's mb functions. (-DX_LOCALE && locale != C) + * C locale, or we're using X's mb functions. (-DX_LOCALE && locale != C) */ current_locale = g_strdup (setlocale (LC_CTYPE, NULL)); @@ -371,7 +369,7 @@ gtk_init (int *argc, /* Set the 'initialized' flag. */ - initialized = TRUE; + gtk_initialized = TRUE; } void @@ -1354,9 +1352,9 @@ gtk_get_event_widget (GdkEvent *event) static void gtk_exit_func (void) { - if (initialized) + if (gtk_initialized) { - initialized = FALSE; + gtk_initialized = FALSE; gtk_preview_uninit (); } } diff --git a/gtk/gtktypeutils.c b/gtk/gtktypeutils.c index 578744ce24..02dd046913 100644 --- a/gtk/gtktypeutils.c +++ b/gtk/gtktypeutils.c @@ -368,11 +368,23 @@ gtk_type_free (GtkType type, g_free (mem); } +GList* +gtk_type_children_types (GtkType type) +{ + GtkTypeNode *node; + + LOOKUP_TYPE_NODE (node, type); + if (node) + return node->children_types; + + return NULL; +} + void gtk_type_describe_heritage (GtkType type) { GtkTypeNode *node; - gint first; + gboolean first; LOOKUP_TYPE_NODE (node, type); first = TRUE; @@ -395,8 +407,8 @@ gtk_type_describe_heritage (GtkType type) } void -gtk_type_describe_tree (GtkType type, - gint show_size) +gtk_type_describe_tree (GtkType type, + gboolean show_size) { GtkTypeNode *node; diff --git a/gtk/gtktypeutils.h b/gtk/gtktypeutils.h index 720fc9ffa7..3f390c3f43 100644 --- a/gtk/gtktypeutils.h +++ b/gtk/gtktypeutils.h @@ -197,6 +197,7 @@ GtkType gtk_type_from_name (const gchar *name); GtkType gtk_type_parent (GtkType type); gpointer gtk_type_class (GtkType type); gpointer gtk_type_parent_class (GtkType type); +GList* gtk_type_children_types (GtkType type); gpointer gtk_type_new (GtkType type); void gtk_type_free (GtkType type, gpointer mem);