Skip to content

Commit

Permalink
CAMEL-21569 - Bump Chicory to 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaTP committed Jan 9, 2025
1 parent 0307817 commit 0208aba
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion components/camel-wasm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<dependency>
<groupId>com.dylibso.chicory</groupId>
<artifactId>runtime</artifactId>
<version>${chicocy-version}</version>
<version>${chicory-version}</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

import java.io.InputStream;

import com.dylibso.chicory.runtime.Module;
import com.dylibso.chicory.wasm.Parser;
import com.dylibso.chicory.wasm.WasmModule;
import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
import org.apache.camel.spi.Resource;
Expand All @@ -33,7 +34,7 @@ public class WasmProducer extends DefaultProducer {
private final String functionModule;
private final String functionName;

private Module module;
private WasmModule module;
private WasmFunction function;

public WasmProducer(Endpoint endpoint, String functionModule, String functionName) throws Exception {
Expand All @@ -49,7 +50,7 @@ public void doInit() throws Exception {
final Resource res = rl.resolveResource(this.functionModule);

try (InputStream is = res.getInputStream()) {
this.module = Module.builder(is).build();
this.module = Parser.parse(is);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import java.io.InputStream;
import java.util.Collection;

import com.dylibso.chicory.runtime.Module;
import com.dylibso.chicory.wasm.Parser;
import com.fasterxml.jackson.databind.node.BooleanNode;
import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
Expand Down Expand Up @@ -72,7 +72,7 @@ public void init(CamelContext camelContext) {
final Resource res = rl.resolveResource(module);

try (InputStream is = res.getInputStream()) {
this.function = new WasmFunction(Module.builder(is).build(), expression);
this.function = new WasmFunction(Parser.parse(is), expression);
} catch (IOException e) {
throw new RuntimeCamelException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,26 @@

import com.dylibso.chicory.runtime.ExportFunction;
import com.dylibso.chicory.runtime.Instance;
import com.dylibso.chicory.runtime.Module;
import com.dylibso.chicory.wasm.types.Value;
import com.dylibso.chicory.wasm.WasmModule;

public class WasmFunction implements AutoCloseable {
private final Object lock;

private final Module module;
private final WasmModule module;
private final String functionName;

private final Instance instance;
private final ExportFunction function;
private final ExportFunction alloc;
private final ExportFunction dealloc;

public WasmFunction(Module module, String functionName) {
public WasmFunction(WasmModule module, String functionName) {
this.lock = new Object();

this.module = Objects.requireNonNull(module);
this.functionName = Objects.requireNonNull(functionName);

this.instance = this.module.instantiate();
this.instance = Instance.builder(this.module).build();
this.function = this.instance.export(this.functionName);
this.alloc = this.instance.export(Wasm.FN_ALLOC);
this.dealloc = this.instance.export(Wasm.FN_DEALLOC);
Expand All @@ -60,11 +59,11 @@ public byte[] run(byte[] in) throws Exception {
//
synchronized (lock) {
try {
inPtr = alloc.apply(Value.i32(inSize))[0].asInt();
inPtr = (int) alloc.apply(inSize)[0];
instance.memory().write(inPtr, in);

Value[] results = function.apply(Value.i32(inPtr), Value.i32(inSize));
long ptrAndSize = results[0].asLong();
long[] results = function.apply(inPtr, inSize);
long ptrAndSize = results[0];

outPtr = (int) (ptrAndSize >> 32);
outSize = (int) ptrAndSize;
Expand All @@ -81,10 +80,10 @@ public byte[] run(byte[] in) throws Exception {
return instance.memory().readBytes(outPtr, outSize);
} finally {
if (inPtr != -1) {
dealloc.apply(Value.i32(inPtr), Value.i32(inSize));
dealloc.apply(inPtr, inSize);
}
if (outPtr != -1) {
dealloc.apply(Value.i32(outPtr), Value.i32(outSize));
dealloc.apply(outPtr, outSize);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
<cassandra-driver-version>4.18.1</cassandra-driver-version>
<jta-api-1.2-version>1.2</jta-api-1.2-version>
<cglib-version>3.3.0</cglib-version>
<chicocy-version>0.0.12</chicocy-version>
<chicory-version>1.0.0</chicory-version>
<chunk-templates-version>3.6.2</chunk-templates-version>
<classgraph-version>4.8.179</classgraph-version>
<cloudant-version>0.9.3</cloudant-version>
Expand Down

0 comments on commit 0208aba

Please sign in to comment.