swig -go: treat a nil argument as NULL

Let Go code pass "nil" when calling a C++ function that accepts a
pointer to a class.  The Go "nil" will be treated as a C++ "nullptr".

Fixes #2203
This commit is contained in:
Ian Lance Taylor 2022-03-08 15:15:05 -08:00
commit 70d530adfc
4 changed files with 53 additions and 12 deletions

View file

@ -149,6 +149,17 @@ type _swig_fnptr *byte
type _swig_memberptr *byte
%}
/* Convert a Go interface value into a C++ pointer. */
%insert(go_header) %{
func getSwigcptr(v interface { Swigcptr() uintptr }) uintptr {
if v == nil {
return 0
}
return v.Swigcptr()
}
%}
/* For directors we need C++ to track a Go pointer. Since we can't
pass a Go pointer into C++, we use a map to track the pointers on
the Go side. */