Objects/numobjects/intobject/ops_toint

Source   Edit  

Procs

func absToUInt[U: uint | uint8 | uint16](pyInt: PyIntObject; x: var U): bool {.
    cdecl.}
Source   Edit  
func absToUInt[U: uint32 | uint64 | BiggestUInt](pyInt: PyIntObject; x: var U): bool {.
    cdecl.}

EXT. unstable.

ignore signbit. returns false on overflow

Source   Edit  
proc asLongAndOverflow(vv: PyIntObject; ovlf: var bool): int {.inline,
    ...raises: [], tags: [], forbids: [].}
PyLong_AsLongAndOverflow Source   Edit  
proc hash(self: PyIntObject): Hash {.inline, cdecl, ...raises: [], tags: [],
                                     forbids: [].}
Source   Edit  
proc PyInt_OverflowCType(ctypeName: string): PyOverflowErrorObject {....raises: [],
    tags: [RootEffect], forbids: [].}
EXT. used to construct OverflowError of PyLong_As<ctypeName> So no need to call PyLong_AsXxx but toSomeXxInt Source   Edit  
proc PyLong_AsSize_t(pyInt: PyIntObject; res: var uint): PyOverflowErrorObject {.
    ...raises: [], tags: [RootEffect], forbids: [].}
Source   Edit  
proc PyLong_AsSize_t(v: PyObject; res: var uint): PyBaseErrorObject {.
    ...raises: [], tags: [RootEffect], forbids: [].}
Source   Edit  
proc PyLong_AsSsize_t(v: PyObject; res: var int): PyBaseErrorObject {.
    ...raises: [], tags: [RootEffect], forbids: [].}
Source   Edit  
proc PyLong_AsSsize_t(vv: PyIntObject; res: var int): PyOverflowErrorObject {.
    ...raises: [], tags: [RootEffect], forbids: [].}
returns nil if not overflow Source   Edit  
proc toInt(pyInt: PyIntObject; overflow: var IntSign): int {....raises: [],
    tags: [], forbids: [].}
Source   Edit  
proc toInt(pyInt: PyIntObject; res: var int): bool {....raises: [], tags: [],
    forbids: [].}
returns false on overflow (x not_in int.low..int.high) Source   Edit  
proc toSomeSignedInt[I: SomeSignedInt](pyInt: PyIntObject; overflow: var IntSign): I

if overflow, overflow will be IntSign.Negative or IntSign.Positive (depending the sign of the argument) and result be `-1

Otherwise, overflow will be IntSign.Zero

Source   Edit  
proc toSomeSignedIntUnsafe[T: SomeSignedInt](pyInt: PyIntObject): T
XXX: the caller should take care of overflow It raises OverflowDefect on non-danger build Source   Edit  
proc toSomeUnsignedInt[U: SomeUnsignedInt](pyInt: PyIntObject;
    overflow: var IntSign): U
like toSomeSignedInt<#toInt,PyIntObject,IntSign>_ but for `uint Source   Edit  
proc toUInt(pyInt: PyIntObject; overflow: var IntSign): uint {....raises: [],
    tags: [], forbids: [].}
like toInt<#toInt,PyIntObject,IntSign>_ but for `uint Source   Edit  
proc toUInt(pyInt: PyIntObject; res: var uint): bool {....raises: [], tags: [],
    forbids: [].}
like toInt<#toInt,PyIntObject,int>_ but for `uint Source   Edit  

Templates

template toIntOrRetOF(vv: PyIntObject): int
a helper wrapper of PyLong_AsSsize_t return OverflowError for outer function Source   Edit