Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!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: 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 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 -----context diffs follow----- *** unixfsys.c.orig Tue Jan 26 17:10:36 1988 --- unixfsys.c Thu Oct 13 14:31:16 1988 *************** *** 4,9 **** --- 4,20 ---- proper "License Agreement for Kyoto Common LISP" with SIGLISP. */ + /* + * Modification History: + * 88.02 - File access routines + * Author: Moises Lejter + * Description: + * KCL as supplied assumes BSD4.2 implementation of internal file table. + * Calls to "fopen()" and "fclose()" were replaced with calls to + * "openFile()" and "closeFile()", which guarantee assumption will + * hold even though internal opsys implementation may change. + */ + #include "include.h" #include #include *************** *** 10,15 **** --- 21,33 ---- #include + #ifdef BRUNIX + #define fopen( file, mode ) openFile( file, mode ) + #define fclose( file ) closeFile( file ) + extern FILE *openFile(); + #endif + + #define MAXPATHLEN 1024 object Kwild; *************** *** 641,643 **** --- 659,710 ---- make_si_function("CHDIR", siLchdir); } + + + #ifdef BRUNIX + + #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 ); + } + } + + #endif + *** unixsave.c.orig Tue Jan 26 17:10:33 1988 --- unixsave.c Thu Oct 13 14:31:35 1988 *************** *** 8,15 **** --- 8,34 ---- unixsave.c */ + /* + * Modification History: + * 88.02 - File access routines + * Author: Moises Lejter + * Description: + * KCL as supplied assumes BSD4.2 implementation of internal file table. + * Calls to "fopen()" and "fclose()" were replaced with calls to + * "openFile()" and "closeFile()", which guarantee assumption will + * hold even though internal opsys implementation may change. + */ + #include "include.h" + + #ifdef BRUNIX + #define fopen( file, mode ) openFile( file, mode ) + #define fclose( file ) closeFile( file ) + extern FILE *openFile(); + #endif + + /* When MACHINE is S3000, use fcntl.h */ #ifdef S3000 #include *************** *** 318,323 **** --- 337,345 ---- /* _cleanup(); */ + #ifdef BRUNIX + closeAllOpenFiles(); + #else { FILE *p; int nfile; *************** *** 330,335 **** --- 352,358 ---- for (p = &_iob[3]; p < &_iob[nfile]; p++) fclose(p); } + #endif memory_save(kcl_self, filename); /* _exit(0); *** unixfasl.c.orig Tue Jan 26 17:10:28 1988 --- unixfasl.c Thu Oct 13 14:32:49 1988 *************** *** 4,10 **** --- 4,28 ---- proper "License Agreement for Kyoto Common LISP" with SIGLISP. */ + /* + * Modification History: + * 88.02 - File access routines + * Author: Moises Lejter + * Description: + * KCL as supplied assumes BSD4.2 implementation of internal file table. + * Calls to "fopen()" and "fclose()" were replaced with calls to + * "openFile()" and "closeFile()", which guarantee assumption will + * hold even though internal opsys implementation may change. + */ + #include "include.h" + + + #ifdef BRUNIX + #define fopen( file, mode ) openFile( file, mode ) + #define fclose( file ) closeFile( file ) + extern FILE *openFile(); + #endif #ifdef BSD *** main.c.orig Tue Jan 26 17:10:21 1988 --- main.c Thu Oct 13 14:32:10 1988 *************** *** 9,15 **** --- 9,34 ---- IMPLEMENTATION-DEPENDENT */ + /* + * Modification History: + * 88.02 - File access routines + * Author: Moises Lejter + * Description: + * KCL as supplied assumes BSD4.2 implementation of internal file table. + * Calls to "fopen()" and "fclose()" were replaced with calls to + * "openFile()" and "closeFile()", which guarantee assumption will + * hold even though internal opsys implementation may change. + */ + #include "include.h" + + + #ifdef BRUNIX + #define fopen( file, mode ) openFile( file, mode ) + #define fclose( file ) closeFile( file ) + extern FILE *openFile(); + #endif + bool saving_system = FALSE; *** file.d.orig Tue Jan 26 17:10:28 1988 --- file.d Fri Mar 25 23:23:23 1988 *************** *** 15,21 **** --- 15,42 ---- It also contains read_fasl_data. */ + /* + * Modification History: + * 88.02 - File access routines + * Author: Moises Lejter + * Description: + * KCL as supplied assumes BSD4.2 implementation of internal file table. + * Calls to "fopen()" and "fclose()" were replaced with calls to + * "openFile()" and "closeFile()", which guarantee assumption will + * hold even though internal opsys implementation may change. + */ + #include "include.h" + + + #ifdef VAX + #ifdef BRUNIX + #define fopen( file, mode ) openFile( file, mode ) + #define fclose( file ) closeFile( file ) + extern FILE *openFile(); + #endif + #endif + #define kclgetc(FP) getc(FP) #define kclungetc(C, FP) ungetc(C, FP) ----------------------------------------------------------------------------- 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