Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overflow checking with ctypes

Is it possible to detect an integer overflow with the Python ctypes module?

The docs suggest that none of the primitives support overflow checking, but I'd like to write my own so I can use native c types for my CPU emulator.

like image 828
mvanveen Avatar asked Jun 26 '26 00:06

mvanveen


1 Answers

ctypes isn’t for doing operations on integers, it’s for calling functions in shareable libraries. Any relevant integer arithmetic would still have to be done in Python.

Unless the sharable library is itself providing integer-arithmetic functions, in which case it would have to do the overflow detection.

like image 168
Lawrence D'Oliveiro Avatar answered Jun 28 '26 15:06

Lawrence D'Oliveiro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!