]> Sergey Matveev's repositories - go-opus.git/commitdiff
Simplify CGO callback chain
authorHraban Luyat <hraban@0brg.net>
Mon, 13 Jul 2015 21:56:08 +0000 (22:56 +0100)
committerHraban Luyat <hraban@0brg.net>
Mon, 13 Jul 2015 21:56:08 +0000 (22:56 +0100)
callback_proxy.c [deleted file]
callback_proxy.h [deleted file]
stream.go

diff --git a/callback_proxy.c b/callback_proxy.c
deleted file mode 100644 (file)
index dfa1031..0000000
+++ /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 (file)
index f8456c8..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-#pragma once
-
-int c_readproxy(void *p, unsigned char *buf, int nbytes);
index 37a039e60f53f9e062330276290e60fdc2a82646..af6cff4acca772bcdca36621ad1b5bc1437f4361 100644 (file)
--- a/stream.go
+++ b/stream.go
@@ -10,7 +10,9 @@ import (
 #cgo CFLAGS: -std=c99 -Wall -Werror -pedantic -Ibuild/include/opus
 #include <opusfile.h>
 #include <string.h>
-#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,