When attempting to use SWIG's -builtin flag, there were a few compile
failures caused by a mismatch between return type and return value. In those
cases, the return type was int but many of the type maps assume returning
NULL/nullptr (only the latter caused compile failures).
This fix abstracts failure paths to use the SWIG_fail macro, which performs
goto fail;. Each of the generated functions contain a fail label, which
performs any resource cleanup and returns the appropriate failure value.
This change isn't strictly necessary at this point, but seems like the right
thing to do, and for anyone who tries -builtin later, it resolves those
issues.