Skip to content

Commit 9106a1b

Browse files
committed
Make third param of HPyMethSSizeObjArgProcRoot optional
1 parent 48ccee7 commit 9106a1b

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,11 @@ Object readMember(String key) throws UnknownIdentifierException {
177177
}
178178
throw UnknownIdentifierException.create(key);
179179
}
180+
181+
@ExportMessage
182+
boolean isNull() {
183+
return id == 0;
184+
}
180185

181186
public GraalHPyHandle copy() {
182187
return new GraalHPyHandle(delegate);

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1795,8 +1795,8 @@ HPyCloseArgHandlesNode createCloseHandleNode() {
17951795
}
17961796

17971797
/**
1798-
* Always closes handle parameter at position {@code destOffset} and {@code destOffset + 2}
1799-
* (assuming that these are handles).
1798+
* Always closes handle parameter at position {@code destOffset} and also closes parameter at
1799+
* position {@code destOffset + 2} if it is not a {@code NULL} handle.
18001800
*/
18011801
public abstract static class HPySSizeObjArgProcCloseNode extends HPyCloseArgHandlesNode {
18021802

@@ -1805,7 +1805,10 @@ static void doConvert(GraalHPyContext hpyContext, Object[] dest, int destOffset,
18051805
@Cached ConditionProfile isAllocatedProfile,
18061806
@Cached HPyEnsureHandleNode ensureHandleNode) {
18071807
ensureHandleNode.execute(hpyContext, dest[destOffset]).close(hpyContext, isAllocatedProfile);
1808-
ensureHandleNode.execute(hpyContext, dest[destOffset + 2]).close(hpyContext, isAllocatedProfile);
1808+
GraalHPyHandle arg2Handle = ensureHandleNode.execute(hpyContext, dest[destOffset + 2]);
1809+
if (!arg2Handle.isNull()) {
1810+
arg2Handle.close(hpyContext, isAllocatedProfile);
1811+
}
18091812
}
18101813
}
18111814

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ static PBuiltinFunction createWrapperFunction(PythonLanguage language, HPyFuncSi
162162
break;
163163
case SSIZEOBJARGPROC:
164164
rootNode = new HPyMethSSizeObjArgProcRoot(language, name);
165+
// the third argument is optional
166+
numDefaults = 1;
165167
break;
166168
case INQUIRY:
167169
rootNode = new HPyMethInquiryRoot(language, name);

0 commit comments

Comments
 (0)