Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Closed
Description
Feature or enhancement
I propose to add functions to convert <stdint.h> integers to/from Python int objects:
PyObject*PyLong_FromInt32(int32_tvalue);PyObject*PyLong_FromInt64(int64_tvalue);PyObject*PyLong_FromUInt32(uint32_tvalue);PyObject*PyLong_FromUInt64(uint64_tvalue);intPyLong_ToInt32(PyObject*obj,int32_t*value);intPyLong_ToInt64(PyObject*obj,int64_t*value);intPyLong_ToUInt32(PyObject*obj,uint32_t*value);intPyLong_ToUInt64(PyObject*obj,uint64_t*value);
Notes:
- I prefer to limit the API to 4 types for now: int32/64_t and uint32/64_t. Later, we can discuss add more types, but let's start with the most common ones. (UPDATE: I removed 8-bit and 16-bit types.)
- I prefer
UInttoUintsince there are two words: Unsigned INTeger. Tofunctions don't return the result, but a status: 0 on success, -1 on error (with an exception set). It's to solve theC API Problem #1: "Ambiguous return values". PyLong_AsLong() returns -1 on success and on error (with an exception set).
Related discussion:Avoid C-specific Types.