Subject: pkg/33865: math/pari: gp crashes due to illegal instruction in init_readline
To: None <pkg-manager@netbsd.org, gnats-admin@netbsd.org,>
From: Johan Wallen <johan.wallen@tkk.fi>
List: pkgsrc-bugs
Date: 06/29/2006 14:30:00
>Number:         33865
>Category:       pkg
>Synopsis:       math/pari: gp crashes due to illegal instruction in init_readline
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    pkg-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Jun 29 14:30:00 +0000 2006
>Originator:     Johan Wallen
>Release:        NetBSD 3.99.21 20060627
>Organization:
Helsinki University of Technology
	
>Environment:
	
	
System: NetBSD enigma.tcs.hut.fi 3.99.21 NetBSD 3.99.21 (GENERIC) #3: Tue Jun 27 13:49:22 EEST 2006 johan@enigma.tcs.hut.fi:/usr/obj/macppc/sys/arch/macppc/compile/GENERIC macppc
Architecture: powerpc
Machine: macppc
gcc version 4.1.2 20060603 prerelease (NetBSD nb1 20060602)
>Description:
	
The gp program in pkgsrc/math/pari crashes at startup in init_readline()
(probably at pari-2.1.6/src/gp/gp_rl.c:633) due to an illegal instruction
trap.  The same error (with SIGILL) occurs also on i386.

The error seems to be caused by several invalid function casts in gp_rl.c.
When compiled with gcc 3.x, these cast seems to be harmless.
>How-To-Repeat:
	
cd pkgsrc/math/pari
make install
gp
>Fix:
	
Simply removing all the function casts from gp_rl.c seems to solve the problem,
as in the patch below.

As a work around, use gcc 3.x to compile the package.

diff -ur --unidirectional-new-file pkgsrc/math/pari/distinfo pkgsrc/math/pari.new/distinfo
--- pkgsrc/math/pari/distinfo	2006-06-29 14:36:51.000000000 +0300
+++ pkgsrc/math/pari.new/distinfo	2006-06-29 14:37:50.000000000 +0300
@@ -21,3 +21,4 @@
 SHA1 (patch-ap) = 985c5c49efb52c04f53f098480f0de1209fa16ef
 SHA1 (patch-aq) = 43a6f7a4b74a2affbdffca7bf781009e3e1dece0
 SHA1 (patch-ar) = 753d10a31dbf106c3217976b6dd16a4d3f864428
