From e20bf69ac5adf3607c6e60ffdd5a0bb40b8f11ed Mon Sep 17 00:00:00 2001 From: grischka Date: Thu, 14 Jan 2010 20:56:35 +0100 Subject: [PATCH] win64: defined size_t and ptrdiff_t to unsigned long long --- include/stddef.h | 20 ++++++++++++++------ libtcc.c | 19 ++++++++++++------- win32/include/_mingw.h | 35 +++++++++++++++++------------------ 3 files changed, 43 insertions(+), 31 deletions(-) diff --git a/include/stddef.h b/include/stddef.h index aef5b39..c5dd13c 100644 --- a/include/stddef.h +++ b/include/stddef.h @@ -1,20 +1,28 @@ #ifndef _STDDEF_H #define _STDDEF_H -#define NULL ((void *)0) typedef __SIZE_TYPE__ size_t; +typedef __PTRDIFF_TYPE__ ssize_t; typedef __WCHAR_TYPE__ wchar_t; typedef __PTRDIFF_TYPE__ ptrdiff_t; -#define offsetof(type, field) ((size_t) &((type *)0)->field) +typedef __PTRDIFF_TYPE__ intptr_t; +typedef __SIZE_TYPE__ uintptr_t; #ifndef __int8_t_defined #define __int8_t_defined -typedef char int8_t; -typedef short int int16_t; -typedef int int32_t; -typedef long long int int64_t; +typedef signed char int8_t; +typedef signed short int int16_t; +typedef signed int int32_t; +typedef signed long long int int64_t; +typedef unsigned char uint8_t; +typedef unsigned short int uint16_t; +typedef unsigned int uint32_t; +typedef unsigned long long int uint64_t; #endif +#define NULL ((void *)0) +#define offsetof(type, field) ((size_t)&((type *)0)->field) + void *alloca(size_t size); #endif diff --git a/libtcc.c b/libtcc.c index e0e8f91..520abfd 100644 --- a/libtcc.c +++ b/libtcc.c @@ -886,9 +886,9 @@ LIBTCCAPI TCCState *tcc_new(void) tcc_define_symbol(s, "__STDC__", NULL); tcc_define_symbol(s, "__STDC_VERSION__", "199901L"); #if defined(TCC_TARGET_I386) - tcc_define_symbol(s, "__i386__", "1"); - tcc_define_symbol(s, "__i386", "1"); - tcc_define_symbol(s, "i386", "1"); + tcc_define_symbol(s, "__i386__", NULL); + tcc_define_symbol(s, "__i386", NULL); + tcc_define_symbol(s, "i386", NULL); #endif #if defined(TCC_TARGET_X86_64) tcc_define_symbol(s, "__x86_64__", NULL); @@ -909,13 +909,12 @@ LIBTCCAPI TCCState *tcc_new(void) tcc_define_symbol(s, "_WIN64", NULL); #endif #else - tcc_define_symbol(s, "__unix__", "1"); - tcc_define_symbol(s, "__unix", "1"); - tcc_define_symbol(s, "unix", "1"); + tcc_define_symbol(s, "__unix__", NULL); + tcc_define_symbol(s, "__unix", NULL); + tcc_define_symbol(s, "unix", NULL); #if defined(__FreeBSD__) #define str(s) #s tcc_define_symbol(s, "__FreeBSD__", str( __FreeBSD__)); - tcc_define_symbol(s, "__INTEL_COMPILER", "1"); #undef str #endif #if defined(__linux) @@ -929,8 +928,14 @@ LIBTCCAPI TCCState *tcc_new(void) tcc_define_symbol(s, "__TINYC__", buffer); /* tiny C & gcc defines */ +#if defined TCC_TARGET_PE && defined TCC_TARGET_X86_64 + tcc_define_symbol(s, "__SIZE_TYPE__", "unsigned long long"); + tcc_define_symbol(s, "__PTRDIFF_TYPE__", "long long"); +#else tcc_define_symbol(s, "__SIZE_TYPE__", "unsigned long"); tcc_define_symbol(s, "__PTRDIFF_TYPE__", "long"); +#endif + #ifdef TCC_TARGET_PE tcc_define_symbol(s, "__WCHAR_TYPE__", "unsigned short"); #else diff --git a/win32/include/_mingw.h b/win32/include/_mingw.h index 04fc1ca..d876625 100644 --- a/win32/include/_mingw.h +++ b/win32/include/_mingw.h @@ -58,28 +58,27 @@ #define _CRT_WIDE(_String) __CRT_WIDE(_String) #ifdef _WIN64 -# define _INTEGRAL_MAX_BITS 64 -typedef __int64 intptr_t; -typedef __int64 ptrdiff_t; -typedef unsigned __int64 uintptr_t; -# define __stdcall -# define _AMD64_ 1 -# define __x86_64 1 -# define USE_MINGW_SETJMP_TWO_ARGS -# define mingw_getsp tinyc_getbp +#define __stdcall +#define _AMD64_ 1 +#define __x86_64 1 +#define USE_MINGW_SETJMP_TWO_ARGS +#define mingw_getsp tinyc_getbp #else -# define _INTEGRAL_MAX_BITS 32 -typedef __int32 intptr_t; -typedef __int32 ptrdiff_t; -typedef unsigned __int32 uintptr_t; -# define __stdcall __attribute__((__stdcall__)) -# define _X86_ 1 -# define WIN32 1 -# define _USE_32BIT_TIME_T +#define __stdcall __attribute__((__stdcall__)) +#define _X86_ 1 +#define WIN32 1 +#define _USE_32BIT_TIME_T #endif + +/* in stddef.h */ +#define _SIZE_T_DEFINED +#define _SSIZE_T_DEFINED +#define _PTRDIFF_T_DEFINED +#define _WCHAR_T_DEFINED #define _UINTPTR_T_DEFINED #define _INTPTR_T_DEFINED -#define _PTRDIFF_T_DEFINED + +#define _INTEGRAL_MAX_BITS 64 typedef long __time32_t; #define _TIME32_T_DEFINED