bind: expose all public types to python module

Change-Id: I948838b37f0d5f909ae58797930ffe598dc539ca
This commit is contained in:
Sebastien Binet 2015-08-05 10:32:38 +02:00
parent 32c6f52cf8
commit a03b288886
1 changed files with 14 additions and 6 deletions

View File

@ -164,10 +164,14 @@ func (g *cpyGen) gen() error {
g.impl.Indent()
g.impl.Printf("PyObject *module = NULL;\n\n")
for _, s := range g.pkg.structs {
for _, n := range g.pkg.syms.names() {
sym := g.pkg.syms.sym(n)
if !sym.isType() {
continue
}
g.impl.Printf(
"if (PyType_Ready(&%sType) < 0) { return; }\n",
s.sym.cpyname,
sym.cpyname,
)
}
@ -176,11 +180,15 @@ func (g *cpyGen) gen() error {
g.pkg.doc.Doc,
)
for _, s := range g.pkg.structs {
g.impl.Printf("Py_INCREF(&%sType);\n", s.sym.cpyname)
for _, n := range g.pkg.syms.names() {
sym := g.pkg.syms.sym(n)
if !sym.isType() {
continue
}
g.impl.Printf("Py_INCREF(&%sType);\n", sym.cpyname)
g.impl.Printf("PyModule_AddObject(module, %q, (PyObject*)&%sType);\n\n",
s.GoName(),
s.sym.cpyname,
sym.goname,
sym.cpyname,
)
}
g.impl.Outdent()