MCPcopy Create free account
hub / github.com/go-python/gopy / DecRef

Function DecRef

gopyh/handle.go:132–160  ·  view source on GitHub ↗

DecRef decrements the reference count for the specified handle and removes it if the reference count goes to zero.

(handle CGoHandle)

Source from the content-addressed store, hash-verified

130// DecRef decrements the reference count for the specified handle
131// and removes it if the reference count goes to zero.
132func DecRef(handle CGoHandle) {
133 if handle < 1 {
134 return
135 }
136 mu.Lock()
137 defer mu.Unlock()
138 if handles == nil {
139 return
140 }
141 ghc := GoHandle(handle)
142 if _, exists := handles[ghc]; !exists {
143 return
144 }
145 counts[ghc]--
146 switch cnt := counts[ghc]; {
147 case cnt == 0:
148 delete(counts, ghc)
149 delete(handles, ghc)
150 if trace {
151 fmt.Printf("gopy DecRef: %d\n", handle)
152 }
153 case cnt < 0:
154 panic(fmt.Sprintf("gopy DecRef ref count %v for handle: %v, ifc %v", cnt, ghc, handles[ghc]))
155 default:
156 if trace {
157 fmt.Printf("gopy DecRef: %d: %d\n", handle, cnt)
158 }
159 }
160}
161
162// IncRef increments the reference count for the specified handle.
163func IncRef(handle CGoHandle) {

Callers

nothing calls this directly

Calls 2

GoHandleTypeAlias · 0.85
PrintfMethod · 0.80

Tested by

no test coverage detected