develooper Front page | perl.perl5.changes | Postings from May 2020

[Perl/perl5] c9a797: Add dualvar-creating newSVpviv and friends

Paul Evans
May 28, 2020 20:35
[Perl/perl5] c9a797: Add dualvar-creating newSVpviv and friends
Message ID:
  Branch: refs/heads/leonerd/newSVpviv
  Commit: c9a797974662f18ba2c6b3bd56069df5f3846c3d
  Author: Paul "LeoNerd" Evans <>
  Date:   2020-05-28 (Thu, 28 May 2020)

  Changed paths:
    M embed.fnc
    M embed.h
    M ext/XS-APItest/
    M ext/XS-APItest/APItest.xs
    A ext/XS-APItest/t/newSVpviv.t
    M handy.h
    M proto.h
    M sv.c

  Log Message:
  Add dualvar-creating newSVpviv and friends

These two new functions and one macro create PV-and-IV dualvars, in
similar style to the other newSV*() family.

They are most convenient for wrapping error values from external
libraries, to create dual number/string values in a similar style to
core's $! wrapping of errno.

For example:

    int err = uv_...();
    if(err != 0) return newSVpviv(uv_strerr(err), err);

This makes the usual style of error-type dualvar that can both be tested
for numerical equality and additionally used as a string to yield its
human-readable error message

    croak "Unable to complete: $err" unless $err == UV::UV_EAGAIN; Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About