Skip to content

Commit 70aa1d8

Browse files
Applied macro to all functions in our API, and excluded director classes
1 parent a4b3478 commit 70aa1d8

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

PDFTronGo/pdftron.i

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,34 @@ import "fmt"
235235
}
236236
}
237237

238+
// Exclude director classes from exception handling typemaps
239+
%typemap(gotype, out) pdftron::PDF::Callback* "$gotype"
240+
%typemap(cgoout, out) pdftron::PDF::Callback* %{
241+
return $cgocall
242+
%}
243+
244+
%typemap(gotype, out) pdftron::SDF::SignatureHandler* "$gotype"
245+
%typemap(cgoout, out) pdftron::SDF::SignatureHandler* %{
246+
return $cgocall
247+
%}
248+
249+
%typemap(gotype, out) pdftron::PDF::Separation* "$gotype"
250+
%typemap(cgoout, out) pdftron::PDF::Separation* %{
251+
return $cgocall
252+
%}
253+
254+
%typemap(gotype, out) pdftron::PDF::Rect* "$gotype"
255+
%typemap(cgoout, out) pdftron::PDF::Rect* %{
256+
return $cgocall
257+
%}
258+
259+
%typemap(gotype, out) pdftron::PDF::Date* "$gotype"
260+
%typemap(cgoout, out) pdftron::PDF::Date* %{
261+
return $cgocall
262+
%}
263+
238264
// Macro for generating gotype (adding error to return) and cgoout (adding panic recovery to return errors) typemaps
239-
%define ERROR_HANDLING_TYPEMAPS(TYPE)
265+
%define EXCEPTION_HANDLING_TYPEMAP(TYPE)
240266
%typemap(gotype) TYPE "$gotype, error"
241267
%typemap(cgoout) TYPE %{
242268
var swig_r $gotypes
@@ -255,6 +281,23 @@ import "fmt"
255281
%}
256282
%enddef
257283

284+
// Apply gotype and cgoout typemaps to functions that return:
285+
286+
// Value types
287+
EXCEPTION_HANDLING_TYPEMAP(SWIGTYPE)
288+
// Pointers
289+
EXCEPTION_HANDLING_TYPEMAP(SWIGTYPE *)
290+
// References
291+
EXCEPTION_HANDLING_TYPEMAP(SWIGTYPE &)
292+
// Primitives
293+
EXCEPTION_HANDLING_TYPEMAP(bool)
294+
EXCEPTION_HANDLING_TYPEMAP(char)
295+
EXCEPTION_HANDLING_TYPEMAP(double)
296+
EXCEPTION_HANDLING_TYPEMAP(int)
297+
EXCEPTION_HANDLING_TYPEMAP(ptrdiff_t)
298+
EXCEPTION_HANDLING_TYPEMAP(size_t)
299+
300+
// Handle edge case: SDF::Obj returns nil when internal pointer is invalid
258301
%typemap(goout) pdftron::SDF::Obj
259302
%{
260303
// Without the brackets, swig attempts to turn $1 into a c++ dereference.. seems like a bug

0 commit comments

Comments
 (0)