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

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

Replies are listed 'Best First'.
Re^3: catch "use Inline::C" death - multiple+dynamic code blocks
by NERDVANA (Priest) on Jun 17, 2024 at 23:34 UTC
    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.