385aba
Description: <short summary="" of="" the="" patch="">
385aba
 TODO: Put a short summary on the line above and replace this paragraph
385aba
 with a longer explanation of this change. Complete the meta-information
385aba
 with other relevant fields (see below for details). To make it easier, the
385aba
 information below has been extracted from the changelog. Adjust it or drop
385aba
 it.
385aba
 .
385aba
 gcl (2.6.12-23) unstable; urgency=medium
385aba
 .
385aba
   * Version_2_6_13pre28
385aba
Author: Camm Maguire <camm@debian.org>
385aba
385aba
---
385aba
The information above should follow the Patch Tagging Guidelines, please
385aba
checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
385aba
are templates for supplementary fields that you might want to add:
385aba
385aba
Origin: <vendor|upstream|other>, <url of="" original="" patch="">
385aba
Bug: <url in="" upstream="" bugtracker="">
385aba
Bug-Debian: https://bugs.debian.org/<bugnumber>
385aba
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
385aba
Forwarded: <no|not-needed|url proving="" that="" it="" has="" been="" forwarded="">
385aba
Reviewed-By: <name and="" email="" of="" someone="" who="" approved="" the="" patch="">
385aba
Last-Update: <yyyy-mm-dd>
385aba
385aba
--- gcl-2.6.12.orig/h/linux.h
385aba
+++ gcl-2.6.12/h/linux.h
385aba
@@ -132,20 +132,18 @@ do { int c = 0; \
385aba
 
385aba
 #include <limits.h>
385aba
 #include <sys stat.h="">
385aba
-#define GET_FULL_PATH_SELF(a_) do {\
385aba
- char b[20];\
385aba
- static char q[PATH_MAX];\
385aba
- struct stat ss;\
385aba
- if (snprintf(b,sizeof(b),"/proc/%d/exe",getpid())<=0)\
385aba
-   error("Cannot write proc exe pathname");\
385aba
- if (stat(b,&ss)) \
385aba
-   (a_)=argv[0];\
385aba
- else {\
385aba
-   if (!realpath(b,q)) \
385aba
-     error("realpath error");\
385aba
-   (a_)=q;\
385aba
- }\
385aba
-} while(0)
385aba
+#define GET_FULL_PATH_SELF(a_) do {		\
385aba
+    static char q[PATH_MAX];			\
385aba
+    const char *s="/proc/self/exe";		\
385aba
+    struct stat ss;				\
385aba
+    if (stat(s,&ss))				\
385aba
+      (a_)=argv[0];				\
385aba
+    else {					\
385aba
+      if (!realpath(s,q))			\
385aba
+	error("realpath error");		\
385aba
+      (a_)=q;					\
385aba
+    }						\
385aba
+  } while(0)
385aba
 
385aba
 
385aba
 #define UC(a_) ((ucontext_t *)a_)
385aba
--- gcl-2.6.12.orig/h/unrandomize.h
385aba
+++ gcl-2.6.12/h/unrandomize.h
385aba
@@ -23,6 +23,7 @@
385aba
 	int i,j,k;
385aba
 	char **n,**a;
385aba
 	void *v;
385aba
+	argv[0]="/proc/self/exe";
385aba
 	for (i=j=0;argv[i];i++)
385aba
 	  j+=strlen(argv[i])+1;
385aba
 	for (k=0;envp[k];k++)
