2010-07-22 Ozkan Sezer <sezeroz@gmail.com>
Varargs & related cleanups and updates:
* stdio.h: Remove the vadefs.h include, it is already included
through _mingw.h.
* wchar.h: Remove the vadefs.h include, it is already included
through _mingw.h. Remove the __gnuc_va_list and va_list type
definitions, already done in vadefs.h (included via _mingw.h.)
* stdarg.h: Guard the whole header with __GNUC__ ifdefs.
* _mingw_stdarg.h: Use _crt_va_copy invented in vadefs.h (see
below) for the __va_copy definition. Move va_copy definition with
ifdefs from vadefs.h to here.
* _mingw.h: Move the #pragma pack(push,_CRT_PACKING) below vadefs.h
inclusion and remove the comment about duplication. Remove the
__gnuc_va_list and va_list type definitions, already done in the
included vadefs.h.
* vadefs.h: Remove _CRT_PACKING definition, already defined in
_mingw.h. Remove _UINTPTR_T_DEFINED & co, already defined in _mingw.h.
Guard __gnuc_va_list type definition with __GNUC__ ifdefs. Add
MSVC version of va_list type definition and guard the gcc version
properly. Restrict some of the macros to MSVC only, apparently
used only by that compiler. Guard the gcc versions of _crt_va_*
macros properly, add MSVC-x86 versions of them from r/os, add
MSVC-AMD64 defs from r/os svn repo ros-amd64-bringup branch and
#error for other cpus and compilers. Invent _crt_va_copy by analogy
to other _crt_va_* macros for use in stdarg.h.
git-svn-id: svn+ssh://svn.code.sf.net/p/mingw-w64/code/trunk@2926 4407c894-4637-0410-b4f5-ada5f102cad1
diff --git a/mingw-w64-headers/crt/ChangeLog b/mingw-w64-headers/crt/ChangeLog
index 1c7b8ea..05097b9 100644
--- a/mingw-w64-headers/crt/ChangeLog
+++ b/mingw-w64-headers/crt/ChangeLog
@@ -1,3 +1,31 @@
+2010-07-22 Ozkan Sezer <sezeroz@gmail.com>
+
+ Varargs & related cleanups and updates:
+
+ * stdio.h: Remove the vadefs.h include, it is already included
+ through _mingw.h.
+ * wchar.h: Remove the vadefs.h include, it is already included
+ through _mingw.h. Remove the __gnuc_va_list and va_list type
+ definitions, already done in vadefs.h (included via _mingw.h.)
+ * stdarg.h: Guard the whole header with __GNUC__ ifdefs.
+ * _mingw_stdarg.h: Use _crt_va_copy invented in vadefs.h (see
+ below) for the __va_copy definition. Move va_copy definition with
+ ifdefs from vadefs.h to here.
+ * _mingw.h: Move the #pragma pack(push,_CRT_PACKING) below vadefs.h
+ inclusion and remove the comment about duplication. Remove the
+ __gnuc_va_list and va_list type definitions, already done in the
+ included vadefs.h.
+ * vadefs.h: Remove _CRT_PACKING definition, already defined in
+ _mingw.h. Remove _UINTPTR_T_DEFINED & co, already defined in _mingw.h.
+ Guard __gnuc_va_list type definition with __GNUC__ ifdefs. Add
+ MSVC version of va_list type definition and guard the gcc version
+ properly. Restrict some of the macros to MSVC only, apparently
+ used only by that compiler. Guard the gcc versions of _crt_va_*
+ macros properly, add MSVC-x86 versions of them from r/os, add
+ MSVC-AMD64 defs from r/os svn repo ros-amd64-bringup branch and
+ #error for other cpus and compilers. Invent _crt_va_copy by analogy
+ to other _crt_va_* macros for use in stdarg.h.
+
2010-07-22 Amine Khaldi <amine.khaldi@reactos.org>
Several patches for MSC/non-GCC:
diff --git a/mingw-w64-headers/crt/_mingw.h b/mingw-w64-headers/crt/_mingw.h
index 3967e77..b8e806f 100644
--- a/mingw-w64-headers/crt/_mingw.h
+++ b/mingw-w64-headers/crt/_mingw.h
@@ -247,10 +247,10 @@
#undef _CRT_PACKING
#define _CRT_PACKING 8
-/* this is duplicated in vadefs.h */
-#pragma pack(push,_CRT_PACKING)
-#include <vadefs.h>
+#include <vadefs.h> /* other headers depend on this include */
+
+#pragma pack(push,_CRT_PACKING)
#ifndef _CRT_STRINGIZE
#define __CRT_STRINGIZE(_Value) #_Value
@@ -412,16 +412,6 @@
#endif /* _WINT_T */
#endif /* _WCTYPE_T_DEFINED */
-#ifndef __GNUC_VA_LIST
-#define __GNUC_VA_LIST
- typedef __builtin_va_list __gnuc_va_list;
-#endif
-
-#ifndef _VA_LIST_DEFINED
-#define _VA_LIST_DEFINED
- typedef __gnuc_va_list va_list;
-#endif /* _VA_LIST_DEFINED */
-
#if defined (_WIN32) && !defined (_WIN64) && !defined (__MINGW_USE_VC2005_COMPAT)
#ifndef _USE_32BIT_TIME_T
#define _USE_32BIT_TIME_T
diff --git a/mingw-w64-headers/crt/_mingw_stdarg.h b/mingw-w64-headers/crt/_mingw_stdarg.h
index 2ffb780..c10272e 100644
--- a/mingw-w64-headers/crt/_mingw_stdarg.h
+++ b/mingw-w64-headers/crt/_mingw_stdarg.h
@@ -16,12 +16,23 @@
#ifndef va_start
#define va_start _crt_va_start
#endif
+
#ifndef va_arg
#define va_arg _crt_va_arg
#endif
+
#ifndef va_end
#define va_end _crt_va_end
#endif
+#ifndef __va_copy
+#define __va_copy _crt_va_copy
+#endif
+
+#if !defined(va_copy) && \
+ !defined(__STRICT_ANSI__) || __STDC_VERSION__ + 0 >= 199900L || defined(__GXX_EXPERIMENTAL_CXX0X__)
+#define va_copy _crt_va_copy
+#endif
+
#endif /* not _INC_STDARG */
diff --git a/mingw-w64-headers/crt/stdarg.h b/mingw-w64-headers/crt/stdarg.h
index 31aa613..2ff5000 100644
--- a/mingw-w64-headers/crt/stdarg.h
+++ b/mingw-w64-headers/crt/stdarg.h
@@ -28,6 +28,8 @@
* ISO C Standard: 7.15 Variable arguments <stdarg.h>
*/
+#if defined(__GNUC__)
+
#ifndef _STDARG_H
#ifndef _ANSI_STDARG_H_
#ifndef __need___va_list
@@ -132,6 +134,8 @@
#endif /* not _ANSI_STDARG_H_ */
#endif /* not _STDARG_H */
+#endif /*__GNUC__ */
+
/* include mingw stuff */
#include <_mingw_stdarg.h>
diff --git a/mingw-w64-headers/crt/stdio.h b/mingw-w64-headers/crt/stdio.h
index 5ae29cd..648529b 100644
--- a/mingw-w64-headers/crt/stdio.h
+++ b/mingw-w64-headers/crt/stdio.h
@@ -401,9 +401,6 @@
_CRTIMP int __cdecl __swprintf_l(wchar_t *_Dest,const wchar_t *_Format,_locale_t _Plocinfo,...) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
_CRTIMP int __cdecl _vswprintf_l(wchar_t *buffer,size_t count,const wchar_t *format,_locale_t locale,va_list argptr) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
_CRTIMP int __cdecl __vswprintf_l(wchar_t *_Dest,const wchar_t *_Format,_locale_t _Plocinfo,va_list _Args) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
-#ifndef RC_INVOKED
-#include <vadefs.h>
-#endif
#ifdef _CRT_NON_CONFORMING_SWPRINTFS
#ifndef __cplusplus
diff --git a/mingw-w64-headers/crt/vadefs.h b/mingw-w64-headers/crt/vadefs.h
index 0f6c0fe..0236b6f 100644
--- a/mingw-w64-headers/crt/vadefs.h
+++ b/mingw-w64-headers/crt/vadefs.h
@@ -12,37 +12,29 @@
#include <_mingw.h>
-#undef _CRT_PACKING
-#define _CRT_PACKING 8
-/* this is duplicated in _mingw.h */
#pragma pack(push,_CRT_PACKING)
#ifdef __cplusplus
extern "C" {
#endif
-#ifndef _UINTPTR_T_DEFINED
-#define _UINTPTR_T_DEFINED
-#ifndef __uintptr_t_defined
-#define __uintptr_t_defined
-#undef uintptr_t
-#ifdef _WIN64
- __MINGW_EXTENSION typedef unsigned __int64 uintptr_t;
-#else
- typedef unsigned long uintptr_t;
-#endif
-#endif
-#endif
-
+#if defined (__GNUC__)
#ifndef __GNUC_VA_LIST
#define __GNUC_VA_LIST
typedef __builtin_va_list __gnuc_va_list;
#endif
+#endif /* __GNUC__ */
-#ifndef _VA_LIST_DEFINED
+#ifndef _VA_LIST_DEFINED /* if stdargs.h didn't define it */
#define _VA_LIST_DEFINED
+#if defined(__GNUC__)
typedef __gnuc_va_list va_list;
+#elif defined(_MSC_VER)
+ typedef char * va_list;
+#else /* !gcc && !msvc */
+#error VARARGS not implemented for this compiler
#endif
+#endif /* _VA_LIST_DEFINED */
#ifdef __cplusplus
#define _ADDRESSOF(v) (&reinterpret_cast<const char &>(v))
@@ -50,12 +42,21 @@
#define _ADDRESSOF(v) (&(v))
#endif
-#if defined(__ia64__)
+#if defined (__GNUC__)
+/* Use GCC builtins */
+
+#define _crt_va_start(v,l) __builtin_va_start(v,l)
+#define _crt_va_arg(v,l) __builtin_va_arg(v,l)
+#define _crt_va_end(v) __builtin_va_end(v)
+#define _crt_va_copy(d,s) __builtin_va_copy(d,s)
+
+#elif defined(_MSC_VER)
+/* MSVC specific */
+
+#if defined(_M_IA64)
#define _VA_ALIGN 8
#define _SLOTSIZEOF(t) ((sizeof(t) + _VA_ALIGN - 1) & ~(_VA_ALIGN - 1))
-
#define _VA_STRUCT_ALIGN 16
-
#define _ALIGNOF(ap) ((((ap)+_VA_STRUCT_ALIGN - 1) & ~(_VA_STRUCT_ALIGN -1)) - (ap))
#define _APALIGN(t,ap) (__alignof(t) > 8 ? _ALIGNOF((uintptr_t) ap) : 0)
#else
@@ -63,20 +64,42 @@
#define _APALIGN(t,ap) (__alignof(t))
#endif
-#if !defined(__STRICT_ANSI__) || __STDC_VERSION__ + 0 >= 199900L
-#define va_copy(d,s) __builtin_va_copy(d,s)
-#endif
-#define __va_copy(d,s) __builtin_va_copy(d,s)
+#if defined(_M_IX86)
#define _INTSIZEOF(n) ((sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1))
+#define _crt_va_start(v,l) ((v) = (va_list)_ADDRESSOF(l) + _INTSIZEOF(l))
+#define _crt_va_arg(v,l) (*(l *)(((v) += _INTSIZEOF(l)) - _INTSIZEOF(l)))
+#define _crt_va_end(v) ((v) = (va_list)0)
+#define _crt_va_copy(d,s) ((d) = (s))
-#define _crt_va_start(v,l) __builtin_va_start(v,l)
-#define _crt_va_arg(v,l) __builtin_va_arg(v,l)
-#define _crt_va_end(v) __builtin_va_end(v)
+#elif defined(_M_AMD64)
+
+#define _PTRSIZEOF(n) ((sizeof(n) + sizeof(void*) - 1) & ~(sizeof(void*) - 1))
+#define _ISSTRUCT(t) ((sizeof(t) > sizeof(void*)) || (sizeof(t) & (sizeof(t) - 1)) != 0)
+#define _crt_va_start(v,l) ((v) = (va_list)_ADDRESSOF(l) + _PTRSIZEOF(l))
+#define _crt_va_arg(v,t) _ISSTRUCT(t) ? \
+ (**(t**)(((v) += sizeof(void*)) - sizeof(void*))) : \
+ ( *(t *)(((v) += sizeof(void*)) - sizeof(void*)))
+#define _crt_va_end(v) ((v) = (va_list)0)
+#define _crt_va_copy(d,s) ((d) = (s))
+
+#elif defined(_M_IA64)
+
+#error VARARGS not implemented for IA64
+
+#else
+
+#error VARARGS not implemented for this TARGET
+
+#endif /* cpu ifdefs */
+
+#endif /* compiler ifdefs */
#ifdef __cplusplus
}
#endif
#pragma pack(pop)
-#endif
+
+#endif /* _INC_VADEFS */
+
diff --git a/mingw-w64-headers/crt/wchar.h b/mingw-w64-headers/crt/wchar.h
index 13af80e..c428c79 100644
--- a/mingw-w64-headers/crt/wchar.h
+++ b/mingw-w64-headers/crt/wchar.h
@@ -19,16 +19,6 @@
#define WCHAR_MAX 0xffffU
#endif
-#ifndef __GNUC_VA_LIST
-#define __GNUC_VA_LIST
- typedef __builtin_va_list __gnuc_va_list;
-#endif
-
-#ifndef _VA_LIST_DEFINED
-#define _VA_LIST_DEFINED
- typedef __gnuc_va_list va_list;
-#endif
-
#ifndef WEOF
#define WEOF (wint_t)(0xFFFF)
#endif
@@ -616,9 +606,6 @@
_CRTIMP int __cdecl __swprintf_l(wchar_t *_Dest,const wchar_t *_Format,_locale_t _Plocinfo,...) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
_CRTIMP int __cdecl _vswprintf_l(wchar_t *_Dest,size_t _MaxCount,const wchar_t *_Format,_locale_t _Locale,va_list _ArgList) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
_CRTIMP int __cdecl __vswprintf_l(wchar_t *_Dest,const wchar_t *_Format,_locale_t _Plocinfo,va_list _Args) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
-#ifndef RC_INVOKED
-#include <vadefs.h>
-#endif
#ifdef _CRT_NON_CONFORMING_SWPRINTFS
#ifndef __cplusplus
@@ -888,4 +875,6 @@
#pragma pack(pop)
#include <sec_api/wchar_s.h>
-#endif
+
+#endif /* _INC_WCHAR */
+