Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

I'm writing an XS interface to a library and could use some advice on how to return error information.

The routines in the library return 0 if the call succeeded or a status value if there was an error. The library contains a routine to convert the status codes into strings that can be displayed for a user.

My interface routines mostly collect the information into a hash and return a reference to the caller. In case of error I'm returning an empty list. I would like to make the error information available to the caller because it could be very meaningful in certain cases (e.g., 'end of file' vs. other I/O error conditions).

I can't really return the status in $! since it isn't an errno value. I can return the error text in $@ but then the programmer would have to parse the error text rather than acting on an error code.

I'm contemplating replacing my simple handle object with a structure that can contain the handle and the last status returned by a library call using that handle. I could then add an XS routine to return that status to the calling program. The user could call the status fetch routine if one of the other calls returned undef. But this still doesn't help the open call that creates the handle (if the handle doesn't exist yet, I can't use it to hold status).

Any ideas?

90% of every Perl application is already written.

In reply to Returning external library status codes from an XS routine by pfaut

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others about the Monastery: (3)
    As of 2018-02-25 10:21 GMT
    Find Nodes?
      Voting Booth?
      When it is dark outside I am happiest to see ...

      Results (312 votes). Check out past polls.