385aba
--- gcl-2.6.12.orig/o/alloc.c
385aba
+++ gcl-2.6.12/o/alloc.c
385aba
@@ -351,7 +351,8 @@ resize_hole(ufixnum hp,enum type tp,bool
385aba
 
385aba
   if (!in_placep &&
385aba
       ((new_start<=start && start
385aba
-    emsg("Toggling relblock when resizing hole to %lu\n",hp);
385aba
+    if (sSAnotify_gbcA->s.s_dbind != Cnil)
385aba
+      emsg("Toggling relblock when resizing hole to %lu\n",hp);
385aba
     tm_table[t_relocatable].tm_adjgbccnt--;
385aba
     GBC(t_relocatable);
385aba
     return resize_hole(hp,tp,in_placep);
385aba
@@ -387,7 +388,8 @@ alloc_page(long n) {
385aba
       d=d<0 ? 0 : d;
385aba
       d=(available_pages/3)
385aba
       
385aba
-      emsg("Hole overrun\n");
385aba
+      if (sSAnotify_gbcA && sSAnotify_gbcA->s.s_dbind != Cnil)
385aba
+	emsg("Hole overrun\n");
385aba
 
385aba
       resize_hole(d+nn,t_relocatable,0);
385aba
 
385aba
@@ -857,7 +859,8 @@ add_pages(struct typemanager *tm,fixnum
385aba
   case t_relocatable:
385aba
 
385aba
     if (rb_high() && m>((rb_start-heap_end)>>PAGEWIDTH)) {
385aba
-      emsg("Moving relblock low before expanding relblock pages\n");
385aba
+      if (sSAnotify_gbcA->s.s_dbind != Cnil)
385aba
+	emsg("Moving relblock low before expanding relblock pages\n");
385aba
       tm_table[t_relocatable].tm_adjgbccnt--;
385aba
       GBC(t_relocatable);
385aba
     }
385aba
@@ -1652,22 +1655,15 @@ DEFUN_NEW("GPROF-QUIT",object,fSgprof_qu
385aba
   if (!gprof_on)
385aba
     return Cnil;
385aba
 
385aba
-  if (!getcwd(b,sizeof(b)))
385aba
-    FEerror("Cannot get working directory", 0);
385aba
-  if (chdir(P_tmpdir))
385aba
-    FEerror("Cannot change directory to tmpdir", 0);
385aba
+  massert(getcwd(b,sizeof(b)));
385aba
+  massert(!chdir(P_tmpdir));
385aba
   _mcleanup();
385aba
-  if (snprintf(b1,sizeof(b1),"gprof %s",kcl_self)<=0)
385aba
-    FEerror("Cannot write gprof command line", 0);
385aba
-  if (!(pp=popen(b1,"r")))
385aba
-    FEerror("Cannot open gprof pipe", 0);
385aba
+  massert(snprintf(b1,sizeof(b1),"gprof %s",kcl_self)>0);
385aba
+  massert((pp=popen(b1,"r")));
385aba
   while ((n=fread(b1,1,sizeof(b1),pp)))
385aba
-    if (!fwrite(b1,1,n,stdout))
385aba
-      FEerror("Cannot write gprof output",0);
385aba
-  if (pclose(pp)<0)
385aba
-    FEerror("Cannot close gprof pipe", 0);
385aba
-  if (chdir(b))
385aba
-    FEerror("Cannot restore working directory", 0);
385aba
+    massert(fwrite(b1,1,n,stdout));
385aba
+  massert(pclose(pp)>=0);
385aba
+  massert(!chdir(b));
385aba
   gprof_on=0;
385aba
 
385aba
   return Cnil;
385aba
@@ -1785,28 +1781,37 @@ static char *baby_malloc(n)
385aba
 
385aba
 bool writable_malloc=0;
385aba
 
385aba
-void *
385aba
-malloc(size_t size) {
385aba
-
385aba
-  static bool in_malloc;
385aba
-
385aba
-  if (in_malloc)
385aba
-    return NULL;
385aba
-  in_malloc=1;
385aba
+static void *
385aba
+malloc_internal(size_t size) {
385aba
 
385aba
-  if (!gcl_alloc_initialized)
385aba
-    gcl_init_alloc(&size);
385aba
 #ifdef CAN_UNRANDOMIZE_SBRK
385aba
-  else if (!gcl_unrandomized)
385aba
-    return sbrk(size);
385aba
+  if (core_end && core_end!=sbrk(0))/*malloc before main in saved_image*/
385aba
+    return sbrk(size);/*will never get to gcl_init_alloc, so brk point irrelevant*/
385aba
 #endif
385aba
-  
385aba
+  if (!gcl_alloc_initialized) {
385aba
+    static bool recursive_malloc;
385aba
+    if (recursive_malloc)
385aba
+      error("Bad malloc");
385aba
+    recursive_malloc=1;
385aba
+    gcl_init_alloc(&size);
385aba
+    recursive_malloc=0;
385aba
+  }
385aba
+
385aba
   CHECK_INTERRUPT;
385aba
   
385aba
   malloc_list = make_cons(alloc_simple_string(size), malloc_list);
385aba
   malloc_list->c.c_car->st.st_self = alloc_contblock(size);
385aba
   malloc_list->c.c_car->st.st_adjustable=writable_malloc;
385aba
   
385aba
+  return(malloc_list->c.c_car->st.st_self);
385aba
+
385aba
+}
385aba
+
385aba
+void *
385aba
+malloc(size_t size) {
385aba
+
385aba
+  void *v=malloc_internal(size);;
385aba
+
385aba
   /* FIXME: this is just to handle clean freeing of the
385aba
      monstartup memory allocated automatically on raw image
385aba
      startup.  In saved images, monstartup memory is only
385aba
@@ -1814,12 +1819,11 @@ malloc(size_t size) {
385aba
 #ifdef GCL_GPROF
385aba
   if (raw_image && size>(textend-textstart) && !initial_monstartup_pointer) {
385aba
     massert(!atexit(gprof_cleanup));
385aba
-    initial_monstartup_pointer=malloc_list->c.c_car->st.st_self;
385aba
+    initial_monstartup_pointer=v;
385aba
   }
385aba
 #endif
385aba
   
385aba
-  in_malloc=0;
385aba
-  return(malloc_list->c.c_car->st.st_self);
385aba
+  return v;
385aba
   
385aba
 }
385aba
 
385aba
--- gcl-2.6.12.orig/o/error.c
385aba
+++ gcl-2.6.12/o/error.c
385aba
@@ -35,7 +35,7 @@ object sSterminal_interrupt;
385aba
 void
385aba
 assert_error(const char *a,unsigned l,const char *f,const char *n) {
385aba
 
385aba
-  if (!raw_image)
385aba
+  if (!raw_image && core_end && core_end==sbrk(0))
385aba
     FEerror("The assertion ~a on line ~a of ~a in function ~a failed",4,
385aba
 	    make_simple_string(a),make_fixnum(l),
385aba
 	    make_simple_string(f),make_simple_string(n));
385aba
--- gcl-2.6.12.orig/o/gbc.c
385aba
+++ gcl-2.6.12/o/gbc.c
385aba
@@ -1170,15 +1170,15 @@ GBC(enum type t) {
385aba
       gc_time=0;
385aba
 
385aba
 #ifdef SGC
385aba
-    printf("[%s for %ld %s pages..",
385aba
-	   (sgc_enabled ? "SGC" : "GC"),
385aba
-	   (sgc_enabled ? sgc_count_type(t) : tm_of(t)->tm_npage),
385aba
-	   (tm_table[(int)t].tm_name)+1);
385aba
+    emsg("[%s for %ld %s pages..",
385aba
+	 (sgc_enabled ? "SGC" : "GC"),
385aba
+	 (sgc_enabled ? sgc_count_type(t) : tm_of(t)->tm_npage),
385aba
+	 (tm_table[(int)t].tm_name)+1);
385aba
 #else
385aba
-    printf("[%s for %ld %s pages..",
385aba
-	   ("GC"),
385aba
-	   (tm_of(t)->tm_npage),
385aba
-	   (tm_table[(int)t].tm_name)+1);
385aba
+    emsg("[%s for %ld %s pages..",
385aba
+	 ("GC"),
385aba
+	 (tm_of(t)->tm_npage),
385aba
+	 (tm_table[(int)t].tm_name)+1);
385aba
 #endif
385aba
 
385aba
 #ifdef SGC
385aba
@@ -1349,10 +1349,9 @@ GBC(enum type t) {
385aba
   if (sSAnotify_gbcA->s.s_dbind != Cnil) {
385aba
     
385aba
     if (gc_recursive)
385aba
-      fprintf(stdout, "(T=...).GC finished]\n");
385aba
+      emsg("(T=...).GC finished]\n");
385aba
     else
385aba
-      fprintf(stdout, "(T=%d).GC finished]\n",gc_start);
385aba
-    fflush(stdout);
385aba
+      emsg("(T=%d).GC finished]\n",gc_start);
385aba
 
385aba
   }
385aba
   
385aba
--- gcl-2.6.12.orig/o/main.c
385aba
+++ gcl-2.6.12/o/main.c
385aba
@@ -205,21 +205,21 @@ get_proc_meminfo_value_in_pages(const ch
385aba
   return n>>(PAGEWIDTH-10);
385aba
 }
385aba
 
385aba
+#include <sys sysinfo.h="">
385aba
+
385aba
 static ufixnum
385aba
 get_phys_pages_no_malloc(char freep) {
385aba
 
385aba
-  return freep ? 
385aba
-    get_proc_meminfo_value_in_pages("MemFree:")+
385aba
-    get_proc_meminfo_value_in_pages("Buffers:")+
385aba
-    get_proc_meminfo_value_in_pages("Cached:") :
385aba
-    get_proc_meminfo_value_in_pages("MemTotal:");
385aba
+  struct sysinfo s;
385aba
+  sysinfo(&s);
385aba
+  return (freep ? s.freeram : s.totalram)>>PAGEWIDTH;
385aba
   
385aba
 }
385aba
 
385aba
 #endif
385aba
 
385aba
 static ufixnum
385aba
-get_phys_pages(char freep) {
385aba
+get_phys_pages1(char freep) {
385aba
 
385aba
   return get_phys_pages_no_malloc(freep);
385aba
 
385aba
@@ -313,7 +313,7 @@ update_real_maxpage(void) {
385aba
       }
385aba
   massert(!mbrk(cur));
385aba
 
385aba
-  phys_pages=ufmin(get_phys_pages(0)+page(beg),real_maxpage)-page(beg);
385aba
+  phys_pages=ufmin(get_phys_pages1(0)+page(beg),real_maxpage)-page(beg);
385aba
 
385aba
   get_gc_environ();
385aba
   setup_maxpages(mem_multiple);
385aba
@@ -412,10 +412,6 @@ DEFVAR("*CODE-BLOCK-RESERVE*",sSAcode_bl
385aba
 
385aba
 #define HAVE_GCL_CLEANUP
385aba
 
385aba
-#ifdef CAN_UNRANDOMIZE_SBRK
385aba
-bool gcl_unrandomized=FALSE;
385aba
-#endif
385aba
-
385aba
 void
385aba
 gcl_cleanup(int gc) {
385aba
 
385aba
@@ -442,10 +438,6 @@ gcl_cleanup(int gc) {
385aba
     cs_org=0;
385aba
     initial_sbrk=core_end;
385aba
 
385aba
-#ifdef CAN_UNRANDOMIZE_SBRK
385aba
-    gcl_unrandomized=FALSE;
385aba
-#endif
385aba
-
385aba
   }
385aba
 
385aba
   close_pool();
385aba
@@ -460,7 +452,6 @@ main(int argc, char **argv, char **envp)
385aba
 #include <stdio.h>
385aba
 #include <stdlib.h>
385aba
 #include "unrandomize.h"
385aba
-  gcl_unrandomized=TRUE;
385aba
 #endif
385aba
 
385aba
   gcl_init_alloc(&argv);
385aba
--- gcl-2.6.12.orig/o/sfaslelf.c
385aba
+++ gcl-2.6.12/o/sfaslelf.c
385aba
@@ -181,8 +181,7 @@ relocate(Sym *sym1,void *v,ul a,ul start
385aba
 #include RELOC_H
385aba
 
385aba
   default:
385aba
-    emsg("Unknown reloc type %lu\n", tp);
385aba
-    massert(tp&~tp);
385aba
+    massert(!emsg("Unknown reloc type %lu\n", tp));
385aba
 
385aba
   }
385aba
 
385aba
--- gcl-2.6.12.orig/o/sgbc.c
385aba
+++ gcl-2.6.12/o/sgbc.c
385aba
@@ -789,10 +789,8 @@ sgc_start(void) {
385aba
   sgc_enabled=1;
385aba
   if (memory_protect(1)) 
385aba
     sgc_quit();
385aba
-  if (sSAnotify_gbcA->s.s_dbind != Cnil) {
385aba
-    printf("[SGC on]"); 
385aba
-    fflush(stdout);
385aba
-  }
385aba
+  if (sSAnotify_gbcA->s.s_dbind != Cnil)
385aba
+    emsg("[SGC on]");
385aba
 
385aba
   sSAoptimize_maximum_pagesA->s.s_dbind=omp;
385aba
 
385aba
@@ -826,7 +824,7 @@ sgc_quit(void) {
385aba
   memory_protect(0);
385aba
 
385aba
   if(sSAnotify_gbcA->s.s_dbind != Cnil) 
385aba
-    printf("[SGC off]"); fflush(stdout);
385aba
+    emsg("[SGC off]");
385aba
 
385aba
   if (sgc_enabled==0) 
385aba
     return 0;