Commit c69e0d81 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Fix this len issue

parent 71ebba5c
language: cpp language: cpp
branches:
except:
- refcounting
compiler: compiler:
- clang - clang
- gcc - gcc
......
...@@ -3188,10 +3188,27 @@ BoxedInt* lenInternal(Box* obj, LenRewriteArgs* rewrite_args) noexcept(S == CAPI ...@@ -3188,10 +3188,27 @@ BoxedInt* lenInternal(Box* obj, LenRewriteArgs* rewrite_args) noexcept(S == CAPI
return (BoxedInt*)boxInt(r); return (BoxedInt*)boxInt(r);
} }
class FixupLenReturn {
public:
static BoxedInt* call(Box* rtn) {
// TODO: support returning longs as the length
if (rtn->cls != int_cls) {
Py_DECREF(rtn);
if (S == CAPI) {
PyErr_Format(TypeError, "an integer is required");
return NULL;
} else
raiseExcHelper(TypeError, "an integer is required");
}
return static_cast<BoxedInt*>(rtn);
};
};
Box* rtn; Box* rtn;
RewriterVar* r_rtn = NULL;
try { try {
if (rewrite_args) { if (rewrite_args) {
assert(0 && "how do we know this is going to return an int?");
CallattrRewriteArgs crewrite_args(rewrite_args->rewriter, rewrite_args->obj, rewrite_args->destination); CallattrRewriteArgs crewrite_args(rewrite_args->rewriter, rewrite_args->obj, rewrite_args->destination);
rtn = callattrInternal0<CXX, REWRITABLE>(obj, len_str, CLASS_ONLY, &crewrite_args, ArgPassSpec(0)); rtn = callattrInternal0<CXX, REWRITABLE>(obj, len_str, CLASS_ONLY, &crewrite_args, ArgPassSpec(0));
if (!crewrite_args.isSuccessful()) if (!crewrite_args.isSuccessful())
...@@ -3204,7 +3221,7 @@ BoxedInt* lenInternal(Box* obj, LenRewriteArgs* rewrite_args) noexcept(S == CAPI ...@@ -3204,7 +3221,7 @@ BoxedInt* lenInternal(Box* obj, LenRewriteArgs* rewrite_args) noexcept(S == CAPI
&& return_convention != ReturnConvention::NO_RETURN) && return_convention != ReturnConvention::NO_RETURN)
rewrite_args = NULL; rewrite_args = NULL;
else { else {
rewrite_args->out_rtn = rtn; r_rtn = rtn;
} }
if (rewrite_args) if (rewrite_args)
...@@ -3231,18 +3248,17 @@ BoxedInt* lenInternal(Box* obj, LenRewriteArgs* rewrite_args) noexcept(S == CAPI ...@@ -3231,18 +3248,17 @@ BoxedInt* lenInternal(Box* obj, LenRewriteArgs* rewrite_args) noexcept(S == CAPI
raiseExcHelper(TypeError, "object of type '%s' has no len()", getTypeName(obj)); raiseExcHelper(TypeError, "object of type '%s' has no len()", getTypeName(obj));
} }
if (rtn->cls != int_cls) { if (rewrite_args) {
Py_DECREF(rtn); if (S == CXX) {
if (S == CAPI) { rewrite_args->out_rtn = rewrite_args->rewriter->call(true, (void*)FixupLenReturn::call, r_rtn)->setType(RefType::OWNED);
PyErr_Format(TypeError, "an integer is required"); rewrite_args->out_success = true;
return NULL; } else {
} else // Don't know how to propagate the exception
raiseExcHelper(TypeError, "an integer is required"); rewrite_args = NULL;
}
} }
if (rewrite_args) return FixupLenReturn::call(rtn);
rewrite_args->out_success = true;
return static_cast<BoxedInt*>(rtn);
} }
// force template instantiation: // force template instantiation:
......
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