Code Monkey home page Code Monkey logo

hs-perl5's Introduction

hs-perl5's People

Contributors

audreyt avatar coke avatar hiratara avatar ingydotnet avatar lumimies avatar moritz avatar phlummox avatar quietfanatic avatar yoshikunijujo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

hs-perl5's Issues

Signature of `withPerl5` gives little clue as to its use.

The withPerl5 function has a rather opaque signature that gives no clue that it's effectively "bracket"-ing an implicit, global Interpreter.

The function's usage could be made more obvious if Interpreter objects were explicitly allocated and finalized (rather than a single global instance being operated on). Then, withPerl5 would take a function which took an Interpreter object, its signature would give a better idea of its purpose, and it'd be more flexible, too.

This shouldn't be hard to do - the perlembed docco gives examples of how to work with multiple interpreter instances.

Programs sporadically segfault when compiled with -threaded

Programs using functions within withPerl5 sporadically segfault (or suffer other memory corruption -- sometimes glib will report errors before the segfault, like "corrupted double-linked list") when compiled with -threaded.

This is (almost certainly) because Perl is not thread-safe - it sets up various global data structures, and if multiple threads can access these at the same time, corruption is eventually inevitable.

The package should have been written so that all calls within withPerl5 occur on a single OS thread, so as to avoid this.

add CI

set up CI using Travis or GitHub Actions. Would be nice to also see if it builds OK on Windows, using Appveyor.

improve return value convention for `hsperl_return_conv`

The C function SV ** hsperl_return_conv (int count) has a needlessly complex way of returning values and errors – it allocates an array of SVs, with up to two NULL terminators (explanation here),

It'd be better to just provide an "out" parameter, that might contain return values or errors, and use an int return value to indicate which is the case. But also - there doesn't seem to be any reason to provide multiple error values. (I think one is intended to be always a string, the other, potentially, a reference to a more complex Perl structure.) We can just provide one, and let the caller work out how best to deal with it.

Incorrect C types are used

For instance, for hsperl_newSViv, the C prototype given is:

hsperl_newSViv ( int iv )

-- limiting us to passing a C int, when the actual parameter type is an "IV" (usually a 64-bit int). There is no reason for this, we can accurately represent the Haskell equivalent of Perl types like IV and NV using hsc2hs. And by using correct types, we can write accurate tests around the boundaries of those types (e.g. checking that maxBound of an Int64 converts correctly).

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

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.

Add `Text` instances for ToSV and FromSV

The String instances for ToSV and FromSV seem flakey - they only reliable work with ASCII-only strings containing no NUL characters. (IIRC, they use withCStringLen, and I thought that could handle NULs, but perhaps not.)

In any case, Text is a far better string type to use.

Namespace is annoying

Given that Perl 5 is the only Perl that is still in use (Perl 6 is now "Raku"), the inconsistent presence of "..5" in module and function names can probably be dropped. (Anyone who somehow manages to get a conflict between this package, and some embedding of Perl 4, the last version of which was released in 1993, would presumably know what they were getting themselves into.) At any rate, the "5" can definitely be dropped from function names.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.