chiark / gitweb /
mp.c: Assert about the Python limb size statically.
authorMark Wooding <mdw@distorted.org.uk>
Mon, 21 Oct 2019 10:40:39 +0000 (11:40 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 11 Apr 2020 11:44:21 +0000 (12:44 +0100)
Python extensions build with assertions off, so this was much less
helpful than it looked.

mp.c

diff --git a/mp.c b/mp.c
index a664627de2def12a198bddf35994e85ff3cc9018..b646846672f8a75a99529fc2a5e13a6bb3054d9a 100644 (file)
--- a/mp.c
+++ b/mp.c
@@ -33,6 +33,9 @@
 PyTypeObject *mp_pytype = 0;
 PyTypeObject *gf_pytype = 0;
 
+STATIC_ASSERT(MPW_BITS >= SHIFT,
+             "Catacomb's limbs are now narrower than than Python's!");
+
 mp *mp_frompylong(PyObject *obj)
 {
   unsigned long bits;
@@ -47,7 +50,6 @@ mp *mp_frompylong(PyObject *obj)
 
   sz = Py_SIZE(l);
   if (sz < 0) sz = -sz;
-  assert(MPW_BITS >= SHIFT);
   bits = (unsigned long)sz * SHIFT;
   w = (bits + MPW_BITS - 1)/MPW_BITS;
   x = mp_new(w, Py_SIZE(l) < 0 ? MP_NEG : 0);
@@ -80,7 +82,6 @@ PyObject *mp_topylong(mp *x)
   mpw *p = x->v;
   int i = 0;
 
-  assert(MPW_BITS >= SHIFT);
   while (i < sz && p < x->vl) {
     r |= (mpd)*p++ << b;
     b += MPW_BITS;