Skip to content

Commit 8f00746

Browse files
committed
Do not make assumptions about type va_list.
1 parent 315b899 commit 8f00746

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

graalpython/com.oracle.graal.python.cext/src/capi.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,13 +352,14 @@ int bufferdecorator_getbuffer(PyBufferDecorator *self, Py_buffer *view, int flag
352352
* together, the managed array with arguments will be escape analyzed away.
353353
*/
354354
#define CallWithPolyglotArgs(result, last, off, function, ...) \
355+
va_list __va_list; \
355356
int __poly_argc = polyglot_get_arg_count(); \
356357
int __poly_args_s = sizeof(void*) * (__poly_argc - off); \
357358
void **__poly_args = truffle_managed_malloc(__poly_args_s); \
358359
for (int i = off; i < __poly_argc; i++) { \
359360
__poly_args[i - off] = polyglot_get_arg(i); \
360361
} \
361-
result = function(__VA_ARGS__, NULL, __poly_args, 0)
362+
result = function(__VA_ARGS__, __va_list, __poly_args, 0)
362363
#else
363364
/*
364365
* (tfel): Just skip the optimization with using a managed malloc and use

graalpython/com.oracle.graal.python.cext/src/unicodeobject.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ MUST_INLINE PyObject* PyTruffle_Unicode_FromFormat(const char *fmt, va_list va,
120120
char* fmtcpy = (char*) malloc(fmt_size*sizeof(char));
121121
memcpy(fmtcpy, fmt, fmt_size);
122122
char* c = fmtcpy;
123+
int use_valist = args == NULL;
123124

124125
int remaining_space = 2047;
125126
char* buffer = (char*)calloc(sizeof(char), remaining_space + 1);
@@ -140,7 +141,7 @@ MUST_INLINE PyObject* PyTruffle_Unicode_FromFormat(const char *fmt, va_list va,
140141
allocated = NULL;
141142
}
142143
variable = NULL;
143-
} else if (va != NULL) {
144+
} else if (use_valist) {
144145
bytes_written = vsnprintf(buffer, remaining_space, fmtcpy, va);
145146
} else {
146147
strncpy(buffer, fmtcpy, remaining_space);
@@ -165,7 +166,7 @@ MUST_INLINE PyObject* PyTruffle_Unicode_FromFormat(const char *fmt, va_list va,
165166
case 'R':
166167
if (converter == NULL) converter = PyObject_Repr;
167168
c[1] = 's';
168-
allocated = variable = as_char_pointer(converter(args == NULL ? va_arg(va, PyObject*) : (PyObject*)(args[argc++])));
169+
allocated = variable = as_char_pointer(converter(use_valist ? va_arg(va, PyObject*) : (PyObject*)(args[argc++])));
169170
break;
170171
case '%':
171172
// literal %
@@ -192,7 +193,7 @@ MUST_INLINE PyObject* PyTruffle_Unicode_FromFormat(const char *fmt, va_list va,
192193
if (allocated) {
193194
free(allocated);
194195
}
195-
} else if (va != NULL) {
196+
} else if (use_valist) {
196197
vsnprintf(buffer, remaining_space, fmtcpy, va);
197198
} else {
198199
strncpy(buffer, fmtcpy, remaining_space);

0 commit comments

Comments
 (0)