win32: malloc.h: fix win32 tcc-tcc complication by correcting _STATIC_ASSERT, ideas...
authorRoy <roytam@gmail.com>
Mon, 31 Dec 2012 00:59:50 +0000 (31 08:59 +0800)
committerRoy <roytam@gmail.com>
Mon, 31 Dec 2012 00:59:50 +0000 (31 08:59 +0800)
stdarg.h, stddef.h: _mingw.h needs them

win32/include/malloc.h
win32/include/stdarg.h [new file with mode: 0644]
win32/include/stddef.h [new file with mode: 0644]

index 8426600..87f1868 100644 (file)
@@ -25,7 +25,7 @@ extern "C" {
 #endif
 
 #ifndef _STATIC_ASSERT
-#define _STATIC_ASSERT(expr) typedef char __static_assert_t[(expr)]
+#define _STATIC_ASSERT(expr) extern void __static_assert_t(int [(expr)?1:-1])
 #endif
 
 /* Return codes for _heapwalk()  */
diff --git a/win32/include/stdarg.h b/win32/include/stdarg.h
new file mode 100644 (file)
index 0000000..666adf7
--- /dev/null
@@ -0,0 +1,41 @@
+#ifndef _STDARG_H
+#define _STDARG_H
+
+#ifdef __x86_64__
+#ifndef _WIN64
+
+typedef void *va_list;
+
+va_list __va_start(void *fp);
+void *__va_arg(va_list ap, int arg_type, int size);
+va_list __va_copy(va_list src);
+void __va_end(va_list ap);
+
+#define va_start(ap, last) ((ap) = __va_start(__builtin_frame_address(0)))
+#define va_arg(ap, type)                                                \
+    (*(type *)(__va_arg(ap, __builtin_va_arg_types(type), sizeof(type))))
+#define va_copy(dest, src) ((dest) = __va_copy(src))
+#define va_end(ap) __va_end(ap)
+
+#else /* _WIN64 */
+typedef char *va_list;
+#define va_start(ap,last) ap = ((char *)&(last)) + ((sizeof(last)+7)&~7)
+#define va_arg(ap,type) (ap += (sizeof(type)+7)&~7, *(type *)(ap - ((sizeof(type)+7)&~7)))
+#define va_copy(dest, src) (dest) = (src)
+#define va_end(ap)
+#endif
+
+#else /* __i386__ */
+typedef char *va_list;
+/* only correct for i386 */
+#define va_start(ap,last) ap = ((char *)&(last)) + ((sizeof(last)+3)&~3)
+#define va_arg(ap,type) (ap += (sizeof(type)+3)&~3, *(type *)(ap - ((sizeof(type)+3)&~3)))
+#define va_copy(dest, src) (dest) = (src)
+#define va_end(ap)
+#endif
+
+/* fix a buggy dependency on GCC in libio.h */
+typedef va_list __gnuc_va_list;
+#define _VA_LIST_DEFINED
+
+#endif /* _STDARG_H */
diff --git a/win32/include/stddef.h b/win32/include/stddef.h
new file mode 100644 (file)
index 0000000..c5dd13c
--- /dev/null
@@ -0,0 +1,28 @@
+#ifndef _STDDEF_H
+#define _STDDEF_H
+
+typedef __SIZE_TYPE__ size_t;
+typedef __PTRDIFF_TYPE__ ssize_t;
+typedef __WCHAR_TYPE__ wchar_t;
+typedef __PTRDIFF_TYPE__ ptrdiff_t;
+typedef __PTRDIFF_TYPE__ intptr_t;
+typedef __SIZE_TYPE__ uintptr_t;
+
+#ifndef __int8_t_defined
+#define __int8_t_defined
+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