Skip to content

Commit 1dfaa02

Browse files
committed
Simpler format specifiers.
Clearer error message in Python API in case the minimum value of `long long` is -9223372036854775807 instead of the usual -9223372036854775808.
1 parent aeef36d commit 1dfaa02

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

lib/pyhdrbg.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <Python.h>
33

44
#include <inttypes.h>
5+
#include <limits.h>
56
#include <stdbool.h>
67

78
#include "hdrbg.h"
@@ -83,7 +84,7 @@ Uint(PyObject *self, PyObject *args)
8384
modulus = PyLong_AsUnsignedLongLong(PyTuple_GET_ITEM(args, 0));
8485
if(PyErr_Occurred() != NULL || modulus == 0 || modulus > UINT64_MAX)
8586
{
86-
return PyErr_Format(PyExc_ValueError, "argument 1 must be an integer in [1, %"PRIu64"]", UINT64_MAX);
87+
return PyErr_Format(PyExc_ValueError, "argument 1 must be an integer in [1, %llu]", UINT64_MAX);
8788
}
8889
uint64_t r = hdrbg_uint(NULL, modulus);
8990
ERR_CHECK;
@@ -108,9 +109,8 @@ Span(PyObject *self, PyObject *args)
108109
{
109110
return PyErr_Format(
110111
PyExc_ValueError,
111-
"argument 1 must be less than argument 2; both must be integers in [%"PRId64", %"PRId64"] "
112-
"and fit in the C `long long` type",
113-
INT64_MIN, INT64_MAX
112+
"argument 1 must be less than argument 2; both must be integers in [%lld, %lld]",
113+
INT64_MIN < LLONG_MIN ? LLONG_MIN : INT64_MIN, INT64_MAX
114114
);
115115
}
116116
int64_t r = hdrbg_span(NULL, left, right);
@@ -191,6 +191,10 @@ static PyModuleDef pyhdrbg =
191191
pyhdrbg_doc,
192192
-1,
193193
pyhdrbg_methods,
194+
NULL,
195+
NULL,
196+
NULL,
197+
NULL,
194198
};
195199

196200

0 commit comments

Comments
 (0)