Commit a20bcabd authored by Kevin Modzelewski's avatar Kevin Modzelewski

Add native tp_descr_get for function_cls and wrapperdescr_cls

parent 85f8fff2
......@@ -143,6 +143,7 @@ public:
DEFAULT_CLASS(wrapperdescr_cls);
static Box* __get__(BoxedWrapperDescriptor* self, Box* inst, Box* owner);
static Box* descr_get(Box* self, Box* inst, Box* owner) noexcept;
static Box* __call__(BoxedWrapperDescriptor* descr, PyObject* self, BoxedTuple* args, Box** _args);
static void gcHandler(GCVisitor* v, Box* _o) {
......
......@@ -69,6 +69,20 @@ Box* BoxedWrapperDescriptor::__get__(BoxedWrapperDescriptor* self, Box* inst, Bo
return new BoxedWrapperObject(self, inst);
}
Box* BoxedWrapperDescriptor::descr_get(Box* _self, Box* inst, Box* owner) noexcept {
RELEASE_ASSERT(_self->cls == wrapperdescr_cls, "");
BoxedWrapperDescriptor* self = static_cast<BoxedWrapperDescriptor*>(_self);
if (inst == None)
return self;
if (!isSubclass(inst->cls, self->type))
PyErr_Format(TypeError, "Descriptor '' for '%s' objects doesn't apply to '%s' object",
getFullNameOfClass(self->type).c_str(), getFullTypeName(inst).c_str());
return new BoxedWrapperObject(self, inst);
}
Box* BoxedWrapperDescriptor::__call__(BoxedWrapperDescriptor* descr, PyObject* self, BoxedTuple* args, Box** _args) {
RELEASE_ASSERT(descr->cls == wrapperdescr_cls, "");
......@@ -1737,6 +1751,7 @@ void setupCAPI() {
wrapperdescr_cls->giveAttr("__doc__",
new (pyston_getset_cls) BoxedGetsetDescriptor(wrapperdescrGetDoc, NULL, NULL));
wrapperdescr_cls->freeze();
wrapperdescr_cls->tp_descr_get = BoxedWrapperDescriptor::descr_get;
wrapperobject_cls->giveAttr(
"__call__", new BoxedFunction(boxRTFunction((void*)BoxedWrapperObject::__call__, UNKNOWN, 1, 0, true, true)));
......
......@@ -857,6 +857,14 @@ static Box* functionGet(BoxedFunction* self, Box* inst, Box* owner) {
return new BoxedInstanceMethod(inst, self, owner);
}
static Box* function_descr_get(Box* self, Box* inst, Box* owner) noexcept {
RELEASE_ASSERT(self->cls == function_cls, "");
if (inst == None)
inst = NULL;
return new BoxedInstanceMethod(inst, self, owner);
}
static Box* functionCall(BoxedFunction* self, Box* args, Box* kwargs) {
RELEASE_ASSERT(self->cls == function_cls, "%s", getTypeName(self));
......@@ -2748,6 +2756,7 @@ void setupRuntime() {
function_cls->giveAttr("__defaults__", function_cls->getattr("func_defaults"));
function_cls->giveAttr("func_globals", function_cls->getattr("__globals__"));
function_cls->freeze();
function_cls->tp_descr_get = function_descr_get;
builtin_function_or_method_cls->giveAttr(
"__module__",
......
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