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.
 .
 gcl (2.6.10-38) unstable; urgency=medium
 .
   * error on overflow of array dimensions
Author: Camm Maguire <camm@debian.org>

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

Origin: <vendor|upstream|other>, <url of original patch>
Bug: <url in upstream bugtracker>
Bug-Debian: http://bugs.debian.org/<bugnumber>
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
Forwarded: <no|not-needed|url proving that it has been forwarded>
Reviewed-By: <name and email of someone who approved the patch>
Last-Update: <YYYY-MM-DD>

--- gcl-2.6.10.orig/configure
+++ gcl-2.6.10/configure
@@ -4977,41 +4977,6 @@ fi
 
 	        { $as_echo "$as_me:${as_lineno-$LINENO}: result: $hz" >&5
 $as_echo "$hz" >&6; }
-		{ $as_echo "$as_me:${as_lineno-$LINENO}: checking _SC_PHYS_PAGES" >&5
-$as_echo_n "checking _SC_PHYS_PAGES... " >&6; }
-		if test "$cross_compiling" = yes; then :
-  { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
-$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error $? "cannot run test program while cross compiling
-See \`config.log' for more details" "$LINENO" 5; }
-else
-  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-
-			#include <stdio.h>
-			#include <unistd.h>
-			int main() {
-			   FILE *fp=fopen("conftest1","w");
-			   fprintf(fp,"%lu\n",sysconf(_SC_PHYS_PAGES));
-			   fclose(fp);
-			   return 0;
-			}
-_ACEOF
-if ac_fn_c_try_run "$LINENO"; then :
-  phys=`cat conftest1`
-			 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $phys" >&5
-$as_echo "$phys" >&6; }
-
-$as_echo "#define HAVE_SYSCONF_PHYS_PAGES \$phys" >>confdefs.h
-
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-fi
-rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
-  conftest.$ac_objext conftest.beam conftest.$ac_ext
-fi
 
 fi
 
--- gcl-2.6.10.orig/configure.in
+++ gcl-2.6.10/configure.in
@@ -754,21 +754,22 @@ AC_CHECK_HEADERS(unistd.h,
 			    AC_DEFINE_UNQUOTED(HZ,$hz,[time system constant])
 			    ,hz=0,hz=0)
 	        [AC_MSG_RESULT($hz)]
-		AC_MSG_CHECKING(_SC_PHYS_PAGES)
-		AC_RUN_IFELSE([
-			AC_LANG_SOURCE([[
-			#include <stdio.h>
-			#include <unistd.h>
-			int main() {
-			   FILE *fp=fopen("conftest1","w");
-			   fprintf(fp,"%lu\n",sysconf(_SC_PHYS_PAGES));
-			   fclose(fp);
-			   return 0;
-			}]])],
-			[phys=`cat conftest1`
-			 AC_MSG_RESULT($phys)
-			 AC_DEFINE(HAVE_SYSCONF_PHYS_PAGES,$phys,[probe runtime phys pages for gc performance])],
-			 [AC_MSG_RESULT(no)])))
+		dnl AC_MSG_CHECKING(_SC_PHYS_PAGES)
+		dnl AC_RUN_IFELSE([
+		dnl 	AC_LANG_SOURCE([[
+		dnl 	#include <stdio.h>
+		dnl 	#include <unistd.h>
+		dnl 	int main() {
+		dnl 	   FILE *fp=fopen("conftest1","w");
+		dnl 	   fprintf(fp,"%lu\n",sysconf(_SC_PHYS_PAGES));
+		dnl 	   fclose(fp);
+		dnl 	   return 0;
+		dnl 	}]])],
+		dnl 	[phys=`cat conftest1`
+		dnl 	 AC_MSG_RESULT($phys)
+		dnl 	 AC_DEFINE(HAVE_SYSCONF_PHYS_PAGES,$phys,[probe runtime phys pages for gc performance])],
+		dnl 	 [AC_MSG_RESULT(no)])
+			 ))
 
 
 #MY_SUBDIRS=
--- gcl-2.6.10.orig/h/gclincl.h.in
+++ gcl-2.6.10/h/gclincl.h.in
@@ -225,9 +225,6 @@
 /* have sv_onstack */
 #undef HAVE_SV_ONSTACK
 
-/* probe runtime phys pages for gc performance */
-#undef HAVE_SYSCONF_PHYS_PAGES
-
 /* Define to 1 if you have the <sys/ioctl.h> header file. */
 #undef HAVE_SYS_IOCTL_H
 
--- gcl-2.6.10.orig/lsp/gcl_autoload.lsp
+++ gcl-2.6.10/lsp/gcl_autoload.lsp
@@ -259,7 +259,8 @@
 	    "cstack alignment:     ~a bytes~%"
 	    "cstack max:           ~a bytes~%"
 	    "immfix start:         0x~x~%"
-	    "immfix size:          ~a fixnums~%"))
+	    "immfix size:          ~a fixnums~%"
+	    "physical memory:      ~a pages~%"))
 	(v (multiple-value-list (si::heap-report))))
     
     (do ((v v (cdr v)) (f f (cdr f))) ((not (car v)))
--- gcl-2.6.10.orig/o/alloc.c
+++ gcl-2.6.10/o/alloc.c
@@ -419,10 +419,8 @@ opt_maxpage(struct typemanager *my_tm) {
   struct typemanager *tm,*tme;
   long mro=0,tro=0;
 
-#ifdef HAVE_SYSCONF_PHYS_PAGES
-  if (page(heap_end)-first_data_page+nrbpage>=phys_pages)
+  if (phys_pages>0 && page(heap_end)-first_data_page+nrbpage>=phys_pages)
     return 0;
-#endif
 
   if (page(core_end)>0.8*real_maxpage)
     return 0;
@@ -1019,6 +1017,8 @@ gcl_init_alloc(void *cs_start) {
 
   fixnum cssize=(1L<<23);
 
+  prelink_init();
+  
 #ifdef RECREATE_HEAP
   if (!raw_image) RECREATE_HEAP;
 #endif
--- gcl-2.6.10.orig/o/gbc.c
+++ gcl-2.6.10/o/gbc.c
@@ -1508,6 +1508,7 @@ FFN(siLheap_report)(void) {
   vs_push(make_fixnum(0));
   vs_push(make_fixnum(0));
 #endif
+  vs_push(make_fixnum(phys_pages));
 
 }  
 
--- gcl-2.6.10.orig/o/main.c
+++ gcl-2.6.10/o/main.c
@@ -27,6 +27,7 @@ Foundation, 675 Mass Ave, Cambridge, MA
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
+#include <fcntl.h>
 
 static void
 init_main(void);
@@ -138,6 +139,25 @@ mbrk(void *v) {
   return uc==(ufixnum)sbrk(uv-uc) ? 0 : -1;
 }
     
+ufixnum
+get_phys_pages_no_malloc(void) {
+  int l;
+  char b[PAGESIZE],*c;
+  const char *k="MemTotal:",*f="/proc/meminfo";
+  ufixnum res=0,n;
+  
+  if ((l=open(f,O_RDONLY))!=-1) {
+    if ((n=read(l,b,sizeof(b)))<sizeof(b) && 
+	!(b[n]=0) && 
+	(c=strstr(b,k)) && 
+	sscanf(c+strlen(k),"%lu",&n)==1)
+      res=n;
+    close(l);
+  }
+  return res>>(PAGEWIDTH-10);
+}
+
+
 int
 update_real_maxpage(void) {
 
@@ -161,12 +181,11 @@ update_real_maxpage(void) {
       }
   massert(!mbrk(cur));
 
-#ifdef HAVE_SYSCONF_PHYS_PAGES
-  phys_pages=raw_image ? 0 : sysconf(_SC_PHYS_PAGES);
+  phys_pages=get_phys_pages_no_malloc();
+
 #ifdef BRK_DOES_NOT_GUARANTEE_ALLOCATION
   if (phys_pages>0 && real_maxpage>phys_pages+first_data_page) real_maxpage=phys_pages+first_data_page;
 #endif
-#endif
 
   available_pages=real_maxpage-first_data_page;
   for (i=t_start,j=0;i<t_other;i++) {
@@ -266,8 +285,6 @@ main(int argc, char **argv, char **envp)
 #include "ld_bind_now.h"
 #endif
   
-  prelink_init();
-  
   setbuf(stdin, stdin_buf); 
   setbuf(stdout, stdout_buf);
 #ifdef _WIN32
