Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-143869: Add PEP 757 functions to the limited API#143906

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
vstinner merged 11 commits intopython:mainfromskirpichev:pep757-sapi/143869
Jan 21, 2026
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletionsDoc/c-api/long.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -687,7 +687,7 @@ Export API

.. versionadded:: 3.14

.. c:struct:: PyLongLayout
.. c:type:: PyLongLayout

Layout of an array of "digits" ("limbs" in the GMP terminology), used to
represent absolute value for arbitrary precision integers.
Expand DownExpand Up@@ -727,15 +727,15 @@ Export API

Get the native layout of Python :class:`int` objects.

See the :c:struct:`PyLongLayout` structure.
See the :c:type:`PyLongLayout` structure.

The function must not be called before Python initialization nor after
Python finalization. The returned layout is valid until Python is
finalized. The layout is the same for all Python sub-interpreters
in a process, and so it can be cached.


.. c:struct:: PyLongExport
.. c:type:: PyLongExport

Export of a Python :class:`int` object.

Expand DownExpand Up@@ -769,7 +769,7 @@ Export API

Export a Python :class:`int` object.

*export_long* must point to a :c:struct:`PyLongExport` structure allocated
*export_long* must point to a :c:type:`PyLongExport` structure allocated
by the caller. It must not be ``NULL``.

On success, fill in *\*export_long* and return ``0``.
Expand DownExpand Up@@ -799,7 +799,7 @@ The :c:type:`PyLongWriter` API can be used to import an integer.

.. versionadded:: 3.14

.. c:struct:: PyLongWriter
.. c:type:: PyLongWriter

A Python :class:`int` writer instance.

Expand DownExpand Up@@ -827,7 +827,7 @@ The :c:type:`PyLongWriter` API can be used to import an integer.
The layout of *digits* is described by :c:func:`PyLong_GetNativeLayout`.

Digits must be in the range [``0``; ``(1 << bits_per_digit) - 1``]
(where the :c:struct:`~PyLongLayout.bits_per_digit` is the number of bits
(where the :c:type:`~PyLongLayout.bits_per_digit` is the number of bits
per digit).
Any unused most significant digits must be set to ``0``.

Expand Down
9 changes: 9 additions & 0 deletionsDoc/data/stable_abi.dat
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

39 changes: 0 additions & 39 deletionsInclude/cpython/longintrepr.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -138,45 +138,6 @@ _PyLong_CompactValue(const PyLongObject *op)

#define PyUnstable_Long_CompactValue _PyLong_CompactValue


/* --- Import/Export API -------------------------------------------------- */

typedef struct PyLongLayout {
uint8_t bits_per_digit;
uint8_t digit_size;
int8_t digits_order;
int8_t digit_endianness;
} PyLongLayout;

PyAPI_FUNC(const PyLongLayout*) PyLong_GetNativeLayout(void);

typedef struct PyLongExport {
int64_t value;
uint8_t negative;
Py_ssize_t ndigits;
const void *digits;
// Member used internally, must not be used for other purpose.
Py_uintptr_t _reserved;
} PyLongExport;

PyAPI_FUNC(int) PyLong_Export(
PyObject *obj,
PyLongExport *export_long);
PyAPI_FUNC(void) PyLong_FreeExport(
PyLongExport *export_long);


/* --- PyLongWriter API --------------------------------------------------- */

typedef struct PyLongWriter PyLongWriter;

PyAPI_FUNC(PyLongWriter*) PyLongWriter_Create(
int negative,
Py_ssize_t ndigits,
void **digits);
PyAPI_FUNC(PyObject*) PyLongWriter_Finish(PyLongWriter *writer);
PyAPI_FUNC(void) PyLongWriter_Discard(PyLongWriter *writer);

#ifdef __cplusplus
}
#endif
Expand Down
38 changes: 38 additions & 0 deletionsInclude/longobject.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -166,6 +166,44 @@ PyAPI_FUNC(PyObject *) PyLong_FromString(const char *, char **, int);
PyAPI_FUNC(unsigned long) PyOS_strtoul(const char *, char **, int);
PyAPI_FUNC(long) PyOS_strtol(const char *, char **, int);

/* --- Import/Export API -------------------------------------------------- */

typedef struct PyLongLayout {
uint8_t bits_per_digit;
uint8_t digit_size;
int8_t digits_order;
int8_t digit_endianness;
} PyLongLayout;

PyAPI_FUNC(const PyLongLayout*) PyLong_GetNativeLayout(void);

typedef struct PyLongExport {
int64_t value;
uint8_t negative;
Py_ssize_t ndigits;
const void *digits;
// Member used internally, must not be used for other purpose.
Py_uintptr_t _reserved;
} PyLongExport;

PyAPI_FUNC(int) PyLong_Export(
PyObject *obj,
PyLongExport *export_long);
PyAPI_FUNC(void) PyLong_FreeExport(
PyLongExport *export_long);


/* --- PyLongWriter API --------------------------------------------------- */

typedef struct PyLongWriter PyLongWriter;

PyAPI_FUNC(PyLongWriter*) PyLongWriter_Create(
int negative,
Py_ssize_t ndigits,
void **digits);
PyAPI_FUNC(PyObject*) PyLongWriter_Finish(PyLongWriter *writer);
PyAPI_FUNC(void) PyLongWriter_Discard(PyLongWriter *writer);

#ifndef Py_LIMITED_API
# define Py_CPYTHON_LONGOBJECT_H
# include "cpython/longobject.h"
Expand Down
6 changes: 6 additions & 0 deletionsLib/test/test_stable_abi_ctypes.py
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
Added :c:func:`PyLong_GetNativeLayout`, :c:struct:`PyLongLayout`,
:c:struct:`PyLongExport`, :c:func:`PyLong_Export`,
:c:func:`PyLong_FreeExport`, :c:struct:`PyLongWriter`,
:c:func:`PyLongWriter_Create`, :c:func:`PyLongWriter_Finish` and
:c:func:`PyLongWriter_Discard` to the limited API.
28 changes: 28 additions & 0 deletionsMisc/stable_abi.toml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -41,6 +41,8 @@
# - 'full-abi': All of the struct is part of the ABI, including the size
# (users may define arrays of these structs).
# Typically used for initialization, rather than at runtime.
# Any members whose names start with an underscore are not part of the
# limited API; they're for CPython's use only.
# - 'opaque': No members are part of the ABI, nor is the size. The Limited
# API only handles these via pointers. The C definition should be
# incomplete (opaque).
Expand DownExpand Up@@ -2664,3 +2666,29 @@
[function.Py_SET_SIZE]
# Before 3.15, this was a macro that accessed the PyObject member
added = '3.15'

# PEP 757 import/export API.

[function.PyLong_GetNativeLayout]
added = '3.15'
[function.PyLong_Export]
added = '3.15'
[function.PyLong_FreeExport]
added = '3.15'
[function.PyLongWriter_Create]
added = '3.15'
[function.PyLongWriter_Finish]
added = '3.15'
[function.PyLongWriter_Discard]
added = '3.15'
[struct.PyLongWriter]
added = '3.15'
struct_abi_kind = 'opaque'
[struct.PyLongLayout]
added = '3.15'
struct_abi_kind = 'full-abi'
[struct.PyLongExport]
added = '3.15'
# Note: The `_reserved` member of this struct is for interal use only.
# (The definition of 'full-abi' was clarified when this entry was added.)
struct_abi_kind = 'full-abi'
6 changes: 6 additions & 0 deletionsPC/python3dll.c
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

Loading

[8]ページ先頭

©2009-2026 Movatter.jp