Skip to content

Commit

Permalink
Fixed PEP 674 and python/cpython#101292
Browse files Browse the repository at this point in the history
  • Loading branch information
EliusSolis committed Jul 28, 2024
1 parent bf9933f commit 32edcc3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
14 changes: 7 additions & 7 deletions charm/core/math/integer/integermodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void longObjToMPZ(mpz_t m, PyObject * o) {
}
mpz_set_ui(m, 0);
for (i = 0; i < size; i++) {
mpz_set_ui(temp, p->ob_digit[i]);
mpz_set_ui(temp, p->long_value.ob_digit[i]);
mpz_mul_2exp(temp2, temp, PyLong_SHIFT * i);
mpz_add(m, m, temp2);
}
Expand All @@ -107,7 +107,7 @@ void longObjToMPZ(mpz_t m, PyObject * o) {
// size = -tmp;
// BN_zero(m, 0);
// for (i = 0; i < size; i++) {
// BN_set_word(temp, p->ob_digit[i]);
// BN_set_word(temp, p->long_value.ob_digit[i]);
// mpz_mul_2exp(temp2, temp, PyLong_SHIFT * i);
// mpz_add(m, m, temp2);
// }
Expand Down Expand Up @@ -162,17 +162,17 @@ PyObject *mpzToLongObj(mpz_t m) {
return NULL;
mpz_init_set(temp, m);
for (i = 0; i < size; i++) {
l->ob_digit[i] = (digit)(mpz_get_ui(temp) & PyLong_MASK);
l->long_value.ob_digit[i] = (digit)(mpz_get_ui(temp) & PyLong_MASK);
mpz_fdiv_q_2exp(temp, temp, PyLong_SHIFT);
}
i = size;
while ((i > 0) && (l->ob_digit[i - 1] == 0))
while ((i > 0) && (l->long_value.ob_digit[i - 1] == 0))
i--;
if(isNeg) {
Py_SIZE(l) = -i;
Py_SET_SIZE(l,-i);
}
else {
Py_SIZE(l) = i;
Py_SET_SIZE(l,i);
}
mpz_clear(temp);
return (PyObject *) l;
Expand Down Expand Up @@ -1378,7 +1378,7 @@ static PyObject *genRandomBits(PyObject *self, PyObject *args) {

v = _PyLong_New(ndigits);
if (v != NULL) {
digit *p = v->ob_digit;
digit *p = v->long_value.ob_digit;
while (digitsleft > 1) {
RAND_bytes(buff, sizeof(long));
memcpy(&t, buff, sizeof(long));
Expand Down
10 changes: 5 additions & 5 deletions charm/core/math/pairing/pairingmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,17 @@ PyObject *mpzToLongObj (mpz_t m)
mpz_init_set (temp, m);
for (i = 0; i < size; i++)
{
l->ob_digit[i] = (digit) (mpz_get_ui (temp) & PyLong_MASK);
l->long_value.ob_digit[i] = (digit) (mpz_get_ui (temp) & PyLong_MASK);
mpz_fdiv_q_2exp (temp, temp, PyLong_SHIFT);
}
i = size;
while ((i > 0) && (l->ob_digit[i - 1] == 0))
while ((i > 0) && (l->long_value.ob_digit[i - 1] == 0))
i--;
if(isNeg) {
Py_SIZE(l) = -i;
Py_SET_SIZE(l,-i);
}
else {
Py_SIZE(l) = i;
Py_SET_SIZE(l,i);
}
mpz_clear (temp);
return (PyObject *) l;
Expand All @@ -153,7 +153,7 @@ void longObjToMPZ (mpz_t m, PyLongObject * p)
mpz_set_ui (m, 0);
for (i = 0; i < size; i++)
{
mpz_set_ui (temp, p->ob_digit[i]);
mpz_set_ui (temp, p->long_value.ob_digit[i]);
mpz_mul_2exp (temp2, temp, PyLong_SHIFT * i);
mpz_add (m, m, temp2);
}
Expand Down

0 comments on commit 32edcc3

Please sign in to comment.