secretflow/yacl

Problems in mp_int.cc

czylzx opened this issue · 1 comments

variables used, sign,alloc are defined in mp_int.cc, However, they are commented.Why? I notice that some of the functions use these variables
MPInt::MPInt(MPInt &&other) noexcept {
// /* the infamous mp_int structure */
// typedef struct {
// int used, alloc;
// mp_sign sign;
// mp_digit *dp;
// } mp_int;
n_ = other.n_;
// NOTE: We've checked mp_clear does nothing if dp is nullptr.
other.n_.dp = nullptr;
}

These variables are essentially defined by Libtommath, not yacl mpint. There may be a slight historical reason here. In the early days, we didn't want to over-couple Libtommath and therefore chose not to access these variables. From today's point of view, it is inevitable to access the underlying variables of n_. So I think it is also possible to explicitly assign initial values to these variables here.

On the other hand, there is nothing wrong with MPInt's current approach. other is a variable that is about to be destroyed. As long as other.n_.dp is nullptr, the destructor can run successfully.