Commit 85780479 authored by Boxiang Sun's avatar Boxiang Sun

let str coul multiple with long

parent 84201c50
...@@ -2071,8 +2071,7 @@ extern "C" PyObject* PyNumber_Long(PyObject* o) noexcept { ...@@ -2071,8 +2071,7 @@ extern "C" PyObject* PyNumber_Long(PyObject* o) noexcept {
return res; return res;
} }
if (PyLong_Check(o)) { /* A long subclass without nb_long */ if (PyLong_Check(o)) { /* A long subclass without nb_long */
BoxedInt* lo = (BoxedInt*)o; return o;
return PyLong_FromLong(lo->n);
} }
trunc_func = PyObject_GetAttr(o, trunc_name); trunc_func = PyObject_GetAttr(o, trunc_name);
if (trunc_func) { if (trunc_func) {
......
...@@ -1146,9 +1146,24 @@ extern "C" Box* strMul(BoxedString* lhs, Box* rhs) { ...@@ -1146,9 +1146,24 @@ extern "C" Box* strMul(BoxedString* lhs, Box* rhs) {
assert(PyString_Check(lhs)); assert(PyString_Check(lhs));
int n; int n;
if (PyIndex_Check(rhs)) {
Box* index = PyNumber_Index(rhs);
if (PyErr_Occurred()) {
throwCAPIException();
}
rhs = index;
}
if (PyInt_Check(rhs)) if (PyInt_Check(rhs))
n = static_cast<BoxedInt*>(rhs)->n; n = static_cast<BoxedInt*>(rhs)->n;
else else if (isSubclass(rhs->cls, long_cls)) {
n = _PyLong_AsInt(rhs);
if (PyErr_Occurred()) {
PyErr_Clear();
raiseExcHelper(OverflowError, "cannot fit 'long' into index-sized integer");
}
} else
return NotImplemented; return NotImplemented;
if (n <= 0) if (n <= 0)
return EmptyString; return EmptyString;
......
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