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

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

I worked on detecting errors from functions and returning a Go error by handling them in a pythonic way. Go handles an abnormal state by returning error values. This is the pretty straightforward way of handling errors. And this is the feature which gopy should provide.

So gopy’s strategy of supporting this features is very simple. If cgo function return values include an error which is not null then gopy raises RuntimeError.

And I wrote implementations of this strategy for the CFFI engine. Finally, I submitted a pull request and got some feedback from Sebastien and then the pull request was merged!, now we can use this feature on PyPy and CPython3.

Here is the example. I tested pyerrors.go and run it on the PyPy with a test.py.

root@180a6474ebba:~/go/src/github.com/go-python/gopy/_examples/pyerrors# pypy test.py 
Divide by zero.
pyerrors.Div(5, 2) = 2

CFFI engine succeeded to detection error! On the week 4, I worked on cffi: Support struct types. I will talk about it in the next post.

Thank you.

Happy hacking

Written on June 24, 2017