Skip to content

Commit 82634ed

Browse files
authored
[mypyc] Properly box int32/int64 (#9119)
Follows #9110's comment. Using CPython API to box int32/int64 into PyObject*.
1 parent b1f5121 commit 82634ed

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

mypyc/codegen/emit.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -695,11 +695,10 @@ def emit_box(self, src: str, dest: str, typ: RType, declare_dest: bool = False,
695695
self.emit_lines('{}{} = Py_None;'.format(declaration, dest))
696696
if not can_borrow:
697697
self.emit_inc_ref(dest, object_rprimitive)
698-
# TODO: This is a hack to handle mypy's false negative on unreachable code.
699-
# All ops returning int32/int64 should not be coerced into object.
700-
# Since their result will not be used elsewhere, it's safe to use NULL here
701-
elif is_int32_rprimitive(typ) or is_int64_rprimitive(typ):
702-
self.emit_lines('{}{} = NULL;'.format(declaration, dest))
698+
elif is_int32_rprimitive(typ):
699+
self.emit_line('{}{} = PyLong_FromLong({});'.format(declaration, dest, src))
700+
elif is_int64_rprimitive(typ):
701+
self.emit_line('{}{} = PyLong_FromLongLong({});'.format(declaration, dest, src))
703702
elif isinstance(typ, RTuple):
704703
self.declare_tuple_struct(typ)
705704
self.emit_line('{}{} = PyTuple_New({});'.format(declaration, dest, len(typ.types)))

0 commit comments

Comments
 (0)