Skip to content

Commit a4b3478

Browse files
Added macro for generating gotype/cgoout typemaps for exception handling with panic recovery
1 parent 11f3d20 commit a4b3478

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

PDFTronGo/pdftron.i

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,26 @@ import "fmt"
235235
}
236236
}
237237

238+
// Macro for generating gotype (adding error to return) and cgoout (adding panic recovery to return errors) typemaps
239+
%define ERROR_HANDLING_TYPEMAPS(TYPE)
240+
%typemap(gotype) TYPE "$gotype, error"
241+
%typemap(cgoout) TYPE %{
242+
var swig_r $gotypes
243+
var swig_err error
244+
245+
func() {
246+
defer func() {
247+
if r := recover(); r != nil {
248+
swig_err = errors.New(fmt.Sprintf("%v", r))
249+
}
250+
}()
251+
swig_r = $cgocall
252+
}()
253+
254+
return swig_r, swig_err
255+
%}
256+
%enddef
257+
238258
%typemap(goout) pdftron::SDF::Obj
239259
%{
240260
// Without the brackets, swig attempts to turn $1 into a c++ dereference.. seems like a bug

0 commit comments

Comments
 (0)