Add experimental "arc" directive to nswrap.yaml to experiment

with enabling Objective-C automatic reference counting. Bindings
currently will not compile with this turned on.
This commit is contained in:
Greg 2019-05-31 12:42:52 -04:00
parent 5a5a4f9406
commit e29ae58a9c
2 changed files with 19 additions and 2 deletions

View File

@ -33,6 +33,8 @@ type conf struct {
Sysimports []string
Pragma []string
Vaargs int
//Arc flag for debugging only, builds will break
Arc bool
}
var Config conf
@ -190,6 +192,9 @@ func Start() (err error) {
if Config.Positions {
ast.TrackPositions = true
}
if Config.Arc {
wrap.Arc = true
}
//NOTE: converting in parallel is slower on my system
//nodes := convertLinesToNodesParallel(lines)
nodes := convertLinesToNodes(lines)

View File

@ -15,6 +15,8 @@ import (
var (
Debug = false
// Arc flag is for debugging only, your builds will break if you turn it on
Arc = false
)
type Wrapper struct {
@ -55,9 +57,13 @@ func NewWrapper(debug bool) *Wrapper {
ProcessedClassMethods: map[string]bool{},
Vaargs: 16,
}
arc := " -fno-objc-arc"
if Arc {
arc = " -fobjc-arc"
}
ret.cgoFlags.WriteString(fmt.Sprintf(`/*
#cgo CFLAGS: -x objective-c
`))
#cgo CFLAGS: -x objective-c%s
`,arc))
ret.goTypes.WriteString(`
type Id struct {
ptr unsafe.Pointer
@ -432,6 +438,12 @@ func (w *Wrapper) AddProtocol(n *ast.ObjCProtocolDecl) {
for _,c := range n.Children() {
switch x := c.(type) {
case *ast.ObjCMethodDecl:
if Arc {
switch x.Name {
case "retain","release","autorelease":
continue
}
}
if x.ClassMethod {
w.AddMethod(p.ClassMethods,x)
} else {