Commit 82e9cdcd authored by Kevin Modzelewski's avatar Kevin Modzelewski

Merge pull request #847 from kmod/format_fix

descriptor/format fix
parents 97c47267 e497a265
......@@ -1888,8 +1888,13 @@ static const slotdef* update_one_slot(BoxedClass* type, const slotdef* p) noexce
point out a bug in this reasoning a beer. */
} else if (offset == offsetof(BoxedClass, tp_descr_get) && descr->cls == function_cls
&& static_cast<BoxedFunction*>(descr)->f->always_use_version) {
type->tpp_descr_get = (descrgetfunc) static_cast<BoxedFunction*>(descr)->f->always_use_version->code;
specific = (void*)slot_tp_tpp_descr_get;
CompiledFunction* cf = static_cast<BoxedFunction*>(descr)->f->always_use_version;
if (cf->exception_style == CXX) {
type->tpp_descr_get = (descrgetfunc)cf->code;
specific = (void*)slot_tp_tpp_descr_get;
} else {
specific = cf->code;
}
} else if (descr == Py_None && ptr == (void**)&type->tp_hash) {
/* We specifically allow __hash__ to be set to None
to prevent inheritance of the default
......
......@@ -407,7 +407,7 @@ static Box* methodRepr(Box* _o) {
return PyString_FromFormat("<method '%s' of '%s' objects>", name, getNameOfClass(md->type));
}
Box* BoxedMethodDescriptor::__get__(BoxedMethodDescriptor* self, Box* inst, Box* owner) {
Box* BoxedMethodDescriptor::descr_get(BoxedMethodDescriptor* self, Box* inst, Box* owner) noexcept {
RELEASE_ASSERT(self->cls == method_cls, "");
// CPython handles this differently: they create the equivalent of different BoxedMethodDescriptor
......@@ -420,7 +420,7 @@ Box* BoxedMethodDescriptor::__get__(BoxedMethodDescriptor* self, Box* inst, Box*
if (self->method->ml_flags & METH_COEXIST)
Py_FatalError("unimplemented");
if (inst == None)
if (inst == NULL)
return self;
else
return boxInstanceMethod(inst, self, self->type);
......@@ -653,8 +653,8 @@ void setupDescr() {
"__get__", new BoxedFunction(boxRTFunction((void*)classmethodGet, UNKNOWN, 3, 1, false, false), { None }));
classmethod_cls->freeze();
method_cls->giveAttr("__get__",
new BoxedFunction(boxRTFunction((void*)BoxedMethodDescriptor::__get__, UNKNOWN, 3)));
method_cls->giveAttr("__get__", new BoxedFunction(boxRTFunction((void*)BoxedMethodDescriptor::descr_get, UNKNOWN, 3,
ParamNames::empty(), CAPI)));
CLFunction* method_call_cl = boxRTFunction((void*)BoxedMethodDescriptor::__call__, UNKNOWN, 2, 0, true, true);
method_cls->giveAttr("__call__", new BoxedFunction(method_call_cl));
method_cls->tpp_call.capi_val = BoxedMethodDescriptor::tppCall<CAPI>;
......
......@@ -1764,63 +1764,34 @@ Box* getattrInternalGeneric(Box* obj, BoxedString* attr, GetattrRewriteArgs* rew
}
// Lookup __get__
RewriterVar* r_get = NULL;
Box* local_get;
descrgetfunc local_get = val->cls->tp_descr_get;
if (rewrite_args) {
RewriterVar* r_val_cls = r_val->getAttr(offsetof(Box, cls), Location::any());
GetattrRewriteArgs grewrite_args(rewrite_args->rewriter, r_val_cls, Location::any());
local_get = typeLookup(val->cls, get_str, &grewrite_args);
if (!grewrite_args.out_success) {
rewrite_args = NULL;
} else if (local_get) {
r_get = grewrite_args.out_rtn;
}
} else {
local_get = typeLookup(val->cls, get_str, NULL);
RewriterVar* r_cls = r_val->getAttr(offsetof(Box, cls));
r_cls->addAttrGuard(offsetof(BoxedClass, tp_descr_get), (intptr_t)local_get);
}
// Call __get__(val, None, obj)
if (local_get) {
Box* res;
if (for_call) {
#if STAT_CALLATTR_DESCR_ABORTS
if (rewrite_args) {
std::string attr_name = "num_callattr_descr_abort";
Stats::log(Stats::getStatCounter(attr_name));
logByCurrentPythonLine(attr_name);
}
#endif
rewrite_args = NULL;
REWRITE_ABORTED("");
}
if (!local_get) {
if (rewrite_args) {
CallRewriteArgs crewrite_args(rewrite_args->rewriter, r_get, rewrite_args->destination);
crewrite_args.arg1 = r_val;
crewrite_args.arg2 = rewrite_args->rewriter->loadConst((intptr_t)None, Location::any());
crewrite_args.arg3 = rewrite_args->obj;
res = runtimeCallInternal<CXX>(local_get, &crewrite_args, ArgPassSpec(3), val, None, obj, NULL,
NULL);
if (!crewrite_args.out_success) {
rewrite_args = NULL;
} else {
rewrite_args->out_success = true;
rewrite_args->out_rtn = crewrite_args.out_rtn;
}
} else {
res = runtimeCallInternal<CXX>(local_get, NULL, ArgPassSpec(3), val, None, obj, NULL, NULL);
rewrite_args->out_rtn = r_val;
rewrite_args->out_success = true;
}
return res;
return val;
}
// If there was no local __get__, just return val
// Call __get__(val, None, obj)
Box* r = local_get(val, NULL, obj);
if (!r)
throwCAPIException();
if (rewrite_args) {
rewrite_args->out_rtn = r_val;
rewrite_args->out_rtn = rewrite_args->rewriter->call(
true, (void*)local_get, r_val, rewrite_args->rewriter->loadConst(0, Location::forArg(1)),
rewrite_args->obj);
rewrite_args->rewriter->checkAndThrowCAPIException(rewrite_args->out_rtn);
rewrite_args->out_success = true;
}
return val;
return r;
}
}
}
......
......@@ -1017,7 +1017,7 @@ public:
DEFAULT_CLASS(method_cls);
static Box* __get__(BoxedMethodDescriptor* self, Box* inst, Box* owner);
static Box* descr_get(BoxedMethodDescriptor* self, Box* inst, Box* owner) noexcept;
static Box* __call__(BoxedMethodDescriptor* self, Box* obj, BoxedTuple* varargs, Box** _args);
template <ExceptionStyle S>
static Box* tppCall(Box* _self, CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Box* arg1, Box* arg2, Box* arg3,
......
......@@ -123,3 +123,5 @@ print apply(sorted, [l], { "reverse" : True })
print format(5.0, '+')
print format(5.011111111111, '+.6')
print format("abc", '')
print '{n}'.format(n=None)
......@@ -105,3 +105,6 @@ for lhs in all_args:
print pow(lhs, rhs, mod)
except Exception as e:
print type(e), e
import sys
print sys.float_info
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