| 1 | // Copyright 2014 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | package seqscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/ |
| 6 | |
| 7 | //#cgo LDFLAGS: -llog |
| 8 | //#include <android/log.h> |
| 9 | //#include <string.h> |
| 10 | //import "C" |
| 11 | |
| 12 | import ( |
| 13 | "fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/" |
| 14 | "runtimescip-go gomod github.com/golang/go/src go1.24.0 runtime/" |
| 15 | "syncscip-go gomod github.com/golang/go/src go1.24.0 sync/" |
| 16 | ) |
| 17 | |
| 18 | type countedObjscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/countedObj# struct { |
| 19 | objscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/countedObj#obj. interface{} |
| 20 | cntscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/countedObj#cnt. int32 |
| 21 | } |
| 22 | |
| 23 | // also known to bind/java/Seq.java and bind/objc/seq_darwin.m |
| 24 | const NullRefNumscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/NullRefNum. = 41 |
| 25 | |
| 26 | // refs stores Go objects that have been passed to another language. |
| 27 | var refsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/refs. struct { |
| 28 | syncscip-go gomod github.com/golang/go/src go1.24.0 sync/.Mutexscip-go gomod github.com/golang/go/src go1.24.0 sync/Mutex# |
| 29 | nextscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/refs:next. int32 // next reference number to use for Go object, always negative |
| 30 | refsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/refs:refs. map[interface{}]int32 |
| 31 | objsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/refs:objs. map[int32]countedObjscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/countedObj# |
| 32 | } |
| 33 | |
| 34 | func initscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/init().() { |
| 35 | refsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/refs..Lockscip-go gomod github.com/golang/go/src go1.24.0 sync/Mutex#Lock().() |
| 36 | refsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/refs..nextscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/refs:next. = -24 // Go objects get negative reference numbers. Arbitrary starting point. |
| 37 | refsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/refs..refsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/refs:refs. = make(map[interface{}]int32) |
| 38 | refsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/refs..objsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/refs:objs. = make(map[int32]countedObjscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/countedObj#) |
| 39 | refsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/refs..Unlockscip-go gomod github.com/golang/go/src go1.24.0 sync/Mutex#Unlock().() |
| 40 | } |
| 41 | |
| 42 | // A Ref represents a Java or Go object passed across the language |
| 43 | // boundary. |
| 44 | type Refscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/Ref# struct { |
| 45 | Bind_Numscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/Ref#Bind_Num. int32 |
| 46 | } |
| 47 | |
| 48 | type proxyscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/proxy# interface { |
| 49 | // Use a strange name and hope that user code does not implement it |
| 50 | Bind_proxy_refnum__scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/proxy#Bind_proxy_refnum__.() int32 |
| 51 | } |
| 52 | |
| 53 | // ToRefNum increments the reference count for an object and |
| 54 | // returns its refnum. |
| 55 | func ToRefNumscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/ToRefNum().(obj interface{}) int32 { |
| 56 | // We don't track foreign objects, so if obj is a proxy |
| 57 | // return its refnum. |
| 58 | if r, ok := obj.(proxyscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/proxy#); ok { |
| 59 | refnum := r.Bind_proxy_refnum__scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/proxy#Bind_proxy_refnum__.() |
| 60 | if refnum <= 0 { |
| 61 | panic(fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("seq: proxy contained invalid Go refnum: %d", refnum)) |
| 62 | } |
| 63 | return refnum |
| 64 | } |
| 65 | refsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/refs..Lockscip-go gomod github.com/golang/go/src go1.24.0 sync/Mutex#Lock().() |
| 66 | num := refsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/refs..refsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/refs:refs.[obj] |
| 67 | if num != 0 { |
| 68 | s := refsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/refs..objsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/refs:objs.[num] |
| 69 | refsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/refs..objsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/refs:objs.[num] = countedObjscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/countedObj#{s.objscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/countedObj#obj., s.cntscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/countedObj#cnt. + 1} |
| 70 | } else { |
| 71 | num = refsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/refs..nextscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/refs:next. |
| 72 | refsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/refs..nextscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/refs:next.-- |
| 73 | if refsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/refs..nextscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/refs:next. > 0 { |
| 74 | panic("refs.next underflow") |
| 75 | } |
| 76 | refsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/refs..refsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/refs:refs.[obj] = num |
| 77 | refsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/refs..objsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/refs:objs.[num] = countedObjscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/countedObj#{obj, 1} |
| 78 | } |
| 79 | refsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/refs..Unlockscip-go gomod github.com/golang/go/src go1.24.0 sync/Mutex#Unlock().() |
| 80 | |
| 81 | return num |
| 82 | } |
| 83 | |
| 84 | // FromRefNum returns the Ref for a refnum. If the refnum specifies a |
| 85 | // foreign object, a finalizer is set to track its lifetime. |
| 86 | func FromRefNumscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/FromRefNum().(num int32) *Refscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/Ref# { |
| 87 | if num == NullRefNumscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/NullRefNum. { |
| 88 | return nil |
| 89 | } |
| 90 | ref := &Refscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/Ref#{num} |
| 91 | if num > 0 { |
| 92 | // This is a foreign object reference. |
| 93 | // Track its lifetime with a finalizer. |
| 94 | runtimescip-go gomod github.com/golang/go/src go1.24.0 runtime/.SetFinalizerscip-go gomod github.com/golang/go/src go1.24.0 runtime/SetFinalizer().(ref, FinalizeRefscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/FinalizeRef.) |
| 95 | } |
| 96 | |
| 97 | return ref |
| 98 | } |
| 99 | |
| 100 | // Bind_IncNum increments the foreign reference count and |
| 101 | // return the refnum. |
| 102 | func (r *Refscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/Ref#) Bind_IncNumscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/Ref#Bind_IncNum().() int32 { |
| 103 | refnum := r.Bind_Numscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/Ref#Bind_Num. |
| 104 | IncForeignRefscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/IncForeignRef.(refnum) |
| 105 | // Make sure this reference is not finalized before |
| 106 | // the foreign reference count is incremented. |
| 107 | runtimescip-go gomod github.com/golang/go/src go1.24.0 runtime/.KeepAlivescip-go gomod github.com/golang/go/src go1.24.0 runtime/KeepAlive().(r) |
| 108 | return refnum |
| 109 | } |
| 110 | |
| 111 | // Get returns the underlying object. |
| 112 | func (r *Refscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/Ref#) Getscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/Ref#Get().() interface{} { |
| 113 | refnum := r.Bind_Numscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/Ref#Bind_Num. |
| 114 | refsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/refs..Lockscip-go gomod github.com/golang/go/src go1.24.0 sync/Mutex#Lock().() |
| 115 | o, ok := refsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/refs..objsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/refs:objs.[refnum] |
| 116 | refsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/refs..Unlockscip-go gomod github.com/golang/go/src go1.24.0 sync/Mutex#Unlock().() |
| 117 | if !ok { |
| 118 | panic(fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Sprintf().("unknown ref %d", refnum)) |
| 119 | } |
| 120 | // This is a Go reference and its refnum was incremented |
| 121 | // before crossing the language barrier. |
| 122 | Deletescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/Delete().(refnum) |
| 123 | return o.objscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/countedObj#obj. |
| 124 | } |
| 125 | |
| 126 | // Inc increments the reference count for a refnum. Called from Bind_proxy_refnum |
| 127 | // functions. |
| 128 | func Incscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/Inc().(num int32) { |
| 129 | refsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/refs..Lockscip-go gomod github.com/golang/go/src go1.24.0 sync/Mutex#Lock().() |
| 130 | o, ok := refsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/refs..objsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/refs:objs.[num] |
| 131 | if !ok { |
| 132 | panic(fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Sprintf().("seq.Inc: unknown refnum: %d", num)) |
| 133 | } |
| 134 | refsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/refs..objsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/refs:objs.[num] = countedObjscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/countedObj#{o.objscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/countedObj#obj., o.cntscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/countedObj#cnt. + 1} |
| 135 | refsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/refs..Unlockscip-go gomod github.com/golang/go/src go1.24.0 sync/Mutex#Unlock().() |
| 136 | } |
| 137 | |
| 138 | // Delete decrements the reference count and removes the pinned object |
| 139 | // from the object map when the reference count becomes zero. |
| 140 | func Deletescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/Delete().(num int32) { |
| 141 | refsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/refs..Lockscip-go gomod github.com/golang/go/src go1.24.0 sync/Mutex#Lock().() |
| 142 | defer refsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/refs..Unlockscip-go gomod github.com/golang/go/src go1.24.0 sync/Mutex#Unlock().() |
| 143 | o, ok := refsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/refs..objsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/refs:objs.[num] |
| 144 | if !ok { |
| 145 | panic(fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Sprintf().("seq.Delete unknown refnum: %d", num)) |
| 146 | } |
| 147 | if o.cntscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/countedObj#cnt. <= 1 { |
| 148 | delete(refsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/refs..objsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/refs:objs., num) |
| 149 | delete(refsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/refs..refsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/refs:refs., o.objscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/countedObj#obj.) |
| 150 | } else { |
| 151 | refsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/refs..objsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/refs:objs.[num] = countedObjscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/countedObj#{o.objscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/countedObj#obj., o.cntscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/countedObj#cnt. - 1} |
| 152 | } |
| 153 | } |