Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Commit

Permalink
Try different approach
Browse files Browse the repository at this point in the history
  • Loading branch information
GustavoCaso committed Jan 19, 2022
1 parent d1b11a5 commit 2075982
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
6 changes: 3 additions & 3 deletions isolate.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ func NewIsolate(opts ...createOptions) *Isolate {
var cOptions C.IsolateOptions

if params.startupData != nil {
p := C.CString(string(params.startupData.data))
cOptions.snapshot_blob_data = p
defer C.free(unsafe.Pointer(p))
// p := C.CString(string(params.startupData.data))
cOptions.snapshot_blob_data = params.startupData.data
// defer C.free(unsafe.Pointer(p))
cOptions.snapshot_blob_raw_size = params.startupData.raw_size
}

Expand Down
9 changes: 4 additions & 5 deletions snapshot_creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package v8go
import "C"
import (
"errors"
"unsafe"
)

type FunctionCodeHandling int
Expand All @@ -20,7 +19,7 @@ const (
)

type StartupData struct {
data []byte
data *C.char
raw_size C.int
index C.size_t
}
Expand Down Expand Up @@ -72,10 +71,10 @@ func (s *SnapshotCreator) Create(functionCode FunctionCodeHandling) (*StartupDat
s.iso.ptr = nil

raw_size := rtn.raw_size
data := C.GoBytes(unsafe.Pointer(rtn.data), raw_size)
defer C.free(unsafe.Pointer(rtn.data))
// data := C.GoBytes(unsafe.Pointer(rtn.data), raw_size)
// defer C.free(unsafe.Pointer(rtn.data))

return &StartupData{data: data, raw_size: raw_size, index: s.index}, nil
return &StartupData{data: rtn.data, raw_size: raw_size, index: s.index}, nil
}

func (s *SnapshotCreator) Dispose() {
Expand Down
7 changes: 3 additions & 4 deletions v8go.cc
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,6 @@ size_t AddContext(SnapshotCreatorPtr snapshotCreator, ContextPtr ctx) {
Local<Context> local_ctx = ctx->ptr.Get(iso);
Context::Scope context_scope(local_ctx);
return snapshotCreator->AddContext(local_ctx);
;
}

RtnSnapshotBlob CreateBlob(SnapshotCreatorPtr snapshotCreator,
Expand All @@ -321,10 +320,10 @@ RtnSnapshotBlob CreateBlob(SnapshotCreatorPtr snapshotCreator,

int length = startup_data.raw_size;

char* data = (char*)malloc(length);
memcpy(data, startup_data.data, length);
// char* data = (char*)malloc(length);
// memcpy(data, startup_data.data, length);

rtn.data = data;
rtn.data = startup_data.data;
rtn.raw_size = length;
delete snapshotCreator;
return rtn;
Expand Down

0 comments on commit 2075982

Please sign in to comment.