[GSoC 2017] Coding period Week 9 with gopy@CERN-HSF

GSoC2017 Hi, all! This post is about what I did for on 9th week of the coding period at Google Summer of Code 2017.

For this week, I worked on Implement wrapping of functions with slices/arrays of builtin arguments. gopy already supported to pass arguments into a function as wrapped Go slices and arrays but did not support Python list arguments. So this week, I worked on to support Python list argument.

Most of the needed thing to support this feature were done after we successfully support unnamed/named types by CFFI backend. So what is needed to be implemented is generating methods which convert types between go types and Python types.

By using this generated methods, a Python function which wrapped a cgo function receives Python argument, function detects this argument is wrapped type or not. if the arguments are not wrapped types then the function will convert arguments into the wrapped type arguments by using generated method.

I submitted my PR based on which I described. My mentor Sebastien commented about the unit tests and I fixed them. After my PR was merged, gopy successfully run slices.go and arrays.go.

root@180a6474ebba:~/go/src/github.com/go-python/gopy/_examples/arrays# gopy bind --lang=cffi .
root@180a6474ebba:~/go/src/github.com/go-python/gopy/_examples/arrays# pypy test.py 
Python list: [1, 2, 3, 4]
Go array:  [4]int{1, 2, 3, 4}
arrays.IntSum from Python list: 10
arrays.IntSum from Go array: 10

root@180a6474ebba:~/go/src/github.com/go-python/gopy/_examples/slices# gopy bind --lang=cffi .
root@180a6474ebba:~/go/src/github.com/go-python/gopy/_examples/slices# pypy test.py 
Python list: [1, 2, 3, 4]
Go slice:  []int{1, 2, 3, 4}
slices.IntSum from Python list: 10
slices.IntSum from Go slice: 10

On the week 10, I worked on cffi: Support map. I will talk about it in the next post.

Thank you.

Happy hacking

Written on August 5, 2017