8000 Add an implementation of Py_InitModule. · hdfsun/go-python@79b593f · GitHub
[go: up one dir, main page]

Skip to content

Commit 79b593f

Browse files
committed
Add an implementation of Py_InitModule.
1 parent f203f28 commit 79b593f

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

heap.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package python
2+
3+
/*
4+
#include <Python.h>
5+
6+
static PyObject* _gopy_InitModule(const char* nm, PyMethodDef* methods) {
7+
return Py_InitModule(nm, methods);
8+
}
9+
*/
10+
import "C"
11+
import (
12+
"errors"
13+
"unsafe"
14+
)
15+
16+
func Py_InitModule(name string) (*PyObject, error) {
17+
c_mname := C.CString(name)
18+
defer C.free(unsafe.Pointer(c_mname))
19+
obj := togo(C._gopy_InitModule(c_mname, nil))
20+
if obj == nil {
21+
return nil, errors.New("python: internal error; module creation failed.")
22+
}
23+
return obj, nil
24+
}
25+
26+
// EOF

0 commit comments

Comments
 (0)
0