From e29ae58a9c75d9249dedc79881c6928ef8784163 Mon Sep 17 00:00:00 2001 From: Greg Date: Fri, 31 May 2019 12:42:52 -0400 Subject: [PATCH] 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. --- main.go | 5 +++++ wrap/main.go | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index c6d589d..8810ee4 100644 --- a/main.go +++ b/main.go @@ -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) diff --git a/wrap/main.go b/wrap/main.go index 8f4e7c2..33e340a 100644 --- a/wrap/main.go +++ b/wrap/main.go @@ -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 {