Throwing exceptions from XS code

[email protected] (Emmanuel Rodriguez)
Newsgroups perl.xs
Message-ID <CAGwXj+S6LHg2P-Y5asLxuXjn-8XZs9XAc8qpstug15uCewQRHg@mail.gmail.com>
Hi,

I'm writing XS bindings for JavaScriptCore (WebKit's JavaScript
engine) and a lot of the functions in the API throw an exception. The
exception it self is a JavaScript variable (kind of like an SV* for
Perl).

At first I though of rethrowing that variable wrapped as an SV but I
don't know how to do this. I read somewhere that Perl_croak_sv can do
that but I get a runtime because the symbol is undefined:

            /*  undefined symbol: Perl_croak_sv */
            SV *err;
            err = jsc_perl_js_value_to_sv(ctx, exception);
            Perl_croak_sv(aTHX_ err);

For now I reverted at returning the error as a JSON string and to use
croak but I'm leaking the string with the message since I can't free
it after croak():

            char *error;
            error = jsc_perl_js_value_to_json(ctx, exception);
            croak("%s", error);/* How can we throw an SV ? */
            free(error);/* FIXME is this free called ? */

Is it possible to throw an blessed exception from XS code? If so how
can I achieve this? Otherwise, how can I propagate an error as a
string and free the string?

-- 
Emmanuel Rodriguez
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.