[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[davy@riacs.edu: Re: KCL on Sun-3 SunOS 4.0 ]



To: boyer@cli.com
Cc: wfs@CLI.COM
Subject: Re: KCL on Sun-3 SunOS 4.0 
In-Reply-To: Your message of Tue, 25 Apr 89 11:01:03 CDT.
             <8904251601.AA02348@CLI.COM> 
Date: Thu, 27 Apr 89 13:00:43 -0700
From: davy@riacs.edu


     From:  Robert S. Boyer <boyer@CLI.COM>
     Date:  Tue, 25 Apr 89 11:01:03 CDT
     Subject:  KCL on Sun-3 SunOS 4.0 

     The original kcl distributed by rascal does not run under lots of
     things and has not been changed since June 1987.  However, Bill
     Schelter (wfs) has incorporate many, many changes and many ports into
     a system called AKCL, Austin Kyoto Common Lisp.  (You need the
     original KCL around to build AKCL).  You may obtain this by anonymous
     ftp from cli.com or rascal.ics.utexas.edu.  I do not know whether Bill
     has AKCL running on SUNOS 4.0 yet, but since he will probably be
     facing that fight himself before too long, he might well give you help
     if you ask him in the right way.  He has completely mastered KCL, and
     improved it in innumerable ways.  I have heard only complaints about
     4.0.  I have heard that many people have found bugs in the Sun c
     compiler under 4.0, some of which Sun even admits to.  Perhaps some of
     these have been fixed in 4.1.  But I have heard serious complaints
     about 4.1, too.  I can sympathize with your desire not to use gcc, but
     on the other hand I have to tell you that I have heard more positive
     reports about it recently than about Sun's cc under 4.0.

     If I were you, I'd ask Bill for help and give him an account and lots
     of room on your machine.  No joke, this is probably your best bet if
     there are serious problems to be fought.  My intution is that several
     Sun cc bugs will have to be identified and then worked-around.


Just so you'll have them too, I received the following note which provided
the fixes.  It seems to work now, although I don't know enough LISP to
test it beyond defining a few trivial functions.

Thanks,
--Dave

Replied: Thu, 27 Apr 89 12:56:54 -0700
Replied: cinelli!handel.colostate.edu!varghese
Return-Path: cinelli!basso!varghese
Received: from icarus.riacs.edu by hydra.riacs.edu (4.12/2.0N)
	   id AA26503; Tue, 25 Apr 89 15:18:58 pdt
Received: from handel.CS.ColoState.EDU by icarus.riacs.edu (5.59/2.0G)
	   id AA23001; Tue, 25 Apr 89 15:18:13 PDT
Received: by handel.colostate.edu (5.58/SMI-DDN)
	id AA05548; Tue, 25 Apr 89 15:17:14 MST
Received: from basso.Horizon.Com by cinelli.Horizon.COM (4.0/SMI-4.0)
	id AA25237; Tue, 25 Apr 89 19:33:56 GMT
Received: by basso.Horizon.Com (4.0/SMI-4.0)
	id AA25818; Tue, 25 Apr 89 13:32:55 MDT
Date: Tue, 25 Apr 89 13:32:55 MDT
From: cinelli!basso!varghese (Joe Varghese)
Message-Id: <8904251932.AA25818@basso.Horizon.Com>
To: davy@riacs.edu
In-Reply-To: davy@riacs.edu's message of Mon, 24 Apr 89 16:29:53 -0700 <8904242329.AA29851@intrepid.riacs.edu>
Subject: KCL on Sun-3 SunOS 4.0
Reply-To: cinelli!handel.colostate.edu!varghese
Postal-Address: QTC Horizon Labs, 2301 Research Blvd. Suite 202, Fort Collins, CO 80526
Business-Phone: (303) 493 7047




    Okay, here's the deal.  We've got the June whatever KCL, on a Sun 3
    running SunOS 4.0.1 with plain Sun "cc".  We tried adding all this
    "-Qoption as -O -Bstatic" stuff to the makefiles and building from
    scratch.

    No dice.  It still dies with a memory fault in raw_kcl when it's
    loading ../cmpnew/cmpmain.lsp.


I had a similar problem and I fixed it with the help of two messages that I
read in comp.lang.lisp. The two (edited) messages are given below and after 
that I've enclosed the context diffs for the files that I changed. 
Good luck. If you need any more help, let me know. 

*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=

>From qtc!verdix!ogccse!blake!uw-beaver!cornell!mailrus!csd4.milw.wisc.edu!lll-winken!uunet!fed!arccs1!m1rcd00 Wed Apr  5 17:42:13 MDT 1989
Article 1705 of comp.lang.lisp:
Path: qtc!verdix!ogccse!blake!uw-beaver!cornell!mailrus!csd4.milw.wisc.edu!lll-winken!uunet!fed!arccs1!m1rcd00
>From: m1rcd00@arccs1.FRB.GOV (Bob Drzyzgula)
Newsgroups: comp.lang.lisp
Subject: Re: Trouble Compiling KCL on Sun3/SunOS4
Summary: Making Progress...
Keywords: KCL, Sun, SunOS4.0
Message-ID: <478@arcfs1.fed.FRB.GOV>
Date: 4 Apr 89 19:40:35 GMT
References: <476@arcfs1.fed.FRB.GOV>
Sender: news@fed.FRB.GOV
Reply-To: rcd@fed.frb.gov (Bob Drzyzgula)
Organization: Federal Reserve Board, Washington, DC
Lines: 117
Posted: Tue Apr  4 12:40:35 1989

Thank you all very much for your responses. There were four basic
suggestions:

	1. Use the gcc compiler. (Moises Lejter)
	2. Use -Bstatic on the Sun C compiler. (Mark Lerner)
	   (to Mark: You suggest that there is a step in the beginning
	   where the makefiles get rewritten. I have looked again
	   through all of the distribution, and I cannot find
	   any such configuration process. I got my copy from uunet.
	   Am I missing something?)
	3. Patch the source (Taizo Kojima's patches are included here).
	4. Buy IBCL. (a solicitation from the purveyor)

So, I first tried using the gcc comiler. To do this, I wound up having
to make two changes: I put -w in the gcc commands, since it got *real*
upset about one of the header files (external.h) not meeting gnu's
specs. I also had to patch the dpp preprocessor to make it generate
gnu-standard #line directives. (gnu uses # linenum filename, and the
filename has to be in double quotes in the general case. Sun's cc uses
#line linenum filename, and doesn't need the quotes. This is real easy
to find... search for #line in dpp.c). This got past loading cmpmain.lsp,
but choked on another memory error soon after loading setdoc.lsp
(transcript later).

Second, I tried putting -Bstatic on Sun's cc (yes, including the
one at the bottom of unixport/makefile that doesn't use CFLAGS). This
made no discernable difference in the outcome.

This was when Taizo Kojima's mail came in. I applied that patch, and
the Sun cc version ran through the cmpmain.lsp, but *failed in exactly
the same place as gcc*. So although I have achieved syncronization
between the two compilers, I have not gotten a running kcl. You've done
great so far, any more ideas? (Yes, I have run memory diagnostics on
my Sun and even tried a seperate compile on a different machine
[a 3/180])

Again, thanks. Transcript of failure follows, followed by Taizo
Kojima's patches:

	Initializing cmpvar...  
	Initializing cmpvs...  
	Initializing cmpwt...  
	Loading ../cmpnew/cmpmain.lsp
	Finished loading ../cmpnew/cmpmain.lsp
	Loading ../cmpnew/lfun_list.lsp
	Finished loading ../cmpnew/lfun_list.lsp
	Loading ../cmpnew/cmpopt.lsp
	Finished loading ../cmpnew/cmpopt.lsp
	Warning: COMPILE-FILE is being redefined.
	Warning: COMPILE is being redefined.
	Warning: DISASSEMBLE is being redefined.
	Loading ../lsp/setdoc.lsp
	Finished loading ../lsp/setdoc.lsp
	Warning: LISP-IMPLEMENTATION-VERSION is being redefined.sh: 954 Memory
	fault - core dumped
	*** Error code 139
	make: Fatal error: Command failed for target `saved_kcl'
	Current working directory /src/kcl/unixport
	*** Error code 1
	make: Fatal error: Command failed for target `all'



>Hello Mr.Drzyzgula
>
> The reason of a memory fault is the implicit return value of
>new Sun C compiler.
> To avoid this, you must add 2 lines at bottom of the functions
>using asm() statement, get_mark_bit() and get_set_mark_bit() in

[ .. stuff deleted but included in the diffs at the end of the message .. Joe]

>
>
>
>Next, CFLAGS in unixport/makefile, add '-Bstatic' option for static binding,
>and add '-Bstatic' option where '/bin/ld' is called in file c/unixfasl.c
>
>- - Bye.
>PS:
> Sorry of my poor English X-<.
>				Mitsubishi Electric, Amagasaki, Japan
>				Taizo Kojima
Bob Drzyzgula
rcd@fed.frb.gov, uunet!fed!rcd
Federal Reserve Board, Washington, DC  20551

*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=

>From qtc!verdix!ogccse!blake!uw-beaver!mit-eddie!bloom-beacon!tut.cis.ohio-state.edu!cs.utexas.edu!uunet!brunix!doorknob!mlm Wed Apr 12 13:23:15 MDT 1989
Article 1714 of comp.lang.lisp:
Path: qtc!verdix!ogccse!blake!uw-beaver!mit-eddie!bloom-beacon!tut.cis.ohio-state.edu!cs.utexas.edu!uunet!brunix!doorknob!mlm
>From: mlm@cs.brown.edu (Moises Lejter)
Newsgroups: comp.lang.lisp
Subject: Re: Trouble Compiling KCL on Sun3/SunOS4
Message-ID: <MLM.89Apr4173615@monaco.cs.brown.edu>
Date: 4 Apr 89 21:36:15 GMT
References: <476@arcfs1.fed.FRB.GOV> <478@arcfs1.fed.FRB.GOV>
Sender: news@brunix.UUCP
Reply-To: mlm@cs.brown.edu
Organization: Brown University Department of Computer Science
Lines: 285
Posted: Tue Apr  4 14:36:15 1989
In-reply-to: m1rcd00@arccs1.FRB.GOV's message of 4 Apr 89 19:40:35 GMT


	I went through my copy of the KCL code, and there is one more
	change I made that could have something to do with it -
	I don't remember what the symptoms were that made me realize
	it was a problem.  KCL was originally written for 4.2 BSD
	systems, and then the kernel allocated a fixed-size table of
	FILE structures.  KCL knew about that table, and used that
	knowledge to close all open files, when needed.
	Unfortunately, 4.3 BSD and SunOS 4.0 systems allocate new FILE 
	structures dynamically (only the initial stdin, stdout, stderr
	are in a preallocated table), so the trick KCL uses does not work
	anymore (I believe it causes seg faults, when KCL tries to
	access and close the fourth file).

	If you look at the code in unixsave.c, function Lsave(),
	you will see it loops over the (nonexistent) file table,
	closing any open files it finds.  At Brown, I added the following
	three functions to unixfsys.c, and then replaced all
	calls everywhere to fopen() and fclose() to calls to these
	functions. I also had Lsave() call the function closeAllOpenFiles(),
	instead of looping as it does.

	At the end of this message you will find context diffs of
	unixfsys.c, unixsave.c, unixfasl.c, main.c, and file.d to
	achieve this.  Note that to have these changes actually
	manifest themselves, you have to #define BRUNIX.  I hadn't
	intended then to make these changes public...

							Moises

-----------------------------------------------------------------------------
Internet/CSnet:   mlm@cs.brown.edu		BITNET:  mlm@browncs.BITNET
UUCP:    ...!uunet!brunix!mlm			Phone:	 (401)863-7664
USmail:  Moises Lejter, Box 1910 Brown University, Providence RI 02912


[ .. stuff deleted but included in the diffs at the end of the message .. Joe]

*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=

My context diffs: 

*** bin/makefile.~1~	Wed Nov 27 14:42:46 1985
--- bin/makefile	Wed Apr 12 14:14:32 1989
***************
*** 1,7 ****
  DEFS	= -DUNIX
! CFLAGS  = $(DEFS) -O
  
  
  all:	dpp
  
  dpp:	dpp.c
--- 1,7 ----
  DEFS	= -DUNIX
! CFLAGS  = -Bstatic $(DEFS) -O
  
  
  all:	dpp
  
  dpp:	dpp.c
*** cmpnew/makefile.~1~	Wed Nov 27 14:42:32 1985
--- cmpnew/makefile	Wed Apr 12 14:12:40 1989
***************
*** 8,18 ****
  	cmpflet.o cmpfun.o cmpif.o cmpinline.o cmplabel.o cmplam.o cmplet.o \
  	cmploc.o cmpmap.o cmpmulti.o cmpspecial.o cmptag.o cmptop.o \
  	cmptype.o cmputil.o cmpvar.o cmpvs.o cmpwt.o
  
  
! CFLAGS	= -c -O
  
  
  all:	$(OBJS)
  
  
--- 8,18 ----
  	cmpflet.o cmpfun.o cmpif.o cmpinline.o cmplabel.o cmplam.o cmplet.o \
  	cmploc.o cmpmap.o cmpmulti.o cmpspecial.o cmptag.o cmptop.o \
  	cmptype.o cmputil.o cmpvar.o cmpvs.o cmpwt.o
  
  
! CFLAGS	= -Bstatic -c -O
  
  
  all:	$(OBJS)
  
  
*** lsp/makefile.~1~	Wed Nov 27 14:42:12 1985
--- lsp/makefile	Wed Apr 12 14:13:08 1989
***************
*** 7,17 ****
  OBJS	= arraylib.o assert.o defmacro.o defstruct.o describe.o evalmacros.o \
  	iolib.o listlib.o mislib.o module.o numlib.o packlib.o predlib.o \
  	seq.o seqlib.o setf.o top.o trace.o 
  
  
! CFLAGS	= -c -O
  
  
  all:	$(OBJS)
  
  
--- 7,17 ----
  OBJS	= arraylib.o assert.o defmacro.o defstruct.o describe.o evalmacros.o \
  	iolib.o listlib.o mislib.o module.o numlib.o packlib.o predlib.o \
  	seq.o seqlib.o setf.o top.o trace.o 
  
  
! CFLAGS	= -Bstatic -c -O
  
  
  all:	$(OBJS)
  
  
*** o/makefile.~1~	Thu Dec 18 14:26:06 1986
--- o/makefile	Wed Apr 12 14:13:47 1989
***************
*** 13,23 ****
  HDIR	= ../h
  CDIR	= ../c
  
  
  DEFS	= -D$(MACHINE) -DMAXPAGE=16384 -DVSSIZE=8152
! CFLAGS	= $(DEFS) -I$(HDIR)
  OFLAG	= -O
  
  DPP	= ../bin/dpp
  
  
--- 13,23 ----
  HDIR	= ../h
  CDIR	= ../c
  
  
  DEFS	= -D$(MACHINE) -DMAXPAGE=16384 -DVSSIZE=8152
! CFLAGS	= -Bstatic $(DEFS) -I$(HDIR)
  OFLAG	= -O
  
  DPP	= ../bin/dpp
  
  
*** unixport/makefile.~1~	Thu Dec 18 14:26:38 1986
--- unixport/makefile	Wed Apr 12 14:16:41 1989
***************
*** 9,19 ****
  CMPDIR	= ../cmpnew
  PORTDIR	= ../unixport
  
  
  DEFS	= -D$(MACHINE) -DMAXPAGE=16384 -DVSSIZE=8152
! CFLAGS	= -c $(DEFS) -I$(HDIR)
  
  LIBS	= -lm
  
  
  OBJS	= $(ODIR)/main.o $(ODIR)/alloc.o $(ODIR)/gbc.o \
--- 9,19 ----
  CMPDIR	= ../cmpnew
  PORTDIR	= ../unixport
  
  
  DEFS	= -D$(MACHINE) -DMAXPAGE=16384 -DVSSIZE=8152
! CFLAGS	= -Bstatic -c $(DEFS) -I$(HDIR)
  
  LIBS	= -lm
  
  
  OBJS	= $(ODIR)/main.o $(ODIR)/alloc.o $(ODIR)/gbc.o \
***************
*** 61,71 ****
  		$(CMPDIR)/lfun_list.lsp \
  		$(CMPDIR)/cmpopt.lsp
  	raw_kcl $(PORTDIR)/ < init_kcl.lsp
  
  raw_kcl:	$(OBJS) sys_kcl.o $(LSPOBJS) $(CMPOBJS)
! 	cc -o raw_kcl $(OBJS) sys_kcl.o $(LSPOBJS) $(CMPOBJS) $(LIBS)
  
  sys_kcl.o:	sys_kcl.c
  	cc $(CFLAGS) sys_kcl.c
  
  
--- 61,71 ----
  		$(CMPDIR)/lfun_list.lsp \
  		$(CMPDIR)/cmpopt.lsp
  	raw_kcl $(PORTDIR)/ < init_kcl.lsp
  
  raw_kcl:	$(OBJS) sys_kcl.o $(LSPOBJS) $(CMPOBJS)
! 	cc -Bstatic -o raw_kcl $(OBJS) sys_kcl.o $(LSPOBJS) $(CMPOBJS) $(LIBS)
  
  sys_kcl.o:	sys_kcl.c
  	cc $(CFLAGS) sys_kcl.c
  
  
*** c/bitop.c.~1~	Thu Jun  4 01:07:54 1987
--- c/bitop.c	Wed Apr 12 15:42:53 1989
***************
*** 77,86 ****
--- 77,89 ----
  	asm("	lsrl	#3,d1");
  	asm("	movl	_mark_table,a0");
  	asm("	btst	d0,a0@(0,d1:L)");
  	asm("	sne	d0");
  	asm("	andl	#1,d0");
+ 	asm("   unlk    a6");	/* for SunOS4.0 */
+ 	asm("   rts");		/* for SunOS4.0 */
+ 
  }
  
  set_mark_bit(x)
  int *x;
  {
***************
*** 88,97 ****
--- 91,102 ----
  	asm("	lsrl	#2,d0");
  	asm("	movl	d0,d1");
  	asm("	lsrl	#3,d1");
  	asm("	movl	_mark_table,a0");
  	asm("	bset	d0,a0@(0,d1:L)");
+ 	asm("   unlk    a6");	/* for SunOS4.0 */
+ 	asm("   rts");		/* for SunOS4.0 */
  }
  
  get_set_mark_bit(x)
  int *x;
  {
***************
*** 101,110 ****
--- 106,117 ----
  	asm("	lsrl	#3,d1");
  	asm("	movl	_mark_table,a0");
  	asm("	bset	d0,a0@(0,d1:L)");
  	asm("	sne	d0");
  	asm("	andl	#1,d0");
+ 	asm("   unlk    a6");	/* for SunOS4.0 */
+ 	asm("   rts");		/* for SunOS4.0 */
  }
  
  #endif
  
  #ifndef NEWS
***************
*** 119,128 ****
--- 126,137 ----
  	asm("	lsrl	#3,d1");
  	asm("	movl	_mark_table,a0");
  	asm("	btst	d0,a0@(0,d1:L)");
  	asm("	sne	d0");
  	asm("	andl	#1,d0");
+ 	asm("   unlk    a6");	/* for SunOS4.0 */
+ 	asm("   rts");		/* for SunOS4.0 */
  }
  
  set_mark_bit(x)
  int *x;
  {
***************
*** 130,139 ****
--- 139,150 ----
  	asm("	lsrl	#2,d0");
  	asm("	movl	d0,d1");
  	asm("	lsrl	#3,d1");
  	asm("	movl	_mark_table,a0");
  	asm("	bset	d0,a0@(0,d1:L)");
+ 	asm("   unlk    a6");	/* for SunOS4.0 */
+ 	asm("   rts");		/* for SunOS4.0 */
  }
  
  get_set_mark_bit(x)
  int *x;
  {
***************
*** 143,152 ****
--- 154,165 ----
  	asm("	lsrl	#3,d1");
  	asm("	movl	_mark_table,a0");
  	asm("	bset	d0,a0@(0,d1:L)");
  	asm("	sne	d0");
  	asm("	andl	#1,d0");
+ 	asm("   unlk    a6");	/* for SunOS4.0 */
+ 	asm("   rts");		/* for SunOS4.0 */
  }
  
  #endif
  #endif
  
