1 Feb 2007 06:27
Safest way to convert any python numerical value to c_int64 ?
David Cournapeau <david <at> ar.media.kyoto-u.ac.jp>
2007-02-01 05:27:53 GMT
2007-02-01 05:27:53 GMT
Hi,
I am using ctypes to use a C library which functions have a 64 bits
integer argument (and expects it to be positive). I am using
ctypes.c_int64 to wrap the argument when calling the C function, but I
was wondering about the best way to treat a value given by the user:
c_int64(10) -> c_lonlong(10L)
c_int64(2 ** 31) -> c_longlong(2147483648L)
c_int64(2 ** 63) -> c_longlong(-9223372036854775808L) !
I thought about converting the user value into a long, check that
log2(value) is below 63, but this is not pretty... Is there a better way
to detect an overflow ?
cheers,
David
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
RSS Feed