Skip to content

Commit 7004871

Browse files
committed
Add relevant parameters for pybindgen when a PyObject* is part of the function signature.
This occurs when dealing with a slice of complex numbers.
1 parent 1018dfd commit 7004871

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

bind/gen_slice.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,13 @@ otherwise parameter is a python list that we copy from
313313
g.gofile.Outdent()
314314
g.gofile.Printf("}\n\n")
315315

316-
g.pybuild.Printf("mod.add_function('%s_elem', retval('%s'), [param('%s', 'handle'), param('int', 'idx')])\n", slNm, esym.cpyname, PyHandle)
316+
var caller_owns_ret string
317+
var transfer_ownership string
318+
if esym.cpyname == "PyObject*" {
319+
caller_owns_ret = ", caller_owns_return=True"
320+
transfer_ownership = ", transfer_ownership=False"
321+
}
322+
g.pybuild.Printf("mod.add_function('%s_elem', retval('%s'%s), [param('%s', 'handle'), param('int', 'idx')])\n", slNm, esym.cpyname, caller_owns_ret, PyHandle)
317323

318324
if slc.isSlice() {
319325
g.gofile.Printf("//export %s_subslice\n", slNm)
@@ -340,7 +346,7 @@ otherwise parameter is a python list that we copy from
340346
g.gofile.Outdent()
341347
g.gofile.Printf("}\n\n")
342348

343-
g.pybuild.Printf("mod.add_function('%s_set', None, [param('%s', 'handle'), param('int', 'idx'), param('%v', 'value')])\n", slNm, PyHandle, esym.cpyname)
349+
g.pybuild.Printf("mod.add_function('%s_set', None, [param('%s', 'handle'), param('int', 'idx'), param('%v', 'value'%s)])\n", slNm, PyHandle, esym.cpyname, transfer_ownership)
344350

345351
if slc.isSlice() {
346352
g.gofile.Printf("//export %s_append\n", slNm)
@@ -355,7 +361,7 @@ otherwise parameter is a python list that we copy from
355361
g.gofile.Outdent()
356362
g.gofile.Printf("}\n\n")
357363

358-
g.pybuild.Printf("mod.add_function('%s_append', None, [param('%s', 'handle'), param('%s', 'value')])\n", slNm, PyHandle, esym.cpyname)
364+
g.pybuild.Printf("mod.add_function('%s_append', None, [param('%s', 'handle'), param('%s', 'value'%s)])\n", slNm, PyHandle, esym.cpyname, transfer_ownership)
359365
}
360366
}
361367
}

0 commit comments

Comments
 (0)