Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: free up memory after we're done with it #12

Merged
merged 5 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ jobs:
uses: actions/setup-go@v3
with:
cache: true
go-version: '1.20'

- name: Install TinyGo
uses: acifani/[email protected]
with:
tinygo-version: 0.25.0
tinygo-version: 0.28.1
binaryen-version: "110"

- name: Setup Python env
Expand Down Expand Up @@ -71,4 +72,4 @@ jobs:
echo $TEST | grep '"config": "1"'
echo $TEST | grep '"a": "this is var a"'

extism call example/http.wasm --wasi http_get | grep '"userId": 1'
extism call example/http.wasm --wasi http_get --allow-host "jsonplaceholder.typicode.com" | grep '"userId": 1'
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ example:
test:
extism call example/example.wasm count_vowels --wasi --input "this is a test" --set-config '{"thing": "1234"}'
@echo ""
extism call example/http.wasm http_get --wasi --log-level info
extism call example/http.wasm http_get --wasi --log-level info --allow-host "jsonplaceholder.typicode.com"
Binary file modified example/example.wasm
Binary file not shown.
Binary file modified example/http.wasm
Binary file not shown.
7 changes: 6 additions & 1 deletion extism_pdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ func OutputString(s string) {

func GetConfig(key string) (string, bool) {
mem := AllocateBytes([]byte(key))
defer mem.Free()

offset := C.extism_config_get(C.uint64_t(mem.offset))
clength := C.extism_length(offset)
Expand Down Expand Up @@ -153,6 +154,8 @@ func LogMemory(level LogLevel, memory Memory) {

func Log(level LogLevel, s string) {
mem := AllocateString(s)
defer mem.Free()

LogMemory(level, mem)
}

Expand All @@ -173,7 +176,10 @@ func GetVar(key string) []byte {

func SetVar(key string, value []byte) {
keyMem := AllocateBytes([]byte(key))
defer keyMem.Free()

valMem := AllocateBytes(value)
defer valMem.Free()

C.extism_var_set(
C.uint64_t(keyMem.offset),
Expand Down Expand Up @@ -259,7 +265,6 @@ func (r *HTTPRequest) Send() HTTPResponse {
status := uint16(C.extism_http_status_code())

memory := Memory{offset, length}
defer memory.Free()

return HTTPResponse{
memory,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module github.com/extism/go-pdk

go 1.19
go 1.20

require github.com/valyala/fastjson v1.6.3
Loading