8000 Cleanup · python/cpython@53d584b · GitHub
[go: up one dir, main page]

Skip to content

Commit 53d584b

Browse files
committed
Cleanup
1 parent a72ff83 commit 53d584b

File tree

4 files changed

+21
-43
lines changed

4 files changed

+21
-43
lines changed

Doc/whatsnew/3.14.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,7 @@ New features
10181018

10191019
(Contributed by Victor Stinner in :gh:`107954`.)
10201020

1021-
* Add a new import and export API for Python :class:`int` objects:
1021+
* Add a new import and export API for Python :class:`int` objects (:pep:`757`):
10221022

10231023
* :c:func:`PyLong_GetNativeLayout`;
10241024
* :c:func:`PyLong_Export`;

Lib/test/test_capi/test_long.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ def test_long_export(self):
751751
pylong_export(value)
752752

753753
def test_longwriter_create(self):
754-
# Test PyLong_Import()
754+
# Test PyLongWriter_Create()
755755
layout = _testcapi.get_pylong_layout()
756756
base = 2 ** layout['bits_per_digit']
757757

Misc/NEWS.d/next/C_API/2024-07-03-17-26-53.gh-issue-102471.XpmKYk.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Add a new import and export API for Python :class:`int` objects:
1+
Add a new import and export API for Python :class:`int` objects (:pep:`757`):
22

33
* :c:func:`PyLong_GetNativeLayout`;
44
* :c:func:`PyLong_Export`;

Modules/_testcapi/long.c

Lines changed: 18 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -145,50 +145,28 @@ static PyObject *
145145
layout_to_dict(const PyLongLayout *layout)
146146
{
147147
PyObject *dict = PyDict_New();
148-
149148
if (dict == NULL) {
150149
goto error;
151150
}
152151

153-
PyObject *value = PyLong_FromUnsignedLong(layout->bits_per_digit);
154-
if (value == NULL) {
155-
goto error;
156-
}
157-
int res = PyDict_SetItemString(dict, "bits_per_digit", value);
158-
Py_DECREF(value);
159-
if (res < 0) {
160-
goto error;
161-
}
162-
163-
value = PyLong_FromUnsignedLong(layout->digit_size);
164-
if (value == NULL) {
165-
goto error;
166-
}
167-
res = PyDict_SetItemString(dict, "digit_size", value);
168-
Py_DECREF(value);
169-
if (res < 0) {
170-
goto error;
171-
}
172-
173-
value = PyLong_FromLong(layout->digits_order);
174-
if (value == NULL) {
175-
goto error;
176-
}
177-
res = PyDict_SetItemString(dict, "digits_order", value);
178-
Py_DECREF(value);
179-
if (res < 0) {
180-
goto error;
181-
}
182-
183-
value = PyLong_FromLong(layout->digit_endianness);
184-
if (value == NULL) {
185-
goto error;
186-
}
187-
res = PyDict_SetItemString(dict, "digit_endianness", value);
188-
Py_DECREF(value);
189-
if (res < 0) {
190-
goto error;
191-
}
152+
#define SET_DICT(KEY, EXPR) \
153+
do { \
154+
PyObject *value = (EXPR); \
155+
if (value == NULL) { \
156+
goto error; \
157+
} \
158+
int res = PyDict_SetItemString(dict, KEY, value); \
159+
Py_DECREF(value); \
160+
if (res < 0) { \
161+
goto error; \
162+
} \
163+
} while (0)
164+
165+
SET_DICT("bits_per_digit", PyLong_FromUnsignedLong(layout->bits_per_digit));
166+
SET_DICT("digit_size", PyLong_FromUnsignedLong(layout->digit_size));
167+
SET_DICT("digits_order", PyLong_FromLong(layout->digits_order));
168+
SET_DICT("digit_endianness", PyLong_FromLong(layout->digit_endianness));
169+
#undef SET_DICT
192170

193171
return dict;
194172

0 commit comments

Comments
 (0)
0