adds vendor directory

vendors dependencies in standard `vendor` directory, managed by glide
This commit is contained in:
Jon Chen
2017-05-14 19:35:03 -07:00
parent 070aa50762
commit 737231705f
2173 changed files with 2312028 additions and 0 deletions

29
vendor/github.com/mattn/go-pointer/README.md generated vendored Normal file
View File

@@ -0,0 +1,29 @@
# go-pointer
Utility for cgo
## Usage
https://github.com/golang/proposal/blob/master/design/12416-cgo-pointers.md
In go 1.6, cgo argument can't be passed Go pointer.
```
var s string
C.pass_pointer(pointer.Save(&s))
v := *(pointer.Restore(C.get_from_pointer()).(*string))
```
## Installation
```
go get github.com/mattn/go-pointer
```
## License
MIT
## Author
Yasuhiro Matsumoto (a.k.a mattn)

View File

@@ -0,0 +1,9 @@
#include <unistd.h>
typedef void (*callback)(void*);
static void call_later(int delay, callback cb, void* data) {
sleep(delay);
cb(data);
}

29
vendor/github.com/mattn/go-pointer/_example/main.go generated vendored Normal file
View File

@@ -0,0 +1,29 @@
package main
/*
#include "callback.h"
void call_later_go_cb(void*);
*/
import "C"
import (
"fmt"
"unsafe"
"github.com/mattn/go-pointer"
)
type Foo struct {
v int
}
func main() {
f := &Foo{123}
C.call_later(3, C.callback(C.call_later_go_cb), pointer.Save(f))
}
//export call_later_go_cb
func call_later_go_cb(data unsafe.Pointer) {
f := pointer.Restore(data).(*Foo)
fmt.Println(f.v)
}

13
vendor/github.com/mattn/go-pointer/example/example.go generated vendored Normal file
View File

@@ -0,0 +1,13 @@
package example
/*
void *pass_pointer(void* p) {
return p;
}
*/
import "C"
import "unsafe"
func PassPointer(ptr unsafe.Pointer) unsafe.Pointer {
return C.pass_pointer(ptr)
}

59
vendor/github.com/mattn/go-pointer/pointer.go generated vendored Normal file
View File

@@ -0,0 +1,59 @@
package pointer
// #include <stdlib.h>
import "C"
import (
"sync"
"unsafe"
)
var (
mutex sync.Mutex
store = map[unsafe.Pointer]interface{}{}
)
func Save(v interface{}) unsafe.Pointer {
if v == nil {
return nil
}
// Generate real fake C pointer.
// This pointer will not store any data, but will bi used for indexing purposes.
// Since Go doest allow to cast dangling pointer to unsafe.Pointer, we do rally allocate one byte.
// Why we need indexing, because Go doest allow C code to store pointers to Go data.
var ptr unsafe.Pointer = C.malloc(C.size_t(1))
if ptr == nil {
panic("can't allocate 'cgo-pointer hack index pointer': ptr == nil")
}
mutex.Lock()
store[ptr] = v
mutex.Unlock()
return ptr
}
func Restore(ptr unsafe.Pointer) interface{} {
if ptr == nil {
return nil
}
mutex.Lock()
defer mutex.Unlock()
if v, ok := store[ptr]; ok {
return v
}
return nil
}
func Unref(ptr unsafe.Pointer) {
if ptr == nil {
return
}
mutex.Lock()
delete(store, ptr)
mutex.Unlock()
C.free(ptr)
}