diff --git a/header.go b/header.go index 1acef16..574e7c6 100644 --- a/header.go +++ b/header.go @@ -30,7 +30,7 @@ func (ctx *Context) SetHeaders(opts libs.SassOptions) { } } // ctx.entries = &entries - libs.BindHeader(opts, &entries) + libs.BindHeader(opts, entries) } type Header struct { diff --git a/libs/header.go b/libs/header.go index 6ac63b9..44d5ffd 100644 --- a/libs/header.go +++ b/libs/header.go @@ -15,16 +15,20 @@ package libs // } // import "C" -import ( - "runtime" - "unsafe" -) +import "unsafe" + +var globalHeaders SafeMap + +func init() { + globalHeaders.init() +} // This binds the header to the libsass header lookup -func BindHeader(opts SassOptions, entries *[]ImportEntry) { - ptr := unsafe.Pointer(entries) - // FIXME: this should be cleaned up manually later - runtime.SetFinalizer(entries, nil) +func BindHeader(opts SassOptions, entries []ImportEntry) { + + idx := globalHeaders.set(entries) + ptr := unsafe.Pointer(idx) + imper := C.sass_make_importer( C.Sass_Importer_Fn(C.SassHeaders), C.double(0), diff --git a/libs/wrap.go b/libs/wrap.go index 7ee0544..049fc15 100644 --- a/libs/wrap.go +++ b/libs/wrap.go @@ -37,7 +37,12 @@ type ImportEntry struct { //export HeaderBridge func HeaderBridge(ptr unsafe.Pointer) C.Sass_Import_List { - entries := *(*[]ImportEntry)(ptr) + idx := (*string)(ptr) + entries, ok := globalHeaders.get(idx).([]ImportEntry) + if !ok { + fmt.Printf("failed to resolve header slice: %p\n", ptr) + return C.sass_make_import_list(C.size_t(1)) + } cents := C.sass_make_import_list(C.size_t(len(entries)))