🌐 AI搜索 & 代理 主页
Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
1fe3270
Merge pull request #1 from rudderlabs/nisshar/VariadicFunctions
nishantsharma Jun 19, 2022
399dd4b
Go module path updated so that it can be installed.
nishant-rudderstack Jun 20, 2022
f6c26ce
Replacing gopy URL so that it works in forks too.
nishant-rudderstack Jun 20, 2022
4ea0c07
go package to test is at rudderlabs/gopy
nishant-rudderstack Jun 20, 2022
3e19314
Added test code for multireturn.
nishant-rudderstack Jun 12, 2022
d0d0d65
First stage changes made. Next step is to change the loop to reflect …
nishant-rudderstack Jun 12, 2022
b5b07fe
Python code being generated sensibly.
nishant-rudderstack Jun 12, 2022
c57ef41
Correcting npyres computation.
nishant-rudderstack Jun 13, 2022
b3c7b5d
Verfied generated python code, atleast for smaller ret-counts.
nishant-rudderstack Jun 13, 2022
d93d069
Code to handle multiple return values as tuples now logically complet…
nishant-rudderstack Jun 14, 2022
1ae7696
Both go and python code is now compiling. Automatic Test are failing.
nishant-rudderstack Jun 14, 2022
05d1874
Working quite a bit as expected. But, some memory corruption is causi…
nishant-rudderstack Jun 15, 2022
1e11675
Tests passing once we let memory leak. Fix for memory leaks to be car…
nishant-rudderstack Jun 19, 2022
14d81b4
Ignoring functions returning functions.
nishant-rudderstack Jun 23, 2022
2cb06f8
__err was getting reused in a way which declarations difficult. Fixed.
nishant-rudderstack Jun 23, 2022
1a54a50
Fixed a few code generation error for methods.
nishant-rudderstack Jun 23, 2022
9350594
Python None now mapped to GoLang nil.
nishant-rudderstack Jun 23, 2022
ea0d913
TestGovet and TestGofmt now passing.
nishant-rudderstack Jun 28, 2022
9020e61
Crash in gen command fixed.
nishant-rudderstack Jun 28, 2022
a44f1e5
gopyerrors is not applicable any more.
nishant-rudderstack Jun 28, 2022
35cda9d
Test failure bug fixed.
nishant-rudderstack Jun 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Both go and python code is now compiling. Automatic Test are failing.
  • Loading branch information
nishant-rudderstack committed Jul 4, 2022
commit 1ae769674dfb9e1330a8be1ab4fafe23bbf56dd9
17 changes: 2 additions & 15 deletions bind/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,26 +86,13 @@ static inline void gopy_err_handle() {
PyErr_Print();
}
}

static PyObject* Py_BuildValue1(const char *format, void* arg0)
{
return Py_BuildValue(format, arg0);
}
static PyObject* Py_BuildValue2(const char *format, void* arg0, void* arg1)
{
return Py_BuildValue(format, arg0, arg1);
}
static PyObject * Py_BuildValue3(const char *format, void* arg0, void* arg1, void* arg2)
{
return Py_BuildValue(format, arg0, arg1, arg2);
}
static PyObject * Py_BuildValue4(const char *format, void* arg0, void* arg1, void* arg2, void* arg3)
{
return Py_BuildValue(format, arg0, arg1, arg2, arg3);
}
static PyObject * Py_BuildValue5(const char *format, void* arg0, void* arg1, void* arg2, void* arg3, void* arg4)
static PyObject* Py_BuildValue2(const char *format, long long arg0)
{
return Py_BuildValue(format, arg0, arg1, arg2, arg3, arg4);
return Py_BuildValue(format, arg0);
}

%[9]s
Expand Down
34 changes: 25 additions & 9 deletions bind/gen_func.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,13 @@ func isIfaceHandle(gdoc string) (bool, string) {
return false, gdoc
}

func isPointer(pyfmt string) bool {
if (pyfmt == "s") {
return true
}
return false
}

func (g *pyGen) genFuncBody(sym *symbol, fsym *Func) {
isMethod := (sym != nil)
isIface := false
Expand Down Expand Up @@ -385,7 +392,7 @@ if __err != nil {
}

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

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

if buildPyTuple(fsym) {
g.gofile.Printf("\n")
formatStr := ""
g.gofile.Printf("retTuple := C.PyTuple_New(%d);\n", npyres)
for i := 0; i < npyres; i++ {
sret := current.symtype(res[i].GoType())
if sret == nil {
Expand All @@ -484,16 +491,25 @@ if __err != nil {
res[i].Name(),
))
}
formatStr := sret.pyfmt
if sret.pyfmt == "" {
formatStr += "?"
} else {
formatStr += sret.pyfmt
formatStr = "?"
}

buildValueFunc := "C.Py_BuildValue1"
typeCast := "unsafe.Pointer"
if !isPointer(formatStr) {
buildValueFunc = "C.Py_BuildValue2"
typeCast = "C.longlong"
}
valueCall := fmt.Sprintf("%s(C.CString(\"%s\"), %s(%s))",
buildValueFunc,
formatStr,
typeCast,
retvals[i])
g.gofile.Printf("C.PyTuple_SetItem(retTuple, %d, %s);\n", i, valueCall)
}
g.gofile.Printf("return unsafe.Pointer(C.Py_BuildValue%d(\"%s\", %s))\n",
npyres,
formatStr,
strings.Join(retvals[0:npyres], ", "))
g.gofile.Printf("return unsafe.Pointer(retTuple);")
} else {
g.gofile.Printf("return %s\n", strings.Join(retvals[0:npyres], ", "))
}
Expand Down