Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
PyLong_Sign -> PyLong_GetSign
  • Loading branch information
skirpichev committed Jun 2, 2024
commit 41a33b4cdd46957a65a5b70bec61456169d3ba4d
2 changes: 1 addition & 1 deletion Doc/c-api/long.rst
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate.
.. versionadded:: 3.13


.. c:function:: int PyLong_Sign(PyObject *obj, int *sign)
.. c:function:: int PyLong_GetSign(PyObject *obj, int *sign)

Retrieve the sign of integer object *obj* (``0``, ``-1`` or ``+1`` for zero,
negative or positive integer, respectively) in a variable *sign*.
Expand Down
2 changes: 1 addition & 1 deletion Doc/whatsnew/3.13.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2130,7 +2130,7 @@ New Features
between native integer types and Python :class:`int` objects.
(Contributed by Steve Dower in :gh:`111140`.)

* Add :c:func:`PyLong_Sign` function to test sign of :class:`int` objects.
* Add :c:func:`PyLong_GetSign` function to test sign of :class:`int` objects.
Comment thread
skirpichev marked this conversation as resolved.
Outdated
Contributed by Sergey B Kirpichev.
Comment thread
skirpichev marked this conversation as resolved.
Outdated

* Add :c:func:`PyType_GetFullyQualifiedName` function to get the type's fully
Expand Down
6 changes: 3 additions & 3 deletions Include/cpython/longobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ PyAPI_FUNC(PyObject*) PyLong_FromUnsignedNativeBytes(const void* buffer,
PyAPI_FUNC(int) PyUnstable_Long_IsCompact(const PyLongObject* op);
PyAPI_FUNC(Py_ssize_t) PyUnstable_Long_CompactValue(const PyLongObject* op);

/* PyLong_Sign. Retrieve the sign of the integer value (0, -1 or +1) in a
variable sign. Return 0 on success, else -1 with an exception set. */
PyAPI_FUNC(int) PyLong_Sign(PyObject *v, int *sign);
/* PyLong_GetSign. Retrieve the sign of the integer value (0, -1 or +1) in
a variable sign. Return 0 on success, else -1 with an exception set. */
Comment thread
skirpichev marked this conversation as resolved.
Outdated
PyAPI_FUNC(int) PyLong_GetSign(PyObject *v, int *sign);

PyAPI_FUNC(int) _PyLong_Sign(PyObject *v);

Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_capi/test_long.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,8 +722,8 @@ def test_long_fromnativebytes(self):
f"PyLong_FromNativeBytes(buffer, {n}, <big|unsigned>)")

def test_long_sign(self):
# Test PyLong_Sign()
sign = _testcapi.pylong_sign
# Test PyLong_GetSign()
sign = _testcapi.pylong_getsign
self.assertEqual(sign(1), 1)
self.assertEqual(sign(123456), 1)
self.assertEqual(sign(-2), -1)
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Add :c:func:`PyLong_Sign` function. Patch by Sergey B Kirpichev.
Add :c:func:`PyLong_GetSign` function. Patch by Sergey B Kirpichev.
6 changes: 3 additions & 3 deletions Modules/_testcapi/long.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ pylong_fromnativebytes(PyObject *module, PyObject *args)


static PyObject *
pylong_sign(PyObject *module, PyObject *arg)
pylong_getsign(PyObject *module, PyObject *arg)
{
NULLABLE(arg);
int sign;
if (PyLong_Sign(arg, &sign) == -1) {
if (PyLong_GetSign(arg, &sign) == -1) {
return NULL;
}
return PyLong_FromLong(sign);
Expand All @@ -122,7 +122,7 @@ static PyMethodDef test_methods[] = {
{"pylong_fromunicodeobject", pylong_fromunicodeobject, METH_VARARGS},
{"pylong_asnativebytes", pylong_asnativebytes, METH_VARARGS},
{"pylong_fromnativebytes", pylong_fromnativebytes, METH_VARARGS},
{"pylong_sign", pylong_sign, METH_O},
{"pylong_getsign", pylong_getsign, METH_O},
{"pylong_aspid", pylong_aspid, METH_O},
{NULL},
};
Expand Down
2 changes: 1 addition & 1 deletion Objects/longobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ _PyLong_Sign(PyObject *vv)
}

int
PyLong_Sign(PyObject *vv, int *sign)
PyLong_GetSign(PyObject *vv, int *sign)
{
if (vv == NULL) {
PyErr_BadInternalCall();
Expand Down