py/mpz: Raise NotImplError instead of failing assertion.

This commit is contained in:
Damien George 2015-10-01 17:57:36 +01:00
parent 5f3c3ec5e6
commit 4c02e54298
3 changed files with 27 additions and 3 deletions

View File

@ -29,6 +29,9 @@
#include "py/mpz.h" #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 #if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_MPZ
#define DIG_SIZE (MPZ_DIG_SIZE) #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; dest->neg = 0;
} else { } else {
// TODO both args are negative // TODO both args are negative
assert(0); mp_not_implemented("bignum and with negative args");
} }
} else { } else {
// args have different sign // args have different sign
@ -1141,7 +1144,7 @@ void mpz_or_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs) {
} else { } else {
mpz_need_dig(dest, lhs->len); mpz_need_dig(dest, lhs->len);
// TODO // 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); // 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 { } else {
mpz_need_dig(dest, lhs->len); mpz_need_dig(dest, lhs->len);
// TODO // 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); // dest->len = mpn_xor_neg(dest->dig, lhs->dig, lhs->len, rhs->dig, rhs->len);
} }

View File

@ -69,3 +69,21 @@ try:
b'123'[0:3:2] b'123'[0:3:2]
except NotImplementedError: except NotImplementedError:
print('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')

View File

@ -9,3 +9,6 @@ NotImplementedError
NotImplementedError NotImplementedError
NotImplementedError NotImplementedError
NotImplementedError NotImplementedError
NotImplementedError
NotImplementedError
NotImplementedError