]> Cypherpunks.ru repositories - gostls13.git/commitdiff
plugin: darwin support
authorDavid Crawshaw <crawshaw@golang.org>
Mon, 19 Sep 2016 18:09:07 +0000 (14:09 -0400)
committerDavid Crawshaw <crawshaw@golang.org>
Fri, 23 Sep 2016 02:16:42 +0000 (02:16 +0000)
Change-Id: I76981d1d83da401178226634d076371a04f5ccb7
Reviewed-on: https://go-review.googlesource.com/29392
Run-TryBot: David Crawshaw <crawshaw@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/plugin/plugin_dlopen.go
src/plugin/plugin_stubs.go

index 45c0eeb07fd141d2958e0ad65034df5b6c72a307..e881b258e0db333a85aad0e284c3094c1a58c16a 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build linux,cgo
+// +build linux,cgo darwin,cgo
 
 package plugin
 
@@ -13,6 +13,8 @@ package plugin
 #include <stdlib.h>
 #include <stdint.h>
 
+#include <stdio.h>
+
 static uintptr_t pluginOpen(const char* path, char** err) {
        void* h = dlopen(path, RTLD_NOW|RTLD_GLOBAL);
        if (h == NULL) {
@@ -38,12 +40,18 @@ import (
 )
 
 func open(name string) (*Plugin, error) {
-       pluginsMu.Lock()
+       cPath := (*C.char)(C.malloc(C.PATH_MAX + 1))
+       defer C.free(unsafe.Pointer(cPath))
+
        cRelName := C.CString(name)
-       cPath := C.realpath(cRelName, nil)
+       if C.realpath(cRelName, cPath) == nil {
+               return nil, errors.New("plugin.Open(" + name + "): realpath failed")
+       }
        C.free(unsafe.Pointer(cRelName))
-       defer C.free(unsafe.Pointer(cPath))
+
        path := C.GoString(cPath)
+
+       pluginsMu.Lock()
        if p := plugins[path]; p != nil {
                pluginsMu.Unlock()
                <-p.loaded
@@ -61,6 +69,7 @@ func open(name string) (*Plugin, error) {
        if len(name) > 3 && name[len(name)-3:] == ".so" {
                name = name[:len(name)-3]
        }
+
        syms := lastmoduleinit()
        if plugins == nil {
                plugins = make(map[string]*Plugin)
index 1b935bffa91c7f641a81cc3676d6cbacae083b92..f0bcb4a3bdf3a0243e98864d566bdb392056f25f 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build !linux !cgo
+// +build !linux,!darwin !cgo
 
 package plugin