This repository has been archived by the owner on Aug 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 140
/
errors.go
167 lines (134 loc) · 5.52 KB
/
errors.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
Unless explicitly stated otherwise all files in this repository are licensed
under the MIT License.
This product includes software developed at Datadog (https://www.datadoghq.com/).
Copyright 2018 Datadog, Inc.
*/
package python3
/*
#include "Python.h"
*/
import "C"
import (
"unsafe"
)
//PyErr_Clear : https://docs.python.org/3/c-api/exceptions.html#c.PyErr_Clear
func PyErr_Clear() {
C.PyErr_Clear()
}
//PyErr_PrintEx : https://docs.python.org/3/c-api/exceptions.html#c.PyErr_PrintEx
func PyErr_PrintEx(setSysLastVars bool) {
if setSysLastVars {
C.PyErr_PrintEx(1)
} else {
C.PyErr_PrintEx(0)
}
}
//PyErr_Print : https://docs.python.org/3/c-api/exceptions.html#c.PyErr_Print
func PyErr_Print() {
C.PyErr_PrintEx(1)
}
//PyErr_WriteUnraisable : https://docs.python.org/3/c-api/exceptions.html#c.PyErr_WriteUnraisable
func PyErr_WriteUnraisable(obj *PyObject) {
C.PyErr_WriteUnraisable(toc(obj))
}
//PyErr_SetString : https://docs.python.org/3/c-api/exceptions.html#c.PyErr_SetString
func PyErr_SetString(pyType *PyObject, message string) {
cmessage := C.CString(message)
defer C.free(unsafe.Pointer(cmessage))
C.PyErr_SetString(toc(pyType), cmessage)
}
//PyErr_SetObject : https://docs.python.org/3/c-api/exceptions.html#c.PyErr_SetObject
func PyErr_SetObject(pyType, value *PyObject) {
C.PyErr_SetObject(toc(pyType), toc(value))
}
//PyErr_SetNone : https://docs.python.org/3/c-api/exceptions.html#c.PyErr_SetNone
func PyErr_SetNone(pyType *PyObject) {
C.PyErr_SetNone(toc(pyType))
}
//PyErr_BadArgument : https://docs.python.org/3/c-api/exceptions.html#c.PyErr_BadArgument
func PyErr_BadArgument() {
C.PyErr_BadArgument()
}
//PyErr_NoMemory : https://docs.python.org/3/c-api/exceptions.html#c.PyErr_NoMemory
func PyErr_NoMemory() *PyObject {
return togo(C.PyErr_NoMemory())
}
//PyErr_SetImportErrorSubclass : https://docs.python.org/3/c-api/exceptions.html#c.PyErr_SetImportErrorSubclass
func PyErr_SetImportErrorSubclass(msg, name, path, subclass *PyObject) *PyObject {
return togo(C.PyErr_SetImportErrorSubclass(toc(msg), toc(name), toc(path), toc(subclass)))
}
//PyErr_SetImportError : https://docs.python.org/3/c-api/exceptions.html#c.PyErr_SetImportError
func PyErr_SetImportError(msg, name, path *PyObject) *PyObject {
return togo(C.PyErr_SetImportError(toc(msg), toc(name), toc(path)))
}
//PyErr_SyntaxLocationObject : https://docs.python.org/3/c-api/exceptions.html#c.PyErr_SyntaxLocationObject
func PyErr_SyntaxLocationObject(filename *PyObject, lineno, col_offset int) {
C.PyErr_SyntaxLocationObject(toc(filename), C.int(lineno), C.int(col_offset))
}
//PyErr_SyntaxLocationEx : https://docs.python.org/3/c-api/exceptions.html#c.PyErr_SyntaxLocationEx
func PyErr_SyntaxLocationEx(filename string, lineno, col_offset int) {
cfilename := C.CString(filename)
defer C.free(unsafe.Pointer(cfilename))
C.PyErr_SyntaxLocationEx(cfilename, C.int(lineno), C.int(col_offset))
}
//PyErr_SyntaxLocation : https://docs.python.org/3/c-api/exceptions.html#c.PyErr_SyntaxLocation
func PyErr_SyntaxLocation(filename string, lineno int) {
cfilename := C.CString(filename)
defer C.free(unsafe.Pointer(cfilename))
C.PyErr_SyntaxLocation(cfilename, C.int(lineno))
}
//PyErr_BadInternalCall : https://docs.python.org/3/c-api/exceptions.html#c.PyErr_BadInternalCall
func PyErr_BadInternalCall() {
C.PyErr_BadInternalCall()
}
//PyErr_Occurred : https://docs.python.org/3/c-api/exceptions.html#c.PyErr_Occurred
func PyErr_Occurred() *PyObject {
return togo(C.PyErr_Occurred())
}
//PyErr_GivenExceptionMatches : https://docs.python.org/3/c-api/exceptions.html#c.PyErr_GivenExceptionMatches
func PyErr_GivenExceptionMatches(given, exc *PyObject) bool {
ret := C.PyErr_GivenExceptionMatches(toc(given), toc(exc))
return ret == 1
}
//PyErr_ExceptionMatches : https://docs.python.org/3/c-api/exceptions.html#c.PyErr_ExceptionMatches
func PyErr_ExceptionMatches(exc *PyObject) bool {
ret := C.PyErr_ExceptionMatches(toc(exc))
return ret == 1
}
//PyErr_Fetch : https://docs.python.org/3/c-api/exceptions.html#c.PyErr_Fetch
func PyErr_Fetch() (*PyObject, *PyObject, *PyObject) {
var pyType, value, traceback *C.PyObject
C.PyErr_Fetch(&pyType, &value, &traceback)
return togo(pyType), togo(value), togo(traceback)
}
//PyErr_Restore : https://docs.python.org/3/c-api/exceptions.html#c.PyErr_Restore
func PyErr_Restore(pyType *PyObject, value *PyObject, traceback *PyObject) {
C.PyErr_Restore(toc(pyType), toc(value), toc(traceback))
}
//PyErr_NormalizeException : https://docs.python.org/3/c-api/exceptions.html#c.PyErr_NormalizeException
func PyErr_NormalizeException(exc, val, tb *PyObject) (*PyObject, *PyObject, *PyObject) {
cexc := toc(exc)
cval := toc(val)
ctb := toc(tb)
C.PyErr_NormalizeException(&cexc, &cval, &ctb)
return togo(cexc), togo(cval), togo(ctb)
}
//PyErr_GetExcInfo : https://docs.python.org/3/c-api/exceptions.html#c.PyErr_GetExcInfo
func PyErr_GetExcInfo() (*PyObject, *PyObject, *PyObject) {
var pyType, value, traceback *C.PyObject
C.PyErr_GetExcInfo(&pyType, &value, &traceback)
return togo(pyType), togo(value), togo(traceback)
}
//PyErr_SetExcInfo : https://docs.python.org/3/c-api/exceptions.html#c.PyErr_SetExcInfo
func PyErr_SetExcInfo(pyType *PyObject, value *PyObject, traceback *PyObject) {
C.PyErr_SetExcInfo(toc(pyType), toc(value), toc(traceback))
}
//PyErr_CheckSignals : https://docs.python.org/3/c-api/exceptions.html#c.PyErr_CheckSignals
func PyErr_CheckSignals() int {
return int(C.PyErr_CheckSignals())
}
//PyErr_SetInterrupt : https://docs.python.org/3/c-api/exceptions.html#c.PyErr_SetInterrupt
func PyErr_SetInterrupt() {
C.PyErr_SetInterrupt()
}