Skip to content
This repository was archived by the owner on Jul 24, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion capi.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ func Py_BuildValue(format string, args ...interface{}) *PyObject {
// ml_doc char * points to the contents of the docstring
type PyMethodDef struct {
Name string // name of the method
Meth func(self, args *PyObject) *PyObject
Meth PyCFunction
Flags MethodDefFlags
Doc string
}

type PyCFunction C.PyCFunction

type MethodDefFlags int

const (
Expand Down
4 changes: 3 additions & 1 deletion heap.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func cpyMethodDefs(name string, methods []PyMethodDef) *C.PyMethodDef {
for i, meth := range methods {
cmeth := C.PyMethodDef{
ml_name: C.CString(meth.Name),
ml_meth: (C.PyCFunction)(unsafe.Pointer(&meth.Meth)),
ml_meth: C.PyCFunction(meth.Meth),
ml_flags: C.int(meth.Flags),
ml_doc: C.CString(meth.Doc),
}
Expand All @@ -43,6 +43,7 @@ func Py_InitModule(name string, methods []PyMethodDef) (*PyObject, error) {

obj := togo(C._gopy_InitModule(c_mname, cmeths))
if obj == nil {
PyErr_Print()
return nil, errors.New("python: internal error; module creation failed.")
}
return obj, nil
Expand All @@ -59,6 +60,7 @@ func Py_InitModule3(name string, methods []PyMethodDef, doc string) (*PyObject,

obj := togo(C._gopy_InitModule3(cname, cmeths, cdoc))
if obj == nil {
PyErr_Print()
return nil, errors.New("python: internal error; module creation failed.")
}
return obj, nil
Expand Down