Skip to content

Commit f997c9f

Browse files
committed
Fix: Do not bind call targets and built-in method descriptors to NFI signature
1 parent a0da349 commit f997c9f

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,7 @@ public static PBuiltinFunction createWrapperFunction(TruffleString name, Object
648648
flags = 0;
649649
}
650650
int numDefaults = -1;
651+
PKeyword[] kwDefaults;
651652
RootCallTarget callTarget;
652653
if (callable instanceof RootCallTarget) {
653654
callTarget = (RootCallTarget) callable;
@@ -667,6 +668,7 @@ public static PBuiltinFunction createWrapperFunction(TruffleString name, Object
667668
if (callTarget.getRootNode() instanceof BuiltinFunctionRootNode builtinFunctionRootNode) {
668669
numDefaults = PythonBuiltins.numDefaults(builtinFunctionRootNode.getBuiltin());
669670
}
671+
kwDefaults = PKeyword.EMPTY_KEYWORDS;
670672
} else if (callable instanceof BuiltinMethodDescriptor builtinMethodDescriptor) {
671673
/*
672674
* If we see a built-in method descriptor here, it was originally retrieved by a
@@ -676,20 +678,24 @@ public static PBuiltinFunction createWrapperFunction(TruffleString name, Object
676678
callTarget = language.getDescriptorCallTarget(builtinMethodDescriptor);
677679
// again: special case for built-in functions
678680
numDefaults = PythonBuiltins.numDefaults(builtinMethodDescriptor.getBuiltinAnnotation());
681+
kwDefaults = PKeyword.EMPTY_KEYWORDS;
679682
} else {
680683
callTarget = getOrCreateCallTarget(sig, language, name, doArgAndResultConversion, CExtContext.isMethStatic(flags));
681684
if (callTarget == null) {
682685
return null;
683686
}
687+
688+
// ensure that 'callable' is executable via InteropLibrary
689+
Object boundCallable = NativeCExtSymbol.ensureExecutable(callable, sig);
690+
kwDefaults = ExternalFunctionNodes.createKwDefaults(boundCallable);
684691
}
692+
693+
// generate default values for positional args (if necessary)
685694
if (numDefaults == -1) {
686695
numDefaults = sig == DELITEM ? 1 : 0;
687696
}
688697
Object[] defaults = PBuiltinFunction.generateDefaults(numDefaults);
689698

690-
// ensure that 'callable' is executable via InteropLibrary
691-
Object boundCallable = NativeCExtSymbol.ensureExecutable(callable, sig);
692-
693699
Object type = (enclosingType == PNone.NO_VALUE || SpecialMethodNames.T___NEW__.equalsUncached(name, TS_ENCODING)) ? null : enclosingType;
694700
// TODO(fa): this should eventually go away
695701
switch (sig) {
@@ -700,9 +706,9 @@ public static PBuiltinFunction createWrapperFunction(TruffleString name, Object
700706
case FASTCALL:
701707
case FASTCALL_WITH_KEYWORDS:
702708
case METHOD:
703-
return factory.createBuiltinFunction(name, type, defaults, ExternalFunctionNodes.createKwDefaults(boundCallable), flags, callTarget);
709+
return factory.createBuiltinFunction(name, type, defaults, kwDefaults, flags, callTarget);
704710
}
705-
return factory.createWrapperDescriptor(name, type, defaults, ExternalFunctionNodes.createKwDefaults(boundCallable), flags, callTarget);
711+
return factory.createWrapperDescriptor(name, type, defaults, kwDefaults, flags, callTarget);
706712
}
707713

708714
private static boolean isClosurePointer(PythonContext context, Object callable, InteropLibrary lib) {

0 commit comments

Comments
 (0)