*** c/file.d.~1~	Thu Jun  4 10:10:50 1987
--- c/file.d	Wed Apr 12 15:22:34 1989
***************
*** 15,24 ****
--- 15,28 ----
  	It also contains read_fasl_data.
  */
  
  #include "include.h"
  
+ #define fopen( file, mode )	openFile( file, mode )
+ #define fclose( file )		closeFile( file )
+ extern FILE *openFile();
+ 
  #define	kclgetc(FP)		getc(FP)
  #define	kclungetc(C, FP)	ungetc(C, FP)
  #define	kclfeof(FP)		feof(FP)
  #define	kclputc(C, FP)		putc(C, FP)
  
*** c/main.c.~1~	Thu Jun  4 01:07:54 1987
--- c/main.c	Wed Apr 12 14:08:50 1989
***************
*** 9,18 ****
--- 9,21 ----
  	IMPLEMENTATION-DEPENDENT
  */
  
  #include "include.h"
  
+ #define fopen( file, mode )	openFile( file, mode )
+ #define fclose( file )		closeFile( file )
+ extern FILE *openFile();
  bool saving_system = FALSE;
  
  #ifdef BSD
  #include <sys/time.h>
  #include <sys/resource.h>
*** c/unixfasl.c.~1~	Thu Jun  4 01:07:55 1987
--- c/unixfasl.c	Wed Apr 12 15:33:28 1989
***************
*** 3,12 ****
--- 3,15 ----
  Copying of this file is authorized to users who have executed the true and
  proper "License Agreement for Kyoto Common LISP" with SIGLISP.
  */
  
  #include "include.h"
