my libproxy-golang

Sometimes it is necessary to write cgo based wrappers for existing libraries. Golang makes this pretty painless, writing 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.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: