Skip to content

Commit 7347ba3

Browse files
committed
treat __new__ specially when addressing it as tp_new
1 parent 87c7203 commit 7347ba3

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/DynamicObjectNativeWrapper.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
import com.oracle.graal.python.builtins.objects.memoryview.PBuffer;
103103
import com.oracle.graal.python.builtins.objects.memoryview.PMemoryView;
104104
import com.oracle.graal.python.builtins.objects.method.PBuiltinMethod;
105+
import com.oracle.graal.python.builtins.objects.method.PDecoratedMethod;
105106
import com.oracle.graal.python.builtins.objects.method.PMethod;
106107
import com.oracle.graal.python.builtins.objects.mmap.PMMap;
107108
import com.oracle.graal.python.builtins.objects.module.PythonModule;
@@ -462,9 +463,15 @@ static Object doTpAsMapping(PythonManagedClass object, @SuppressWarnings("unused
462463

463464
@Specialization(guards = "eq(TP_NEW, key)")
464465
static Object doTpNew(PythonManagedClass object, @SuppressWarnings("unused") PythonNativeWrapper nativeWrapper, @SuppressWarnings("unused") String key,
466+
@Cached ConditionProfile profileNewType,
465467
@Cached LookupAttributeInMRONode.Dynamic getAttrNode,
466468
@Cached PCallCapiFunction callGetNewfuncTypeidNode) {
467-
return ManagedMethodWrappers.createKeywords(getAttrNode.execute(object, __NEW__), callGetNewfuncTypeidNode.call(NativeCAPISymbols.FUN_GET_NEWFUNC_TYPE_ID));
469+
// __new__ is magically a staticmethod for Python types. The tp_new slot lookup expects to get the function
470+
Object newFunction = getAttrNode.execute(object, __NEW__);
471+
if (profileNewType.profile(newFunction instanceof PDecoratedMethod)) {
472+
newFunction = ((PDecoratedMethod) newFunction).getCallable();
473+
}
474+
return ManagedMethodWrappers.createKeywords(newFunction, callGetNewfuncTypeidNode.call(NativeCAPISymbols.FUN_GET_NEWFUNC_TYPE_ID));
468475
}
469476

470477
@Specialization(guards = "eq(TP_HASH, key)")

0 commit comments

Comments
 (0)