Skip to content

Commit

Permalink
codegen: change structs generation engine
Browse files Browse the repository at this point in the history
gengo_structs.go seemd to be extremely useful, however
it generated several bugs that cannot be fixed using that engine.

Some of the reported issues are:
- AllenDang#206
  • Loading branch information
gucio321 committed Dec 18, 2023
1 parent 8da65d5 commit ad2f046
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
18 changes: 10 additions & 8 deletions cmd/codegen/gengo_typedefs.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import "unsafe"
continue
}

if IsEnumName(k, enums) || IsStructName(k, structs) {
if IsEnumName(k, enums) /*|| IsStructName(k, structs)*/ {
glg.Infof("typedef %s has extended deffinition in structs_and_enums.json. Will generate later", k)
continue
}
Expand Down Expand Up @@ -164,21 +164,23 @@ func new%[1]sFromC(cvalue *C.%[8]s) *%[1]s {
}

func writeOpaqueStruct(name CIdentifier, sb *strings.Builder) {
// we need to make it a struct, because we need to hide C type (otherwise it will duplicate methods)
fmt.Fprintf(sb, `
type %[1]s C.%[2]s
type %[1]s struct {
data *C.%[2]s
}
func (self %[1]s) handle() (result *C.%[2]s, fin func()) {
result = (*C.%[2]s)(unsafe.Pointer(&self))
return result, func() {}
func (self *%[1]s) handle() (result *C.%[2]s, fin func()) {
return self.data, func() {}
}
func (self %[1]s) c() (C.%[2]s, func()) {
result, fin := self.handle()
return *result, fin
result, fn := self.handle()
return *result, fn
}
func new%[1]sFromC(cvalue *C.%[2]s) *%[1]s {
return (*%[1]s)(cvalue)
return &%[1]s{data: cvalue}
}
`, name.renameGoIdentifier(), name)
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/codegen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ func main() {

// generate code
enumNames := generateGoEnums(*prefix, enums)
structNames := generateGoStructs(*prefix, structs, enums, es, ss, refTypedefs)
//structNames := generateGoStructs(*prefix, structs, enums, es, ss, refTypedefs)
structNames := make([]CIdentifier, 0)

structAccessorFuncs, err := generateCppStructsAccessor(*prefix, validFuncs, structs)
if err != nil {
Expand Down

0 comments on commit ad2f046

Please sign in to comment.