Skip to content

Commit 26cd5c6

Browse files
committed
fix: specialize
1 parent d7b0023 commit 26cd5c6

File tree

3 files changed

+18
-22
lines changed

3 files changed

+18
-22
lines changed

mypyc/irbuild/specialize.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,6 @@ def specialize_int_to_bytes(builder: IRBuilder, expr: CallExpr, callee: RefExpr)
10281028
)
10291029
# Fallback to generic primitive op
10301030
byteorder_arg = builder.accept(byteorder_expr)
1031-
return builder.primitive_op(
1031+
return builder.call_c(
10321032
int_to_bytes_op, [self_arg, length_arg, byteorder_arg, signed_arg], expr.line
10331033
)

mypyc/primitives/int_ops.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -314,19 +314,9 @@ def int_unary_op(name: str, c_function_name: str) -> PrimitiveDescription:
314314
error_kind=ERR_NEVER,
315315
)
316316

317-
# int.to_bytes(length, byteorder)
318-
method_op(
319-
name="to_bytes",
320-
arg_types=[int_rprimitive, int_rprimitive, str_rprimitive],
321-
extra_int_constants=[(0, bool_rprimitive)],
322-
return_type=bytes_rprimitive,
323-
c_function_name="CPyTagged_ToBytes",
324-
error_kind=ERR_MAGIC,
325-
)
326317

327318
# int.to_bytes(length, byteorder, signed=...)
328-
int_to_bytes_op = method_op(
329-
name="to_bytes",
319+
int_to_bytes_op = custom_op(
330320
arg_types=[int_rprimitive, int_rprimitive, str_rprimitive, bool_rprimitive],
331321
return_type=bytes_rprimitive,
332322
c_function_name="CPyTagged_ToBytes",

mypyc/test-data/irbuild-int.test

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -216,20 +216,26 @@ def f(x: int) -> bytes:
216216
return x.to_bytes(2, "big")
217217
def g(x: int) -> bytes:
218218
return x.to_bytes(4, "little", signed=True)
219+
def h(x: int, byteorder: str) -> bytes:
220+
return x.to_bytes(8, byteorder)
221+
219222
[out]
220223
def f(x):
221224
x :: int
222-
r0 :: str
223-
r1 :: bytes
225+
r0 :: bytes
224226
L0:
225-
r0 = 'big'
226-
r1 = CPyTagged_ToBytes(x, 4, r0, 0)
227-
return r1
227+
r0 = CPyTagged_ToBigEndianBytes(x, 4, 0)
228+
return r0
228229
def g(x):
229230
x :: int
230-
r0 :: str
231-
r1 :: bytes
231+
r0 :: bytes
232232
L0:
233-
r0 = 'little'
234-
r1 = CPyTagged_ToBytes(x, 8, r0, 1)
235-
return r1
233+
r0 = CPyTagged_ToLittleEndianBytes(x, 8, 1)
234+
return r0
235+
def h(x):
236+
x :: int
237+
byteorder :: str
238+
r0 :: bytes
239+
L0:
240+
r0 = CPyTagged_ToBytes(x, 8, byteorder, 0)
241+
return r0

0 commit comments

Comments
 (0)