Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
3 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//go:build !windows
 
package onnxruntime
 
/*
#cgo LDFLAGS: -ldl
#include <dlfcn.h>
#include <stdlib.h>
#include "cshim.h"
 
static void *ort_dlopen(const char *path) {
    return dlopen(path, RTLD_NOW | RTLD_LOCAL);
}
 
static void *ort_dlsym(void *handle, const char *symbol) {
    return dlsym(handle, symbol);
}
 
static void ort_dlclose(void *handle) {
    dlclose(handle);
}
 
static const char *ort_dlerror(void) {
    return dlerror();
}
*/
import "C"
import (
    "fmt"
    "runtime"
    "unsafe"
)
 
func platformLibraryName() string {
    if runtime.GOOS == "darwin" {
        return "libonnxruntime.dylib"
    }
    return "libonnxruntime.so"
}
 
// libHandle is the platform handle for a loaded shared library.
type libHandle unsafe.Pointer
 
// loadLibrary loads the shared library at path and resolves OrtGetApiBase.
// On success the caller owns the returned handle and must pass it to
// closeLibrary to unload the library.
func loadLibrary(path string) (unsafe.Pointer, libHandle, error) {
    if err := rejectNUL(path, "shared library path"); err != nil {
        return nil, nil, err
    }
    cpath := C.CString(path)
    defer C.free(unsafe.Pointer(cpath))
 
    handle := C.ort_dlopen(cpath)
    if handle == nil {
        errMsg := C.GoString(C.ort_dlerror())
        return nil, nil, fmt.Errorf("dlopen %s: %s", path, errMsg)
    }
 
    sym := C.CString("OrtGetApiBase")
    defer C.free(unsafe.Pointer(sym))
 
    fn := C.ort_dlsym(handle, sym)
    if fn == nil {
        errMsg := C.GoString(C.ort_dlerror())
        C.ort_dlclose(handle)
        return nil, nil, fmt.Errorf("dlsym OrtGetApiBase: %s", errMsg)
    }
 
    return fn, libHandle(handle), nil
}
 
// closeLibrary unloads a library previously returned by loadLibrary.
func closeLibrary(h libHandle) {
    if h != nil {
        C.ort_dlclose(unsafe.Pointer(h))
    }
}