Skip to content

Commit

Permalink
Merge pull request #363 from gucio321/vectors-rework
Browse files Browse the repository at this point in the history
Vectors rework
  • Loading branch information
gucio321 authored Oct 29, 2024
2 parents faa6646 + 0421557 commit 0e9d3e5
Show file tree
Hide file tree
Showing 7 changed files with 224 additions and 199 deletions.
11 changes: 10 additions & 1 deletion cmd/codegen/arguments_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,18 @@ func getArgWrapper(
return "", ArgumentWrapperData{}, fmt.Errorf("creating vector wrapper %w", err)
}

// NOTE Special Case
if pureType == "char*" { // we need to handle it as *byte, not string
charWrapper := simplePtrW("int8", "C.char")
w = charWrapper(ArgDef{
Name: dataName,
Type: pureType,
})
}

data = ArgumentWrapperData{
VarName: string("*" + a.Name + "VecArg"),
ArgType: GoIdentifier(fmt.Sprintf("vectors.Vector[%s]", w.ArgType)),
ArgType: GoIdentifier(fmt.Sprintf("vectors.Vector[%s]", Replace(w.ArgType, "*", "", 1))),
ArgDef: fmt.Sprintf(`%[5]s := %[2]s.Data
%[1]s
%[2]sVecArg := new(C.%[3]s)
Expand Down
7 changes: 6 additions & 1 deletion cmd/codegen/return_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,13 @@ func getReturnWrapper(
return returnWrapper{}, fmt.Errorf("creating vector wrapper %w", err)
}

// NOTE: Special Case
if pureType == "char*" {
rw = simplePtrR("int8")
}

return returnWrapper{
returnType: GoIdentifier(fmt.Sprintf("vectors.Vector[%s]", rw.returnType)),
returnType: GoIdentifier(fmt.Sprintf("vectors.Vector[%s]", Replace(rw.returnType, "*", "", 1))),
returnStmt: fmt.Sprintf("vectors.NewVectorFromC(%%[1]s.Size, %%[1]s.Capacity, %s)", fmt.Sprintf(rw.returnStmt, "%[1]s.Data")),
}, nil
case HasSuffix(t, "*") && isEnum(TrimSuffix(t, "*"), context.enumNames):
Expand Down
Loading

0 comments on commit 0e9d3e5

Please sign in to comment.