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.
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);
}