+ #define fopen( file, mode )	openFile( file, mode )
+ #define fclose( file )		closeFile( file )
+ extern FILE *openFile();
  
  
  #ifdef BSD
  #include <a.out.h>
  #endif
***************
*** 144,154 ****
  
  AGAIN:
  
  #ifdef BSD
  	sprintf(command,
! 		"ld -d -N -x -A %s -T %x %s -o %s",
  		kcl_self,
  		memory->cf.cf_start,
  		filename,
  		tempfilename);
  #endif
--- 147,157 ----
  
  AGAIN:
  
  #ifdef BSD
  	sprintf(command,
! 		"ld -Bstatic -d -N -x -A %s -T %x %s -o %s",
  		kcl_self,
  		memory->cf.cf_start,
  		filename,
  		tempfilename);
  #endif
***************
*** 256,266 ****
  	coerce_to_filename(faslfile, filename);
  
  	sprintf(tempfilename, "/tmp/fasltemp%d", getpid());
  
  	sprintf(command,
! 		"ld -d -N -x -A %s -T %x %s %s -o %s",
  		kcl_self,
  		(int)core_end,
  		filename,
  		ldargstr,
  		tempfilename);
--- 259,269 ----
  	coerce_to_filename(faslfile, filename);
  
  	sprintf(tempfilename, "/tmp/fasltemp%d", getpid());
  
  	sprintf(command,
! 		"ld -Bstatic -d -N -x -A %s -T %x %s %s -o %s",
  		kcl_self,
  		(int)core_end,
  		filename,
  		ldargstr,
  		tempfilename);
