aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George2015-10-01 17:57:36 +0100
committerDamien George2015-10-01 17:57:36 +0100
commit4c02e54298b0f955c5d60023310b724baa890d67 (patch)
tree0b78cc275adf00b35d794e1247a2bd5a3b472fd3
parent5f3c3ec5e62e64872bfd3f274473db86c2b7fd25 (diff)
py/mpz: Raise NotImplError instead of failing assertion.
-rw-r--r--py/mpz.c9
-rw-r--r--tests/misc/non_compliant.py18
-rw-r--r--tests/misc/non_compliant.py.exp3
3 files changed, 27 insertions, 3 deletions
diff --git a/py/mpz.c b/py/mpz.c
index 3bd309041..e7d9972e0 100644
--- a/py/mpz.c
+++ b/py/mpz.c
@@ -29,6 +29,9 @@
#include "py/mpz.h"
+// this is only needed for mp_not_implemented, which should eventually be removed
+#include "py/runtime.h"
+
#if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_MPZ
#define DIG_SIZE (MPZ_DIG_SIZE)
@@ -1108,7 +1111,7 @@ void mpz_and_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs) {
dest->neg = 0;
} else {
// TODO both args are negative
- assert(0);
+ mp_not_implemented("bignum and with negative args");
}
} else {
// args have different sign
@@ -1141,7 +1144,7 @@ void mpz_or_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs) {
} else {
mpz_need_dig(dest, lhs->len);
// TODO
- assert(0);
+ mp_not_implemented("bignum or with negative args");
// dest->len = mpn_or_neg(dest->dig, lhs->dig, lhs->len, rhs->dig, rhs->len);
}
@@ -1164,7 +1167,7 @@ void mpz_xor_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs) {
} else {
mpz_need_dig(dest, lhs->len);
// TODO
- assert(0);
+ mp_not_implemented("bignum xor with negative args");
// dest->len = mpn_xor_neg(dest->dig, lhs->dig, lhs->len, rhs->dig, rhs->len);
}
diff --git a/tests/misc/non_compliant.py b/tests/misc/non_compliant.py
index de8457906..0cf462abb 100644
--- a/tests/misc/non_compliant.py
+++ b/tests/misc/non_compliant.py
@@ -69,3 +69,21 @@ try:
b'123'[0:3:2]
except NotImplementedError:
print('NotImplementedError')
+
+# mpz and with both args negative
+try:
+ -(1<<70) & -2
+except NotImplementedError:
+ print('NotImplementedError')
+
+# mpz or with args opposite sign
+try:
+ -(1<<70) | 2
+except NotImplementedError:
+ print('NotImplementedError')
+
+# mpz xor with args opposite sign
+try:
+ -(1<<70) ^ 2
+except NotImplementedError:
+ print('NotImplementedError')
diff --git a/tests/misc/non_compliant.py.exp b/tests/misc/non_compliant.py.exp
index 28b1470d7..5937ccb2f 100644
--- a/tests/misc/non_compliant.py.exp
+++ b/tests/misc/non_compliant.py.exp
@@ -9,3 +9,6 @@ NotImplementedError
NotImplementedError
NotImplementedError
NotImplementedError
+NotImplementedError
+NotImplementedError
+NotImplementedError