From 20759823232d363ba480d0a325c7732d8ffdafd0 Mon Sep 17 00:00:00 2001 From: Gustavo Caso Date: Wed, 19 Jan 2022 13:50:36 +0100 Subject: [PATCH] Try different approach --- isolate.go | 6 +++--- snapshot_creator.go | 9 ++++----- v8go.cc | 7 +++---- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/isolate.go b/isolate.go index 317e9c852..f69fc28e5 100644 --- a/isolate.go +++ b/isolate.go @@ -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 } diff --git a/snapshot_creator.go b/snapshot_creator.go index 2894de817..f43846d1f 100644 --- a/snapshot_creator.go +++ b/snapshot_creator.go @@ -9,7 +9,6 @@ package v8go import "C" import ( "errors" - "unsafe" ) type FunctionCodeHandling int @@ -20,7 +19,7 @@ const ( ) type StartupData struct { - data []byte + data *C.char raw_size C.int index C.size_t } @@ -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() { diff --git a/v8go.cc b/v8go.cc index 206cdee97..51a842df4 100644 --- a/v8go.cc +++ b/v8go.cc @@ -306,7 +306,6 @@ size_t AddContext(SnapshotCreatorPtr snapshotCreator, ContextPtr ctx) { Local local_ctx = ctx->ptr.Get(iso); Context::Scope context_scope(local_ctx); return snapshotCreator->AddContext(local_ctx); - ; } RtnSnapshotBlob CreateBlob(SnapshotCreatorPtr snapshotCreator, @@ -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;