Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hsperl_init prints to stderr in event of failure (and exits the process) #18

Open
phlummox opened this issue Feb 6, 2021 · 0 comments
Labels
04-minor minor issue defect Flaw in code that can or will result in a bug

Comments

@phlummox
Copy link
Owner

phlummox commented Feb 6, 2021

The hsperl_init C function is poorly behaved in the event it fails to parse a given Perl-code "preamble": (a) it prints to stderr, bad behaviour for a library, and (b) calls exit(), terminating the whole process. See here:

    if (SvTRUE(ERRSV)) {
        STRLEN n_a;
        // TODO: see if we can raise a proper exception instead
        fprintf(stderr, "Error init perl: %s\n", SvPV(ERRSV,n_a));
        // NO. Should _NOT_ be aborting, mid-program.
        exit(1);
    }

This should be fixed – we should indicate errors through our return value. Either we can return a NULL pointer on error, and provide an "out" parameter where an error code can be set; or we can have an int return value (0 for success, anything else for failure) and return the Interpreter pointer via an Interpreter **.

The particular condition above is admittedly unlikely to occur – unless the preamble being parsed is deliberately changed, Perl should always be able to parse it – so this is low-ish priority, but no doubt there are other errors in hsperl_init we're not currently checking for.

@phlummox phlummox added defect Flaw in code that can or will result in a bug 04-minor minor issue labels Feb 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
04-minor minor issue defect Flaw in code that can or will result in a bug
Projects
None yet
Development

No branches or pull requests

1 participant