Skip to content

Commit 8383bd7

Browse files
Both go and python code is now compiling. Automatic Test are failing.
1 parent a01ef4e commit 8383bd7

File tree

2 files changed

+27
-24
lines changed

2 files changed

+27
-24
lines changed

bind/gen.go

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -86,26 +86,13 @@ static inline void gopy_err_handle() {
8686
PyErr_Print();
8787
}
8888
}
89-
9089
static PyObject* Py_BuildValue1(const char *format, void* arg0)
9190
{
9291
return Py_BuildValue(format, arg0);
9392
}
94-
static PyObject* Py_BuildValue2(const char *format, void* arg0, void* arg1)
95-
{
96-
return Py_BuildValue(format, arg0, arg1);
97-
}
98-
static PyObject * Py_BuildValue3(const char *format, void* arg0, void* arg1, void* arg2)
99-
{
100-
return Py_BuildValue(format, arg0, arg1, arg2);
101-
}
102-
static PyObject * Py_BuildValue4(const char *format, void* arg0, void* arg1, void* arg2, void* arg3)
103-
{
104-
return Py_BuildValue(format, arg0, arg1, arg2, arg3);
105-
}
106-
static PyObject * Py_BuildValue5(const char *format, void* arg0, void* arg1, void* arg2, void* arg3, void* arg4)
93+
static PyObject* Py_BuildValue2(const char *format, long long arg0)
10794
{
108-
return Py_BuildValue(format, arg0, arg1, arg2, arg3, arg4);
95+
return Py_BuildValue(format, arg0);
10996
}
11097
11198
%[9]s

bind/gen_func.go

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,13 @@ func isIfaceHandle(gdoc string) (bool, string) {
239239
return false, gdoc
240240
}
241241

242+
func isPointer(pyfmt string) bool {
243+
if (pyfmt == "s") {
244+
return true
245+
}
246+
return false
247+
}
248+
242249
func (g *pyGen) genFuncBody(sym *symbol, fsym *Func) {
243250
isMethod := (sym != nil)
244251
isIface := false
@@ -385,7 +392,7 @@ if __err != nil {
385392
}
386393

387394
// Call upstream method and collect returns.
388-
g.pywrap.Printf(fmt.Sprintf("%s := %s\n", strings.Join(retvars, ", "), pyFuncCall))
395+
g.pywrap.Printf(fmt.Sprintf("%s = %s\n", strings.Join(retvars, ", "), pyFuncCall))
389396

390397
// ReMap handle returns from pyFuncCall.
391398
for i := 0; i < npyres; i++ {
@@ -475,7 +482,7 @@ if __err != nil {
475482

476483
if buildPyTuple(fsym) {
477484
g.gofile.Printf("\n")
478-
formatStr := ""
485+
g.gofile.Printf("retTuple := C.PyTuple_New(%d);\n", npyres)
479486
for i := 0; i < npyres; i++ {
480487
sret := current.symtype(res[i].GoType())
481488
if sret == nil {
@@ -484,16 +491,25 @@ if __err != nil {
484491
res[i].Name(),
485492
))
486493
}
494+
formatStr := sret.pyfmt
487495
if sret.pyfmt == "" {
488-
formatStr += "?"
489-
} else {
490-
formatStr += sret.pyfmt
496+
formatStr = "?"
497+
}
498+
499+
buildValueFunc := "C.Py_BuildValue1"
500+
typeCast := "unsafe.Pointer"
501+
if !isPointer(formatStr) {
502+
buildValueFunc = "C.Py_BuildValue2"
503+
typeCast = "C.longlong"
491504
}
505+
valueCall := fmt.Sprintf("%s(C.CString(\"%s\"), %s(%s))",
506+
buildValueFunc,
507+
formatStr,
508+
typeCast,
509+
retvals[i])
510+
g.gofile.Printf("C.PyTuple_SetItem(retTuple, %d, %s);\n", i, valueCall)
492511
}
493-
g.gofile.Printf("return unsafe.Pointer(C.Py_BuildValue%d(\"%s\", %s))\n",
494-
npyres,
495-
formatStr,
496-
strings.Join(retvals[0:npyres], ", "))
512+
g.gofile.Printf("return unsafe.Pointer(retTuple);")
497513
} else {
498514
g.gofile.Printf("return %s\n", strings.Join(retvals[0:npyres], ", "))
499515
}

0 commit comments

Comments
 (0)