Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: catch "use Inline::C" death

by Corion (Patriarch)
on Jun 14, 2024 at 10:41 UTC ( [id://11159982]=note: print w/replies, xml ) Need Help??


in reply to catch "use Inline::C" death

use is basically require + ->import, so you can do the following:

eval { require Inline; Inline->import( C => Config => ccflagsex => '-test-bliako-A' ); Inline->import( C => $c_code ); };

Replies are listed 'Best First'.
Re^2: catch "use Inline::C" death
by bliako (Abbot) on Jun 14, 2024 at 11:14 UTC

    Thanks Corion++ that does the trick! nice.

Re^2: catch "use Inline::C" death - multiple+dynamic code blocks
by bliako (Abbot) on Jun 14, 2024 at 23:42 UTC

    I found another way with The-bind()-Function of Inline which works fine for multiple code blocks and recovers from previous bad configuration. Unfortunately there is a caveat mentioned in the documentation, which I did not understand:

    Although bind() is a powerful feature, it is not recommended for use i +n Inline based modules. In fact, it won't work at all for installable + modules.

    This is how I use bind() with code and configuration:

    use Inline; Inline->bind( CUDA => $code, BUILD_NOISY => 1, clean_after_build => 0, warnings => 10, );

    And it is happy inside eval or try/catch (Try::Tiny).

    I was thinking about this and realised that one can have multiple Inline code blocks. I have tried it and also within eval and try/catch and they work except that if a configuration fails (for my tests) then it sticks with it and does not seem to re-configure. Using bind() as above seems to recover from previous bad compilations.

    Inline's preferred way is to specify the code in a BEGIN block and then use Inline => ... which does not allow for inlining code dynamically. bind() does.

    PS: I have also asked the author a question here

      The advantage of "use Inline C => ..." is that it happens at compile-time when there is still a chance to declare functions for use further down in the module. Otherwise, perl code later in the module (as it is being compiled) won't know that the XS functions exist, forcing you to use parentheses when calling them.

      This advantage might not apply to that many people, but I'm guessing that was why it was done as a BEGIN behavior.

        thank's, it is clearer now. I wonder still if bind() is safe.not important though.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11159982]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-10-09 00:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The PerlMonks site front end has:





    Results (44 votes). Check out past polls.

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.