Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
MinGW-w64 build patch for newlisp v10.6.2
diff --git a/newlisp.c b/newlisp.c
index 211ad93..1b9b851 100644
--- a/newlisp.c
+++ b/newlisp.c
@@ -18,7 +18,6 @@
*/
#include "newlisp.h"
-#include "pcre.h"
#include "protos.h"
#include "primes.h"
@@ -2539,19 +2538,11 @@ switch(cell->type)
varPrintf(device, "true"); break;
case CELL_LONG:
- varPrintf(device,"%ld", cell->contents); break;
+ varPrintf(device,"%"PRIdPTR, cell->contents); break;
#ifndef NEWLISP64
case CELL_INT64:
-#ifdef TRU64
- varPrintf(device,"%ld", *(INT64 *)&cell->aux); break;
-#else
-#ifdef WINDOWS
- varPrintf(device,"%I64d", *(INT64 *)&cell->aux); break;
-#else
- varPrintf(device,"%lld", *(INT64 *)&cell->aux); break;
-#endif /* WIN32 */
-#endif /* TRU64 */
+ varPrintf(device,"%"PRId64, *(INT64 *)&cell->aux); break;
#endif /* NEWLISP64 */
#ifdef BIGINT
case CELL_BIGINT:
@@ -7063,7 +7054,7 @@ if(params->type == CELL_STRING)
}
else if(params != nilCell)
{
- snprintf(sigStr, 11, "$signal-%ld", sig);
+ snprintf(sigStr, 11, "$signal-%d", (int)sig);
getCreateSymbol(params, &signalEvent, sigStr);
symHandler[sig - 1] = signalEvent;
if(signal(sig, signal_handler) == SIG_ERR) return(nilCell);
diff --git a/newlisp.h b/newlisp.h
index dfc710b..74b2c1e 100644
--- a/newlisp.h
+++ b/newlisp.h
@@ -29,6 +29,12 @@
#define BIGINT
#define KMEANS
+/* disable -DNEWLISP64 in Makefile */
+#undef NEWLISP64
+/* detect memory model LP64 (unix/linux) and LLP64 (win64) */
+#if defined(_LP64) || defined(_WIN64)
+#define NEWLISP64
+#endif
/* config.h is only needed when doing auto configuration with ./configure-alt */
#ifdef NEWCONFIG
@@ -38,7 +44,7 @@
#endif
/* force ISO_C90 restrictions */
-#if defined(CYGWN) || defined(OS2) || defined(SOLARIS) || defined(AIX) || defined(SUNOS)
+#if defined(CYGWIN) || defined(OS2) || defined(SOLARIS) || defined(AIX) || defined(SUNOS)
#define ISO_C90
#endif
@@ -107,11 +113,11 @@
#include <ffi/ffi.h>
#endif
-#if defined(WINDOWS) || defined(CYGWN)
+#if defined(WINDOWS)
#include "win-ffi.h"
#endif
-#if defined(LINUX) || defined(_BSD) /* makefiles specify include directory */
+#if defined(LINUX) || defined(_BSD) || defined(CYGWIN) /* makefiles specify include directory */
#include <ffi.h>
#endif
@@ -307,36 +313,19 @@ This is for 64bit large file support (LFS),
#define UTF8_MAX_BYTES 6
-/* autosize on 32-bit ILP32 and 64-bit on LP64 and LLP64 */
-#ifndef WIN_64 /* UNIX 32 or 64 or WIN_32 */
-#define INT long
-#define UINT unsigned long
-#else /* WIN_64 LLP64 */
-#define INT long long
-#define UINT unsigned long long
-#endif
+/* autosize on 32-bit ILP32 and 64-bit on LP64 (unix) and LLP64 (win64) */
+#include <stdint.h>
+#include <inttypes.h>
-#define INT16 short int
-#ifndef NEWLISP64
-#define MAX_LONG 0x7FFFFFFF
-#else
-#define MAX_LONG 0x7FFFFFFFFFFFFFFFLL
-#endif
+#define UINT uintptr_t
+#define INT intptr_t
+#define INT16 int16_t
+#define INT64 int64_t
+#define UINT64 int64_t
-#define CONNECT_TIMEOUT 10000
+#define MAX_LONG INTPTR_MAX
-#ifndef NEWLISP64
-#ifdef TRU64
-#define INT64 long
-#define UINT64 unsigned long
-#else /* not TRU64 */
-#define INT64 long long int
-#define UINT64 unsigned long long int
-#endif
-#else /* NEWLISP64 */
-#define INT64 long
-#define UINT64 unsigned long
-#endif
+#define CONNECT_TIMEOUT 10000
#define pushEnvironment(A) (*(envStackIdx++) = (UINT)(A))
#define popEnvironment() (*(--envStackIdx))
@@ -707,7 +696,7 @@ extern int ADDR_FAMILY;
extern int IOchannelIsSocket;
#endif
extern int MAX_CPU_STACK;
-extern long MAX_CELL_COUNT;
+extern INT MAX_CELL_COUNT;
extern int version;
extern int opsys;
extern char ostype[];
diff --git a/nl-filesys.c b/nl-filesys.c
index f8a7ac9..d807011 100644
--- a/nl-filesys.c
+++ b/nl-filesys.c
@@ -72,6 +72,7 @@ extern char ** environ;
#define srandom srand
#include <conio.h>
#include <dir.h>
+#include <direct.h>
#define popen _popen
#define pclose _pclose
#define pipe _pipe
diff --git a/nl-import.c b/nl-import.c
index e7ad243..81cc480 100644
--- a/nl-import.c
+++ b/nl-import.c
@@ -427,28 +427,30 @@ INT callback14(INT p1, INT p2, INT p3, INT p4, INT p5, INT p6, INT p7, INT p8)
INT callback15(INT p1, INT p2, INT p3, INT p4, INT p5, INT p6, INT p7, INT p8)
{return template(15, p1, p2, p3, p4, p5, p6, p7, p8);}
+typedef INT (*lib_callback_t)(INT p1, INT p2, INT p3, INT p4, INT p5, INT p6, INT p7, INT p8);
+
typedef struct {
SYMBOL * sym;
- UINT func;
+ lib_callback_t func;
} LIBCALLBACK;
LIBCALLBACK callback[] = {
- { NULL, (UINT)callback0 },
- { NULL, (UINT)callback1 },
- { NULL, (UINT)callback2 },
- { NULL, (UINT)callback3 },
- { NULL, (UINT)callback4 },
- { NULL, (UINT)callback5 },
- { NULL, (UINT)callback6 },
- { NULL, (UINT)callback7 },
- { NULL, (UINT)callback8 },
- { NULL, (UINT)callback9 },
- { NULL, (UINT)callback10 },
- { NULL, (UINT)callback11 },
- { NULL, (UINT)callback12 },
- { NULL, (UINT)callback13 },
- { NULL, (UINT)callback14 },
- { NULL, (UINT)callback15 },
+ { NULL, callback0 },
+ { NULL, callback1 },
+ { NULL, callback2 },
+ { NULL, callback3 },
+ { NULL, callback4 },
+ { NULL, callback5 },
+ { NULL, callback6 },
+ { NULL, callback7 },
+ { NULL, callback8 },
+ { NULL, callback9 },
+ { NULL, callback10 },
+ { NULL, callback11 },
+ { NULL, callback12 },
+ { NULL, callback13 },
+ { NULL, callback14 },
+ { NULL, callback15 },
};
@@ -612,7 +614,7 @@ if(n > 15) return(errorProc(ERR_NUMBER_OUT_OF_RANGE));
getSymbol(params->next, &sPtr);
callback[n].sym = sPtr;
-return(stuffInteger(callback[n].func));
+return(stuffInteger((UINT)callback[n].func));
}
/* ========================= FFFI using ffilib ========================== */
diff --git a/nl-liststr.c b/nl-liststr.c
index 0585d96..1b90b91 100644
--- a/nl-liststr.c
+++ b/nl-liststr.c
@@ -19,7 +19,6 @@
*/
#include "newlisp.h"
-#include "pcre.h"
#include "protos.h"
extern CELL * lastCellCopied;
diff --git a/nl-math.c b/nl-math.c
index 3b95cf3..f7cbc4a 100644
--- a/nl-math.c
+++ b/nl-math.c
@@ -569,7 +569,7 @@ double floatNum = 0.0;
if(param->type == CELL_FLOAT)
return(*(double *)&param->aux);
else if(param->type == CELL_LONG)
- floatNum = (long)param->contents;
+ floatNum = (long)param->contents; /* INT ? */
else if(param->type == CELL_INT64)
floatNum = *(INT64 *)&param->aux;
#ifdef BIGINT
@@ -1066,8 +1066,8 @@ switch(left->type)
#endif
case CELL_LONG:
default:
- if((long)left->contents > (long)right->contents) return(1);
- if((long)left->contents < (long)right->contents) return(-1);
+ if((INT)left->contents > (INT)right->contents) return(1);
+ if((INT)left->contents < (INT)right->contents) return(-1);
break;
}
diff --git a/nl-sock.c b/nl-sock.c
index b1576e4..6246228 100644
--- a/nl-sock.c
+++ b/nl-sock.c
@@ -24,7 +24,10 @@
#ifdef WINDOWS
#include <winsock2.h>
+#pragma push_macro("UINT")
+#undef UINT
#include <ws2tcpip.h>
+#pragma pop_macro("UINT")
#include <ws2spi.h>
#define fdopen win32_fdopen
#define SHUT_RDWR 2
@@ -156,7 +159,7 @@ if(defaultIn != NULL) free(defaultIn);
defaultInLen = (ADDR_FAMILY == AF_INET6) ?
sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in);
-defaultIn = allocMemory(defaultInLen);
+defaultIn = callocMemory(defaultInLen);
if(ADDR_FAMILY == AF_INET6)
{
diff --git a/nl-string.c b/nl-string.c
index 00b1d08..2119adc 100644
--- a/nl-string.c
+++ b/nl-string.c
@@ -21,6 +21,7 @@
#ifdef SUPPORT_UTF8
#include <wctype.h>
#endif
+#define PCRE_STATIC
#include "pcre.h"
#include "protos.h"
@@ -627,7 +628,11 @@ if(*fmt == 'l' && *(fmt + 1) == 'l' && (*(fmt + 2) == 'd' || *(fmt + 2) == 'u' |
if(memcmp(fmt, "I64", 3) == 0 &&
(*(fmt + 3) == 'd' || *(fmt + 3) == 'u' || *(fmt + 3) =='x' || *(fmt + 3) == 'X'))
{
+#ifndef NEWLISP64
*type = CELL_INT64;
+#else
+ *type = CELL_LONG;
+#endif
return(fmt+4);
}
#endif
@@ -1208,31 +1213,17 @@ char number[32];
SYMBOL * context;
SYMBOL * sPtr;
CELL * cell;
-#ifdef WINDOWS
-char * fmt = "%I64d";
-#endif
-
cell = evaluateExpression(params);
switch(cell->type)
{
case CELL_LONG:
- snprintf(number, 30, "%ld", cell->contents);
+ snprintf(number, 30, "%"PRIdPTR, cell->contents);
token = number;
break;
#ifndef NEWLISP64
case CELL_INT64:
-#ifdef TRU64
- snprintf(number, 30, "%ld", *(INT64 *)&cell->aux);
-#else
-
-#ifdef WINDOWS
- snprintf(number, 30, fmt, *(INT64 *)&cell->aux);
-#else
- snprintf(number, 30, "%lld", *(INT64 *)&cell->aux);
-#endif /* WINDOWS */
-
-#endif /* TRU64 */
+ snprintf(number, 30, "%"PRId64, *(INT64 *)&cell->aux);
token = number;
break;
#endif /* NEWLISP64 */
@@ -2308,11 +2299,7 @@ if((cPattern == NULL) || (strcmp(cPattern, pattern) != 0) || (options != cacheOp
len = strlen(pattern);
cPattern = (char *)allocMemory(len + 1);
memcpy(cPattern, pattern, len + 1);
-#ifdef WINDOWS
- if(re != NULL) free(re);
-#else
if(re != NULL) (pcre_free)(re);
-#endif
re = pcre_compile(pattern, options, &error, &errOffset, NULL);
/* Compilation failed: print the error message and exit */
diff --git a/nl-symbol.c b/nl-symbol.c
index 81fef8b..1267c47 100644
--- a/nl-symbol.c
+++ b/nl-symbol.c
@@ -139,7 +139,7 @@ if(isNumber(cell->type))
{
token = alloca(32);
getIntegerExt(cell, &number, FALSE);
- snprintf(token, 31, "_%ld", number);
+ snprintf(token, 31, "_%"PRIdPTR, number);
}
else
{
diff --git a/nl-web.c b/nl-web.c
index 85cb460..ed2372d 100644
--- a/nl-web.c
+++ b/nl-web.c
@@ -1120,15 +1120,9 @@ switch(type)
if(type == HTTP_HEAD)
{
-#if defined(WINDOWS) || defined(TRU64)
- snprintf(buff, MAX_BUFF - 1,
- "Content-length: %ld\r\nContent-type: %s\r\n\r\n",
- (INT)fileSize(request), mediaType);
-#else
snprintf(buff, MAX_BUFF - 1,
- "Content-length: %lld\r\nContent-type: %s\r\n\r\n",
- (long long int)fileSize(request), mediaType);
-#endif
+ "Content-length: %"PRId64"\r\nContent-type: %s\r\n\r\n",
+ fileSize(request), mediaType);
sendHTTPpage(buff, strlen(buff), NULL);
}
else
diff --git a/win32-path.c b/win32-path.c
index f9a5103..01cf068 100644
--- a/win32-path.c
+++ b/win32-path.c
@@ -284,12 +284,29 @@ int rename_utf16(const char* oldname8, const char* newname8)
int stat_utf16(const char* filename8, struct stat* buf)
{
int i = -1;
+ struct _stat st;
WCHAR * filename16 = utf8_to_utf16(filename8);
if (filename16)
{
- i = _wstat(filename16, (struct _stat*)buf);
+ i = _wstat(filename16, &st);
free(filename16);
}
+
+ if (i == 0) {
+ /* FIXME: incompatible type 'struct _stat' and 'struct stat' in MinGW64 ? */
+ buf->st_dev = st.st_dev;
+ buf->st_ino = st.st_ino;
+ buf->st_mode = st.st_mode;
+ buf->st_nlink = st.st_nlink;
+ buf->st_uid = st.st_uid;
+ buf->st_gid = st.st_gid;
+ buf->st_rdev = st.st_rdev;
+ buf->st_size = st.st_size;
+ buf->st_atime = st.st_atime;
+ buf->st_mtime = st.st_mtime;
+ buf->st_ctime = st.st_ctime;
+ }
+
return i;
}
diff --git a/win32-util.c b/win32-util.c
index 58f4bc8..1bd62a5 100644
--- a/win32-util.c
+++ b/win32-util.c
@@ -17,11 +17,14 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "newlisp.h"
+#include "protos.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <time.h>
+#define WIN32_LEAN_AND_MEAN /* exclude rarely-used windows headers */
#include <windows.h>
#include <io.h>
#include <process.h>
@@ -94,7 +97,7 @@ UINT winPipedProcess(char * cmd, int inpipe, int outpipe, int option)
STARTUPINFO si = { 0 };
PROCESS_INFORMATION process;
int result;
-long fin, fout;
+HANDLE fin, fout;
UINT pid;
if(inpipe == -1 && outpipe == -1)
@@ -111,12 +114,12 @@ else
si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
si.wShowWindow = option; /* SW_SHOW, SW_HIDE get additional user option in Win32 versions */
- fin = _get_osfhandle(inpipe);
- fout = _get_osfhandle(outpipe);
+ fin = (HANDLE)_get_osfhandle(inpipe);
+ fout = (HANDLE)_get_osfhandle(outpipe);
- si.hStdInput = (inpipe) ? (HANDLE)fin : GetStdHandle(STD_INPUT_HANDLE);
- si.hStdOutput = (outpipe) ? (HANDLE)fout : GetStdHandle(STD_OUTPUT_HANDLE);
- si.hStdError = (outpipe) ? (HANDLE)fout : GetStdHandle(STD_OUTPUT_HANDLE);
+ si.hStdInput = (inpipe) ? fin : GetStdHandle(STD_INPUT_HANDLE);
+ si.hStdOutput = (outpipe) ? fout : GetStdHandle(STD_OUTPUT_HANDLE);
+ si.hStdError = (outpipe) ? fout : GetStdHandle(STD_OUTPUT_HANDLE);
}
if((result = CreateProcess(NULL,cmd,NULL,NULL,TRUE,DETACHED_PROCESS,NULL,NULL,&si, &process)) == 0)
@@ -141,8 +144,8 @@ sa.lpSecurityDescriptor = NULL;
if(!CreatePipe(&pipe_r, &pipe_w, &sa, 0))
return(0);
-*inpipe = _open_osfhandle((long) pipe_r, 0);
-*outpipe = _open_osfhandle((long) pipe_w, 0);
+*inpipe = _open_osfhandle((intptr_t) pipe_r, 0);
+*outpipe = _open_osfhandle((intptr_t) pipe_w, 0);
return(1);
@@ -204,22 +207,19 @@ sa.nLength = sizeof(sa);
sa.bInheritHandle = TRUE;
sa.lpSecurityDescriptor = NULL; /* default of caller */
-hMemory = CreateFileMapping((HANDLE)0xFFFFFFFF, &sa, PAGE_READWRITE, 0, size, NULL);
+hMemory = CreateFileMapping(INVALID_HANDLE_VALUE, &sa, PAGE_READWRITE, 0, size, NULL);
return((UINT)hMemory);
}
UINT * winMapView(UINT hMemory, int size)
{
-return((UINT*)MapViewOfFile((HANDLE)hMemory, FILE_MAP_WRITE, 0, 0, size));
+return((UINT *)MapViewOfFile((HANDLE)hMemory, FILE_MAP_WRITE, 0, 0, size));
}
/* ---------------------------- timer -------------------------------------- */
-#include "newlisp.h"
-#include "protos.h"
-
extern SYMBOL * timerEvent;
extern int milliSecTime(void);
extern CELL * getCreateSymbol(CELL * params, SYMBOL * * symbol, char * name);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.