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

Commit974d26b

Browse files
committed
gh-106320: Remove private _PyLong_IsCompact() function
Move the private _PyLong_IsCompact() and _PyLong_CompactValue()functions to the internal C API (pycore_long.h). PublicPyUnstable_Long_IsCompact() and PyUnstable_Long_CompactValue()functions can be used instead.Remove "const" qualifier from PyUnstable_Long_IsCompact() andPyUnstable_Long_CompactValue() parameter type.
1 parentc1e2f3b commit974d26b

File tree

5 files changed

+24
-37
lines changed

5 files changed

+24
-37
lines changed

‎Doc/c-api/long.rst‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate.
332332
Returns ``NULL`` on error. Use:c:func:`PyErr_Occurred` to disambiguate.
333333
334334
335-
..c:function::intPyUnstable_Long_IsCompact(constPyLongObject* op)
335+
..c:function::intPyUnstable_Long_IsCompact(PyLongObject* op)
336336
337337
Return 1 if *op* is compact, 0 otherwise.
338338
@@ -347,7 +347,7 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate.
347347
Exactly what values are considered compact is an implementation detail
348348
and is subject to change.
349349
350-
..c:function:: Py_ssize_tPyUnstable_Long_CompactValue(constPyLongObject* op)
350+
..c:function:: Py_ssize_tPyUnstable_Long_CompactValue(PyLongObject* op)
351351
352352
If *op* is compact, as determined by :c:func:`PyUnstable_Long_IsCompact`,
353353
return its value.

‎Include/cpython/longintrepr.h‎

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -89,34 +89,6 @@ struct _longobject {
8989
_PyLongValuelong_value;
9090
};
9191

92-
93-
/* Inline some internals for speed. These should be in pycore_long.h
94-
* if user code didn't need them inlined. */
95-
96-
#define_PyLong_SIGN_MASK 3
97-
#define_PyLong_NON_SIZE_BITS 3
98-
99-
100-
staticinlineint
101-
_PyLong_IsCompact(constPyLongObject*op) {
102-
assert(PyType_HasFeature((op)->ob_base.ob_type,Py_TPFLAGS_LONG_SUBCLASS));
103-
returnop->long_value.lv_tag< (2 <<_PyLong_NON_SIZE_BITS);
104-
}
105-
106-
#definePyUnstable_Long_IsCompact _PyLong_IsCompact
107-
108-
staticinlinePy_ssize_t
109-
_PyLong_CompactValue(constPyLongObject*op)
110-
{
111-
assert(PyType_HasFeature((op)->ob_base.ob_type,Py_TPFLAGS_LONG_SUBCLASS));
112-
assert(PyUnstable_Long_IsCompact(op));
113-
Py_ssize_tsign=1- (op->long_value.lv_tag&_PyLong_SIGN_MASK);
114-
returnsign* (Py_ssize_t)op->long_value.ob_digit[0];
115-
}
116-
117-
#definePyUnstable_Long_CompactValue _PyLong_CompactValue
118-
119-
12092
#ifdef__cplusplus
12193
}
12294
#endif

‎Include/cpython/longobject.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ PyAPI_FUNC(int) _PyLong_Sign(PyObject *v);
1919
*/
2020
PyAPI_FUNC(size_t)_PyLong_NumBits(PyObject*v);
2121

22-
PyAPI_FUNC(int)PyUnstable_Long_IsCompact(constPyLongObject*op);
23-
PyAPI_FUNC(Py_ssize_t)PyUnstable_Long_CompactValue(constPyLongObject*op);
22+
PyAPI_FUNC(int)PyUnstable_Long_IsCompact(PyLongObject*op);
23+
PyAPI_FUNC(Py_ssize_t)PyUnstable_Long_CompactValue(PyLongObject*op);
2424

‎Include/internal/pycore_long.h‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ PyAPI_FUNC(int) _PyLong_UnsignedLongLong_Converter(PyObject *, void *);
214214
// Export for '_testclinic' shared extension (Argument Clinic code)
215215
PyAPI_FUNC(int)_PyLong_Size_t_Converter(PyObject*,void*);
216216

217+
#define_PyLong_SIGN_MASK 3
218+
#define_PyLong_NON_SIZE_BITS 3
219+
217220
/* Long value tag bits:
218221
* 0-1: Sign bits value = (1-sign), ie. negative=2, positive=0, zero=1.
219222
* 2: Reserved for immortality bit
@@ -245,6 +248,21 @@ static_assert(NON_SIZE_BITS == _PyLong_NON_SIZE_BITS, "NON_SIZE_BITS does not ma
245248
* will be signed 63 (or fewer) bit values
246249
*/
247250

251+
staticinlineint
252+
_PyLong_IsCompact(constPyLongObject*op) {
253+
assert(PyType_HasFeature((op)->ob_base.ob_type,Py_TPFLAGS_LONG_SUBCLASS));
254+
returnop->long_value.lv_tag< (2 <<_PyLong_NON_SIZE_BITS);
255+
}
256+
257+
staticinlinePy_ssize_t
258+
_PyLong_CompactValue(constPyLongObject*op)
259+
{
260+
assert(PyType_HasFeature((op)->ob_base.ob_type,Py_TPFLAGS_LONG_SUBCLASS));
261+
assert(_PyLong_IsCompact(op));
262+
Py_ssize_tsign=1- (op->long_value.lv_tag&_PyLong_SIGN_MASK);
263+
returnsign* (Py_ssize_t)op->long_value.ob_digit[0];
264+
}
265+
248266
/* Return 1 if the argument is compact int */
249267
staticinlineint
250268
_PyLong_IsNonNegativeCompact(constPyLongObject*op) {

‎Objects/longobject.c‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6369,16 +6369,13 @@ _PyLong_FiniTypes(PyInterpreterState *interp)
63696369
_PyStructSequence_FiniBuiltin(interp,&Int_InfoType);
63706370
}
63716371

6372-
#undef PyUnstable_Long_IsCompact
63736372

63746373
int
6375-
PyUnstable_Long_IsCompact(constPyLongObject*op) {
6374+
PyUnstable_Long_IsCompact(PyLongObject*op) {
63766375
return_PyLong_IsCompact(op);
63776376
}
63786377

6379-
#undef PyUnstable_Long_CompactValue
6380-
63816378
Py_ssize_t
6382-
PyUnstable_Long_CompactValue(constPyLongObject*op) {
6379+
PyUnstable_Long_CompactValue(PyLongObject*op) {
63836380
return_PyLong_CompactValue(op);
63846381
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp