Fix C exception handling & null-termination error.

rb_raise() uses longjmp() to exit the function scope. The goto done
method of cleanup does not executed with the longjmp. Fix by delaying
all raises until the end of the function to preserve a uniform error
handling pattern.

Also, ruby strings are not guaranteed to be null terminated. Strings
that are passed to APIs without explicit length arguments are copied and
cleaned up.

Lastly, enforce type checks everywhere before grabbing an RSTRING_PTR.