callbacks.c | 8 +++----- stream.go | 5 ++--- diff --git a/callbacks.c b/callbacks.c index 5645f30ddfee04b5ee6be70ab1a79834cf311cc8..d966f8c4e1bc916e78e76484542ece427651cc73 100644 --- a/callbacks.c +++ b/callbacks.c @@ -11,9 +11,7 @@ // Defined in Go. Uses the same signature as Go, no need for proxy function. int go_readcallback(void *p, unsigned char *buf, int nbytes); -// Allocated once, never moved. Pointer to this is safe for passing around -// between Go and C. -struct OpusFileCallbacks callbacks = { +static struct OpusFileCallbacks callbacks = { .read = go_readcallback, }; @@ -23,7 +21,7 @@ // value. This is legal C, but go test -race (-d=checkptr) complains anyway. So // we have this wrapper function to shush it. // https://groups.google.com/g/golang-nuts/c/995uZyRPKlU OggOpusFile * -my_open_callbacks(uintptr_t p, const OpusFileCallbacks *cb, int *error) +my_open_callbacks(uintptr_t p, int *error) { - return op_open_callbacks((void *)p, cb, NULL, 0, error); + return op_open_callbacks((void *)p, &callbacks, NULL, 0, error); } diff --git a/stream.go b/stream.go index 60f99e0ad515537a8d3684fcef9b088c5f6c7d6e..46e30fa56e92db4b9a3c0750a7d51777a506faa4 100644 --- a/stream.go +++ b/stream.go @@ -16,8 +16,7 @@ #include #include #include -extern struct OpusFileCallbacks callbacks; -OggOpusFile *my_open_callbacks(uintptr_t p, const OpusFileCallbacks *cb, int *error); +OggOpusFile *my_open_callbacks(uintptr_t p, int *error); */ import "C" @@ -105,7 +104,7 @@ // Save and Delete from the map around that every time a reader function is // called. streams.Save(s) defer streams.Del(s) - oggfile := C.my_open_callbacks(C.uintptr_t(s.id), &C.callbacks, &errno) + oggfile := C.my_open_callbacks(C.uintptr_t(s.id), &errno) if errno != 0 { return StreamError(errno) }