Archive for June, 2017

my libproxy-golang

June 22, 2017

Sometimes it is necessary to write cgo based wrappers for existing libraries. Golang makes this pretty painless, writing https://github.com/mvo5/libproxy-golang was really quick and a fun Saturday morning project.

The only slight annoyance is the lack of convenience helpers around dealing with C `char**`. Fortunately there are some tricks like creating an “overlay” go-slice of `*C.char` which makes working with `char**` easier:

p := C.thing_that_returns_char**()
// go provides no pointer arithmetic, so make a new huge
// go slice of char* and iterate over that
tmpSlice := (*[1<<30]*C.char)(unsafe.Pointer(p))

It would be nice though if cgo had some better helpers for this.