-
- Notifications
You must be signed in to change notification settings - Fork 33.5k
gh-111140: Adds PyLong_AsNativeBytes and PyLong_FromNative[Unsigned]Bytes functions #114886
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 18 commits
c86821e cd6754a bf86f85 22f3d14 0dc0bcc c30e65a 9661b65 79d4942 bc9e48c b4761be 043947f 761db5c 22c2a64 6e1a89a 7b44648 79dd452 9693afe 376e358 1f2cf3a 7f4431d 2649d94 39962de File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| | @@ -4,6 +4,40 @@ | |
| | ||
| PyAPI_FUNC(PyObject*) PyLong_FromUnicodeObject(PyObject *u, int base); | ||
| | ||
| /* PyLong_AsNativeBytes: Copy the integer value to a native variable. | ||
| buffer points to the first byte of the variable. | ||
| n_bytes is the number of bytes available in the buffer. Pass 0 to request | ||
| the required size for the value. | ||
| endianness is -1 for native endian, 0 for big endian or 1 for little. | ||
| Big endian mode will write the most significant byte into the address | ||
| directly referenced by buffer; little endian will write the least significant | ||
| byte into that address. | ||
| | ||
| If an exception is raised, returns a negative value. | ||
| Otherwise, returns the number of bytes that are required to store the value. | ||
| To check that the full value is represented, ensure that the return value is | ||
| equal or less than n_bytes. | ||
| All n_bytes are guaranteed to be written (unless an exception occurs), and | ||
| so ignoring a positive return value is the equivalent of a downcast in C. | ||
| In cases where the full value could not be represented, the returned value | ||
| may be larger than necessary - this function is not an accurate way to | ||
| calculate the bit length of an integer object. | ||
| */ | ||
| PyAPI_FUNC(int) PyLong_AsNativeBytes(PyObject* v, void* buffer, size_t n_bytes, | ||
| int endianness); | ||
| ||
| | ||
| /* PyLong_FromNativeBytes: Create an int value from a native integer | ||
| n_bytes is the number of bytes to read from the buffer. Passing 0 will | ||
| always produce the zero int. | ||
| PyLong_FromUnsignedNativeBytes always produces a non-negative int. | ||
| endianness is -1 for native endian, 0 for big endian or 1 for little. | ||
| | ||
| Returns the int object, or NULL with an exception set. */ | ||
| PyAPI_FUNC(PyObject*) PyLong_FromNativeBytes(const void* buffer, size_t n_bytes, | ||
| int endianness); | ||
| PyAPI_FUNC(PyObject*) PyLong_FromUnsignedNativeBytes(const void* buffer, | ||
| size_t n_bytes, int endianness); | ||
| | ||
| PyAPI_FUNC(int) PyUnstable_Long_IsCompact(const PyLongObject* op); | ||
| PyAPI_FUNC(Py_ssize_t) PyUnstable_Long_CompactValue(const PyLongObject* op); | ||
| | ||
| | @@ -50,7 +84,7 @@ PyAPI_FUNC(PyObject *) _PyLong_FromByteArray( | |
| */ | ||
| PyAPI_FUNC(int) _PyLong_AsByteArray(PyLongObject* v, | ||
| unsigned char* bytes, size_t n, | ||
| int little_endian, int is_signed); | ||
| int little_endian, int is_signed, int with_exceptions); | ||
| | ||
| /* For use by the gcd function in mathmodule.c */ | ||
| PyAPI_FUNC(PyObject *) _PyLong_GCD(PyObject *, PyObject *); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Adds :c:func:`PyLong_AsNativeBytes`, :c:func:`PyLong_FromNativeBytes` and | ||
| :c:func:`PyLong_FromUnsignedNativeBytes` functions. |
Uh oh!
There was an error while loading. Please reload this page.