Stop passing Go pointers to C

This commit is contained in:
Michael Steinert
2015-12-03 14:59:51 -06:00
parent 6534f23b39
commit 8ec1202046
5 changed files with 77 additions and 30 deletions

30
callback.go Normal file
View File

@@ -0,0 +1,30 @@
package pam
import "sync"
var cb struct {
sync.Mutex
m map[int]interface{}
c int
}
func cbAdd(v interface{}) int {
cb.Lock()
defer cb.Unlock()
if cb.m == nil {
cb.m = make(map[int]interface{})
}
cb.c++
cb.m[cb.c] = v
return cb.c
}
func cbGet(c int) interface{} {
cb.Lock()
defer cb.Unlock()
v := cb.m[c]
if v == nil {
panic("Callback pointer not found")
}
return v
}