Description: <short summary of the patch>
 TODO: Put a short summary on the line above and replace this paragraph
 with a longer explanation of this change. Complete the meta-information
 with other relevant fields (see below for details). To make it easier, the
 information below has been extracted from the changelog. Adjust it or drop
 it.
 .
 gcl27 (2.7.0-16) unstable; urgency=medium
 .
   * Version_2_7_0pre19
Author: Camm Maguire <camm@debian.org>

---
The information above should follow the Patch Tagging Guidelines, please
checkout https://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:

Origin: (upstream|backport|vendor|other), (<patch-url>|commit:<commit-id>)
Bug: <upstream-bugtracker-url>
Bug-Debian: https://bugs.debian.org/<bugnumber>
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
Forwarded: (no|not-needed|<patch-forwarded-url>)
Applied-Upstream: <version>, (<commit-url>|commit:<commid-id>)
Reviewed-By: <name and email of someone who approved/reviewed the patch>
Last-Update: 2024-02-23

--- gcl27-2.7.0.orig/cmpnew/gcl_cmptype.lsp
+++ gcl27-2.7.0/cmpnew/gcl_cmptype.lsp
@@ -768,15 +768,11 @@
 	(#tcons)))
 (si::putprop 'cons 'cons-propagator 'type-propagator)
 
-(defvar *in-co1carcdr* nil);FIXME
-
 (defun co1carcdr (f x)
-  (unless *in-co1carcdr*
-    (let ((*in-co1carcdr* t))
-      (let* ((tp (car (atomic-tp (info-type (cadr (with-restore-vars (c1arg (car x))))))))
-	     (tp (when (consp tp) (funcall f tp)))
-	     (tp (get-var tp)))
-	(when tp (c1var tp))))))
+  (let* ((tp (car (atomic-tp (info-type (cadr (with-restore-vars (c1arg (car x))))))))
+	 (tp (when (consp tp) (funcall f tp)))
+	 (tp (get-var tp)))
+    (when tp (c1var tp))))
 
 (setf (get 'car 'co1) 'co1carcdr)
 (setf (get 'cdr 'co1) 'co1carcdr)
--- gcl27-2.7.0.orig/gcl-tk/sheader.h
+++ gcl27-2.7.0/gcl-tk/sheader.h
@@ -104,7 +104,7 @@ struct connection_state
 extern struct connection_state *dsfd;
 
 #define fScheck_dsfd_for_input(sf,timeout) \
- (sf->valid_data_size > 0 ? make_fixnum(1) : fScheck_fd_for_input(sf->fd,timeout))
+  (sf->valid_data_size > 0 ? 1 : (fixnum)fScheck_fd_for_input(sf->fd,timeout))
 
 #define OBJ_TO_CONNECTION_STATE(x) \
   ((struct connection_state *)(void *)((x)->ust.ust_self))
--- gcl27-2.7.0.orig/gcl-tk/tkMain.c
+++ gcl27-2.7.0/gcl-tk/tkMain.c
@@ -570,7 +570,7 @@ StdinProc(clientData, mask)
 	  dfprintf(stderr, "Error !!! Unknown command %d\n"
 		   , msg->type);
 	}
-      fNotDone = fix(fScheck_dsfd_for_input(dsfd,0));
+      fNotDone = fScheck_dsfd_for_input(dsfd,0);
       
       if (fNotDone > 0)
 	{
--- gcl27-2.7.0.orig/git.tag
+++ gcl27-2.7.0/git.tag
@@ -1,2 +1,2 @@
-"Version_2_7_0pre18"
+"Version_2_7_0pre19"
 
--- gcl27-2.7.0.orig/h/notcomp.h
+++ gcl27-2.7.0/h/notcomp.h
@@ -309,6 +309,14 @@ extern bool writable_malloc;
 
 #include "error.h"
 
+#if __GNU_MP_VERSION > 4 || (__GNU_MP_VERSION == 4 && __GNU_MP_VERSION_MINOR >= 2)
+extern void __gmp_randget_mt ();
+extern void __gmp_randclear_mt ();
+extern void __gmp_randiset_mt ();
+
+typedef struct {void *a,*b,*c,*d;} gmp_randfnptr_t;
+EXTER gmp_randfnptr_t Mersenne_Twister_Generator_Noseed;
+#endif
 
 /* #define BV_BITS CHAR_SIZE */
 /* #define BV_ALLOC (BV_BITS*SIZEOF_LONG) */
--- gcl27-2.7.0.orig/h/protoize.h
+++ gcl27-2.7.0/h/protoize.h
@@ -1666,3 +1666,5 @@ object Iapply_fun_n2(object,int,int,...)
 object Ifuncall_n(object,int,...);
 object funcall_cfun(void(*)(),int,...);
 int gcl_init_cmp_anon(void);
+int is_bigger_fixnum(void *);
+int is_text_addr(void *);
--- gcl27-2.7.0.orig/o/cfun.c
+++ gcl27-2.7.0/o/cfun.c
@@ -85,10 +85,12 @@ DEFUN("DLSYM",object,fSdlsym,SI,2,2,NONE
   name->st.st_self[VLEN(name)]=0;
   ad=dlsym(h ? (void *)h : RTLD_DEFAULT,name->st.st_self);
   ad=ad ? ad : dlsym(RTLD_DEFAULT,name->st.st_self);
-  ad=ad<data_start ? dlsym(RTLD_NEXT,name->st.st_self) : ad;
+  ad=is_text_addr(ad) ? dlsym(RTLD_NEXT,name->st.st_self) : ad;
   name->st.st_self[VLEN(name)]=ch;
-  if (ad<data_start)
-    FEerror("dlsym lookup failure on ~s: ~s",2,name,make_simple_string(dlerror()));
+  if (!ad) {
+    char *er=dlerror();
+    FEerror("dlsym lookup failure on ~s: ~s",2,name,make_simple_string(er ? er : ""));
+  }
   RETURN1(make_fixnum((fixnum)ad));
 
 }
--- gcl27-2.7.0.orig/o/character.d
+++ gcl27-2.7.0/o/character.d
@@ -531,7 +531,6 @@ gcl_init_character()
 
 	for (i = 0;  i < CHCODELIM;  i++) {
 	  object x=(object)(character_table+i),y=(object)(character_name_table+i);
-	  x->fw=0;
 	  set_type_of(x,t_character);
 	  x->ch.ch_code = i;
 	  x->ch.tt=((' ' <= i && i < '\177') || i == '\n');
--- gcl27-2.7.0.orig/o/gmp_big.c
+++ gcl27-2.7.0/o/gmp_big.c
@@ -97,6 +97,14 @@ object big_fixnum5;
 void
 gcl_init_big1(void) {
     mp_set_memory_functions( gcl_gmp_alloc,gcl_gmp_realloc,gcl_gmp_free);
+    jmp_gmp=0;
+
+#if __GNU_MP_VERSION > 4 || (__GNU_MP_VERSION == 4 && __GNU_MP_VERSION_MINOR >= 2)
+    Mersenne_Twister_Generator_Noseed.b=__gmp_randget_mt;
+    Mersenne_Twister_Generator_Noseed.c=__gmp_randclear_mt;
+    Mersenne_Twister_Generator_Noseed.d=__gmp_randiset_mt;
+#endif
+
 }
 
 #else
--- gcl27-2.7.0.orig/o/gprof.c
+++ gcl27-2.7.0/o/gprof.c
@@ -69,7 +69,7 @@ DEFUN("GPROF-ADDRESSES",object,fSgprof_a
   if (max<min)
     min=max;
 
-  if (!mintext) {
+  if (!mintext) {/*FIXME min_text*/
 
     mintext=data_start;
 
--- gcl27-2.7.0.orig/o/main.c
+++ gcl27-2.7.0/o/main.c
@@ -419,6 +419,8 @@ dir_name_length(const char *s) {
   return m;
 }
 
+int initializing_boot=0;
+
 void
 init_boot(void) {
 
@@ -435,7 +437,9 @@ init_boot(void) {
     printf("%s\n",dlerror());
   if (!(q=dlsym(v,"gcl_init_boot")))
     printf("%s\n",dlerror());
+  initializing_boot=1;
   ((void (*)())q)();
+  initializing_boot=0;
   sSAoptimize_maximum_pagesA->s.s_dbind=omp;
 
 }
--- gcl27-2.7.0.orig/o/makefun.c
+++ gcl27-2.7.0/o/makefun.c
@@ -87,7 +87,12 @@ DEFUN("INIT-FUNCTION",object,fSinit_func
   d=data!=Cnil ? data : m;
   i=sSPinit;
   i=i ? i->s.s_dbind : i;
-  s=i && i!=OBJNULL && !get_pageinfo(addr) && type_of(addr)==t_fixnum ? i->v.v_self[fix(addr)] : addr;
+  if (is_text_addr(addr)||get_pageinfo(addr))
+    s=addr;
+  else {
+    massert(i && i!=OBJNULL && type_of(addr)==t_fixnum);
+    s=i->v.v_self[fix(addr)];
+  }
   z=type_of(sc)==t_cons && sc->c.c_car==sSmacro; /*FIXME limited no. of args.*/
   sc=z ? sc->c.c_cdr : sc;
   sc=type_of(sc)==t_function ? sc->fun.fun_plist : sc;
--- gcl27-2.7.0.orig/o/number.c
+++ gcl27-2.7.0/o/number.c
@@ -57,12 +57,13 @@ object small_fixnum ( int i ) {
 #endif
 
 
+/*FIXME, make these immutable and of type immfix*/
 #define BIGGER_FIXNUM_RANGE
 
 #ifdef BIGGER_FIXNUM_RANGE
 struct {int min,max;} bigger_fixnums;
 
-struct fixnum_struct *bigger_fixnum_table;
+struct fixnum_struct *bigger_fixnum_table=NULL,*bigger_fixnum_table_end=NULL;
 #if !defined(IM_FIX_BASE) || defined(USE_SAFE_CDR)
 #define STATIC_BIGGER_FIXNUM_TABLE_BITS 10
 static struct fixnum_struct bigger_fixnum_table1[1<<(STATIC_BIGGER_FIXNUM_TABLE_BITS+1)] OBJ_ALIGN;
@@ -75,11 +76,15 @@ DEFUN("ALLOCATE-BIGGER-FIXNUM-RANGE",obj
   if (min > max) FEerror("Need Min <= Max",0);
 
 #if !defined(IM_FIX_BASE) || defined(USE_SAFE_CDR)
-  if (min==-(1<<STATIC_BIGGER_FIXNUM_TABLE_BITS) && max==(1<<STATIC_BIGGER_FIXNUM_TABLE_BITS))
+  if (min==-(1<<STATIC_BIGGER_FIXNUM_TABLE_BITS) && max==(1<<STATIC_BIGGER_FIXNUM_TABLE_BITS)) {
     bigger_fixnum_table=bigger_fixnum_table1;
-  else
+    bigger_fixnum_table_end=(void *)bigger_fixnum_table+sizeof(bigger_fixnum_table1);
+  } else
 #endif
-    bigger_fixnum_table=(void *)malloc(sizeof(struct fixnum_struct)*(max - min));
+    {
+      bigger_fixnum_table=(void *)malloc(sizeof(struct fixnum_struct)*(max - min));
+      bigger_fixnum_table_end=(void *)bigger_fixnum_table+sizeof(struct fixnum_struct)*(max - min);
+    }
   
   for (j=min ; j < max ; j=j+1) { 		
     object x=(object)(bigger_fixnum_table+j-min);
@@ -94,6 +99,11 @@ DEFUN("ALLOCATE-BIGGER-FIXNUM-RANGE",obj
 }
 #endif
 
+int
+is_bigger_fixnum(void *v)  {
+  return v>=(void *)bigger_fixnum_table && v<(void *)bigger_fixnum_table_end ? 1 : 0;
+}
+
 object
 make_fixnum1(long i)
 {
--- gcl27-2.7.0.orig/o/sfasli.c
+++ gcl27-2.7.0/o/sfasli.c
@@ -94,7 +94,18 @@ build_symbol_table_bfd(void) {
 
 #endif /* special_rsym */
 
-LFD(build_symbol_table)(void) { 
+static void *min_text;
+extern char etext/* ,edata,end */;
+
+int
+is_text_addr(void *p) {
+  extern int initializing_boot;
+  if (!min_text) return 1;/*FIXME build_symbol_table before initlisp*/
+  if (initializing_boot) return 1;/*FIXME*/
+  return p>=min_text && p<(void *)&etext ? 1 : 0;
+}
+
+LFD(build_symbol_table)(void) {
 
   printf("Building symbol table for %s ..\n",kcl_self);fflush(stdout);
 
@@ -110,6 +121,16 @@ LFD(build_symbol_table)(void) {
 
 #endif
 
+  {
+    fixnum i;
+
+    min_text=(void *)&etext;
+    for (i=0;i<c_table.alloc_length;i++) {
+      void *p=(void *)c_table.ptable[i].address;
+      min_text=p<min_text ? p : min_text;
+    }
+  }
+
 }
 
 #ifndef _WIN32
--- gcl27-2.7.0.orig/o/sockets.c
+++ gcl27-2.7.0/o/sockets.c
@@ -530,10 +530,10 @@ and positioning the ouput/input to start
   return strm;
 }
 
-DEFUN("CHECK-STATE-INPUT",object,fScheck_state_input,SI,2,2,NONE,OO,IO,OO,OO,(object osfd,fixnum timeout),
+DEFUN("CHECK-STATE-INPUT",object,fScheck_state_input,SI,2,2,NONE,IO,IO,OO,OO,(object osfd,fixnum timeout),
       "") 
 {
-  return fScheck_dsfd_for_input(OBJ_TO_CONNECTION_STATE(osfd),timeout);
+  return (object)fScheck_dsfd_for_input(OBJ_TO_CONNECTION_STATE(osfd),timeout);
 
 }
 
