[Python-Dev] Returning -1 from function with unsigned long type (original) (raw)
Tim Peters tim.peters at gmail.com
Mon Apr 17 23:48:10 CEST 2006
- Previous message: [Python-Dev] Returning -1 from function with unsigned long type
- Next message: [Python-Dev] Returning -1 from function with unsigned long type
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
I'm fiddling with the "compile Python w/ C++" stuff and came across a number of places where a function is defined as returning unsigned long or unsigned long long but returns -1. For example, see PyIntAsUnsignedLongMask. What's the correct fix for that, return ~0 (assuming twos-complement arithmetic), cast -1 to unsigned long?
Explicitly casting -1 is both the obvious and best way, and is guaranteed to "work as intended" by the standards.
Or does the API need to be changed somehow?
Well, it's ubiquitous in Python that C API calls returning any kind of integer return -1 (and arrange to make PyErr_Occurred() return true) in case of error. This is clumsy when the integer retured is of an unsigned type, but it is C we're talking about ;-)
- Previous message: [Python-Dev] Returning -1 from function with unsigned long type
- Next message: [Python-Dev] Returning -1 from function with unsigned long type
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]