Skip to content
This repository was archived by the owner on Jul 24, 2023. It is now read-only.

Commit 5167a7b

Browse files
committed
capi: prevent from directly wrapping Go functions
Fixes #102.
1 parent fb007b5 commit 5167a7b

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

capi.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ func Py_BuildValue(format string, args ...interface{}) *PyObject {
1616
// ml_doc char * points to the contents of the docstring
1717
type PyMethodDef struct {
1818
Name string // name of the method
19-
Meth func(self, args *PyObject) *PyObject
19+
Meth PyCFunction
2020
Flags MethodDefFlags
2121
Doc string
2222
}
2323

24+
type PyCFunction C.PyCFunction
25+
2426
type MethodDefFlags int
2527

2628
const (

heap.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func cpyMethodDefs(name string, methods []PyMethodDef) *C.PyMethodDef {
2424
for i, meth := range methods {
2525
cmeth := C.PyMethodDef{
2626
ml_name: C.CString(meth.Name),
27-
ml_meth: (C.PyCFunction)(unsafe.Pointer(&meth.Meth)),
27+
ml_meth: C.PyCFunction(meth.Meth),
2828
ml_flags: C.int(meth.Flags),
2929
ml_doc: C.CString(meth.Doc),
3030
}
@@ -43,6 +43,7 @@ func Py_InitModule(name string, methods []PyMethodDef) (*PyObject, error) {
4343

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

6061
obj := togo(C._gopy_InitModule3(cname, cmeths, cdoc))
6162
if obj == nil {
63+
PyErr_Print()
6264
return nil, errors.New("python: internal error; module creation failed.")
6365
}
6466
return obj, nil

0 commit comments

Comments
 (0)