Skip to content

Commit 2f87efa

Browse files
committed
Use explicit polyglot cast.
1 parent 9befed8 commit 2f87efa

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ PyObject * PyUnicode_FromStringAndSize(const char *u, Py_ssize_t size) {
112112
return to_sulong(polyglot_from_string_n(u, size, SRC_CS));
113113
}
114114

115+
#define AS_I64(__arg__) (polyglot_fits_in_i64((__arg__)) ? polyglot_as_i64((__arg__)) : (int64_t)(__arg__))
116+
115117
MUST_INLINE PyObject* PyTruffle_Unicode_FromFormat(const char *fmt, va_list va, void **args, int argc) {
116118
size_t fmt_size = strlen(fmt) + 1;
117119
// n.b. avoid using 'strdup' for compatiblity with MUSL libc
@@ -132,7 +134,7 @@ MUST_INLINE PyObject* PyTruffle_Unicode_FromFormat(const char *fmt, va_list va,
132134
c[0] = '\0';
133135
int bytes_written;
134136
if (variable != NULL) {
135-
bytes_written = snprintf(buffer, remaining_space, fmtcpy, (unsigned long)variable);
137+
bytes_written = snprintf(buffer, remaining_space, fmtcpy, AS_I64(variable));
136138
if (allocated != NULL) {
137139
free(allocated);
138140
allocated = NULL;
@@ -186,7 +188,7 @@ MUST_INLINE PyObject* PyTruffle_Unicode_FromFormat(const char *fmt, va_list va,
186188

187189
// write the remaining buffer
188190
if (variable != NULL) {
189-
snprintf(buffer, remaining_space, fmtcpy, (unsigned long)variable);
191+
snprintf(buffer, remaining_space, fmtcpy, AS_I64(variable));
190192
if (allocated) {
191193
free(allocated);
192194
}

0 commit comments

Comments
 (0)