Commit 092351e9 authored by Kevin Modzelewski's avatar Kevin Modzelewski

some ref fixes to complex

parent 7e42a198
......@@ -5932,7 +5932,7 @@ init_stuff(PyObject *module_dict)
{
PyObject *copyreg, *t, *r;
#define INIT_STR(S) if (!( S ## _str=PyString_InternFromString(#S))) return -1;
#define INIT_STR(S) if (!( S ## _str=PyGC_RegisterStaticConstant(PyString_InternFromString(#S)))) return -1;
if (PyType_Ready(&Unpicklertype) < 0)
return -1;
......
......@@ -289,6 +289,7 @@ try_complex_special_method(PyObject *op) {
complexstr = PyString_InternFromString("__complex__");
if (complexstr == NULL)
return NULL;
PyGC_RegisterStaticConstant(complexstr);
}
if (PyInstance_Check(op)) {
f = PyObject_GetAttr(op, complexstr);
......
......@@ -37,7 +37,7 @@ static Box* toComplex(Box* self) noexcept {
}
if (PyComplex_Check(self)) {
r = (BoxedComplex*)self;
r = (BoxedComplex*)incref(self);
} else if (PyInt_Check(self)) {
r = new BoxedComplex(static_cast<BoxedInt*>(self)->n, 0.0);
} else if (PyFloat_Check(self)) {
......@@ -285,7 +285,7 @@ Box* complexTruediv(BoxedComplex* lhs, Box* rhs) {
double res = PyLong_AsDouble(rhs);
if (res == -1 && PyErr_Occurred())
throwCAPIException();
return complexDivFloat(lhs, (BoxedFloat*)boxFloat(res));
return complexDivFloat(lhs, (BoxedFloat*)autoDecref(boxFloat(res)));
} else {
return incref(NotImplemented);
}
......@@ -517,7 +517,7 @@ Box* complexDivmodComplex(BoxedComplex* lhs, Box* _rhs) {
AUTO_DECREF(div);
div->real = floor(div->real); /* Use the floor of the real part. */
div->imag = 0.0;
BoxedComplex* mod = (BoxedComplex*)complexSubComplex(lhs, (BoxedComplex*)complexMulComplex(rhs_complex, div));
BoxedComplex* mod = (BoxedComplex*)complexSubComplex(lhs, (BoxedComplex*)autoDecref(complexMulComplex(rhs_complex, div)));
AUTO_DECREF(mod);
Box* res = BoxedTuple::create({ div, mod });
return res;
......@@ -574,7 +574,7 @@ Box* complexModComplex(BoxedComplex* lhs, Box* _rhs) {
AUTO_DECREF(div);
div->real = floor(div->real); /* Use the floor of the real part. */
div->imag = 0.0;
BoxedComplex* mod = (BoxedComplex*)complexSubComplex(lhs, (BoxedComplex*)complexMulComplex(rhs, div));
BoxedComplex* mod = (BoxedComplex*)complexSubComplex(lhs, (BoxedComplex*)autoDecref(complexMulComplex(rhs, div)));
return mod;
}
......
......@@ -1915,7 +1915,8 @@ Box* dataDescriptorInstanceSpecialCases(GetattrRewriteArgs* rewrite_args, BoxedS
RewriterVar::SmallVector normal_args;
RewriterVar::SmallVector float_args;
float_args.push_back(r_unboxed_val);
RewriterVar* r_rtn = rewrite_args->rewriter->call(false, (void*)boxFloat, normal_args, float_args);
RewriterVar* r_rtn = rewrite_args->rewriter->call(false, (void*)boxFloat, normal_args, float_args)
->setType(RefType::OWNED);
rewrite_args->setReturn(r_rtn, ReturnConvention::HAS_RETURN);
}
......@@ -7075,6 +7076,7 @@ extern "C" Box* boxedLocalsGet(Box* boxedLocals, BoxedString* attr, Box* globals
if (!isSubclass(e.value->cls, KeyError)) {
throw e;
}
e.clear();
}
}
......
# expected: reffail
# TODO repr is wrong, so for now, only printing complex numbers whose real
# and imaginary parts are non-integers
......
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