[AD] [PATCH] Solaris Fixes and dev notes

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Attached is a patch that fixes the following issues:

1) The System V procfs calls method that Allegro was using to get the executable name was segfaulting in the method _unix_get_executable_name. Specifically, for whatever reason psinfo.pr_argv is undefined on Solaris 10. The code assumes that is not and as a result segfaults. I have instead placed a properly #ifdef'd solution at the beginning of this routine that is significantly less code, faster, and more reliable. I leave it as an exercise to someone more involved in this project to properly check psinfo before trying to access data members as an array, etc.

2) In several key cases XKeysymToString was being used to directly pass arguments to other routines, without checking the return value first. This is bad. XKeysymToString can return NULL as a value. I only fixed the places that were causing Allegro to segfault for me, not all of them. I noted that the Allegro code was already checking this in some places, but not in others. This should be addressed.

3) I was unable to compile on Solaris since there is no GFX_MODEX support available, and the #ifdef checks being used are rather pointless since I'm told the GFX_MODEX is always defined. So, they were changed to GFX_HAS_VGA instead per the recommendation of one of the other list members here.

Feedback is appreciated,
--
Shawn Walker, Software and Systems Analyst
binarycrusader@xxxxxxxxxx - http://binarycrusader.blogspot.com/
diff -ur allegro-4.2.0/examples/exscroll.c allegro-4.2.0-mine/examples/exscroll.c
--- allegro-4.2.0/examples/exscroll.c	2005-02-13 16:13:27.000000000 -0600
+++ allegro-4.2.0-mine/examples/exscroll.c	2005-06-02 17:17:23.214818000 -0500
@@ -29,7 +29,7 @@
       return 1;
    install_keyboard();
 
-   #ifdef GFX_MODEX
+   #ifdef GFX_HAS_VGA
 
       /* create a nice wide virtual screen, and split it at line 200 */
       if (set_gfx_mode(GFX_MODEX, 320, 240, 640, 240) != 0) {
diff -ur allegro-4.2.0/src/unix/usystem.c allegro-4.2.0-mine/src/unix/usystem.c
--- allegro-4.2.0/src/unix/usystem.c	2005-03-12 01:54:27.000000000 -0600
+++ allegro-4.2.0-mine/src/unix/usystem.c	2005-06-05 00:41:26.357220000 -0500
@@ -328,10 +328,20 @@
    pid_t pid;
    int len;
 
+   /* The System V way doesn't work on Solaris */
+   #if ((defined(sun) || defined(__sun__)) && defined(__svr4__))
+     s = getexecname();
+     if (s) {
+       do_uconvert (s, U_ASCII, output, U_CURRENT, size);
+       return;
+     }
+     s = NULL;
+   #endif
+
    /* We need the PID in order to query procfs */
    pid = getpid();
 
-   /* First try a Linux-like procfs */   
+   /* Try a Linux-like procfs */   
    /* get symolic link to executable from proc fs */
    sprintf (linkname, "/proc/%d/exe", pid);
    if (stat (linkname, &finfo) == 0) {
@@ -343,7 +353,7 @@
 	 return;
       }
    }
-   
+
    /* Use System V procfs calls if available */
    #ifdef ALLEGRO_HAVE_SV_PROCFS
       sprintf (linkname, "/proc/%d/exe", pid);
diff -ur allegro-4.2.0/src/x/xkeyboard.c allegro-4.2.0-mine/src/x/xkeyboard.c
--- allegro-4.2.0/src/x/xkeyboard.c	2005-03-27 15:08:08.000000000 -0600
+++ allegro-4.2.0-mine/src/x/xkeyboard.c	2005-06-05 00:27:05.176171000 -0500
@@ -346,9 +346,14 @@
    }
 
    TRACE ("Key %i missing:", i);
-   for (j = 0; j < sym_per_key; j++)
-      TRACE (" %s", XKeysymToString(
-	 keysyms[sym_per_key * (i - min_keycode) + j]));
+   for (j = 0; j < sym_per_key; j++) {
+      char *sym_str = XKeysymToString(keysyms[sym_per_key * (i - min_keycode) + j]);
+
+      if (!sym_str)
+        sym_str = empty_string; // XKeysymToString can return NULL
+
+      TRACE (" %s", sym_str);
+   }
    TRACE (" - assigned to %i.\n", _xwin.keycode_to_scancode[i]);
 
    return _xwin.keycode_to_scancode[i];
@@ -532,9 +537,19 @@
    for (i = min_keycode; i <= max_keycode; i++) {
       KeySym sym = keysyms[sym_per_key * (i - min_keycode)];
       KeySym sym2 =  keysyms[sym_per_key * (i - min_keycode) + 1];
+      char *sym_str;
+      char *sym2_str;
       int allegro_key = 0;
 
-      TRACE ("key [%i: %s %s]", i, XKeysymToString(sym), XKeysymToString(sym2));
+      sym_str = XKeysymToString(sym);
+      if (!sym_str)
+        sym_str = empty_string; // XKeysymToString can return NULL
+
+      sym2_str = XKeysymToString(sym2);
+      if (!sym2_str)
+        sym2_str = empty_string; // XKeysymToString can return NULL
+
+      TRACE ("key [%i: %s %s]", i, sym_str, sym2_str);
 
       /* Hack for French keyboards, to correctly map KEY_0 to KEY_9. */
       if (sym2 >= XK_0 && sym2 <= XK_9)
@@ -590,7 +605,12 @@
       for (j = 0; j < xmodmap->max_keypermod; j++) {
 	 KeySym sym = XKeycodeToKeysym(_xwin.display,
 	    xmodmap->modifiermap[i * xmodmap->max_keypermod + j], 0);
-	 TRACE (" %s", XKeysymToString(sym));
+         char *sym_str = XKeysymToString(sym);
+
+         if (!sym_str)
+           sym_str = empty_string; // XKeysymToString can return NULL
+
+	 TRACE (" %s", sym_str);
       }
       TRACE ("\n");
    }
diff -ur allegro-4.2.0/tests/test.c allegro-4.2.0-mine/tests/test.c
--- allegro-4.2.0/tests/test.c	2005-03-31 14:46:32.000000000 -0600
+++ allegro-4.2.0-mine/tests/test.c	2005-06-02 17:13:34.720120000 -0500
@@ -1983,7 +1983,7 @@
 
    if (gfx_driver->scroll == NULL)
       textout_ex(screen, font, "Hardware scrolling not supported", 32, 112, palette_color[15], -1);
- #ifdef GFX_MODEX
+ #ifdef GFX_HAS_VGA
    else if (gfx_driver->id == GFX_MODEX)
       textout_ex(screen, font, "PGUP/PGDN to adjust the split screen", 32, 112, palette_color[15], -1);
  #endif
@@ -2029,7 +2029,7 @@
 
       scroll_screen(x, y);
 
-    #ifdef GFX_MODEX
+    #ifdef GFX_HAS_VGA
       if (gfx_driver->id == GFX_MODEX)
 	 split_modex_screen(split);
     #endif
@@ -2044,7 +2044,7 @@
 
    scroll_screen(0, 0);
 
- #ifdef GFX_MODEX
+ #ifdef GFX_HAS_VGA
    if (gfx_driver->id == GFX_MODEX)
       split_modex_screen(0);
  #endif


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/