|
70 | 70 | import com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyNodes.HPyGetNativeSpacePointerNode;
|
71 | 71 | import com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyNodes.PCallHPyFunction;
|
72 | 72 | import com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyNodesFactory.HPyAllAsHandleNodeGen;
|
73 |
| -import com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyNodesFactory.HPyAsPythonObjectNodeGen; |
| 73 | +import com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyNodesFactory.HPyEnsureHandleNodeGen; |
74 | 74 | import com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyNodesFactory.HPyGetBufferProcToSulongNodeGen;
|
75 | 75 | import com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyNodesFactory.HPyGetNativeSpacePointerNodeGen;
|
76 | 76 | import com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyNodesFactory.HPyGetSetGetterToSulongNodeGen;
|
@@ -1588,12 +1588,14 @@ static final class HPyGetBufferRootNode extends HPyMethodDescriptorRootNode {
|
1588 | 1588 | @Child private InteropLibrary valueLib;
|
1589 | 1589 | @Child private PCallCapiFunction callGetByteArrayTypeId;
|
1590 | 1590 | @Child private PCallCapiFunction callFromTyped;
|
1591 |
| - @Child private HPyAsPythonObjectNode asPythonObjectNode; |
| 1591 | + @Child private HPyEnsureHandleNode asPythonObjectNode; |
1592 | 1592 | @Child private FromCharPointerNode fromCharPointerNode;
|
1593 | 1593 | @Child private CastToJavaStringNode castToJavaStringNode;
|
1594 | 1594 | @Child private GetIntArrayNode getIntArrayNode;
|
1595 | 1595 | @Child private PRaiseNode raiseNode;
|
1596 | 1596 |
|
| 1597 | + @CompilationFinal private ConditionProfile isAllocatedProfile; |
| 1598 | + |
1597 | 1599 | @TruffleBoundary
|
1598 | 1600 | public HPyGetBufferRootNode(PythonLanguage language, String name) {
|
1599 | 1601 | super(language, name, HPyCheckPrimitiveResultNodeGen.create(), HPyGetBufferProcToSulongNodeGen.create());
|
@@ -1655,7 +1657,7 @@ private CExtPyBuffer createPyBuffer(GraalHPyContext hpyContext, Object bufferPtr
|
1655 | 1657 | }
|
1656 | 1658 | if (asPythonObjectNode == null) {
|
1657 | 1659 | CompilerDirectives.transferToInterpreterAndInvalidate();
|
1658 |
| - asPythonObjectNode = insert(HPyAsPythonObjectNodeGen.create()); |
| 1660 | + asPythonObjectNode = insert(HPyEnsureHandleNodeGen.create()); |
1659 | 1661 | }
|
1660 | 1662 | if (fromCharPointerNode == null) {
|
1661 | 1663 | CompilerDirectives.transferToInterpreterAndInvalidate();
|
@@ -1687,7 +1689,11 @@ private CExtPyBuffer createPyBuffer(GraalHPyContext hpyContext, Object bufferPtr
|
1687 | 1689 | ownerObj = ptrLib.readMember(ownerObj, GraalHPyHandle.I);
|
1688 | 1690 | Object owner = null;
|
1689 | 1691 | if (!valueLib.isNull(ownerObj)) {
|
1690 |
| - owner = asPythonObjectNode.execute(hpyContext, ownerObj); |
| 1692 | + GraalHPyHandle ownerHandle = asPythonObjectNode.execute(hpyContext, ownerObj); |
| 1693 | + // Since we are now the owner of the handle and no one else will ever use it, we |
| 1694 | + // need to close it. |
| 1695 | + ownerHandle.close(hpyContext, ensureIsAllocatedProfile()); |
| 1696 | + owner = ownerHandle.getDelegate(); |
1691 | 1697 | }
|
1692 | 1698 |
|
1693 | 1699 | int ndim = castToInt(ptrLib.readMember(bufferPtr, "ndim"));
|
@@ -1727,6 +1733,14 @@ private CExtPyBuffer createPyBuffer(GraalHPyContext hpyContext, Object bufferPtr
|
1727 | 1733 | }
|
1728 | 1734 | }
|
1729 | 1735 |
|
| 1736 | + private ConditionProfile ensureIsAllocatedProfile() { |
| 1737 | + if (isAllocatedProfile == null) { |
| 1738 | + CompilerDirectives.transferToInterpreterAndInvalidate(); |
| 1739 | + isAllocatedProfile = ConditionProfile.create(); |
| 1740 | + } |
| 1741 | + return isAllocatedProfile; |
| 1742 | + } |
| 1743 | + |
1730 | 1744 | private int castToInt(Object value) {
|
1731 | 1745 | if (valueLib.fitsInInt(value)) {
|
1732 | 1746 | try {
|
|
0 commit comments