MCPcopy Create free account
hub / github.com/MagicStack/asyncpg / PyLongWriter_Finish

Function PyLongWriter_Finish

asyncpg/protocol/record/pythoncapi_compat.h:1889–1917  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1887}
1888
1889static inline PyObject*
1890PyLongWriter_Finish(PyLongWriter *writer)
1891{
1892 PyObject *obj = (PyObject *)writer;
1893 PyLongObject *self = (PyLongObject*)obj;
1894 Py_ssize_t j = _PyLong_DigitCount(self);
1895 Py_ssize_t i = j;
1896 int sign = _PyLong_Sign(obj);
1897
1898 assert(Py_REFCNT(obj) == 1);
1899
1900 // Normalize and get singleton if possible
1901 while (i > 0 && _PyLong_GetDigits(self)[i-1] == 0) {
1902 --i;
1903 }
1904 if (i != j) {
1905 if (i == 0) {
1906 sign = 0;
1907 }
1908 _PyLong_SetSignAndDigitCount(self, sign, i);
1909 }
1910 if (i <= 1) {
1911 long val = sign * (long)(_PyLong_GetDigits(self)[0]);
1912 Py_DECREF(obj);
1913 return PyLong_FromLong(val);
1914 }
1915
1916 return obj;
1917}
1918#endif
1919
1920

Callers

nothing calls this directly

Calls 3

_PyLong_DigitCountFunction · 0.85
_PyLong_GetDigitsFunction · 0.85

Tested by

no test coverage detected