[python] long_as_ulong

This commit is contained in:
nick black 2021-11-29 12:57:19 -05:00
parent b6bcf93f83
commit 8d0e452c9c
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
2 changed files with 14 additions and 4 deletions

View File

@ -99,22 +99,22 @@ Notcurses_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)
if (NULL != margin_top)
{
options.margin_t = GNU_PY_LONG_CHECK(margin_top);
options.margin_t = GNU_PY_ULONG_CHECK(margin_top);
}
if (NULL != margin_right)
{
options.margin_r = GNU_PY_LONG_CHECK(margin_right);
options.margin_r = GNU_PY_ULONG_CHECK(margin_right);
}
if (NULL != margin_bottom)
{
options.margin_b = GNU_PY_LONG_CHECK(margin_bottom);
options.margin_b = GNU_PY_ULONG_CHECK(margin_bottom);
}
if (NULL != margin_left)
{
options.margin_l = GNU_PY_LONG_CHECK(margin_left);
options.margin_l = GNU_PY_ULONG_CHECK(margin_left);
}
options.flags = (uint64_t)flags;

View File

@ -238,6 +238,16 @@ static inline void PyObject_cleanup(PyObject **object)
return_ptr; \
})
#define GNU_PY_ULONG_CHECK(py_ulong) \
({ \
unsigned long new_long = PyLong_AsUnsignedLong(py_ulong); \
if (PyErr_Occurred()) \
{ \
return NULL; \
} \
new_long; \
})
#define GNU_PY_LONG_CHECK(py_long) \
({ \
long new_long = PyLong_AsLong(py_long); \