Skip to content

Commit

Permalink
sync with CPython pr
Browse files Browse the repository at this point in the history
  • Loading branch information
skirpichev committed Dec 13, 2024
1 parent cc05a9a commit eb966bf
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions pythoncapi_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -1789,6 +1789,7 @@ static inline int
PyLong_Export(PyObject *obj, PyLongExport *export_long)
{
if (!PyLong_Check(obj)) {
memset(export_long, 0, sizeof(*export_long));
PyErr_Format(PyExc_TypeError, "expected int, got %s",
Py_TYPE(obj)->tp_name);
return -1;
Expand Down Expand Up @@ -1841,7 +1842,7 @@ PyLong_FreeExport(PyLongExport *export_long)
static inline PyLongWriter*
PyLongWriter_Create(int negative, Py_ssize_t ndigits, void **digits)
{
if (ndigits < 0) {
if (ndigits <= 0) {
PyErr_SetString(PyExc_ValueError, "ndigits must be positive");
return NULL;
}
Expand All @@ -1851,9 +1852,6 @@ PyLongWriter_Create(int negative, Py_ssize_t ndigits, void **digits)
if (obj == NULL) {
return NULL;
}
if (ndigits == 0) {
assert(_PyLong_GetDigits(obj)[0] == 0);
}
_PyLong_SetSignAndDigitCount(obj, negative?-1:1, ndigits);

*digits = _PyLong_GetDigits(obj);
Expand Down

0 comments on commit eb966bf

Please sign in to comment.