Исходный код СУБД 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
//go:build windows
 
package onnxruntime
 
/*
#include "cshim.h"
#include <stdlib.h>
*/
import "C"
import (
    "fmt"
    "syscall"
    "unsafe"
)
 
// ortPath converts path to a NUL-terminated ORTCHAR_T* for the ORT C API.
// The returned release func must be called once the C call has returned.
//
// On Windows ORTCHAR_T is wchar_t, so the path must be UTF-16. The []uint16
// that UTF16PtrFromString allocates holds no Go pointers, and ORT copies the
// path during the call rather than retaining it, so passing Go memory to C is
// permitted here and no copy into C memory is needed.
func ortPath(path string) (*C.ORTCHAR_T, func(), error) {
    if err := rejectNUL(path, "path"); err != nil {
        return nil, func() {}, err
    }
    p, err := syscall.UTF16PtrFromString(path)
    if err != nil {
        return nil, func() {}, fmt.Errorf("ort: invalid path %q: %w", path, err)
    }
    return (*C.ORTCHAR_T)(unsafe.Pointer(p)), func() {}, nil
}