Search in sources :

Example 1 with InvalidBufferOffsetException

use of com.oracle.truffle.api.interop.InvalidBufferOffsetException in project graal by oracle.

the class PolyglotHostObjectPartialEvaluationTest method readBufferByte.

@Test
public void readBufferByte() {
    for (final Buffer buffer : ValueAPITest.makeTestBuffers()) {
        getContext().initialize(ProxyLanguage.ID);
        final Object bufferHostObject = LanguageContext.get(null).getEnv().asGuestValue(buffer);
        final RootNode node = new RootNode(null) {

            @Child
            InteropLibrary interop = InteropLibrary.getFactory().createDispatched(1);

            @Override
            public Object execute(VirtualFrame frame) {
                try {
                    return interop.readBufferByte(bufferHostObject, 0);
                } catch (UnsupportedMessageException | InvalidBufferOffsetException e) {
                    throw new RuntimeException(e);
                }
            }
        };
        assertPartialEvalNoInvokes(node);
    }
}
Also used : Buffer(java.nio.Buffer) VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) RootNode(com.oracle.truffle.api.nodes.RootNode) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) InvalidBufferOffsetException(com.oracle.truffle.api.interop.InvalidBufferOffsetException) InteropLibrary(com.oracle.truffle.api.interop.InteropLibrary) Test(org.junit.Test) ValueAPITest(com.oracle.truffle.api.test.polyglot.ValueAPITest)

Example 2 with InvalidBufferOffsetException

use of com.oracle.truffle.api.interop.InvalidBufferOffsetException in project graal by oracle.

the class PolyglotHostObjectPartialEvaluationTest method writeBufferByte.

@Test
public void writeBufferByte() {
    for (final Buffer buffer : ValueAPITest.makeTestBuffers()) {
        if (buffer.isReadOnly()) {
            continue;
        }
        getContext().initialize(ProxyLanguage.ID);
        final Object bufferHostObject = LanguageContext.get(null).getEnv().asGuestValue(buffer);
        final RootNode node = new RootNode(null) {

            @Child
            InteropLibrary interop = InteropLibrary.getFactory().createDispatched(1);

            @Override
            public Object execute(VirtualFrame frame) {
                try {
                    interop.writeBufferByte(bufferHostObject, 0, (byte) 42);
                } catch (UnsupportedMessageException | InvalidBufferOffsetException e) {
                    throw new RuntimeException(e);
                }
                return null;
            }
        };
        assertPartialEvalNoInvokes(node);
    }
}
Also used : Buffer(java.nio.Buffer) VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) RootNode(com.oracle.truffle.api.nodes.RootNode) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) InvalidBufferOffsetException(com.oracle.truffle.api.interop.InvalidBufferOffsetException) InteropLibrary(com.oracle.truffle.api.interop.InteropLibrary) Test(org.junit.Test) ValueAPITest(com.oracle.truffle.api.test.polyglot.ValueAPITest)

Aggregations

VirtualFrame (com.oracle.truffle.api.frame.VirtualFrame)2 InteropLibrary (com.oracle.truffle.api.interop.InteropLibrary)2 InvalidBufferOffsetException (com.oracle.truffle.api.interop.InvalidBufferOffsetException)2 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)2 RootNode (com.oracle.truffle.api.nodes.RootNode)2 ValueAPITest (com.oracle.truffle.api.test.polyglot.ValueAPITest)2 Buffer (java.nio.Buffer)2 Test (org.junit.Test)2