Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(703)

Unified Diff: mojo/public/platform/native_cgo/system_cgo.go

Issue 1000213003: go/bindings/cgo: allocate C structs on C side (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/public/go/bindings/interface.go ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/platform/native_cgo/system_cgo.go
diff --git a/mojo/public/platform/native_cgo/system_cgo.go b/mojo/public/platform/native_cgo/system_cgo.go
index 5b97e4060b93dc6fa013cca72a355c437927c549..d1f4700de727332d021dc6532954dd3c91b394dd 100644
--- a/mojo/public/platform/native_cgo/system_cgo.go
+++ b/mojo/public/platform/native_cgo/system_cgo.go
@@ -5,6 +5,31 @@
package native_cgo
//#include "mojo/public/c/system/core.h"
+// // These functions are used to 8-byte align C structs.
+// MojoResult CreateSharedBuffer(struct MojoCreateSharedBufferOptions* options,
+// uint64_t num_bytes, MojoHandle* handle) {
+// struct MojoCreateSharedBufferOptions aligned_options = *options;
+// return MojoCreateSharedBuffer(&aligned_options, num_bytes, handle);
+// }
+//
+// MojoResult DuplicateBufferHandle(MojoHandle handle,
+// struct MojoDuplicateBufferHandleOptions* options, MojoHandle* duplicate) {
+// struct MojoDuplicateBufferHandleOptions aligned_options = *options;
+// return MojoDuplicateBufferHandle(handle, &aligned_options, duplicate);
+// }
+//
+// MojoResult CreateDataPipe(struct MojoCreateDataPipeOptions* options,
+// MojoHandle* producer, MojoHandle* consumer) {
+// struct MojoCreateDataPipeOptions aligned_options = *options;
+// return MojoCreateDataPipe(&aligned_options, producer, consumer);
+// }
+//
+// MojoResult CreateMessagePipe(struct MojoCreateMessagePipeOptions* options,
+// MojoHandle* handle0, MojoHandle* handle1) {
+// struct MojoCreateMessagePipeOptions aligned_options = *options;
+// return MojoCreateMessagePipe(&aligned_options, handle0, handle1);
+// }
+//
import "C"
import (
"reflect"
@@ -21,7 +46,7 @@ func (c *CGoSystem) CreateSharedBuffer(flags uint32, numBytes uint64) (int32, ui
C.MojoCreateSharedBufferOptionsFlags(flags),
}
var cHandle C.MojoHandle
- r := C.MojoCreateSharedBuffer(opts, C.uint64_t(numBytes), &cHandle)
+ r := C.CreateSharedBuffer(opts, C.uint64_t(numBytes), &cHandle)
return int32(r), uint32(cHandle)
}
@@ -32,7 +57,7 @@ func (c *CGoSystem) DuplicateBufferHandle(handle uint32, flags uint32) (int32, u
C.MojoDuplicateBufferHandleOptionsFlags(flags),
}
var cDuplicateHandle C.MojoHandle
- r := C.MojoDuplicateBufferHandle(C.MojoHandle(handle), opts, &cDuplicateHandle)
+ r := C.DuplicateBufferHandle(C.MojoHandle(handle), opts, &cDuplicateHandle)
return int32(r), uint32(cDuplicateHandle)
}
@@ -51,7 +76,7 @@ func (c *CGoSystem) UnmapBuffer(buf []byte) (result int32) {
func createDataPipeWithCOptions(opts *C.struct_MojoCreateDataPipeOptions) (result int32, producerHandle, consumerHandle uint32) {
var cProducerHandle, cConsumerHandle C.MojoHandle
- r := C.MojoCreateDataPipe(opts, &cProducerHandle, &cConsumerHandle)
+ r := C.CreateDataPipe(opts, &cProducerHandle, &cConsumerHandle)
return int32(r), uint32(cProducerHandle), uint32(cConsumerHandle)
}
@@ -162,7 +187,7 @@ func (c *CGoSystem) CreateMessagePipe(flags uint32) (int32, uint32, uint32) {
C.uint32_t(unsafe.Sizeof(*opts)),
C.MojoCreateMessagePipeOptionsFlags(flags),
}
- r := C.MojoCreateMessagePipe(opts, &handle0, &handle1)
+ r := C.CreateMessagePipe(opts, &handle0, &handle1)
return int32(r), uint32(handle0), uint32(handle1)
}
« no previous file with comments | « mojo/public/go/bindings/interface.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698