diff --git a/configure.ac b/configure.ac index e6f7d7a..ba57733 100644 --- a/configure.ac +++ b/configure.ac @@ -52,7 +52,7 @@ AC_CHECK_FUNCS(random) # Does the system have the index library function? If not, strchr # will be used. -dnl FIXME +AC_CHECK_FUNCS(index) # Does the system have the bcopy, bzero, and bcmp library functions? # If not, memcpy/memset/memcmp will be used. @@ -105,10 +105,8 @@ AC_EGREP_HEADER(_SC_PAGESIZE, unistd.h, [ # signals (has sigblock and related functions); set reliable_signals=posix # for POSIX-style signals (sigprocmask, sigsets); otherwise old V7/SysV # signal semantics are assumed. -if false; then - AC_DEFINE(BSD_SIGNALS, 1, [FIXME HARD]) -fi -AC_DEFINE(POSIX_SIGNALS, 1, [FIXME HARD]) +AC_CHECK_HEADERS(signal.h) +AC_CHECK_FUNCS(sigprocmask sigblock) # To support dynamic loading of object files and "dump", the system's # a.out format has to be known. Choose one of the following: @@ -293,9 +291,8 @@ AC_CHECK_HEADERS(termio.h termios.h) # The interpreter uses the getrlimit function to determine the maximum # stack size of the running program. If this function is not supported, # set max_stack_size to a (fixed) maximum stack size (in bytes). -if false; then - AC_DEFINE(MAX_STACK_SIZE, 1, [FIXME HARD]) -fi +AC_CHECK_FUNCS(getrlimit) +AC_DEFINE(DEFAULT_MAX_STACK_SIZE, 1024*1024, [Define default max stack size]) # Is the mprotect system call supported? The generational garbage collector # requires mprotect to implement incremental GC. $mprotect is ignored if @@ -339,7 +336,7 @@ fi # function actually extend the stack? If in doubt, extract alloca.o # from the C library and check if it contains the symbols malloc and free. # If this is the case, forget it. -AC_DEFINE(USE_ALLOCA, 1, [FIXME HARD]) +AC_CHECK_FUNCS(alloca) # Must be included to use alloca? Is "#pragma alloca" required? AC_CHECK_HEADERS(alloca.h) @@ -391,6 +388,8 @@ AC_DEFINE(OBJ_DIR, "/usr/lib/elk", [FIXME HARD]) #define FIND_AOUT defined(USE_LD) || defined(CAN_DUMP) || defined(INIT_OBJECTS) AC_DEFINE(FIND_AOUT, 1, [FIXME HARD]) +AC_CHECK_HEADERS(pwd.h sys/resource.h) + dnl dnl Check for available compiler features dnl diff --git a/include/exception.h b/include/exception.h index 8a83c36..bc8c948 100644 --- a/include/exception.h +++ b/include/exception.h @@ -28,22 +28,24 @@ * THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. */ +#ifdef HAVE_SIGNAL_H +# include +#endif + extern int Intr_Was_Ignored; extern unsigned long Intr_Level; -#ifdef POSIX_SIGNALS +#if defined(HAVE_SIGPROCMASK) extern sigset_t Sigset_Old, Sigset_Block; -#else -#ifdef BSD_SIGNALS +#elif defined(HAVE_SIGBLOCK) extern int Sigmask_Old, Sigmask_Block; #else C_LINKAGE_BEGIN extern void Intr_Handler P_((int)); C_LINKAGE_END #endif -#endif -#ifdef BSD_SIGNALS +#if defined(HAVE_SIGPROCMASK) || ! defined(HAVE_SIGBLOCK) # ifndef sigmask # define sigmask(n) (1 << ((n)-1)) # endif @@ -57,15 +59,14 @@ extern unsigned long Intr_Level; if (Intr_Level > 0 && --Intr_Level == 0) Force_Enable_Interrupts;\ } -#ifdef BSD_SIGNALS -#define Force_Disable_Interrupts (void)sigblock (Sigmask_Block) -#define Force_Enable_Interrupts (void)sigsetmask (Sigmask_Old) -#else -#ifdef POSIX_SIGNALS +#ifdef HAVE_SIGPROCMASK #define Force_Disable_Interrupts (void)sigprocmask (SIG_BLOCK, &Sigset_Block,\ (sigset_t *)0) #define Force_Enable_Interrupts (void)sigprocmask (SIG_SETMASK, &Sigset_Old,\ (sigset_t *)0) +#elif defined(HAVE_SIGBLOCK) +#define Force_Disable_Interrupts (void)sigblock (Sigmask_Block) +#define Force_Enable_Interrupts (void)sigsetmask (Sigmask_Old) #else #define Force_Disable_Interrupts {\ if (!Intr_Was_Ignored) (void)signal (SIGINT, SIG_IGN);\ @@ -74,4 +75,4 @@ extern unsigned long Intr_Level; if (!Intr_Was_Ignored) (void)signal (SIGINT, Intr_Handler);\ } #endif -#endif + diff --git a/include/intern.h b/include/intern.h index 5b3a815..48f5629 100644 --- a/include/intern.h +++ b/include/intern.h @@ -149,7 +149,7 @@ extern SYMTAB *Open_File_And_Snarf_Symbols P_((char *)); /* stkmem.c */ -#ifndef USE_ALLOCA +#ifndef HAVE_ALLOCA extern Object Save_GC_Nodes P_((void)); #endif diff --git a/include/object.h b/include/object.h index 407060b..755f214 100644 --- a/include/object.h +++ b/include/object.h @@ -29,6 +29,7 @@ * THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. */ +#include #include #include diff --git a/include/scheme.h b/include/scheme.h index 5ca64be..1e88dd1 100644 --- a/include/scheme.h +++ b/include/scheme.h @@ -31,9 +31,6 @@ #ifndef SCHEME_H #define SCHEME_H -#include -#include - #include "site.h" #include "funcproto.h" #include "param.h" diff --git a/include/stkmem.h b/include/stkmem.h index 2756b3a..6e8b1d3 100644 --- a/include/stkmem.h +++ b/include/stkmem.h @@ -28,7 +28,7 @@ * THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. */ -#ifdef USE_ALLOCA +#ifdef HAVE_ALLOCA #ifdef HAVE_ALLOCA_H # include @@ -59,7 +59,7 @@ C_LINKAGE_END (ret) = (type)alloca((size))) #define Alloca_End -#else /* USE_ALLOCA */ +#else /* HAVE_ALLOCA */ extern MEM_NODE *Mem_List; extern char *Mem_Alloc P_((unsigned)); diff --git a/lib/unix/signal.c b/lib/unix/signal.c index b041bc8..872dc33 100644 --- a/lib/unix/signal.c +++ b/lib/unix/signal.c @@ -201,11 +201,7 @@ static Object P_Pause() { Fatal_Error("pause() returned unexpectedly"); } -#if defined(POSIX_SIGNALS) || defined(BSD_SIGNALS) -# define RELIABLE_SIGNALS -#endif - -#ifdef RELIABLE_SIGNALS +#if defined(HAVE_SIGPROCMASK) || defined(HAVE_SIGBLOCK) static Object Handlers; @@ -217,7 +213,7 @@ static Object P_Alarm(Object s) { void General_Handler(int sig) { Object fun, args; -#ifndef BSD_SIGNALS +#if defined(HAVE_SIGPROCMASK) (void)signal(sig, General_Handler); #endif Set_Error_Tag("signal-handler"); @@ -248,7 +244,7 @@ static Object Action_To_Sym(void (*act)()) { } void Add_To_Mask(int sig) { -#ifdef POSIX_SIGNALS +#ifdef HAVE_SIGPROCMASK sigaddset(&Sigset_Block, sig); #else Sigmask_Block |= sigmask(sig); @@ -258,7 +254,7 @@ void Add_To_Mask(int sig) { } void Remove_From_Mask(int sig) { -#ifdef POSIX_SIGNALS +#ifdef HAVE_SIGPROCMASK sigdelset(&Sigset_Block, sig); #else Sigmask_Block &= ~sigmask(sig); @@ -319,7 +315,7 @@ static Object P_Signal(int argc, Object *argv) { Raise_System_Error("~E"); return Truep(old) ? old : Action_To_Sym(disp); } -#endif /* RELIABLE_SIGNALS */ +#endif /* defined(HAVE_SIGPROCMASK) || defined(HAVE_SIGBLOCK) */ void elk_init_unix_signal() { Define_Symbol(&Sym_Exit, "exit"); @@ -328,7 +324,7 @@ void elk_init_unix_signal() { Def_Prim(P_Kill, "unix-kill", 2, 2, EVAL); Def_Prim(P_List_Signals, "unix-list-signals", 0, 0, EVAL); Def_Prim(P_Pause, "unix-pause", 0, 0, EVAL); -#ifdef RELIABLE_SIGNALS +#if defined(HAVE_SIGPROCMASK) || defined(HAVE_SIGBLOCK) Def_Prim(P_Alarm, "unix-alarm", 1, 1, EVAL); Handlers = Make_Vector(NSIG, False); Global_GC_Link(Handlers); diff --git a/src/cont.c b/src/cont.c index ecebe48..666b4c1 100644 --- a/src/cont.c +++ b/src/cont.c @@ -98,7 +98,7 @@ convex_longjmp (char *p, int i) { WIND *First_Wind, *Last_Wind; static Object Cont_Value; -#ifndef USE_ALLOCA +#ifndef HAVE_ALLOCA static Object Cont_GCsave; #endif @@ -161,7 +161,7 @@ void Jump_Cont (struct S_Control *cp, Object val) { longjmp (p->j, 1); } -#ifndef USE_ALLOCA +#ifndef HAVE_ALLOCA Object Terminate_Cont (Object cont) { Free_Mem_Nodes (CONTROL(cont)->memlist); return Void; @@ -190,7 +190,7 @@ Object Internal_Call_CC (int from_dump, Object proc) { control = gcsave = Null; GC_Link3 (proc, control, gcsave); -#ifndef USE_ALLOCA +#ifndef HAVE_ALLOCA gcsave = Save_GC_Nodes (); #endif @@ -220,12 +220,12 @@ Object Internal_Call_CC (int from_dump, Object proc) { to = cp->stack; memcpy (to, p, cp->size); cp->delta = to - p; -#ifndef USE_ALLOCA +#ifndef HAVE_ALLOCA Register_Object (control, (GENERIC)0, Terminate_Cont, 0); Save_Mem_Nodes (control); #endif if (setjmp (CONTROL(control)->j) != 0) { -#ifndef USE_ALLOCA +#ifndef HAVE_ALLOCA Restore_GC_Nodes (Cont_GCsave); #endif if (Intr_Level == 0) { @@ -289,7 +289,7 @@ void Funcall_Control_Point (Object control, Object argl, int eval) { cp = CONTROL(control); Switch_Environment (cp->env); GC_List = cp->gclist; -#ifndef USE_ALLOCA +#ifndef HAVE_ALLOCA Restore_Mem_Nodes (control); Cont_GCsave = CONTROL(control)->gcsave; #endif diff --git a/src/exception.c b/src/exception.c index c6db738..f9f1ee8 100644 --- a/src/exception.c +++ b/src/exception.c @@ -39,13 +39,11 @@ extern void Reset () elk_attribute(__noreturn__); int Intr_Was_Ignored; unsigned long int Intr_Level; -#ifdef POSIX_SIGNALS +#if defined(HAVE_SIGPROCMASK) sigset_t Sigset_Old, Sigset_Block; -#else -#ifdef BSD_SIGNALS +#elif defined(HAVE_SIGBLOCK) int Sigmask_Old, Sigmask_Block; #endif -#endif static Object V_Interrupt_Handler; @@ -59,25 +57,27 @@ void Signal_Exit (int sig) { void Init_Exception () { Define_Variable (&V_Interrupt_Handler, "interrupt-handler", Null); -#ifdef POSIX_SIGNALS +#if defined(HAVE_SIGPROCMASK) sigemptyset (&Sigset_Block); sigaddset (&Sigset_Block, SIGINT); (void)sigprocmask (0, (sigset_t *)0, &Sigset_Old); -#else -#ifdef BSD_SIGNALS +#elif defined(HAVE_SIGBLOCK) Sigmask_Block = sigmask (SIGINT); Sigmask_Old = sigblock (0); #endif -#endif +#ifdef SIGHUP (void)signal (SIGHUP, Signal_Exit); +#endif +#ifdef SIGPIPE (void)signal (SIGPIPE, Signal_Exit); +#endif } /*ARGSUSED*/ void Intr_Handler (int sig) { Object fun; -#ifndef BSD_SIGNALS +#if defined(HAVE_SIGPROCMASK) || ! defined(HAVE_SIGBLOCK) (void)signal (SIGINT, Intr_Handler); #endif Set_Error_Tag ("interrupt-handler"); diff --git a/src/heap-gen.c b/src/heap-gen.c index ca57173..b89fff3 100644 --- a/src/heap-gen.c +++ b/src/heap-gen.c @@ -1183,7 +1183,7 @@ static void ScanPage (Object *currentp, Object *nextcp) { case T_Control_Point: (CONTROL(obj)->delta) += CONTROL(obj)->reloc; -#ifdef USE_ALLOCA +#ifdef HAVE_ALLOCA Visit_GC_List (CONTROL(obj)->gclist, CONTROL(obj)->delta); #else Visit (&CONTROL(obj)->gcsave); diff --git a/src/heap-sc.c b/src/heap-sc.c index 981d5c9..a30d0cc 100644 --- a/src/heap-sc.c +++ b/src/heap-sc.c @@ -243,7 +243,7 @@ again: case T_Control_Point: Recursive_Visit (&CONTROL(*p)->memsave); CONTROL(*p)->delta += reloc; -#ifdef USE_ALLOCA +#ifdef HAVE_ALLOCA Visit_GC_List (CONTROL(*p)->gclist, CONTROL(*p)->delta); #else Recursive_Visit (&CONTROL(*p)->gcsave); diff --git a/src/io.c b/src/io.c index df9786e..4ecc97c 100644 --- a/src/io.c +++ b/src/io.c @@ -32,7 +32,9 @@ #include #include -#include +#ifdef HAVE_PWD_H +# include +#endif #include #include #include @@ -147,13 +149,16 @@ Object Get_File_Name (Object name) { char *Internal_Tilde_Expand (register char *s, register char **dirp) { register char *p; +#ifdef HAVE_PWD_H struct passwd *pw, *getpwnam(); +#endif if (*s++ != '~') return 0; for (p = s; *p && *p != '/'; p++) ; if (*p == '/') *p++ = 0; +#ifdef HAVE_PWD_H if (*s == '\0') { if ((*dirp = getenv ("HOME")) == 0) *dirp = ""; @@ -162,6 +167,9 @@ char *Internal_Tilde_Expand (register char *s, register char **dirp) { Primitive_Error ("unknown user: ~a", Make_String (s, strlen (s))); *dirp = pw->pw_dir; } +#else + *dirp = ""; +#endif return p; } @@ -175,7 +183,8 @@ Object General_File_Operation (Object s, register int op) { switch (op) { case 0: { char *p, *dir; - if ((p = Internal_Tilde_Expand (r, &dir)) == 0) { + p = Internal_Tilde_Expand (r, &dir); + if (p == 0) { Alloca_End; return s; } @@ -224,7 +233,8 @@ Object Open_File (char *name, int flags, int err) { struct stat st; Alloca_Begin; - if ((p = Internal_Tilde_Expand (name, &dir))) { + p = Internal_Tilde_Expand (name, &dir); + if (p) { Alloca (name, char*, strlen (dir) + 1 + strlen (p) + 1); sprintf (name, "%s/%s", dir, p); } diff --git a/src/libelk.c b/src/libelk.c index 5f99b80..e93e326 100644 --- a/src/libelk.c +++ b/src/libelk.c @@ -38,17 +38,19 @@ #include #include -#ifndef MAX_STACK_SIZE -# include -# include +#ifdef HAVE_GETRLIMIT +# include +# ifdef HAVE_SYS_RESOURCES_H +# include +# endif #endif #ifdef FIND_AOUT -# ifdef HAVE_UNISTD_H -# include -# else -# include -# endif +# ifdef HAVE_UNISTD_H +# include +# else +# include +# endif #endif #include "kernel.h" @@ -383,9 +385,7 @@ void Init_Everything () { } void Get_Stack_Limit () { -#ifdef MAX_STACK_SIZE - Max_Stack = MAX_STACK_SIZE; -#else +#ifdef HAVE_GETRLIMIT struct rlimit rl; if (getrlimit (RLIMIT_STACK, &rl) == -1) { @@ -393,6 +393,8 @@ void Get_Stack_Limit () { exit (1); } Max_Stack = rl.rlim_cur; +#else + Max_Stack = DEFAULT_MAX_STACK_SIZE; #endif Max_Stack -= STACK_MARGIN; } diff --git a/src/proc.c b/src/proc.c index 400581c..d49cf85 100644 --- a/src/proc.c +++ b/src/proc.c @@ -33,7 +33,7 @@ #include "kernel.h" -#ifdef USE_ALLOCA +#ifdef HAVE_ALLOCA # define MAX_ARGS_ON_STACK 4 #else # define MAX_ARGS_ON_STACK 8 diff --git a/src/read.c b/src/read.c index 8714664..57b9e12 100644 --- a/src/read.c +++ b/src/read.c @@ -52,7 +52,6 @@ extern void Flush_Output (Object); -extern char *index(); extern double atof(); int Skip_Comment (Object); @@ -659,7 +658,11 @@ Object Parse_Number (Object port, char const *buf, int radix) { return Null; if (p[1] == '+' || p[1] == '-') p++; +#ifdef HAVE_INDEX } else if (radix == 16 && !index ("0123456789abcdefABCDEF", c)) { +#else + } else if (radix == 16 && !strchr ("0123456789abcdefABCDEF", c)) { +#endif return Null; } else if (radix < 16 && (c < '0' || c > '0' + radix-1)) { return Null; diff --git a/src/stkmem.c b/src/stkmem.c index 4e49765..2b5eb5a 100644 --- a/src/stkmem.c +++ b/src/stkmem.c @@ -32,7 +32,7 @@ #include "kernel.h" -#ifndef USE_ALLOCA +#ifndef HAVE_ALLOCA extern char *malloc();