From 1dfaa02673f4660ae01c48cb6243e5900e2f61f9 Mon Sep 17 00:00:00 2001 From: Vishal Pankaj Chandratreya <19171016+tfpf@users.noreply.github.com> Date: Sat, 22 Jul 2023 00:02:32 +0530 Subject: [PATCH] Simpler format specifiers. Clearer error message in Python API in case the minimum value of `long long` is -9223372036854775807 instead of the usual -9223372036854775808. --- lib/pyhdrbg.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/pyhdrbg.c b/lib/pyhdrbg.c index 34cb908..5b26716 100644 --- a/lib/pyhdrbg.c +++ b/lib/pyhdrbg.c @@ -2,6 +2,7 @@ #include #include +#include #include #include "hdrbg.h" @@ -83,7 +84,7 @@ Uint(PyObject *self, PyObject *args) modulus = PyLong_AsUnsignedLongLong(PyTuple_GET_ITEM(args, 0)); if(PyErr_Occurred() != NULL || modulus == 0 || modulus > UINT64_MAX) { - return PyErr_Format(PyExc_ValueError, "argument 1 must be an integer in [1, %"PRIu64"]", UINT64_MAX); + return PyErr_Format(PyExc_ValueError, "argument 1 must be an integer in [1, %llu]", UINT64_MAX); } uint64_t r = hdrbg_uint(NULL, modulus); ERR_CHECK; @@ -108,9 +109,8 @@ Span(PyObject *self, PyObject *args) { return PyErr_Format( PyExc_ValueError, - "argument 1 must be less than argument 2; both must be integers in [%"PRId64", %"PRId64"] " - "and fit in the C `long long` type", - INT64_MIN, INT64_MAX + "argument 1 must be less than argument 2; both must be integers in [%lld, %lld]", + INT64_MIN < LLONG_MIN ? LLONG_MIN : INT64_MIN, INT64_MAX ); } int64_t r = hdrbg_span(NULL, left, right); @@ -191,6 +191,10 @@ static PyModuleDef pyhdrbg = pyhdrbg_doc, -1, pyhdrbg_methods, + NULL, + NULL, + NULL, + NULL, };