From: Mark Wooding Date: Thu, 30 Mar 2006 23:25:22 +0000 (+0100) Subject: field: Correct conversions from integers. X-Git-Tag: 1.0.1~19 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/catacomb-python/commitdiff_plain/c62f9ebfe16a96a771af2343c2358d49668e31b0?ds=inline field: Correct conversions from integers. The function tofe refused to convert integers to field elements. I seem to remember deciding that this was too weird for binary fields, but in retrospect this seems a mistake, since there's nothing stopping a binary field element converting to an mp (or gf). Previously, binary operations between a field element and a Python integer failed, but a binop with a fe and an mp would force the fe to downgrade to an mp, which seems really bizarre. Also, I think there was a possibility of a memory leak in the old code. --- diff --git a/field.c b/field.c index bb99b77..d0ab05d 100644 --- a/field.c +++ b/field.c @@ -115,16 +115,16 @@ static mp *tofe(field *f, PyObject *o) if (FE_PYCHECK(o)) { if (FE_F(o) != f && !field_samep(FE_F(o), f)) return (0); - y = FE_X(o); - } - if ((x = tomp(o)) != 0) { + y = MP_COPY(FE_X(o)); + } else if ((x = tomp(o)) != 0) { if (MP_ZEROP(x)) - y = f->zero; + y = MP_COPY(f->zero); else if (MP_EQ(x, MP_ONE)) - y = f->one; + y = MP_COPY(f->one); + else + y = F_IN(f, MP_NEW, x); + MP_DROP(x); } - if (x) MP_DROP(x); - if (y) MP_COPY(y); return (y); }