***************
*** 293,303 ****
  	data = read_fasl_vector(faslfile);
  	vs_push(data);
  	close_stream(faslfile, TRUE);
  
  	sprintf(command,
! 		"ld -d -N -x -A %s -T %x %s %s -o %s",
  		kcl_self,
  		memory->cf.cf_start,
  		filename,
  		ldargstr,
  		tempfilename);
--- 296,306 ----
  	data = read_fasl_vector(faslfile);
  	vs_push(data);
  	close_stream(faslfile, TRUE);
  
  	sprintf(command,
! 		"ld -Bstatic -d -N -x -A %s -T %x %s %s -o %s",
  		kcl_self,
  		memory->cf.cf_start,
  		filename,
  		ldargstr,
  		tempfilename);
*** c/unixfsys.c.~1~	Thu Jun  4 01:07:55 1987
--- c/unixfsys.c	Wed Apr 12 14:04:48 1989
***************
*** 7,16 ****
--- 7,19 ----
  #include "include.h"
  #include <sys/types.h>
  #include <sys/stat.h>
  #include <pwd.h>
  
+ #define fopen( file, mode ) openFile(file, mode)
+ #define fclose(file) closeFile(file)
+ extern FILE *openFile();
  
  #define	MAXPATHLEN	1024
  
  object Kwild;
  
