@@ -475,8 +475,9 @@ Object doNativeWrapper(PythonNativeWrapper object) {
475
475
Object doNativeObject (TruffleObject object ,
476
476
@ Cached PythonObjectFactory factory ,
477
477
@ SuppressWarnings ("unused" ) @ Cached ("create()" ) GetLazyClassNode getClassNode ,
478
- @ SuppressWarnings ("unused" ) @ Cached ("create()" ) IsBuiltinClassProfile isForeignClassProfile ) {
479
- return factory .createNativeObjectWrapper (object );
478
+ @ SuppressWarnings ("unused" ) @ Cached ("create()" ) IsBuiltinClassProfile isForeignClassProfile ,
479
+ @ CachedContext (PythonLanguage .class ) PythonContext context ) {
480
+ return factory .createNativeObjectWrapper (object , context );
480
481
}
481
482
482
483
@ Specialization
@@ -543,13 +544,13 @@ public static Object doSlowPath(Object object, boolean forceNativeClass) {
543
544
return ((PythonNativeWrapper ) object ).getDelegate ();
544
545
} else if (IsBuiltinClassProfile .profileClassSlowPath (GetClassNode .getUncached ().execute (object ), PythonBuiltinClassType .TruffleObject )) {
545
546
if (forceNativeClass ) {
546
- return PythonLanguage . getCore (). factory ().createNativeClassWrapper ((TruffleObject ) object );
547
+ return PythonObjectFactory . getUncached ().createNativeClassWrapper ((TruffleObject ) object );
547
548
}
548
- return PythonLanguage . getCore (). factory ().createNativeObjectWrapper ((TruffleObject ) object );
549
+ return PythonObjectFactory . getUncached ().createNativeObjectWrapper ((TruffleObject ) object );
549
550
} else if (object instanceof String || object instanceof Number || object instanceof Boolean || object instanceof PythonNativeNull || object instanceof PythonAbstractObject ) {
550
551
return object ;
551
552
}
552
- throw PythonLanguage . getCore ().raise (PythonErrorType .SystemError , "invalid object from native: %s" , object );
553
+ throw PRaiseNode . getUncached ().raise (PythonErrorType .SystemError , "invalid object from native: %s" , object );
553
554
}
554
555
555
556
// TODO(fa): Workaround for DSL bug: did not import factory at users
@@ -1673,11 +1674,14 @@ public abstract static class GetTypeMemberNode extends CExtBaseNode {
1673
1674
* native context, so we can be sure that the "nativeClassStableAssumption" (which is
1674
1675
* per-context) is from the context in which this native object was created.
1675
1676
*/
1676
- @ Specialization (guards = {"cachedObj.equals(obj)" , "memberName == cachedMemberName" }, limit = "1" , assumptions = "getNativeClassStableAssumption(cachedObj)" )
1677
- public Object doCachedObj (@ SuppressWarnings ("unused" ) PythonNativeClass obj , @ SuppressWarnings ("unused" ) String memberName ,
1677
+ @ Specialization (guards = {"isSameNativeObjectNode.execute(cachedObj, obj)" , "memberName == cachedMemberName" }, //
1678
+ limit = "1" , //
1679
+ assumptions = {"getNativeClassStableAssumption(cachedObj)" , "singleContextAssumption()" })
1680
+ public Object doCachedObj (@ SuppressWarnings ("unused" ) PythonAbstractNativeObject obj , @ SuppressWarnings ("unused" ) String memberName ,
1681
+ @ SuppressWarnings ("unused" ) @ Cached IsSameNativeObjectFastNode isSameNativeObjectNode ,
1678
1682
@ SuppressWarnings ("unused" ) @ Cached ("memberName" ) String cachedMemberName ,
1679
1683
@ SuppressWarnings ("unused" ) @ Cached ("getterFuncName(memberName)" ) String getterFuncName ,
1680
- @ Cached ("obj" ) @ SuppressWarnings ("unused" ) PythonNativeClass cachedObj ,
1684
+ @ Cached ("obj" ) @ SuppressWarnings ("unused" ) PythonAbstractNativeObject cachedObj ,
1681
1685
@ Cached ("doSlowPath(obj, getterFuncName)" ) Object result ) {
1682
1686
return result ;
1683
1687
}
@@ -1757,4 +1761,39 @@ static Object getNativeNullWithoutModule(@SuppressWarnings("unused") Object modu
1757
1761
}
1758
1762
1759
1763
}
1764
+
1765
+ public abstract static class IsSameNativeObjectNode extends CExtBaseNode {
1766
+
1767
+ public abstract boolean execute (PythonAbstractNativeObject left , PythonAbstractNativeObject right );
1768
+
1769
+ protected static boolean doNativeFast (PythonAbstractNativeObject left , PythonAbstractNativeObject right ) {
1770
+ // This check is a bit dangerous since we cannot be sure about the code that is running.
1771
+ // Currently, we assume that the pointer object is a Sulong pointer and for this it's
1772
+ // fine.
1773
+ return left .equals (right );
1774
+ }
1775
+
1776
+ }
1777
+
1778
+ @ GenerateUncached
1779
+ public abstract static class IsSameNativeObjectFastNode extends IsSameNativeObjectNode {
1780
+
1781
+ @ Specialization
1782
+ boolean doSingleContext (PythonAbstractNativeObject left , PythonAbstractNativeObject right ) {
1783
+ return IsSameNativeObjectNode .doNativeFast (left , right );
1784
+ }
1785
+ }
1786
+
1787
+ @ GenerateUncached
1788
+ public abstract static class IsSameNativeObjectSlowNode extends IsSameNativeObjectNode {
1789
+
1790
+ @ Specialization
1791
+ boolean doSingleContext (PythonAbstractNativeObject left , PythonAbstractNativeObject right ,
1792
+ @ Cached PointerCompareNode pointerCompareNode ) {
1793
+ if (IsSameNativeObjectNode .doNativeFast (left , right )) {
1794
+ return true ;
1795
+ }
1796
+ return pointerCompareNode .execute (SpecialMethodNames .__EQ__ , left , right );
1797
+ }
1798
+ }
1760
1799
}
0 commit comments