Skip to content

Commit d138748

Browse files
Reset to before error handling changes for testing
1 parent db9e880 commit d138748

File tree

1 file changed

+6
-71
lines changed

1 file changed

+6
-71
lines changed

PDFTronGo/pdftron.i

Lines changed: 6 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -214,91 +214,26 @@
214214
#undef SetPort
215215
%}
216216

217-
// ==============
218-
// ERROR HANDLING
219-
// ==============
220-
// Converts C++ exceptions to Go errors using panic/recovery mechanism.
221-
// All functions now return an error in addition to their return type instead of panicking on exceptions.
222-
223-
// Ensure necessary imports for error handling code
224-
%insert(go_imports) %{
225-
import "errors"
226-
import "fmt"
227-
%}
228-
229-
// Handle exceptions by triggering recoverable panic containing the exception message
217+
%include "exception.i"
230218
%exception {
231219
try {
232-
$action
233-
} catch (const std::exception &e) {
220+
$action;
221+
} catch (std::exception &e) {
234222
_swig_gopanic(e.what());
235-
} catch (...) {
236-
_swig_gopanic("unknown exception occurred");
237223
}
238224
}
239225

240-
// Macro for generating gotype (adding error to return) and cgoout (adding panic recovery to return errors) typemaps
241-
%define ERROR_HANDLING_TYPEMAP(TYPE)
242-
%typemap(gotype, out) TYPE "$gotype, error"
243-
%typemap(cgoout, out) TYPE %{
244-
var swig_r $gotypes
245-
var swig_err error
246-
247-
func() {
248-
defer func() {
249-
if r := recover(); r != nil {
250-
swig_err = errors.New(fmt.Sprintf("%v", r))
251-
}
252-
}()
253-
swig_r = $cgocall
254-
}()
255-
256-
return swig_r, swig_err
257-
%}
258-
%enddef
259-
260-
// Apply gotype and cgoout typemaps to functions that return:
261-
262-
/*// Primitives
263-
ERROR_HANDLING_TYPEMAP(bool)
264-
ERROR_HANDLING_TYPEMAP(char)
265-
ERROR_HANDLING_TYPEMAP(double)
266-
ERROR_HANDLING_TYPEMAP(int)
267-
ERROR_HANDLING_TYPEMAP(ptrdiff_t)
268-
ERROR_HANDLING_TYPEMAP(size_t)*/
269-
270-
/*// Generate gotype and cgoout typemaps for void separately
271-
%typemap(gotype, out) void "error"
272-
%typemap(cgoout, out) void %{
273-
var swig_err error
274-
275-
func() {
276-
defer func() {
277-
if r := recover(); r != nil {
278-
swig_err = errors.New(fmt.Sprintf("%v", r))
279-
}
280-
}()
281-
$cgocall
282-
}()
283-
284-
return swig_err
285-
%}*/
286-
287-
// Handle edge case: SDF::Obj returns nil when internal pointer is invalid
288226
%typemap(goout) pdftron::SDF::Obj
289227
%{
290228
// Without the brackets, swig attempts to turn $1 into a c++ dereference.. seems like a bug
291229
if ($1).GetMp_obj().Swigcptr() != 0 {
292-
return $1, swig_err
230+
$result = $1
231+
return $result
293232
}
294233

295-
return nil, swig_err
234+
$result = nil
296235
%}
297236

298-
// ==================
299-
// END ERROR HANDLING
300-
// ==================
301-
302237
/**
303238
* Provides mapping for C++ vectors.
304239
* For example, vector<double> will be called as VectorDouble in GoLang.

0 commit comments

Comments
 (0)