Skip to content

Commit e98007f

Browse files
committed
[GR-17674] Avoid platform-specific code in C API.
PullRequest: graalpython/619
2 parents 25b0af7 + 1f7cc64 commit e98007f

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

graalpython/com.oracle.graal.python.cext/include/pyconfig.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -41,6 +41,8 @@
4141
#ifndef Py_PYCONFIG_H
4242
#define Py_PYCONFIG_H
4343

44+
// required for __UINT32_MAX__ etc.
45+
#include <limits.h>
4446

4547
// defines based on Clang defines
4648
#define SIZEOF_DOUBLE __SIZEOF_DOUBLE__
@@ -60,13 +62,21 @@
6062
#define SIZEOF_VOID_P __SIZEOF_POINTER__
6163
#define SIZEOF_WCHAR_T __SIZEOF_WCHAR_T__
6264
#define SIZEOF__BOOL 1
63-
#define INT_MIN ((-__INT32_MAX__)-1)
64-
#define INT_MAX __INT32_MAX__
65+
# ifndef UINT_MAX
6566
#define UINT_MAX __UINT32_MAX__
67+
#endif
68+
# ifndef SHRT_MIN
6669
#define SHRT_MIN ((-__INT16_MAX__)-1)
70+
#endif
71+
# ifndef SHRT_MAX
6772
#define SHRT_MAX __INT16_MAX__
73+
#endif
74+
# ifndef USHRT_MAX
6875
#define USHRT_MAX __UINT16_MAX__
76+
#endif
77+
# ifndef CHAR_BIT
6978
#define CHAR_BIT __CHAR_BIT__
79+
#endif
7080
// #define Py_LIMITED_API 1
7181
#define _Py_BEGIN_SUPPRESS_IPH
7282
#define _Py_END_SUPPRESS_IPH

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)