fix win32 warnings: unsigned long != CELL, IOSTREAM with sace restore, _ffsll and _isatty, fp patches
This commit is contained in:
44
C/arith1.c
44
C/arith1.c
@@ -330,22 +330,32 @@ msb(Int inp USES_REGS) /* calculate the most significant bit for an integer */
|
||||
"msb/1 received %d", inp);
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
#if HAVE__BUILTIN_FFSLL
|
||||
out = __builtin_ffsll(inp);
|
||||
#elif HAVE_FFSLL
|
||||
out = ffsll(inp);
|
||||
#else
|
||||
int off = sizeof(CELL)*4;
|
||||
while (off) {
|
||||
Int limit = ((CELL)1) << (off);
|
||||
if (inp >= limit) {
|
||||
out += off;
|
||||
inp >>= off;
|
||||
}
|
||||
off >>= 1;
|
||||
}
|
||||
if (inp==0)
|
||||
return 0L;
|
||||
#if SIZEOF_INT_P == 8
|
||||
if (inp & ((CELL)0xffffffffLL << 32)) {inp >>= 32; out += 32;}
|
||||
#endif
|
||||
return(out);
|
||||
if (inp & ((CELL)0xffffL << 16)) {inp >>= 16; out += 16;}
|
||||
if (inp & ((CELL)0xffL << 8)) {inp >>= 8; out += 8;}
|
||||
if (inp & ((CELL)0xfL << 4)) {inp >>= 4; out += 4;}
|
||||
if (inp & ((CELL)0x3L << 2)) {inp >>= 2; out += 2;}
|
||||
if (inp & ((CELL)0x1 << 1)) out++;
|
||||
#endif
|
||||
return out;
|
||||
}
|
||||
|
||||
Int
|
||||
Yap_msb(Int inp USES_REGS) /* calculate the most significant bit for an integer */
|
||||
{
|
||||
return msb(inp PASS_REGS);
|
||||
}
|
||||
|
||||
|
||||
static Int
|
||||
lsb(Int inp USES_REGS) /* calculate the least significant bit for an integer */
|
||||
{
|
||||
@@ -359,12 +369,12 @@ lsb(Int inp USES_REGS) /* calculate the least significant bit for an integer */
|
||||
if (inp==0)
|
||||
return 0L;
|
||||
#if SIZEOF_INT_P == 8
|
||||
if (!(inp & 0xffffffffLL)) {inp >>= 32; out += 32;}
|
||||
if (!(inp & (CELL)0xffffffffLL)) {inp >>= 32; out += 32;}
|
||||
#endif
|
||||
if (!(inp & 0xffffL)) {inp >>= 16; out += 16;}
|
||||
if (!(inp & 0xffL)) {inp >>= 8; out += 8;}
|
||||
if (!(inp & 0xfL)) {inp >>= 4; out += 4;}
|
||||
if (!(inp & 0x3L)) {inp >>= 2; out += 2;}
|
||||
if (!(inp & (CELL)0xffffL)) {inp >>= 16; out += 16;}
|
||||
if (!(inp & (CELL)0xffL)) {inp >>= 8; out += 8;}
|
||||
if (!(inp & (CELL)0xfL)) {inp >>= 4; out += 4;}
|
||||
if (!(inp & (CELL)0x3L)) {inp >>= 2; out += 2;}
|
||||
if (!(inp & ((CELL)0x1))) out++;
|
||||
|
||||
return out;
|
||||
|
||||
@@ -4,6 +4,12 @@
|
||||
#define PL_KERNEL 1
|
||||
|
||||
#include <stdio.h>
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#if HAVE_SYS_TIMES_H
|
||||
#include <sys/times.h>
|
||||
#endif
|
||||
#include "Yap.h"
|
||||
#include "Yatom.h"
|
||||
#include "pl-incl.h"
|
||||
|
||||
82
C/save.c
82
C/save.c
@@ -19,8 +19,6 @@ static char SccsId[] = "@(#)save.c 1.3 3/15/90";
|
||||
#endif
|
||||
|
||||
#include "config.h"
|
||||
#include "absmi.h"
|
||||
#include "SWI-Stream.h"
|
||||
#if _MSC_VER || defined(__MINGW32__)
|
||||
#if HAVE_WINSOCK2_H
|
||||
#include <winsock2.h>
|
||||
@@ -28,6 +26,8 @@ static char SccsId[] = "@(#)save.c 1.3 3/15/90";
|
||||
#include <windows.h>
|
||||
#include <psapi.h>
|
||||
#endif
|
||||
#include "absmi.h"
|
||||
#include "SWI-Stream.h"
|
||||
#include "alloc.h"
|
||||
#if USE_DL_MALLOC
|
||||
#include "dlmalloc.h"
|
||||
@@ -89,9 +89,9 @@ void initIO(void);
|
||||
|
||||
#endif
|
||||
|
||||
static int myread(int, char *, Int);
|
||||
static Int mywrite(int, char *, Int);
|
||||
static int open_file(char *, int);
|
||||
static int myread(IOSTREAM *, char *, Int);
|
||||
static Int mywrite(IOSTREAM *, char *, Int);
|
||||
static IOSTREAM *open_file(char *, int);
|
||||
static int close_file(void);
|
||||
static Int putout(CELL);
|
||||
static Int putcellptr(CELL *);
|
||||
@@ -187,11 +187,11 @@ do_system_error(yap_error_number etype, const char *msg)
|
||||
|
||||
|
||||
inline static
|
||||
int myread(int fd, char *buffer, Int len) {
|
||||
int myread(IOSTREAM *fd, char *buffer, Int len) {
|
||||
ssize_t nread;
|
||||
|
||||
while (len > 0) {
|
||||
nread = read(fd, buffer, (int)len);
|
||||
nread = Sfread(buffer, 1, (int)len, fd);
|
||||
if (nread < 1) {
|
||||
return do_system_error(PERMISSION_ERROR_INPUT_PAST_END_OF_STREAM,"bad read on saved state");
|
||||
}
|
||||
@@ -203,11 +203,11 @@ int myread(int fd, char *buffer, Int len) {
|
||||
|
||||
inline static
|
||||
Int
|
||||
mywrite(int fd, char *buff, Int len) {
|
||||
mywrite(IOSTREAM *fd, char *buff, Int len) {
|
||||
ssize_t nwritten;
|
||||
|
||||
while (len > 0) {
|
||||
nwritten = write(fd, buff, (size_t)len);
|
||||
nwritten = Sfwrite(buff, 1, (size_t)len, fd);
|
||||
if (nwritten < 0) {
|
||||
return do_system_error(SYSTEM_ERROR,"bad write on saved state");
|
||||
}
|
||||
@@ -225,7 +225,7 @@ mywrite(int fd, char *buff, Int len) {
|
||||
|
||||
typedef CELL *CELLPOINTER;
|
||||
|
||||
static int splfild = 0;
|
||||
static IOSTREAM *splfild = NULL;
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
@@ -242,10 +242,12 @@ static Int OldHeapUsed;
|
||||
static CELL which_save;
|
||||
|
||||
/* Open a file to read or to write */
|
||||
static int
|
||||
static IOSTREAM *
|
||||
open_file(char *my_file, int flag)
|
||||
{
|
||||
int splfild;
|
||||
IOSTREAM *splfild;
|
||||
char flags[6];
|
||||
int i=0;
|
||||
|
||||
#if __ANDROID__
|
||||
if (strstr(my_file, "/assets/") == my_file) {
|
||||
@@ -253,36 +255,34 @@ open_file(char *my_file, int flag)
|
||||
my_file += strlen("/assets/");
|
||||
AAsset* asset = AAssetManager_open(GLOBAL_assetManager, my_file, AASSET_MODE_UNKNOWN);
|
||||
if (!asset)
|
||||
return -1;
|
||||
return NULL;
|
||||
AAsset_close( asset );
|
||||
return 0; // usually the file will be compressed, so there is no point in actually trying to open it.
|
||||
return NULL; // usually the file will be compressed, so there is no point in actually trying to open it.
|
||||
}
|
||||
return -1;
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
#ifdef M_WILLIAMS
|
||||
if (flag & O_CREAT)
|
||||
splfild = creat(my_file, flag);
|
||||
else
|
||||
splfild = open(my_file, flag);
|
||||
if (splfild < 0) {
|
||||
#else
|
||||
#ifdef O_BINARY
|
||||
#if _MSC_VER
|
||||
if ((splfild = _open(my_file, flag | O_BINARY), _S_IREAD | _S_IWRITE) < 0)
|
||||
#else
|
||||
if ((splfild = open(my_file, flag | O_BINARY, 0775)) < 0)
|
||||
if (flag & O_RDONLY) {
|
||||
flags[i++] = 'r';
|
||||
}
|
||||
if (flag & O_CREAT) {
|
||||
flags[i++] = 'w';
|
||||
}
|
||||
if (flag & O_WRONLY) {
|
||||
flags[i++] = 'w';
|
||||
}
|
||||
if (flag & O_APPEND) {
|
||||
flags[i++] = 'a';
|
||||
}
|
||||
#if _WIN32
|
||||
if (flag & O_BINARY) {
|
||||
flags[i++] = 'b';
|
||||
}
|
||||
#endif
|
||||
#else /* O_BINARY */
|
||||
if ((splfild = open(my_file, flag, 0755)) < 0)
|
||||
#endif /* O_BINARY */
|
||||
#endif /* M_WILLIAMS */
|
||||
{
|
||||
splfild = -1; /* We do not have an open file */
|
||||
return -1;
|
||||
}
|
||||
flags[i] = '\0';
|
||||
splfild = Sopen_file( my_file, flags);
|
||||
#ifdef undf0
|
||||
fprintf(errout, "Opened file %s\n", my_file);
|
||||
fprintf(errout, "Opened file %s\n", my_file);
|
||||
#endif
|
||||
return splfild;
|
||||
}
|
||||
@@ -292,7 +292,7 @@ close_file(void)
|
||||
{
|
||||
if (splfild == 0)
|
||||
return 0;
|
||||
if (close(splfild) < 0)
|
||||
if (Sclose(splfild) < 0)
|
||||
return do_system_error(SYSTEM_ERROR,"bad close on saved state");
|
||||
splfild = 0;
|
||||
return 1;
|
||||
@@ -326,9 +326,9 @@ static CELL
|
||||
get_header_cell(void)
|
||||
{
|
||||
CELL l;
|
||||
int count = 0, n;
|
||||
size_t count = 0, n;
|
||||
while (count < sizeof(CELL)) {
|
||||
if ((n = read(splfild, &l, sizeof(CELL)-count)) < 0) {
|
||||
if ((n = Sfread(&l, 1, sizeof(CELL)-count, splfild)) < 0) {
|
||||
do_system_error(PERMISSION_ERROR_INPUT_PAST_END_OF_STREAM,"failed to read saved state header");
|
||||
return 0L;
|
||||
}
|
||||
@@ -684,7 +684,7 @@ check_header(CELL *info, CELL *ATrail, CELL *AStack, CELL *AHeap USES_REGS)
|
||||
/* skip the first line */
|
||||
pp[0] = '\0';
|
||||
do {
|
||||
if ((n = read(splfild, pp, 1)) <= 0) {
|
||||
if ((n = Sfread(pp, 1, 1, splfild)) <= 0) {
|
||||
do_system_error(PERMISSION_ERROR_INPUT_PAST_END_OF_STREAM,"failed to scan first line from saved state");
|
||||
return FAIL_RESTORE;
|
||||
}
|
||||
@@ -694,7 +694,7 @@ check_header(CELL *info, CELL *ATrail, CELL *AStack, CELL *AHeap USES_REGS)
|
||||
{
|
||||
int count = 0, n, to_read = Unsigned(strlen(msg) + 1);
|
||||
while (count < to_read) {
|
||||
if ((n = read(splfild, pp, to_read-count)) <= 0) {
|
||||
if ((n = Sfread(pp, 1, to_read-count, splfild)) <= 0) {
|
||||
do_system_error(PERMISSION_ERROR_INPUT_PAST_END_OF_STREAM,"failed to scan version info from saved state");
|
||||
return FAIL_RESTORE;
|
||||
}
|
||||
|
||||
16
C/signals.c
16
C/signals.c
@@ -21,6 +21,10 @@ static char SccsId[] = "%W% %G%";
|
||||
#define HAS_CACHE_REGS 1
|
||||
|
||||
#include "Yap.h"
|
||||
#if _WIN32
|
||||
#include <stdio.h>
|
||||
#include <io.h>
|
||||
#endif
|
||||
#include "Yatom.h"
|
||||
#include "YapHeap.h"
|
||||
#include "eval.h"
|
||||
@@ -105,7 +109,11 @@ ProcessSIGINT(void)
|
||||
{
|
||||
CACHE_REGS
|
||||
int ch, out;
|
||||
#if HAVE_ISATTY
|
||||
#if _WIN32
|
||||
if (!_isatty(0)) {
|
||||
return YAP_INT_SIGNAL;
|
||||
}
|
||||
#elif HAVE_ISATTY
|
||||
if (!isatty(0)) {
|
||||
return YAP_INT_SIGNAL;
|
||||
}
|
||||
@@ -318,7 +326,13 @@ p_first_signal( USES_REGS1 )
|
||||
uint64_t mask = LOCAL_Signals;
|
||||
if (mask == 0)
|
||||
return FALSE;
|
||||
#if HAVE___BUILTIN_FFSLL
|
||||
x sig = __builtin_ffsll(mask);
|
||||
#elif HAVE_FFSLL
|
||||
sig = ffsll(mask);
|
||||
#else
|
||||
sig = Yap_msb( mask );
|
||||
#endif
|
||||
if (get_signal(sig PASS_REGS)) {
|
||||
break;
|
||||
}
|
||||
|
||||
34
C/sysbits.c
34
C/sysbits.c
@@ -1419,12 +1419,36 @@ HandleSIGSEGV(int sig, void *sipv, void *uap)
|
||||
yap_error_number
|
||||
Yap_MathException__( USES_REGS1 )
|
||||
{
|
||||
#if HAVE_FETESTEXCEPT
|
||||
int raised;
|
||||
|
||||
#if HAVE_FETESTEXCEPT
|
||||
// #pragma STDC FENV_ACCESS ON
|
||||
if ((raised = fetestexcept( FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW)) ) {
|
||||
|
||||
feclearexcept(FE_ALL_EXCEPT);
|
||||
if (raised & FE_OVERFLOW) {
|
||||
return EVALUATION_ERROR_FLOAT_OVERFLOW;
|
||||
} else if (raised & FE_DIVBYZERO) {
|
||||
return EVALUATION_ERROR_ZERO_DIVISOR;
|
||||
} else if (raised & FE_UNDERFLOW) {
|
||||
return EVALUATION_ERROR_FLOAT_UNDERFLOW;
|
||||
//} else if (raised & (FE_INVALID|FE_INEXACT)) {
|
||||
// return EVALUATION_ERROR_UNDEFINED;
|
||||
} else {
|
||||
return EVALUATION_ERROR_UNDEFINED;
|
||||
}
|
||||
}
|
||||
#elif _WIN32
|
||||
unsigned int raised;
|
||||
int err;
|
||||
|
||||
// Show original FP control word and do calculation.
|
||||
err = _controlfp_s(&raised, 0, 0);
|
||||
if (err) {
|
||||
return EVALUATION_ERROR_UNDEFINED;
|
||||
}
|
||||
if (raised ) {
|
||||
|
||||
feclearexcept(FE_ALL_EXCEPT);
|
||||
if (raised & FE_OVERFLOW) {
|
||||
return EVALUATION_ERROR_FLOAT_OVERFLOW;
|
||||
@@ -1522,7 +1546,7 @@ my_signal(int sig, void * handler)
|
||||
static void
|
||||
my_signal(int sig, void *handler)
|
||||
{
|
||||
signal(sig, void *handler);
|
||||
signal(sig, handler);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -2544,6 +2568,9 @@ set_fpu_exceptions(bool flag)
|
||||
#elif HAVE_FEENABLEEXCEPT
|
||||
/* I shall ignore de-normalization and precision errors */
|
||||
feenableexcept(FE_DIVBYZERO| FE_INVALID|FE_OVERFLOW);
|
||||
#elif _WIN32
|
||||
// Enable zero-divide, overflow and underflow exception
|
||||
_controlfp_s(0, ~(_EM_ZERODIVIDE|_EM_UNDERFLOW|_EM_OVERFLOW), _MCW_EM); // Line B
|
||||
#elif defined(__hpux)
|
||||
# if HAVE_FESETTRAPENABLE
|
||||
/* From HP-UX 11.0 onwards: */
|
||||
@@ -2580,6 +2607,9 @@ set_fpu_exceptions(bool flag)
|
||||
#elif HAVE_FEENABLEEXCEPT
|
||||
/* I shall ignore de-normalization and precision errors */
|
||||
feenableexcept(0);
|
||||
#elif _WIN32
|
||||
// Enable zero-divide, overflow and underflow exception
|
||||
_controlfp_s(0, (_EM_ZERODIVIDE|_EM_UNDERFLOW|_EM_OVERFLOW), _MCW_EM); // Line B
|
||||
#elif defined(__hpux)
|
||||
# if HAVE_FESETTRAPENABLE
|
||||
fesettrapenable(FE_ALL_EXCEPT);
|
||||
|
||||
Reference in New Issue
Block a user