-
Notifications
You must be signed in to change notification settings - Fork 119
/
Copy pathbind.go
79 lines (62 loc) · 1.64 KB
/
bind.go
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
79
// Copyright 2015 The go-python Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package bind
import (
"bytes"
"errors"
"fmt"
"io"
"os"
)
// BindCfg is a configuration used during binding generation
type BindCfg struct {
// output directory for bindings
OutputDir string
// name of output package (otherwise name of first package is used)
Name string
// code string to run in the go main() function in the cgo library
Main string
// the full command args as a string, without path to exe
Cmd string
// path to python interpreter
VM string
// package prefix used when generating python import statements
PkgPrefix string
// rename Go exported symbols to python PEP snake_case
RenameCase bool
// If set, python exceptions are not thrown.
NoPyExceptions bool
// Path to Go module, which is to be used to translate Go errors to Python exceptions.
ModPathGoErr2PyEx string
// If set, when a Go function returns a (value, err), python returns (value, ) tuple.
// By default, we return just value.
UsePyTuple4VE bool
}
// ErrorList is a list of errors
type ErrorList []error
func (list *ErrorList) Add(err error) {
if err == nil {
return
}
*list = append(*list, err)
}
func (list *ErrorList) Error() error {
buf := new(bytes.Buffer)
for i, err := range *list {
if i > 0 {
buf.WriteRune('\n')
}
io.WriteString(buf, err.Error())
}
return errors.New(buf.String())
}
const (
doDebug = true
)
func debugf(format string, args ...interface{}) (int, error) {
if doDebug {
return fmt.Fprintf(os.Stderr, format, args...)
}
return 0, nil
}