Skip to content

Commit 0e9d3e5

Browse files
authored
Merge pull request #363 from gucio321/vectors-rework
Vectors rework
2 parents faa6646 + 0421557 commit 0e9d3e5

File tree

7 files changed

+224
-199
lines changed

7 files changed

+224
-199
lines changed

cmd/codegen/arguments_wrapper.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,18 @@ func getArgWrapper(
195195
return "", ArgumentWrapperData{}, fmt.Errorf("creating vector wrapper %w", err)
196196
}
197197

198+
// NOTE Special Case
199+
if pureType == "char*" { // we need to handle it as *byte, not string
200+
charWrapper := simplePtrW("int8", "C.char")
201+
w = charWrapper(ArgDef{
202+
Name: dataName,
203+
Type: pureType,
204+
})
205+
}
206+
198207
data = ArgumentWrapperData{
199208
VarName: string("*" + a.Name + "VecArg"),
200-
ArgType: GoIdentifier(fmt.Sprintf("vectors.Vector[%s]", w.ArgType)),
209+
ArgType: GoIdentifier(fmt.Sprintf("vectors.Vector[%s]", Replace(w.ArgType, "*", "", 1))),
201210
ArgDef: fmt.Sprintf(`%[5]s := %[2]s.Data
202211
%[1]s
203212
%[2]sVecArg := new(C.%[3]s)

cmd/codegen/return_wrapper.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,13 @@ func getReturnWrapper(
115115
return returnWrapper{}, fmt.Errorf("creating vector wrapper %w", err)
116116
}
117117

118+
// NOTE: Special Case
119+
if pureType == "char*" {
120+
rw = simplePtrR("int8")
121+
}
122+
118123
return returnWrapper{
119-
returnType: GoIdentifier(fmt.Sprintf("vectors.Vector[%s]", rw.returnType)),
124+
returnType: GoIdentifier(fmt.Sprintf("vectors.Vector[%s]", Replace(rw.returnType, "*", "", 1))),
120125
returnStmt: fmt.Sprintf("vectors.NewVectorFromC(%%[1]s.Size, %%[1]s.Capacity, %s)", fmt.Sprintf(rw.returnStmt, "%[1]s.Data")),
121126
}, nil
122127
case HasSuffix(t, "*") && isEnum(TrimSuffix(t, "*"), context.enumNames):

0 commit comments

Comments
 (0)