@@ -77,30 +77,6 @@ int get_buffer_rw(PyObject *arg, Py_buffer *view) {
77
77
return 0 ;
78
78
}
79
79
80
- typedef union {
81
- void * ptr ;
82
- float f ;
83
- double d ;
84
- int64_t i64 ;
85
- int32_t i32 ;
86
- int16_t i16 ;
87
- int8_t i8 ;
88
- uint64_t u64 ;
89
- uint32_t u32 ;
90
- uint16_t u16 ;
91
- uint8_t u8 ;
92
- Py_complex c ;
93
- } OutVar ;
94
-
95
- POLYGLOT_DECLARE_TYPE (OutVar );
96
-
97
- typedef struct { OutVar * content ; } OutVarPtr ;
98
-
99
- POLYGLOT_DECLARE_TYPE (OutVarPtr );
100
-
101
- typedef char * CharPtr ;
102
- POLYGLOT_DECLARE_TYPE (CharPtr );
103
-
104
80
105
81
typedef int (* parseargs_func )(PyObject * argv , PyObject * kwds , const char * format , void * kwdnames , void * varargs );
106
82
@@ -111,53 +87,35 @@ static void init_upcall_PyTruffle_Arg_ParseTupleAndKeyword(void) {
111
87
PyTruffle_Arg_ParseTupleAndKeywords = polyglot_get_member (PY_TRUFFLE_CEXT , polyglot_from_string ("PyTruffle_Arg_ParseTupleAndKeywords" , SRC_CS ));
112
88
}
113
89
90
+ typedef char * char_ptr_t ;
91
+ POLYGLOT_DECLARE_TYPE (char_ptr_t );
92
+
114
93
#define CallParseTupleAndKeywordsWithPolyglotArgs (__res__ , __offset__ , __args__ , __kwds__ , __fmt__ , __kwdnames__ ) \
115
- int __poly_argc = polyglot_get_arg_count() - (__offset__); \
116
- void **__poly_args = truffle_managed_malloc(sizeof(void*) * __poly_argc); \
94
+ va_list __vl; \
117
95
int __kwdnames_cnt = 0; \
118
- for (int i = 0; i < __poly_argc; i++) { \
119
- __poly_args[i] = polyglot_get_arg(i + (__offset__)); \
120
- } \
121
96
if((__kwdnames__) != NULL){ \
122
97
for (; (__kwdnames__)[__kwdnames_cnt] != NULL ; __kwdnames_cnt++); \
123
98
} \
124
- __res__ = PyTruffle_Arg_ParseTupleAndKeywords((__args__), (__kwds__), polyglot_from_string((__fmt__), SRC_CS), polyglot_from_CharPtr_array(__kwdnames__, __kwdnames_cnt), polyglot_from_OutVarPtr_array((OutVarPtr*)__poly_args, __poly_argc));
99
+ va_start(__vl, __offset__); \
100
+ __res__ = PyTruffle_Arg_ParseTupleAndKeywords((__args__), (__kwds__), polyglot_from_string((__fmt__), SRC_CS), polyglot_from_char_ptr_t_array(__kwdnames__, __kwdnames_cnt), &__vl); \
101
+ va_end(__vl);
125
102
126
103
127
104
#define CallParseTupleWithPolyglotArgs (__res__ , __offset__ , __args__ , __fmt__ ) \
128
- int __poly_argc = polyglot_get_arg_count() - (__offset__); \
129
- void **__poly_args = truffle_managed_malloc(sizeof(void*) * __poly_argc); \
130
- for (int i = 0; i < __poly_argc; i++) { \
131
- __poly_args[i] = polyglot_get_arg(i + (__offset__)); \
132
- } \
133
- __res__ = PyTruffle_Arg_ParseTupleAndKeywords((__args__), NULL, polyglot_from_string((__fmt__), SRC_CS), NULL, polyglot_from_OutVarPtr_array((OutVarPtr*)__poly_args, __poly_argc));
105
+ va_list __vl; \
106
+ va_start(__vl, __offset__); \
107
+ __res__ = PyTruffle_Arg_ParseTupleAndKeywords((__args__), NULL, polyglot_from_string((__fmt__), SRC_CS), NULL, &__vl); \
108
+ va_end(__vl);
134
109
135
110
136
111
#define CallParseStackWithPolyglotArgs (__res__ , __offset__ , __args__ , __nargs__ , __fmt__ ) \
137
- int __poly_argc = polyglot_get_arg_count() - (__offset__); \
138
- void **__poly_args = truffle_managed_malloc(sizeof(void*) * __poly_argc); \
139
- for (int i = 0; i < __poly_argc; i++) { \
140
- __poly_args[i] = polyglot_get_arg(i + (__offset__)); \
141
- } \
142
- __res__ = PyTruffle_Arg_ParseTupleAndKeywords(polyglot_from_PyObjectPtr_array((__args__), (__nargs__)), NULL, polyglot_from_string((__fmt__), SRC_CS), NULL, polyglot_from_OutVarPtr_array((OutVarPtr*)__poly_args, __poly_argc));
112
+ va_list __vl; \
113
+ va_start(__vl, __offset__); \
114
+ __res__ = PyTruffle_Arg_ParseTupleAndKeywords(polyglot_from_PyObjectPtr_array((__args__), (__nargs__)), NULL, polyglot_from_string((__fmt__), SRC_CS), NULL, &__vl); \
115
+ va_end(__vl);
143
116
144
117
/* argparse */
145
118
146
- OutVarPtr * allocate_outvar () {
147
- return polyglot_from_OutVarPtr (truffle_managed_malloc (sizeof (OutVarPtr )));
148
- }
149
-
150
- void get_next_vaarg (va_list * p_va , OutVarPtr * p_outvar ) {
151
- p_outvar -> content = (OutVar * )va_arg (* p_va , void * );
152
- }
153
-
154
- static parseargs_func PyTruffle_Arg_ParseTupleAndKeywords_VaList ;
155
-
156
- __attribute__((constructor ))
157
- static void init_upcall_PyTruffle_Arg_ParseTupleAndKeyword_VaList (void ) {
158
- PyTruffle_Arg_ParseTupleAndKeywords_VaList = polyglot_get_member (PY_TRUFFLE_CEXT , polyglot_from_string ("PyTruffle_Arg_ParseTupleAndKeywords_VaList" , SRC_CS ));
159
- }
160
-
161
119
int PyArg_VaParseTupleAndKeywords (PyObject * argv , PyObject * kwds , const char * format , char * * kwdnames , va_list va ) {
162
120
va_list lva ;
163
121
va_copy (lva , va );
@@ -166,7 +124,7 @@ int PyArg_VaParseTupleAndKeywords(PyObject *argv, PyObject *kwds, const char *fo
166
124
if (kwdnames != NULL ) {
167
125
for (; kwdnames [__kwdnames_cnt ] != NULL ; __kwdnames_cnt ++ );
168
126
}
169
- res = PyTruffle_Arg_ParseTupleAndKeywords_VaList (native_to_java (argv ), native_to_java (kwds ), polyglot_from_string (format , SRC_CS ), polyglot_from_CharPtr_array (kwdnames , __kwdnames_cnt ), & lva );
127
+ res = PyTruffle_Arg_ParseTupleAndKeywords (native_to_java (argv ), native_to_java (kwds ), polyglot_from_string (format , SRC_CS ), polyglot_from_char_ptr_t_array (kwdnames , __kwdnames_cnt ), & lva );
170
128
va_end (lva );
171
129
return res ;
172
130
}
@@ -179,32 +137,31 @@ int _PyArg_VaParseTupleAndKeywords_SizeT(PyObject *argv, PyObject *kwds, const c
179
137
if (kwdnames != NULL ) {
180
138
for (; kwdnames [__kwdnames_cnt ] != NULL ; __kwdnames_cnt ++ );
181
139
}
182
- res = PyTruffle_Arg_ParseTupleAndKeywords_VaList (native_to_java (argv ), native_to_java (kwds ), polyglot_from_string (format , SRC_CS ), polyglot_from_CharPtr_array (kwdnames , __kwdnames_cnt ), & lva );
140
+ res = PyTruffle_Arg_ParseTupleAndKeywords (native_to_java (argv ), native_to_java (kwds ), polyglot_from_string (format , SRC_CS ), polyglot_from_char_ptr_t_array (kwdnames , __kwdnames_cnt ), & lva );
183
141
va_end (lva );
184
142
return res ;
185
143
}
186
144
187
- NO_INLINE
188
145
int PyArg_ParseTupleAndKeywords (PyObject * argv , PyObject * kwds , const char * format , char * * kwdnames , ...) {
189
- CallParseTupleAndKeywordsWithPolyglotArgs (int result , 4 , native_to_java (argv ), native_to_java (kwds ), format , kwdnames );
146
+ CallParseTupleAndKeywordsWithPolyglotArgs (int result , kwdnames , native_to_java (argv ), native_to_java (kwds ), format , kwdnames );
190
147
return result ;
191
148
}
192
149
193
- NO_INLINE
150
+
194
151
int _PyArg_ParseTupleAndKeywords_SizeT (PyObject * argv , PyObject * kwds , const char * format , char * * kwdnames , ...) {
195
- CallParseTupleAndKeywordsWithPolyglotArgs (int result , 4 , native_to_java (argv ), native_to_java (kwds ), format , kwdnames );
152
+ CallParseTupleAndKeywordsWithPolyglotArgs (int result , kwdnames , native_to_java (argv ), native_to_java (kwds ), format , kwdnames );
196
153
return result ;
197
154
}
198
155
199
156
NO_INLINE
200
157
int PyArg_ParseStack (PyObject * * args , Py_ssize_t nargs , const char * format , ...) {
201
- CallParseStackWithPolyglotArgs (int result , 3 , args , nargs , format );
158
+ CallParseStackWithPolyglotArgs (int result , format , args , nargs , format );
202
159
return result ;
203
160
}
204
161
205
162
NO_INLINE
206
163
int _PyArg_ParseStack_SizeT (PyObject * * args , Py_ssize_t nargs , const char * format , ...) {
207
- CallParseStackWithPolyglotArgs (int result , 3 , args , nargs , format );
164
+ CallParseStackWithPolyglotArgs (int result , format , args , nargs , format );
208
165
return result ;
209
166
}
210
167
@@ -216,28 +173,26 @@ int _PyArg_VaParseTupleAndKeywordsFast_SizeT(PyObject *args, PyObject *kwargs, s
216
173
return _PyArg_VaParseTupleAndKeywords_SizeT (args , kwargs , parser -> format , parser -> keywords , va );
217
174
}
218
175
219
- NO_INLINE
220
176
int _PyArg_ParseTupleAndKeywordsFast (PyObject * args , PyObject * kwargs , struct _PyArg_Parser * parser , ...) {
221
- CallParseTupleAndKeywordsWithPolyglotArgs (int result , 3 , native_to_java (args ), native_to_java (kwargs ), parser -> format , parser -> keywords );
177
+ CallParseTupleAndKeywordsWithPolyglotArgs (int result , parser , native_to_java (args ), native_to_java (kwargs ), parser -> format , parser -> keywords );
222
178
return result ;
223
179
}
224
180
225
- NO_INLINE
226
181
int _PyArg_ParseTupleAndKeywordsFast_SizeT (PyObject * args , PyObject * kwargs , struct _PyArg_Parser * parser , ...) {
227
- CallParseTupleAndKeywordsWithPolyglotArgs (int result , 3 , native_to_java (args ), native_to_java (kwargs ), parser -> format , parser -> keywords );
182
+ CallParseTupleAndKeywordsWithPolyglotArgs (int result , parser , native_to_java (args ), native_to_java (kwargs ), parser -> format , parser -> keywords );
228
183
return result ;
229
184
}
230
185
231
186
232
187
NO_INLINE
233
188
int PyArg_ParseTuple (PyObject * args , const char * format , ...) {
234
- CallParseTupleWithPolyglotArgs (int result , 2 , native_to_java (args ), format );
189
+ CallParseTupleWithPolyglotArgs (int result , format , native_to_java (args ), format );
235
190
return result ;
236
191
}
237
192
238
193
NO_INLINE
239
194
int _PyArg_ParseTuple_SizeT (PyObject * args , const char * format , ...) {
240
- CallParseTupleWithPolyglotArgs (int result , 2 , native_to_java (args ), format );
195
+ CallParseTupleWithPolyglotArgs (int result , format , native_to_java (args ), format );
241
196
return result ;
242
197
}
243
198
@@ -251,13 +206,13 @@ int _PyArg_VaParse_SizeT(PyObject *args, const char *format, va_list va) {
251
206
252
207
NO_INLINE
253
208
int PyArg_Parse (PyObject * args , const char * format , ...) {
254
- CallParseTupleWithPolyglotArgs (int result , 2 , native_to_java (PyTuple_Pack (1 , args )), format );
209
+ CallParseTupleWithPolyglotArgs (int result , format , native_to_java (PyTuple_Pack (1 , args )), format );
255
210
return result ;
256
211
}
257
212
258
213
NO_INLINE
259
214
int _PyArg_Parse_SizeT (PyObject * args , const char * format , ...) {
260
- CallParseTupleWithPolyglotArgs (int result , 2 , native_to_java (PyTuple_Pack (1 , args )), format );
215
+ CallParseTupleWithPolyglotArgs (int result , format , native_to_java (PyTuple_Pack (1 , args )), format );
261
216
return result ;
262
217
}
263
218
0 commit comments