Skip to content

Commit

Permalink
remove go pointer in array
Browse files Browse the repository at this point in the history
  • Loading branch information
flier committed Oct 23, 2024
1 parent 66efc0e commit c03acd7
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions internal/hs/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,12 @@ type ExprExt struct {
HammingDistance uint32
}

func (e *ExprExt) c() *C.hs_expr_ext_t {
func (e *ExprExt) c() (ext *C.hs_expr_ext_t) {
if e == nil {
return nil
}

var ext C.hs_expr_ext_t
ext = (*C.hs_expr_ext_t)(C.malloc(C.sizeof_hs_expr_ext_t))

if e.Flags&ExtMinOffset != 0 {
ext.flags |= C.HS_EXT_FLAG_MIN_OFFSET
Expand All @@ -189,7 +189,7 @@ func (e *ExprExt) c() *C.hs_expr_ext_t {
ext.hamming_distance = C.uint(e.HammingDistance)
}

return &ext
return
}

func ExpressionInfo(expression string, flags CompileFlag) (*ExprInfo, error) {
Expand Down Expand Up @@ -443,6 +443,8 @@ func CompileMulti(input Patterns, mode ModeFlag, info *PlatformInfo) (Database,
flags[i] = C.uint(pattern.Flags)
ids[i] = C.uint(pattern.ID)
exts[i] = pattern.Ext.c()

p.Pin(exts[i])
}

ret := C.hs_compile_ext_multi(cexprs, cflags, cids, cexts, C.uint(n), C.uint(mode), platform, &db, &err)
Expand All @@ -451,6 +453,10 @@ func CompileMulti(input Patterns, mode ModeFlag, info *PlatformInfo) (Database,
C.free(unsafe.Pointer(expr))
}

for _, ext := range exts {
C.free(unsafe.Pointer(ext))
}

if err != nil {
defer C.hs_free_compile_error(err)
}
Expand Down

0 comments on commit c03acd7

Please sign in to comment.