Skip to content

Commit c52f215

Browse files
committed
Fix: used asInt instead of asLong
1 parent a6f3e06 commit c52f215

File tree

2 files changed

+20
-13
lines changed
  • graalpython
    • com.oracle.graal.python.test/src/tests/cpyext
    • com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi

2 files changed

+20
-13
lines changed

graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_unicode.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,15 @@ def _reference_unicode_escape(args):
7575
return _codecs.unicode_escape_encode(args[0])[0]
7676

7777

78+
def _reference_fromformat(args):
79+
fmt = args[0]
80+
fmt_args = args[1:]
81+
# replace specifiers
82+
for s in ["%ld", "%li", "%lu", "%lld", "%lli", "%llu"]:
83+
fmt = fmt.replace(s, "%d")
84+
return fmt % fmt_args
85+
86+
7887
class CustomString(str):
7988
pass
8089

@@ -128,7 +137,7 @@ def compile_module(self, name):
128137
)
129138

130139
test_PyUnicode_FromFormat0 = CPyExtFunction(
131-
lambda args: args[0] % tuple(args[1:]),
140+
_reference_fromformat,
132141
lambda: (
133142
("hello, world!",),
134143
),
@@ -143,19 +152,17 @@ def compile_module(self, name):
143152
cmpfunc=unhandled_error_compare
144153
)
145154

146-
test_PyUnicode_FromFormat3 = CPyExtFunction(
147-
lambda args: args[0] % tuple(args[1:]),
155+
test_PyUnicode_FromFormat4 = CPyExtFunction(
156+
_reference_fromformat,
148157
lambda: (
149-
("word0: %s; word1: %s; int: %d", "hello", "world", 1234),
158+
("word0: %s; word1: %s; int: %d; long long: %lld", "hello", "world", 1234, 1234),
159+
("word0: %s; word1: %s; int: %d; long long: %lld", "hello", "world", 1234, (1<<44)+123),
150160
),
151-
code="""PyObject* wrap_PyUnicode_FromFormat3(char* fmt, char* arg0, char* arg1, int n) {
152-
return PyUnicode_FromFormat(fmt, arg0, arg1, n);
153-
}
154-
""",
161+
code="typedef long long longlong_t;",
155162
resultspec="O",
156-
argspec='sssi',
157-
arguments=["char* fmt", "char* arg0", "char* arg1", "int n"],
158-
callfunction="wrap_PyUnicode_FromFormat3",
163+
argspec='sssiL',
164+
arguments=["char* fmt", "char* arg0", "char* arg1", "int n", "longlong_t l"],
165+
callfunction="PyUnicode_FromFormat",
159166
cmpfunc=unhandled_error_compare
160167
)
161168

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CExtNodes.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3386,9 +3386,9 @@ private static int getAndCastToInt(GetVaArgsNode getVaArgsNode, InteropLibrary l
33863386
* possible.
33873387
*/
33883388
private static long castToLong(InteropLibrary lib, PRaiseNode raiseNode, Object value) {
3389-
if (lib.fitsInInt(value)) {
3389+
if (lib.fitsInLong(value)) {
33903390
try {
3391-
return lib.asInt(value);
3391+
return lib.asLong(value);
33923392
} catch (UnsupportedMessageException e) {
33933393
throw CompilerDirectives.shouldNotReachHere();
33943394
}

0 commit comments

Comments
 (0)