Skip to content

Commit

Permalink
cleanup: default to json when dict is used for input/output type
Browse files Browse the repository at this point in the history
  • Loading branch information
zshipko committed Sep 16, 2024
1 parent a3917c1 commit 75a8e7c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:

- name: Update deps (Linux)
run: |
go install github.com/extism/cli/extism@latest
go install github.com/extism/cli/extism@main
cd /tmp
# get just wasm-merge and wasm-opt
curl -L https://github.com/WebAssembly/binaryen/releases/download/version_116/binaryen-version_116-x86_64-linux.tar.gz > binaryen.tar.gz
Expand All @@ -45,7 +45,7 @@ jobs:
- name: Update deps (Windows)
run: |
powershell -executionpolicy bypass -File .\install-wasi-sdk.ps1
go install github.com/extism/cli/extism@latest
go install github.com/extism/cli/extism@main
Remove-Item -Recurse -Path "c:\Program files\Binaryen" -Force -ErrorAction SilentlyContinue > $null 2>&1
New-Item -ItemType Directory -Force -Path "c:\Program files\Binaryen" -ErrorAction Stop > $null 2>&1
Invoke-WebRequest -Uri "https://github.com/WebAssembly/binaryen/releases/download/version_116/binaryen-version_116-x86_64-windows.tar.gz" -OutFile "$env:TMP\binaryen-version_116-x86_64-windows.tar.gz"
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ core:

test: examples
EXTISM_ENABLE_WASI_OUTPUT=1 extism call ./examples/count-vowels.wasm count_vowels --wasi --input "this is a test"
# EXTISM_ENABLE_WASI_OUTPUT=1 extism call ./examples/imports.wasm count_vowels --wasi --input "this is a test" --link example=./examples/imports_example.wasm
EXTISM_ENABLE_WASI_OUTPUT=1 extism call ./examples/imports.wasm count_vowels --wasi --input "this is a test" --link example=./examples/imports_example.wasm


.PHONY: examples
Expand Down
6 changes: 6 additions & 0 deletions lib/src/prelude.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ def _alloc(x):
return ffi.memory.alloc(x.encode()).offset
elif isinstance(x, bytes):
return ffi.memory.alloc(x).offset
elif isinstance(x, dict):
return ffi.memory.alloc(json.dumps(x)).offset
elif isinstance(x, Codec):
return ffi.memory.alloc(x.encode()).offset
elif isinstance(x, ffi.memory.MemoryHandle):
Expand All @@ -65,8 +67,12 @@ def _read(t, x):
return ffi.memory.string(mem)
elif t == bytes:
return ffi.memory.bytes(mem)
elif t == dict:
return json.loads(ffi.memory.string(mem))
elif t == Json:
return Json.decode(ffi.memory.bytes(mem))
elif t == ffi.memory.MemoryHandle:
return mem
else:
raise Exception(f"Unsupported python type: {t}")

Expand Down

0 comments on commit 75a8e7c

Please sign in to comment.