You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stdcxx.apache.org by se...@apache.org on 2005/12/20 03:32:11 UTC
svn commit: r357880 - in /incubator/stdcxx/trunk/etc/config/src: SIZE_T.cpp
VA_LIST.cpp
Author: sebor
Date: Mon Dec 19 18:32:06 2005
New Revision: 357880
URL: http://svn.apache.org/viewcvs?rev=357880&view=rev
Log:
2005-12-19 Martin Sebor <se...@roguewave.com>
* SIZE_T.cpp (_RWSTD_VA_LIST): Moved the definition of the macro
from here...
* VA_LIST.cpp: ...to here. New config test to determine the underlying
type of va_list and whether it is an array type or object type.
Added:
incubator/stdcxx/trunk/etc/config/src/VA_LIST.cpp (with props)
Modified:
incubator/stdcxx/trunk/etc/config/src/SIZE_T.cpp
Modified: incubator/stdcxx/trunk/etc/config/src/SIZE_T.cpp
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/etc/config/src/SIZE_T.cpp?rev=357880&r1=357879&r2=357880&view=diff
==============================================================================
--- incubator/stdcxx/trunk/etc/config/src/SIZE_T.cpp (original)
+++ incubator/stdcxx/trunk/etc/config/src/SIZE_T.cpp Mon Dec 19 18:32:06 2005
@@ -4,7 +4,6 @@
# include "config.h"
#endif // _RWSTD_USE_CONFIG
-#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
@@ -44,45 +43,6 @@
const char* get_type_name (...) { return 0; }
-// determine the underlying pointer type of a typedef
-#define DEFINE_VA_LIST_HELPER(T) \
- const char* get_va_list_type_name (T) { return # T; } \
- typedef void unused_type
-
-DEFINE_VA_LIST_HELPER (char*);
-DEFINE_VA_LIST_HELPER (short*);
-DEFINE_VA_LIST_HELPER (unsigned short*);
-DEFINE_VA_LIST_HELPER (int*);
-DEFINE_VA_LIST_HELPER (unsigned int*);
-DEFINE_VA_LIST_HELPER (long*);
-DEFINE_VA_LIST_HELPER (unsigned long*);
-
-#ifndef _RWSTD_NO_LONG_LONG
-
-DEFINE_VA_LIST_HELPER (long long*);
-DEFINE_VA_LIST_HELPER (unsigned long long*);
-
-#elif defined (_MSC_VER)
-
-DEFINE_VA_LIST_HELPER (__int64*);
-DEFINE_VA_LIST_HELPER (unsigned __int64*);
-
-#endif // _RWSTD_NO_LONG_LONG, _MSC_VER
-
-DEFINE_VA_LIST_HELPER (float*);
-DEFINE_VA_LIST_HELPER (double*);
-
-#ifndef _RWSTD_NO_LONG_DOUBLE
-
-DEFINE_VA_LIST_HELPER (long double*);
-
-#endif // _RWSTD_NO_LONG_DOUBLE
-
-DEFINE_VA_LIST_HELPER (void*);
-
-const char* get_va_list_type_name (...) { return 0; }
-
-
void get_type_names (int dummy, ...)
{
clock_t clk = 0; // arithmetic type
@@ -90,10 +50,6 @@
ptrdiff_t diff = 0; // signed integral type
size_t size = 0; // unsigned integral type
time_t tim = 0; // arithmetic type
- va_list va; // object type
-
- // initialize va to prevent an MSVC 8 debug assertion
- va_start (va, dummy);
#if !defined (_RWSTD_USE_CONFIG)
@@ -105,15 +61,6 @@
printf ("#define _RWSTD_PTRDIFF_T %s\n", get_type_name (diff));
printf ("#define _RWSTD_SIZE_T %s\n", get_type_name (size));
printf ("#define _RWSTD_TIME_T %s\n", get_type_name (tim));
-
- if (get_va_list_type_name (va))
- printf ("#define _RWSTD_VA_LIST %s\n", get_va_list_type_name (va));
- else {
- printf ("#define _RWSTD_NO_NATIVE_VA_LIST "
- "/* may be an aggregate */\n");
- printf ("#define _RWSTD_VA_LIST_SIZE %u\n", sizeof va);
- }
-
#if defined (CLOCKS_PER_SEC)
printf ("#define _RWSTD_CLOCKS_PER_SEC %d\n", CLOCKS_PER_SEC);
Added: incubator/stdcxx/trunk/etc/config/src/VA_LIST.cpp
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/etc/config/src/VA_LIST.cpp?rev=357880&view=auto
==============================================================================
--- incubator/stdcxx/trunk/etc/config/src/VA_LIST.cpp (added)
+++ incubator/stdcxx/trunk/etc/config/src/VA_LIST.cpp Mon Dec 19 18:32:06 2005
@@ -0,0 +1,167 @@
+// checking the type of va_list
+
+#if defined (_RWSTD_USE_CONFIG)
+# include "config.h"
+#endif // _RWSTD_USE_CONFIG
+
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <string.h>
+
+
+// determine the underlying pointer type of a typedef
+#define GET_TYPE_NAME(T) \
+ const char* get_type_name (T) { return # T; } \
+ const char* get_type_name (T*) { return # T "*"; } \
+ typedef void unused_type
+
+GET_TYPE_NAME (char);
+GET_TYPE_NAME (signed char);
+GET_TYPE_NAME (unsigned char);
+GET_TYPE_NAME (short);
+GET_TYPE_NAME (unsigned short);
+GET_TYPE_NAME (int);
+GET_TYPE_NAME (unsigned int);
+GET_TYPE_NAME (long);
+GET_TYPE_NAME (unsigned long);
+
+#ifndef _RWSTD_NO_LONG_LONG
+
+GET_TYPE_NAME (long long);
+GET_TYPE_NAME (unsigned long long);
+
+#elif defined (_MSC_VER)
+
+GET_TYPE_NAME (__int64);
+GET_TYPE_NAME (unsigned __int64);
+
+#endif // _RWSTD_NO_LONG_LONG, _MSC_VER
+
+GET_TYPE_NAME (float);
+GET_TYPE_NAME (double);
+
+#ifndef _RWSTD_NO_LONG_DOUBLE
+
+GET_TYPE_NAME (long double);
+
+#endif // _RWSTD_NO_LONG_DOUBLE
+
+GET_TYPE_NAME (void*);
+
+const char* get_type_name (...) { return 0; }
+
+#if 1 // ndef _RWSTD_NO_CLASS_PARTIAL_SPEC
+
+template <class T>
+struct Type {
+ enum { array_size = 0 };
+ static const char* type_name () { return get_type_name (T ()); }
+};
+
+template <class T, int N>
+struct Type<T [N]> {
+ enum { array_size = N };
+ static const char* type_name () { return get_type_name (T ()); }
+};
+
+
+int va_list_array_size (va_list)
+{
+ return Type<va_list>::array_size;
+}
+
+const char* va_list_type_name (va_list)
+{
+ return Type<va_list>::type_name ();
+}
+
+
+#else // if defined (_RWSTD_NO_CLASS_PARTIAL_SPEC)
+
+template <class T>
+int va_list_array_size_imp (T *va)
+{
+ return 0;
+}
+
+template <class T>
+int va_list_array_size_imp (T **va)
+{
+ return sizeof (va_list) / sizeof **va;
+}
+
+int va_list_array_size (va_list va)
+{
+ return va_list_array_size_imp (&va);
+}
+
+template <class T>
+const char* va_list_type (T *va)
+{
+ return get_type_name (*va);
+}
+
+const char* va_list_type_name (va_list va)
+{
+ va_list va2;
+ memset (&va2, 0, sizeof va2);
+
+ const int array_size = va_list_array_size (va2);
+
+ return array_size ? va_list_type (va2) : get_type_name (va);
+}
+
+#endif // _RWSTD_NO_CLASS_PARTIAL_SPEC
+
+
+int main ()
+{
+#if !defined (_RWSTD_USE_CONFIG)
+
+ printf ("/**/\n#undef _RWSTD_VA_LIST\n");
+
+#endif // _RWSTD_USE_CONFIG
+
+ va_list va;
+ memset (&va, 0, sizeof va);
+
+ const int array_size = va_list_array_size (va);
+
+ const char* type_name = va_list_type_name (va);
+
+ if (0 == type_name) {
+ puts ("typedef struct {");
+
+ int elem_size = sizeof va;
+ if (array_size)
+ elem_size /= array_size;
+
+ if (1 < elem_size / sizeof (void*))
+ printf (" void* _C_data [%u];\n", elem_size / sizeof (void*));
+ else if (1 == elem_size / sizeof (void*))
+ puts (" void* _C_data;");
+ else if (1 < elem_size % sizeof (void*))
+ printf (" char _C_data [%u]\n", elem_size % sizeof (void*));
+ else if (1 == elem_size % sizeof (void*))
+ puts (" char _C_data;");
+
+ puts ("} __rw_va_elem;");
+ type_name = "__rw_va_elem";
+ }
+
+ if (array_size) {
+ printf ("typedef %s __rw_va_list [%d];\n"
+ "// #define _RWSTD_NO_VA_LIST_ARRAY // va_list is an array\n",
+ type_name, array_size);
+ }
+ else {
+ printf ("typedef %s __rw_va_list;\n"
+ "#define _RWSTD_NO_VA_LIST_ARRAY // va_list is object type\n",
+ type_name);
+ }
+
+ puts ("#define _RWSTD_VA_LIST __rw_va_list");
+
+ return 0;
+}
Propchange: incubator/stdcxx/trunk/etc/config/src/VA_LIST.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/stdcxx/trunk/etc/config/src/VA_LIST.cpp
------------------------------------------------------------------------------
svn:keywords = Id