Skip to content

Commit

Permalink
fix #4
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieuancelin committed Nov 18, 2024
1 parent f0327c5 commit ac0d6c8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
5 changes: 2 additions & 3 deletions src/main/scala/io/otoroshi/wasm4s/impl/opa.scala
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ object OPA extends AwaitCapable {
)
}

def getLinearMemories(): Seq[LinearMemory] = {
def getLinearMemories(size: Int): Seq[LinearMemory] = {
Seq(
new LinearMemory("memory", "env", new LinearMemoryOptions(4, Optional.empty()))
new LinearMemory("memory", "env", new LinearMemoryOptions(size, Optional.empty()))
)
}

Expand Down Expand Up @@ -255,7 +255,6 @@ object OPA extends AwaitCapable {
val ret = plugin.call("opa_eval", ptr, 1)

val memory = plugin.getLinearMemory( "env", "memory")

val offset: Int = ret.getValue(0).v.i32
val arraySize: Int = 65356

Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/io/otoroshi/wasm4s/scaladsl/opa.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ object LinearMemories {
if (config.opa) {
if (memories.get.isEmpty) {
memories.set(
io.otoroshi.wasm4s.impl.OPA.getLinearMemories()
io.otoroshi.wasm4s.impl.OPA.getLinearMemories(config.memoryPages)
)
}
memories.get().toArray
Expand Down
10 changes: 5 additions & 5 deletions src/test/scala/io/otoroshi/wasm4s/test/WasmSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package io.otoroshi.wasm4s.test

import io.otoroshi.wasm4s.scaladsl._
import io.otoroshi.wasm4s.scaladsl.implicits._
import play.api.libs.json.Json
import play.api.libs.json.{JsArray, Json}

import scala.concurrent.Await
import scala.concurrent.duration.DurationInt
Expand Down Expand Up @@ -68,13 +68,13 @@ class WasmSpec extends munit.FunSuite {
}

test("opa manual setup with auto release should work") {

import wasmIntegration.executionContext

val callCtx = Json.obj("request" -> Json.obj("headers" -> Json.obj("foo" -> "bar"))).stringify
val cc = callCtx
println(s"payload size: ${cc.size}")
val fu = wasmIntegration.withPooledVm(wasmStore.wasmConfigurationUnsafe("opa")) { vm =>
vm.ensureOpaInitialized(callCtx.some).call(
WasmFunctionParameters.OPACall("execute", vm.getOpaPointers(), callCtx), None
vm.ensureOpaInitialized(cc.some).call(
WasmFunctionParameters.OPACall("execute", vm.getOpaPointers(), cc), None
).map {
case Left(error) => println(s"error: ${error.prettify}")
case Right((out, _)) => {
Expand Down

0 comments on commit ac0d6c8

Please sign in to comment.