***************
*** 639,643 ****
--- 642,693 ----
  	make_function("USER-HOMEDIR-PATHNAME", Luser_homedir_pathname);
  	make_function("DIRECTORY", Ldirectory);
  
  	make_si_function("CHDIR", siLchdir);
  }
+ 
+ 
+ #undef fopen
+ #undef fclose
+ 
+ FILE **filesAlreadyOpened = NULL;
+ 
+ FILE *openFile( file, mode )
+     char *file, *mode;
+     {
+ 	FILE *newFile = fopen( file, mode );
+ 
+ 	if (! newFile) return( newFile );
+ 
+ 	if (! filesAlreadyOpened)
+ 	    filesAlreadyOpened =
+ 		(FILE **) calloc( getdtablesize(), sizeof( FILE * ));
+ 
+ 	return( filesAlreadyOpened[ fileno( newFile ) ] = newFile );
+     }
+ 
+ 
+ int closeFile( someFile )
+     FILE *someFile;
+     {
+ 	int result = fclose( someFile );
+ 
+ 	if (filesAlreadyOpened)
+ 	    filesAlreadyOpened[ fileno( someFile ) ] = NULL;
+ 
+ 	return( result );
+     }
+ 
+ 
+ void closeAllOpenFiles()
+     {
+ 	if (filesAlreadyOpened)
+ 	    {
+ 		FILE **ptr, **end = filesAlreadyOpened + getdtablesize();
+ 		
+ 		for (ptr = filesAlreadyOpened; ptr < end; ptr++ )
+ 		    if (*ptr) fclose( *ptr );
+ 	    }
+     }
+ 
+ 
+ 
*** c/unixsave.c.~1~	Thu Jun  4 01:07:55 1987
--- c/unixsave.c	Wed Apr 12 14:07:49 1989
***************
*** 7,16 ****
--- 7,19 ----
  /*
  	unixsave.c
  */
  
  #include "include.h"
+ #define fopen( file, mode )	openFile( file, mode )
+ #define fclose( file )		closeFile( file )
+ extern FILE *openFile();
  
  /* When MACHINE is S3000, use fcntl.h */
  #ifdef S3000
  #include <fcntl.h>
  #else
***************
*** 316,325 ****
--- 319,331 ----
  	check_type_or_pathname_string_symbol_stream(&vs_base[0]);
  	coerce_to_filename(vs_base[0], filename);
  /*
  	_cleanup();
  */
+ 	closeAllOpenFiles();
+ 
+ /*
  	{
  		FILE *p;
  		int nfile;
  
  #ifdef BSD
***************
*** 328,337 ****
--- 334,345 ----
  		nfile = _NFILE;
  #endif
  		for (p = &_iob[3];  p < &_iob[nfile];  p++)
  			fclose(p);
  	}
+ */
+ 
  	memory_save(kcl_self, filename);
  /*
  	_exit(0);
  */
  	exit(0);



*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=




Joe Varghese
varghese@handel.colostate.edu   (Internet)
verdix!qtc!cinelli!varghese   (UUCP)
(303) 493 7047