Browse code

enforce C11, get rid of gnuisms

Nat! authored on 04-06-2016 17:08:26
Showing 5 changed files
... ...
@@ -10,3 +10,4 @@ project.xcworkspace/
10 10
 dependencies/
11 11
 mulle-configuration/
12 12
 tmp/
13
+research/
... ...
@@ -1,6 +1,7 @@
1 1
 # mulle-vararg
2 2
 
3
-The variable argument passing scheme used in the MetaABI of mulle_objc.
3
+The variable argument passing scheme used in the MetaABI of mulle-objc.
4
+Written in C (C11).
4 5
 
5 6
 ## How it works
6 7
 
... ...
@@ -1,4 +1,10 @@
1
+## 0.3
2
+
3
+* removed gnuisms to be C99 compliant
4
+
5
+
1 6
 ## 0.2
7
+
2 8
 * fixed catastrophic miscalculation
3 9
    
4 10
 ## 0.1
... ...
@@ -216,6 +216,7 @@
216 216
 			baseConfigurationReference = 41998A331CB6693400D18DD8 /* Debug.xcconfig */;
217 217
 			buildSettings = {
218 218
 				CURRENT_PROJECT_VERSION = 0.2;
219
+				GCC_C_LANGUAGE_STANDARD = c99;
219 220
 			};
220 221
 			name = Debug;
221 222
 		};
... ...
@@ -224,6 +225,7 @@
224 225
 			baseConfigurationReference = 41998A3A1CB6693400D18DD8 /* Release.xcconfig */;
225 226
 			buildSettings = {
226 227
 				CURRENT_PROJECT_VERSION = 0.2;
228
+				GCC_C_LANGUAGE_STANDARD = c99;
227 229
 			};
228 230
 			name = Release;
229 231
 		};
... ...
@@ -11,7 +11,7 @@
11 11
 
12 12
 #include "mulle_align.h"
13 13
 
14
-#define MULLE_VARARG_VERSION  ((0 << 20) | (2 << 8) | 0)
14
+#define MULLE_VARARG_VERSION  ((0 << 20) | (3 << 8) | 0)
15 15
 
16 16
 
17 17
 /*
... ...
@@ -62,41 +62,51 @@ do                                             \
62 62
 while( 0)
63 63
 
64 64
 
65
+
66
+
65 67
 // use this for integer types
66
-#define mulle_vararg_next_integer( args, type)              \
67
-({                                                          \
68
-   type   *q;                                               \
69
-                                                            \
70
-   q      = (type *) mulle_align_pointer( args.p, sizeof( type) < sizeof( int) ? alignof( int) : alignof( type)); \
71
-   args.p = &((char *) q)[ sizeof( type) < sizeof( int) ? sizeof( int) : sizeof( type)];  \
72
-                                                            \
73
-   (sizeof( type) < sizeof( int) ? (type) *(int *) q : *q); \
74
-})
75 68
 
69
+static inline char  *_mulle_vararg_int_aligned_pointer( mulle_vararg_list *args, size_t size, unsigned int align)
70
+{
71
+   char   *q;
72
+   
73
+   if( size < sizeof( int))
74
+   {
75
+      align = sizeof( int);
76
+      size  = sizeof( int);
77
+   }
78
+   
79
+   q       = mulle_align_pointer( args->p, align);
80
+   args->p = &q[ size];
81
+   return( q);
82
+}
83
+   
84
+
85
+#define mulle_vararg_next_integer( args, type)                                                   \
86
+   (sizeof( type) < sizeof( int)                                                                 \
87
+      ? (type) *(int *) _mulle_vararg_int_aligned_pointer( &args, sizeof( type), alignof( type)) \
88
+      : *(type *) _mulle_vararg_int_aligned_pointer( &args, sizeof( type), alignof( type)))
89
+
90
+
91
+static inline char  *_mulle_vararg_aligned_pointer( mulle_vararg_list *args, unsigned int align)
92
+{
93
+   char   *q;
94
+   
95
+   q       = mulle_align_pointer( args->p, align);
96
+   args->p = &q[ sizeof( void *)];
97
+   return( q);
98
+}
76 99
 
77
-// use this for objects types
78
-#define mulle_vararg_next( args)                                \
79
-({                                                              \
80
-   id   *q;                                                     \
81
-                                                                \
82
-   q      = (id *) mulle_align_pointer( args.p, alignof( id));  \
83
-   args.p = &((char *) q)[ sizeof( id)];                        \
84
-                                                                \
85
-   *q;                                                          \
86
-})
87 100
 
88 101
 
89 102
 
90 103
 // use this for all pointer and id types
91 104
 #define mulle_vararg_next_pointer( args, type)                  \
92
-({                                                              \
93
-   type   *q;                                                   \
94
-                                                                \
95
-   q      = (type *) mulle_align_pointer( args.p, alignof( void *)); \
96
-   args.p = &((char *) q)[ sizeof( void *)];                    \
97
-                                                                \
98
-   *q;                                                          \
99
-})
105
+   (*(type *) _mulle_vararg_aligned_pointer( &args, alignof( type)))
106
+
107
+// use this for objects types
108
+#define mulle_vararg_next( args)                               \
109
+   mulle_vararg_next_pointer( args, id)
100 110
 
101 111
 // synonym
102 112
 #define mulle_vararg_next_object( args, type)                  \
... ...
@@ -105,26 +115,32 @@ while( 0)
105 115
 
106 116
 // use this for all struct types
107 117
 #define mulle_vararg_next_struct( args, type)                   \
108
-({                                                              \
109
-   type   *q;                                                   \
110
-                                                                \
111
-   q      = (type *) mulle_align_pointer( args.p, alignof( type)); \
112
-   args.p = &((char *) q)[ sizeof( type)];                      \
113
-                                                                \
114
-   *q;                                                          \
115
-})
118
+   (*(type *) _mulle_vararg_aligned_pointer( &args, alignof( type)))
119
+
120
+
121
+static inline char  *_mulle_vararg_double_aligned_pointer( mulle_vararg_list *args, size_t size, unsigned int align)
122
+{
123
+   char   *q;
124
+   
125
+   if( size < sizeof( double))
126
+   {
127
+      align = sizeof( double);
128
+      size  = sizeof( double);
129
+   }
130
+   
131
+   q       = mulle_align_pointer( args->p, align);
132
+   args->p = &q[ size];
133
+   return( q);
134
+}
116 135
 
117 136
 
118 137
 // need separate routine for FP arguments, as float promotes to double
119
-#define mulle_vararg_next_fp( args, type)                         \
120
-({                                                                \
121
-   type   *q;                                                     \
122
-                                                                  \
123
-   q      = (type *) mulle_align_pointer( args.p, sizeof( type) < sizeof( double) ? alignof( double) : alignof( type)); \
124
-   args.p = &((char *) q)[ sizeof( type) < sizeof( double) ? sizeof( double) : sizeof( type)]; \
125
-                                                                  \
126
-   (sizeof( type) < sizeof( double) ? (type) *(double *) q : *q); \
127
-})
138
+#define mulle_vararg_next_fp( args, type)                                                           \
139
+   (sizeof( type) < sizeof( double)                                                                 \
140
+      ? (type) *(int *) _mulle_vararg_double_aligned_pointer( &args, sizeof( type), alignof( type)) \
141
+      : *(type *) _mulle_vararg_double_aligned_pointer( &args, sizeof( type), alignof( type)))
142
+
143
+
128 144
 
129 145
 
130 146
 #define mulle_vararg_copy( dst, src)         \