From: Hraban Luyat Date: Mon, 13 Jul 2015 21:56:08 +0000 (+0100) Subject: Simplify CGO callback chain X-Git-Tag: v2.0.0~81 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=ea0b415d37b5bf9e8423a9e132e59a14d1ddd241;p=go-opus.git Simplify CGO callback chain --- diff --git a/callback_proxy.c b/callback_proxy.c deleted file mode 100644 index dfa1031..0000000 --- a/callback_proxy.c +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Named proxy callback function, see - * - * https://code.google.com/p/go-wiki/wiki/cgo - */ - -#include "callback_proxy.h" - -int go_readproxy(void *p, unsigned char *buf, int nbytes); - -int -c_readproxy(void *p, unsigned char *buf, int nbytes) -{ - return go_readproxy(p, buf, nbytes); -} diff --git a/callback_proxy.h b/callback_proxy.h deleted file mode 100644 index f8456c8..0000000 --- a/callback_proxy.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -int c_readproxy(void *p, unsigned char *buf, int nbytes); diff --git a/stream.go b/stream.go index 37a039e..af6cff4 100644 --- a/stream.go +++ b/stream.go @@ -10,7 +10,9 @@ import ( #cgo CFLAGS: -std=c99 -Wall -Werror -pedantic -Ibuild/include/opus #include #include -#include "callback_proxy.h" + +// Uses the same signature as Go, no need for proxy +int go_readcallback(void *p, unsigned char *buf, int nbytes); */ import "C" @@ -21,8 +23,8 @@ type Stream struct { buf []byte } -//export go_readproxy -func go_readproxy(p unsafe.Pointer, cbuf *C.uchar, cmaxbytes C.int) C.int { +//export go_readcallback +func go_readcallback(p unsafe.Pointer, cbuf *C.uchar, cmaxbytes C.int) C.int { stream := (*Stream)(p) maxbytes := int(cmaxbytes) if maxbytes > cap(stream.buf) { @@ -39,7 +41,7 @@ func go_readproxy(p unsafe.Pointer, cbuf *C.uchar, cmaxbytes C.int) C.int { } var callbacks = C.struct_OpusFileCallbacks{ - read: C.op_read_func(C.c_readproxy), + read: C.op_read_func(C.go_readcallback), seek: nil, tell: nil, close: nil,