|
102 | 102 | import com.oracle.graal.python.builtins.objects.memoryview.PBuffer;
|
103 | 103 | import com.oracle.graal.python.builtins.objects.memoryview.PMemoryView;
|
104 | 104 | import com.oracle.graal.python.builtins.objects.method.PBuiltinMethod;
|
| 105 | +import com.oracle.graal.python.builtins.objects.method.PDecoratedMethod; |
105 | 106 | import com.oracle.graal.python.builtins.objects.method.PMethod;
|
106 | 107 | import com.oracle.graal.python.builtins.objects.mmap.PMMap;
|
107 | 108 | import com.oracle.graal.python.builtins.objects.module.PythonModule;
|
@@ -462,9 +463,15 @@ static Object doTpAsMapping(PythonManagedClass object, @SuppressWarnings("unused
|
462 | 463 |
|
463 | 464 | @Specialization(guards = "eq(TP_NEW, key)")
|
464 | 465 | static Object doTpNew(PythonManagedClass object, @SuppressWarnings("unused") PythonNativeWrapper nativeWrapper, @SuppressWarnings("unused") String key,
|
| 466 | + @Cached ConditionProfile profileNewType, |
465 | 467 | @Cached LookupAttributeInMRONode.Dynamic getAttrNode,
|
466 | 468 | @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)); |
468 | 475 | }
|
469 | 476 |
|
470 | 477 | @Specialization(guards = "eq(TP_HASH, key)")
|
|
0 commit comments