Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Using stderr from Inline::C: (part deux)

by syphilis (Canon)
on May 23, 2013 at 10:20 UTC ( #1034928=note: print w/ replies, xml ) Need Help??


in reply to Using stderr from Inline::C: (part deux)

Using the perlio layer works fine for me:

#!perl -w use warnings; use strict; use Inline C => Config => USING => 'ParseRegExp', BUILD_NOISY => 1; use Inline C => <<'EOC'; void foo(char * x, int y) { PerlIO_write(PerlIO_stderr(), x, y); } EOC my $str = "hello world\n"; foo($str, length($str)); foo($str, 8); __END__ Outputs: hello world hello wo
Does that also work for you ? Is it acceptable ? (IIRC, you're not a big fan of the perlio layer.)

Alternatively, what about the XSubs warn() and/or vwarn() - both of which write to stderr ?

Cheers,
Rob


Comment on Re: Using stderr from Inline::C: (part deux)
Download Code
Re^2: Using stderr from Inline::C: (part deux)
by BrowserUk (Pope) on May 23, 2013 at 12:05 UTC
    (IIRC, you're not a big fan of the perlio layer.)

    I'm not a fan of anything that imposes itself on me. Even less so when it is done by overriding standard names with text macros.

    The latter wouldn't be so bad if it was only done if I explicitly requested it. Say, by adding: #include <perlIO.h> or similar.

    It would also not be so bad if it was documented what extra these PerlIO equivalent were doing for me (as opposed to just their existence.). One assumes they must be doing something extra, otherwise there would be no benefit for the cost of all those extra indirections; but I have yet to see what that is documented.

    Talking of control, is it possible to avoid/prevent I::C from automatically adding the standard Perl/XS headers to my I::C code?

    I wondering how I might use the NO_XSLOCKS that bulk88 mentions with I::C?


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      I wondering how I might use the NO_XSLOCKS that bulk88 mentions with I::C?

      Should be easy enough.
      Looking at the post to which bulk88 provided a link, I see:
      >You need to add > > #define NO_XSLOCKS > >before > > #include <xsub.h>
      If that's correct, then this should provide what's needed:
      use Inline C => Config => PRE_HEAD => "#define NO_XSLOCKS\n";
      (Not sure if the '\n' is needed or not ... and haven't checked.)
      The PRE_HEAD config option is a recent addition (beginning in 0.51) - it's documented in 'perldoc Inline::C'.

      Cheers,
      Rob
        The PRE_HEAD config option is a recent addition (beginning in 0.51) - it's documented in 'perldoc Inline::C'.

        Thank you. That looks perfect for this and a couple of other things I've wanted in the past.

        With regard to using PerlIO*. I often use I::C to prototype ideas that ultimately might end up being used or reused in stand alone C programs.

        I::C is so useful because it allows me to try things out without having to build a working C front end first, (file handling, argument handling, error handling etc.), which Perl gives me, and does so much better anyway. Hence I often try to avoid using any XS/perlish stuff within the routines themselves.

        In this case, the output I'm writing goes to a file that exists (is opened/written/closed) entirely within the C code, but it runs a long time and is quite hard to get right. Rather than having to wait until the code completes and then inspect the file, I wanted to direct the output to stderr so that I could send it to the file by way of tee, so that I could keep an eye on things and abort early if I could see they were going wrong.

        That should have been as easy as just substituting stderr for the FILE* I've opened in the output calls, but then I re-encountered the old problem.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2014-07-24 05:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (158 votes), past polls