+SHA1 (patch-as) = d433dedf76ec9fcbd4d84d463a82ff6ef959c368
diff -ur --unidirectional-new-file pkgsrc/math/pari/patches/patch-as pkgsrc/math/pari.new/patches/patch-as
--- pkgsrc/math/pari/patches/patch-as	1970-01-01 02:00:00.000000000 +0200
+++ pkgsrc/math/pari.new/patches/patch-as	2006-06-29 14:37:54.000000000 +0300
@@ -0,0 +1,83 @@
+--- src/gp/gp_rl.c.orig2	2006-06-28 16:12:19.000000000 +0300
++++ src/gp/gp_rl.c	2006-06-28 16:14:00.000000000 +0300
+@@ -79,13 +79,13 @@
+ #endif
+ 
+ #ifdef HAS_RL_COMPLETION_MATCHES
+-#  define COMPLETION_MATCHES ((CF)rl_completion_matches)
+-#  define FILE_COMPLETION ((GF)rl_filename_completion_function)
+-#  define USER_COMPLETION ((GF)rl_username_completion_function)
++#  define COMPLETION_MATCHES (rl_completion_matches)
++#  define FILE_COMPLETION (rl_filename_completion_function)
++#  define USER_COMPLETION (rl_username_completion_function)
+ #else
+-#  define COMPLETION_MATCHES ((CF)completion_matches)
+-#  define FILE_COMPLETION ((GF)filename_completion_function)
+-#  define USER_COMPLETION ((GF)username_completion_function)
++#  define COMPLETION_MATCHES (completion_matches)
++#  define FILE_COMPLETION (filename_completion_function)
++#  define USER_COMPLETION (username_completion_function)
+ #endif
+ 
+ #define ELECTRIC_PAREN 1
+@@ -304,7 +304,7 @@
+   rl_completion_append_character = ' ';
+ #endif
+   current_ep = NULL;
+-  matches = COMPLETION_MATCHES(text, (char *(*)())f);
++  matches = COMPLETION_MATCHES(text, f);
+   if (matches && !matches[1]) /* a single match */
+   {
+     if (add_paren(end))
+@@ -625,32 +625,27 @@
+   /* we always want the whole list of completions under emacs */
+   if (under_emacs) rl_completion_query_items = 0x8fff;
+ 
+-#define Bind(a,b,c) (((void(*)(int,Function*,Keymap)) rl_bind_key_in_map)\
+-  ((a), (Function*)(b), (c)))
+-#define Defun(a,b,c) (((void(*)(const char*,Function*,int)) rl_add_defun)\
+-  ((a), (Function*)(b), (c)))
+-
+-  Defun("short-help", rl_short_help, -1);
+-  Defun("long-help", rl_long_help, -1);
+-  Defun("pari-complete", pari_rl_complete, '\t');
+-  Defun("pari-matched-insert", pari_rl_default_matched_insert, -1);
+-  Defun("pari-forward-sexp", pari_rl_forward_sexp, -1);
+-  Defun("pari-backward-sexp", pari_rl_backward_sexp, -1);
+-
+-  Bind('h', rl_short_help, emacs_meta_keymap);
+-  Bind('H', rl_long_help,  emacs_meta_keymap);
+-  Bind('h', rl_short_help, vi_movement_keymap);
+-  Bind('H', rl_long_help,  vi_movement_keymap);
+-  Bind('(', pari_rl_matched_insert, emacs_standard_keymap);
+-  Bind('[', pari_rl_matched_insert, emacs_standard_keymap);
+-  Bind(6, pari_rl_forward_sexp,  emacs_meta_keymap); /* M-C-f */
+-  Bind(2, pari_rl_backward_sexp, emacs_meta_keymap); /* M-C-b */
++  rl_add_defun("short-help", rl_short_help, -1);
++  rl_add_defun("long-help", rl_long_help, -1);
++  rl_add_defun("pari-complete", pari_rl_complete, '\t');
++  rl_add_defun("pari-matched-insert", pari_rl_default_matched_insert, -1);
++  rl_add_defun("pari-forward-sexp", pari_rl_forward_sexp, -1);
++  rl_add_defun("pari-backward-sexp", pari_rl_backward_sexp, -1);
++
++  rl_bind_key_in_map('h', rl_short_help, emacs_meta_keymap);
++  rl_bind_key_in_map('H', rl_long_help,  emacs_meta_keymap);
++  rl_bind_key_in_map('h', rl_short_help, vi_movement_keymap);
++  rl_bind_key_in_map('H', rl_long_help,  vi_movement_keymap);
++  rl_bind_key_in_map('(', pari_rl_matched_insert, emacs_standard_keymap);
++  rl_bind_key_in_map('[', pari_rl_matched_insert, emacs_standard_keymap);
++  rl_bind_key_in_map(6, pari_rl_forward_sexp,  emacs_meta_keymap); /* M-C-f */
++  rl_bind_key_in_map(2, pari_rl_backward_sexp, emacs_meta_keymap); /* M-C-b */
+ 
+ #ifdef EMACS_DOS_KEYMAP
+-  Bind(';', rl_short_help, emacs_dos_keymap); /* F1 */
+-  Bind('T', rl_long_help,  emacs_dos_keymap); /* Shift-F1 */
+-  Bind(155, pari_rl_backward_sexp, emacs_dos_keymap); /* Alt-Left */
+-  Bind(157, pari_rl_forward_sexp,  emacs_dos_keymap); /* Alt-Right*/
++  rl_bind_key_in_map(';', rl_short_help, emacs_dos_keymap); /* F1 */
++  rl_bind_key_in_map('T', rl_long_help,  emacs_dos_keymap); /* Shift-F1 */
++  rl_bind_key_in_map(155, pari_rl_backward_sexp, emacs_dos_keymap); /* Alt-Left */
++  rl_bind_key_in_map(157, pari_rl_forward_sexp,  emacs_dos_keymap); /* Alt-Right*/
+ #endif
+ }
+ #endif

>Unformatted: