Skip to content

Commit 7ecce93

Browse files
committed
Use cached SignatureLibrary
1 parent 12147a7 commit 7ecce93

File tree

5 files changed

+23
-10
lines changed

5 files changed

+23
-10
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,14 +1198,14 @@ private static Source buildNFISource(Object srcObj) {
11981198
return Source.newBuilder(J_NFI_LANGUAGE, (String) srcObj, "exec").build();
11991199
}
12001200

1201-
public long registerClosure(String nfiSignature, Object executable, Object delegate) {
1201+
public long registerClosure(String nfiSignature, Object executable, Object delegate, SignatureLibrary signatureLibrary) {
12021202
CompilerAsserts.neverPartOfCompilation();
12031203
PythonContext context = getContext();
1204-
boolean panama = PythonOptions.UsePanama.getValue(context.getEnv().getOptions());
1204+
boolean panama = context.getOption(PythonOptions.UsePanama);
12051205
String srcString = (panama ? "with panama " : "") + nfiSignature;
12061206
Source nfiSource = context.getLanguage().getOrCreateSource(CApiContext::buildNFISource, srcString);
12071207
Object signature = context.getEnv().parseInternal(nfiSource).call();
1208-
Object closure = SignatureLibrary.getUncached().createClosure(signature, executable);
1208+
Object closure = signatureLibrary.createClosure(signature, executable);
12091209
long pointer = PythonUtils.coerceToLong(closure, InteropLibrary.getUncached());
12101210
setClosurePointer(closure, delegate, executable, pointer);
12111211
return pointer;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1761,6 +1761,7 @@ static int doGeneric(CApiContext capiContext, PythonModule module, Object module
17611761
@Cached CStructAccess.ReadPointerNode readPointerNode,
17621762
@Cached CStructAccess.ReadI32Node readI32Node,
17631763
@CachedLibrary(limit = "3") InteropLibrary interopLib,
1764+
@CachedLibrary(limit = "1") SignatureLibrary signatureLibrary,
17641765
@Cached PRaiseNode raiseNode) {
17651766
InteropLibrary U = InteropLibrary.getUncached();
17661767
// call to type the pointer
@@ -1800,7 +1801,7 @@ static int doGeneric(CApiContext capiContext, PythonModule module, Object module
18001801
if (!U.isExecutable(execFunction)) {
18011802
boolean panama = context.getOption(PythonOptions.UsePanama);
18021803
Object signature = context.getEnv().parseInternal(panama ? NFI_PANAMA_EXEC : NFI_LIBFFI_EXEC).call();
1803-
execFunction = SignatureLibrary.getUncached().bind(signature, execFunction);
1804+
execFunction = signatureLibrary.bind(signature, execFunction);
18041805
}
18051806
Object result = interopLib.execute(execFunction, PythonToNativeNode.executeUncached(module));
18061807
int iResult = interopLib.asInt(result);

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,11 @@
6262
import com.oracle.truffle.api.dsl.Cached.Exclusive;
6363
import com.oracle.truffle.api.interop.ArityException;
6464
import com.oracle.truffle.api.interop.InteropLibrary;
65+
import com.oracle.truffle.api.library.CachedLibrary;
6566
import com.oracle.truffle.api.library.ExportLibrary;
6667
import com.oracle.truffle.api.library.ExportMessage;
6768
import com.oracle.truffle.api.nodes.Node;
69+
import com.oracle.truffle.nfi.api.SignatureLibrary;
6870

6971
/**
7072
* Wrappers for methods used by native code.
@@ -90,9 +92,11 @@ public long asPointer() {
9092

9193
@ExportMessage
9294
@TruffleBoundary
93-
public void toNative() {
95+
public void toNative(
96+
@CachedLibrary(limit = "1") SignatureLibrary signatureLibrary) {
9497
if (!isPointer()) {
95-
setNativePointer(PythonContext.get(null).getCApiContext().registerClosure(getSignature(), this, getDelegate()));
98+
CApiContext cApiContext = PythonContext.get(null).getCApiContext();
99+
setNativePointer(cApiContext.registerClosure(getSignature(), this, getDelegate(), signatureLibrary));
96100
}
97101
}
98102

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,12 @@
8383
import com.oracle.truffle.api.interop.TruffleObject;
8484
import com.oracle.truffle.api.interop.UnsupportedMessageException;
8585
import com.oracle.truffle.api.interop.UnsupportedTypeException;
86+
import com.oracle.truffle.api.library.CachedLibrary;
8687
import com.oracle.truffle.api.library.ExportLibrary;
8788
import com.oracle.truffle.api.library.ExportMessage;
8889
import com.oracle.truffle.api.nodes.Node;
8990
import com.oracle.truffle.api.strings.TruffleString;
91+
import com.oracle.truffle.nfi.api.SignatureLibrary;
9092

9193
/**
9294
* A wrapper class for managed functions such that they can be called with native function pointers
@@ -157,9 +159,11 @@ protected Object execute(Object[] arguments) throws UnsupportedTypeException, Ar
157159

158160
@ExportMessage
159161
@TruffleBoundary
160-
protected void toNative() {
162+
protected void toNative(
163+
@CachedLibrary(limit = "1") SignatureLibrary signatureLibrary) {
161164
if (pointer == 0) {
162-
pointer = PythonContext.get(null).getCApiContext().registerClosure(getSignature(), this, getDelegate());
165+
CApiContext cApiContext = PythonContext.get(null).getCApiContext();
166+
pointer = cApiContext.registerClosure(getSignature(), this, getDelegate(), signatureLibrary);
163167
}
164168
}
165169

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,12 @@
7979
import com.oracle.truffle.api.interop.InteropLibrary;
8080
import com.oracle.truffle.api.interop.UnsupportedMessageException;
8181
import com.oracle.truffle.api.interop.UnsupportedTypeException;
82+
import com.oracle.truffle.api.library.CachedLibrary;
8283
import com.oracle.truffle.api.library.ExportLibrary;
8384
import com.oracle.truffle.api.library.ExportMessage;
8485
import com.oracle.truffle.api.nodes.Node;
8586
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
87+
import com.oracle.truffle.nfi.api.SignatureLibrary;
8688

8789
@ExportLibrary(InteropLibrary.class)
8890
public abstract class PyProcsWrapper extends PythonStructNativeWrapper {
@@ -119,9 +121,11 @@ protected long asPointer() {
119121

120122
@ExportMessage
121123
@TruffleBoundary
122-
protected void toNative() {
124+
protected void toNative(
125+
@CachedLibrary(limit = "1") SignatureLibrary signatureLibrary) {
123126
if (!isPointer()) {
124-
setNativePointer(PythonContext.get(null).getCApiContext().registerClosure(getSignature(), this, getDelegate()));
127+
CApiContext cApiContext = PythonContext.get(null).getCApiContext();
128+
setNativePointer(cApiContext.registerClosure(getSignature(), this, getDelegate(), signatureLibrary));
125129
}
126130
}
127131

0 commit comments

Comments
 (0)