Commit 541b7543 authored by Boxiang Sun's avatar Boxiang Sun

add _PyLong_Copy implementation, return a copy in PyNumber_Long if the type of...

add _PyLong_Copy implementation, return a copy in PyNumber_Long if the type of argument is long or long subclass
parent 85780479
......@@ -75,6 +75,9 @@ PyAPI_FUNC(PyObject *) PyLong_FromUnicode(Py_UNICODE*, Py_ssize_t, int) PYSTON_N
*/
PyAPI_FUNC(int) _PyLong_Sign(PyObject *v) PYSTON_NOEXCEPT;
// Pyston change: copied from CPython/Include/longintrepr.h
/* Return a copy of src. */
PyAPI_FUNC(PyObject *) _PyLong_Copy(PyLongObject *src) PYSTON_NOEXCEPT;
/* _PyLong_NumBits. Return the number of bits needed to represent the
absolute value of a long. For example, this returns 1 for 1 and -1, 2
......
......@@ -2071,7 +2071,7 @@ extern "C" PyObject* PyNumber_Long(PyObject* o) noexcept {
return res;
}
if (PyLong_Check(o)) { /* A long subclass without nb_long */
return o;
return _PyLong_Copy((PyLongObject*)o);
}
trunc_func = PyObject_GetAttr(o, trunc_name);
if (trunc_func) {
......
......@@ -72,6 +72,12 @@ extern "C" int _PyLong_Sign(PyObject* l) noexcept {
return mpz_sgn(static_cast<BoxedLong*>(l)->n);
}
extern "C" PyObject* _PyLong_Copy(PyLongObject* src) noexcept {
BoxedLong* rtn = new BoxedLong();
mpz_init_set(((BoxedLong*)src)->n, rtn->n);
return rtn;
}
extern "C" unsigned PY_LONG_LONG PyLong_AsUnsignedLongLong(PyObject* vv) noexcept {
unsigned PY_LONG_LONG bytes;
int one = 1;
......
......@@ -1149,7 +1149,7 @@ extern "C" Box* strMul(BoxedString* lhs, Box* rhs) {
if (PyIndex_Check(rhs)) {
Box* index = PyNumber_Index(rhs);
if (PyErr_Occurred()) {
if (!index) {
throwCAPIException();
}
rhs = index;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment