Ticket #592 (closed defect: fixed)

Opened 3 years ago

Last modified 3 years ago

Large integer literals/constants can generate invalid C code

Reported by: scoder Owned by: scoder
Priority: major Milestone: 0.14
Component: Code Generation Keywords:
Cc:

Description

The perfectly valid Python code

def test():
    return 1L << 200

generates either

PyInt_FromLong(1L << 200)

without constant folding, or

PyInt_FromLong(1606938044258990275541962092341162602522202993782792835301376)

with constant folding enabled. Both do not work in C.

Change History

Changed 3 years ago by scoder

  • owner changed from somebody to scoder
  • status changed from new to assigned
  • milestone changed from wishlist to 0.13.1

The new behaviour is that Cython will convert integer literals that do not fit into signed 32bits into Python objects, unless explicitly coerced into a C integer, e.g. in typed assignments. This assures that literals do not unexpectedly loose bit precision.

Changed 3 years ago by scoder

  • status changed from assigned to closed
  • resolution set to fixed
Note: See TracTickets for help on using tickets.