[gnu.bash.bug] Bash 1.04 patch: extern+static

chip@ateng.ateng.com (Chip Salzenberg) (01/23/90)

Bash 1.04 uses two constructs which cause linkage trouble for some compilers,
in particular the Microsoft compiler provided with SCO Xenix 2.3.  These
constructs are:

	extern int foo;
	func() {
		foo = 1;
	}
	static int foo = 0;

and:

	extern int xyzzy();
	func() {
		xyzzy();
	}
	static xyzzy() {
		printf("hello\n");
	}

These constructs are both legal ANSI C, but they confuse compilers of older
vintage.  The patches below:
	avoid forward references to statically declared objects, and
	declare static functions static in all declarations.

Index: builtins.c
***************
*** 1229,1232 ****
--- 1233,1238 ----
       WORD_LIST *list;
  {
+   extern int interactive;
+ 
    if (!login_shell && interactive)
      {
***************
*** 2383,2387 ****
       int no_modifiers;
  {
!   extern int variable_context;
    int flags_on = 0, flags_off = 0;
  
--- 2389,2393 ----
       int no_modifiers;
  {
!   extern int array_needs_making, variable_context;
    int flags_on = 0, flags_off = 0;
  

Index: readline/funmap.c
***************
*** 25,28 ****
--- 25,29 ----
  #else
  static char *xmalloc (), *xrealloc ();
+ static memory_error_and_abort ();
  #endif
  
***************
*** 183,187 ****
       int bytes;
  {
-   static memory_error_and_abort ();
    char *temp = (char *)malloc (bytes);
  
--- 184,187 ----
***************
*** 196,200 ****
       int bytes;
  {
-   static memory_error_and_abort ();
    char *temp = (char *)realloc (pointer, bytes);
  
--- 196,199 ----

Index: readline/history.c
***************
*** 31,34 ****
--- 31,35 ----
  #else
  static char *xmalloc (), *xrealloc ();
+ static memory_error_and_abort ();
  #endif
  
***************
*** 1350,1354 ****
       int bytes;
  {
-   static memory_error_and_abort ();
    char *temp = (char *)malloc (bytes);
  
--- 1351,1354 ----
***************
*** 1363,1367 ****
       int bytes;
  {
-   static memory_error_and_abort ();
    char *temp = (char *)realloc (pointer, bytes);
  
--- 1363,1366 ----

Index: readline/keymaps.c
***************
*** 33,36 ****
--- 33,37 ----
  #else
  static char *xmalloc (), *xrealloc ();
+ static memory_error_and_abort ();
  #endif
  
***************
*** 143,147 ****
       int bytes;
  {
-   static memory_error_and_abort ();
    char *temp = (char *)malloc (bytes);
  
--- 144,147 ----
***************
*** 156,160 ****
       int bytes;
  {
-   static memory_error_and_abort ();
    char *temp = (char *)realloc (pointer, bytes);
  
--- 156,159 ----

Index: readline/readline.c
***************
*** 115,118 ****
--- 119,123 ----
  static start_insert ();
  static end_insert ();
+ static memory_error_and_abort();
  
  #ifdef VOID_SIGHANDLER
***************
*** 696,703 ****
       Keymap map;
  {
!   extern int defining_kbd_macro;
! 
!   if (defining_kbd_macro)
!     add_macro_char (key);
  
    if (key > 127 && key < 256)
--- 701,705 ----
       Keymap map;
  {
!   add_macro_char (key);
  
    if (key > 127 && key < 256)
***************
*** 879,882 ****
--- 881,887 ----
       int c;
  {
+   if (!defining_kbd_macro)
+     return;
+ 
    if (current_macro_index + 1 >= current_macro_size)
      {
***************
*** 990,997 ****
  
    /* Parsing of key-bindings begins in an enabled state. */
!   {
!     extern unsigned char parsing_conditionalized_out;
!     parsing_conditionalized_out = 0;
!   }
  }
  
--- 995,999 ----
  
    /* Parsing of key-bindings begins in an enabled state. */
!   parser_enable ();
  }
  
Index: readline/readline.c
***************
*** 1595,1599 ****
  {
    register int i;
-   static void output_character_function ();
  
    /* It may be faster to output a CR, and then move forwards instead
--- 1616,1619 ----
***************
*** 1641,1645 ****
       int to;
  {
-   void output_character_function ();
    register int delta, i;
  
--- 1661,1664 ----
***************
*** 2465,2469 ****
  {
    extern char *term_clrpag;
-   static void output_character_function ();
  
    if (rl_explicit_arg)
--- 2484,2487 ----
***************
*** 2592,2603 ****
  
  #ifdef VI_MODE
!   {
!     extern int vi_doing_insert;
!     if (vi_doing_insert)
!       {
! 	rl_end_undo_group ();
! 	vi_doing_insert = 0;
!       }
!   }
  #endif /* VI_MODE */
  
--- 2610,2614 ----
  
  #ifdef VI_MODE
!   vi_done_inserting ();
  #endif /* VI_MODE */
  
***************
*** 5026,5029 ****
--- 5037,5045 ----
  static int if_stack_size = 0;
  
+ parser_enable ()
+ {
+   parsing_conditionalized_out = 0;
+ }
+ 
  /* Push parsing_conditionalized_out, and set parser state based on ARGS. */
  parser_if (args)
***************
*** 5481,5485 ****
       int bytes;
  {
-   static memory_error_and_abort ();
    char *temp = (char *)malloc (bytes);
  
--- 5497,5500 ----
***************
*** 5494,5498 ****
       int bytes;
  {
-   static memory_error_and_abort ();
    char *temp = (char *)realloc (pointer, bytes);
  
--- 5509,5512 ----

Index: readline/vi_mode.c
***************
*** 362,365 ****
--- 362,370 ----
  
    keymap = vi_movement_keymap;
+   vi_done_inserting ();
+ }
+ 
+ vi_done_inserting ()
+ {
    if (vi_doing_insert)
      {