1
0
mirror of https://github.com/Interlisp/maiko.git synced 2026-01-13 15:18:14 +00:00
Interlisp.maiko/inc/timeout.h
Nick Briggs de5ea2110f
Correct integer type warnings (#405)
* Correct warning: cast to smaller integer type -- X_init/lispbitmap

* Fixes to INTRSAFE, INTRSAFE0 and ensure TIMEOUT, TIMEOUT0 used appropriately

INTRSAFE and INTRSAFE0 must clear errno before executing the library or system
call because not all library calls set errno on success.
Avoid casting pointers or larger integer values down to smaller ints before
comparing to 0 or -1, and use NULL (a pointer) rather than 0.

Fix cases where the result of the library call is a pointer rather than an int
to use TIMEOUT0 instead of TIMEOUT, testing for NULL rather than -1
on timeout (errno == EINTR)

* Remove useless validity check of LASTVMEMFILEPAGE_word pointer

* Convert pointer arithmetic type in drawline from int to ptrdiff_t

* Add NOTE warning about a 32-bit vs 64-bit issue affecting currently unused GET_NATIVE_ADDR_FROM_LISP_PTR
2021-11-04 09:08:55 -07:00

69 lines
1.6 KiB
C

#ifndef TIMEOUT_H
#define TIMEOUT_H 1
/* $Id: timeout.h,v 1.2 1999/01/03 02:06:27 sybalsky Exp $ (C) Copyright Venue, All Rights Reserved */
/************************************************************************/
/* */
/* (C) Copyright 1989-98 Venue. All Rights Reserved. */
/* Manufactured in the United States of America. */
/* */
/************************************************************************/
#include "setjmp.h" /* for jmp_buf */
extern jmp_buf jmpbuf;
/*** TIMEOUT_TIME is changeable by UNIX env var LDEFILETIMEOUT.
#define TIMEOUT_TIME 10 **/
extern int TIMEOUT_TIME;
#define SETJMP(x) \
{ \
if(setjmp(jmpbuf) != 0) return(x); \
}
#define TIMEOUT(exp) \
{ \
alarm(TIMEOUT_TIME); \
INTRSAFE(exp); \
alarm(0); \
}
#define TIMEOUT0(exp) \
{ \
alarm(TIMEOUT_TIME); \
INTRSAFE0(exp); \
alarm(0); \
}
#define S_TOUT(exp) \
alarm(TIMEOUT_TIME),\
(exp), \
alarm(0)
#define ERRSETJMP(rval) \
{ \
if(setjmp(jmpbuf) != 0) \
{ \
*Lisp_errno = 100; \
return(rval); \
} \
}
/************************************************************************/
/* */
/* INTRSAFE */
/* */
/* Put a check for EINTR around a system call, and keep executing */
/* the call until we don't get that error any more. */
/* */
/************************************************************************/
#define INTRSAFE(exp) \
do {errno = 0; } while ((exp) == -1 && errno == EINTR)
#define INTRSAFE0(exp) \
do {errno = 0; } while ((exp) == NULL && errno == EINTR)
#endif /* TIMEOUT_H */