C++ SWIG annoyances for Go

322 views
Skip to first unread message

Yutong Zhao

unread,
Sep 13, 2015, 3:18:43 PM9/13/15
to golang-nuts
I'm not sure who else here has been wrapping C++ code for Go, but some of the annoyances I've ran into are:

-lack of shared_ptr typemaps for Go (both std:: and boost::)
-std::vector doesn't map to go slices
-std::map doesn't map to go map
-go doesn't support permit overloaded functions
-not clear to me how to wrap virtual functions

If anyone has any suggestions for the problems above I'd love to hear solutions. Alternatively, I was wondering what were some of other issues people here have ran into?

Ian Lance Taylor

unread,
Sep 13, 2015, 3:27:48 PM9/13/15
to Yutong Zhao, golang-nuts
On Sun, Sep 13, 2015 at 12:10 PM, Yutong Zhao <prot...@gmail.com> wrote:
>
> I'm not sure who else here has been wrapping C++ code for Go, but some of
> the annoyances I've ran into are:
>
> -lack of shared_ptr typemaps for Go (both std:: and boost::)

This is hard to solve. We could use finalizers on the Go side but
it's hard to ensure that they only run when the pointer is no longer
being used.

> -std::vector doesn't map to go slices
> -std::map doesn't map to go map

What would these mean? Go slices and maps are reference types. C++
vector and map are not.

> -go doesn't support permit overloaded functions

Well, yes. It does permit SWIG wrapping C++ overloaded functions,
though.

> -not clear to me how to wrap virtual functions

This could mean a few different things, and I'm not sure what you
mean. Have you seen the code in misc/swig/callback in the Go
repository?


In general, Go and C++ are different languages. It's unrealistic to
safely and efficiently convert all constructs between them. I view
SWIG as doing the mechanical parts of calling between the languages.
You still have to write Go to provide an idiomatic Go interface.

Ian
Reply all
Reply to author
Forward
0 new messages