Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems in mp_int.cc #195

Closed
czylzx opened this issue Jan 9, 2024 · 1 comment
Closed

Problems in mp_int.cc #195

czylzx opened this issue Jan 9, 2024 · 1 comment
Assignees

Comments

@czylzx
Copy link

czylzx commented Jan 9, 2024

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

@usafchn
Copy link
Member

usafchn commented Jan 9, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants