Skip to content

Commit 4bd7e75

Browse files
author
g.ph
committed
add UserException
1 parent 4ec546e commit 4bd7e75

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

PyErr.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@ package py3
22

33
import "github.com/aadog/py3-go/cpy3"
44

5+
var _UserException *PyObject
6+
7+
func UserException() *PyObject {
8+
return _UserException
9+
}
10+
11+
func PyErr_NewException(name string,base *PyObject,dict *PyObject)*PyObject{
12+
return PyObjectFromInst(cpy3.PyErr_NewException(name,base.instance,dict.instance))
13+
}
14+
515
func PyExc_Exception() *PyObject {
616
return PyObjectFromInst(cpy3.PyExc_Exception())
717
}

PyFunc.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ var SystemModuleMap = sync.Map{}
99

1010
func Initialize() {
1111
cpy3.Py_Initialize()
12+
_UserException=PyErr_NewException("gofunction.error",PyNil,PyNil)
1213
}
1314
func AddModuleToSystemMap(m *PyModule) {
1415
SystemModuleMap.Store(m.GetName(), m)

cpy3/PyErr.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package cpy3
22

3+
4+
func PyErr_NewException(name string,base uintptr,dict uintptr) uintptr {
5+
r,_,_:=pyErr_NewException.Call(GoStrToCStr(name),base,dict)
6+
return r
7+
}
38
func PyExc_Exception() uintptr {
49
return pyExc_Exception.Addr()
510
}

cpy3/importfuncs.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ var (
113113
pyExc_Exception = libpython3.NewProc("PyExc_Exception")
114114
pyExc_ValueError = libpython3.NewProc("PyExc_ValueError")
115115
pyErr_SetString = libpython3.NewProc("PyErr_SetString")
116+
pyErr_NewException = libpython3.NewProc("PyErr_NewException")
116117

117118
pyInstanceMethod_New = libpython3.NewProc("PyInstanceMethod_New")
118119

0 commit comments

Comments
 (0)