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

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

For this week, I worked on cffi: Support struct types. A struct is very useful user defined type of Go. So that supporting the struct by gopy is a very important goal for this project. If you want to know more about struct in Go. Please read this documentation.

My approach to support struct types could be divided into 3 steps.

  1. Generating C definitions of the struct, member methods and member variables which should be exported.
  2. Generating wrapped Python class for the struct type.
  3. Generating utility functions which converting between Python class and C.

I submitted a PR for this works after implemented this 3 steps. And Sebastien reviewed codes and left comments for test codes. Also requested generating comments for C definitions.

After review process was done, this PR was merged!!! Now, structs.go could be run on the PyPy and Python3 by CFFI engine.

root@180a6474ebba:~/go/src/github.com/go-python/gopy/_examples/structs# pypy test.py 
s = structs.S()
s = structs.S{}
s.Init()
s.Upper('boo')= 'BOO'
s1 = structs.S1()
s1 = structs.S1{private:0}
caught error: 'S1' object has no attribute 'private'
s2 = structs.S2()
s2 = structs.S2{Public:0, private:0}
s2 = structs.S2(1)
s2 = structs.S2{Public:1, private:0}
caught error: S2.__init__ takes at most 1 argument(s)
s2 = structs.S2{Public:42, private:0}
s2.Public = 42
caught error: 'S2' object has no attribute 'private'

On the week 7, I worked on cffi: Support named type. I will talk about it in the next post.

Thank you.

Happy hacking

Written on July 15, 2017