newXS("Tie::Hash::NamedCapture::flags", XS_Tie_Hash_NamedCapture_flags, file);
}
+/*
+=for apidoc croak_xs_usage
+
+A specialised variant of C<croak()> for emitting the usage message for xsubs
+
+ croak_xs_usage(cv, "eee_yow");
+
+works out the package name and subroutine name from C<cv>, and then calls
+C<croak()>. Hence if C<cv> is C<&ouch::awk>, it would call C<croak> as:
+
+ Perl_croak(aTHX_ "Usage %s::%s(%s)", "ouch" "awk", "eee_yow");
+
+=cut
+*/
+
+void
+Perl_croak_xs_usage(pTHX_ const CV *const cv, const char *const params)
+{
+ const GV *const gv = CvGV(cv);
+
+ PERL_ARGS_ASSERT_CROAK_XS_USAGE;
+
+ if (gv) {
+ const char *const gvname = GvNAME(gv);
+ const HV *const stash = GvSTASH(gv);
+ const char *const hvname = stash ? HvNAME_get(stash) : NULL;
+
+ if (hvname)
+ Perl_croak(aTHX_ "Usage: %s::%s(%s)", hvname, gvname, params);
+ else
+ Perl_croak(aTHX_ "Usage: %s(%s)", gvname, params);
+ } else {
+ /* Pants. I don't think that it should be possible to get here. */
+ Perl_croak(aTHX_ "Usage: CODE(%"UVXf")(%s)", (UV)cv, params);
+ }
+}
XS(XS_UNIVERSAL_isa)
{
dVAR;
dXSARGS;
- PERL_UNUSED_ARG(cv);
if (items != 2)
- Perl_croak(aTHX_ "Usage: UNIVERSAL::isa(reference, kind)");
+ croak_xs_usage(cv, "reference, kind");
else {
SV * const sv = ST(0);
const char *name;
const char *name;
SV *rv;
HV *pkg = NULL;
- PERL_UNUSED_ARG(cv);
if (items != 2)
- Perl_croak(aTHX_ "Usage: UNIVERSAL::can(object-ref, method)");
+ croak_xs_usage(cv, "object-ref, method");
sv = ST(0);
{
dVAR;
dXSARGS;
- PERL_UNUSED_ARG(cv);
if (items > 3)
- Perl_croak(aTHX_ "Usage: version::new(class, version)");
+ croak_xs_usage(cv, "class, version");
SP -= items;
{
SV *vs = ST(1);
{
dVAR;
dXSARGS;
- PERL_UNUSED_ARG(cv);
if (items < 1)
- Perl_croak(aTHX_ "Usage: version::stringify(lobj, ...)");
+ croak_xs_usage(cv, "lobj, ...");
SP -= items;
{
SV * lobj;
{
dVAR;
dXSARGS;
- PERL_UNUSED_ARG(cv);
if (items < 1)
- Perl_croak(aTHX_ "Usage: version::numify(lobj, ...)");
+ croak_xs_usage(cv, "lobj, ...");
SP -= items;
{
SV * lobj;
{
dVAR;
dXSARGS;
- PERL_UNUSED_ARG(cv);
if (items < 1)
- Perl_croak(aTHX_ "Usage: version::normal(lobj, ...)");
+ croak_xs_usage(cv, "lobj, ...");
SP -= items;
{
SV * lobj;
{
dVAR;
dXSARGS;
- PERL_UNUSED_ARG(cv);
if (items < 1)
- Perl_croak(aTHX_ "Usage: version::vcmp(lobj, ...)");
+ croak_xs_usage(cv, "lobj, ...");
SP -= items;
{
SV * lobj;
{
dVAR;
dXSARGS;
- PERL_UNUSED_ARG(cv);
if (items < 1)
- Perl_croak(aTHX_ "Usage: version::boolean(lobj, ...)");
+ croak_xs_usage(cv, "lobj, ...");
SP -= items;
if (sv_derived_from(ST(0), "version")) {
SV * const lobj = SvRV(ST(0));
{
dVAR;
dXSARGS;
- PERL_UNUSED_ARG(cv);
if (items < 1)
- Perl_croak(aTHX_ "Usage: version::noop(lobj, ...)");
+ croak_xs_usage(cv, "lobj, ...");
if (sv_derived_from(ST(0), "version"))
Perl_croak(aTHX_ "operation not supported with version object");
else
{
dVAR;
dXSARGS;
- PERL_UNUSED_ARG(cv);
if (items != 1)
- Perl_croak(aTHX_ "Usage: version::is_alpha(lobj)");
+ croak_xs_usage(cv, "lobj");
SP -= items;
if (sv_derived_from(ST(0), "version")) {
SV * const lobj = ST(0);
{
dVAR;
dXSARGS;
- PERL_UNUSED_ARG(cv);
if (items != 1)
- Perl_croak(aTHX_ "Usage: version::qv(ver)");
+ croak_xs_usage(cv, "ver");
SP -= items;
{
SV * ver = ST(0);
{
dVAR;
dXSARGS;
- PERL_UNUSED_ARG(cv);
if (items != 1)
- Perl_croak(aTHX_ "Usage: utf8::is_utf8(sv)");
+ croak_xs_usage(cv, "sv");
else {
const SV * const sv = ST(0);
if (SvUTF8(sv))
{
dVAR;
dXSARGS;
- PERL_UNUSED_ARG(cv);
if (items != 1)
- Perl_croak(aTHX_ "Usage: utf8::valid(sv)");
+ croak_xs_usage(cv, "sv");
else {
SV * const sv = ST(0);
STRLEN len;
{
dVAR;
dXSARGS;
- PERL_UNUSED_ARG(cv);
if (items != 1)
- Perl_croak(aTHX_ "Usage: utf8::encode(sv)");
+ croak_xs_usage(cv, "sv");
sv_utf8_encode(ST(0));
XSRETURN_EMPTY;
}
{
dVAR;
dXSARGS;
- PERL_UNUSED_ARG(cv);
if (items != 1)
- Perl_croak(aTHX_ "Usage: utf8::decode(sv)");
+ croak_xs_usage(cv, "sv");
else {
SV * const sv = ST(0);
const bool RETVAL = sv_utf8_decode(sv);
{
dVAR;
dXSARGS;
- PERL_UNUSED_ARG(cv);
if (items != 1)
- Perl_croak(aTHX_ "Usage: utf8::upgrade(sv)");
+ croak_xs_usage(cv, "sv");
else {
SV * const sv = ST(0);
STRLEN RETVAL;
{
dVAR;
dXSARGS;
- PERL_UNUSED_ARG(cv);
if (items < 1 || items > 2)
- Perl_croak(aTHX_ "Usage: utf8::downgrade(sv, failok=0)");
+ croak_xs_usage(cv, "sv, failok=0");
else {
SV * const sv = ST(0);
const bool failok = (items < 2) ? 0 : (int)SvIV(ST(1));
dVAR;
dXSARGS;
const UV uv = SvUV(ST(0));
- PERL_UNUSED_ARG(cv);
if (items > 1)
- Perl_croak(aTHX_ "Usage: utf8::native_to_unicode(sv)");
+ croak_xs_usage(cv, "sv");
ST(0) = sv_2mortal(newSViv(NATIVE_TO_UNI(uv)));
XSRETURN(1);
dVAR;
dXSARGS;
const UV uv = SvUV(ST(0));
- PERL_UNUSED_ARG(cv);
if (items > 1)
- Perl_croak(aTHX_ "Usage: utf8::unicode_to_native(sv)");
+ croak_xs_usage(cv, "sv");
ST(0) = sv_2mortal(newSViv(UNI_TO_NATIVE(uv)));
XSRETURN(1);
{
dVAR;
dXSARGS;
- PERL_UNUSED_ARG(cv);
if (items != 1)
- Perl_croak(aTHX_ "Usage: UNIVERSAL::hv_clear_placeholders(hv)");
+ croak_xs_usage(cv, "hv");
else {
HV * const hv = (HV *) SvRV(ST(0));
hv_clear_placeholders(hv);
{
dVAR;
dXSARGS;
- PERL_UNUSED_ARG(cv);
if (items < 1 || items % 2 == 0)
- Perl_croak(aTHX_ "Usage: PerlIO_get_layers(filehandle[,args])");
+ croak_xs_usage(cv, "filehandle[,args]");
#ifdef USE_PERLIO
{
SV * sv;
{
dVAR;
dXSARGS;
- PERL_UNUSED_ARG(cv);
if (SvROK(ST(0))) {
const HV * const hv = (HV *) SvRV(ST(0));
if (items == 1 && SvTYPE(hv) == SVt_PVHV) {
PERL_UNUSED_VAR(cv);
if (items != 1)
- Perl_croak(aTHX_ "Usage: %s(%s)", "re::is_regexp", "sv");
+ croak_xs_usage(cv, "sv");
SP -= items;
SV * ret;
dVAR;
dXSARGS;
- PERL_UNUSED_ARG(cv);
if (items != 0)
- Perl_croak(aTHX_ "Usage: %s(%s)", "re::regnames_count", "");
+ croak_xs_usage(cv, "");
SP -= items;
REGEXP * rx;
U32 flags;
SV * ret;
- PERL_UNUSED_ARG(cv);
if (items < 1 || items > 2)
- Perl_croak(aTHX_ "Usage: %s(%s)", "re::regname", "name[, all ]");
+ croak_xs_usage(cv, "name[, all ]");
SP -= items;
I32 length;
I32 i;
SV **entry;
- PERL_UNUSED_ARG(cv);
if (items > 1)
- Perl_croak(aTHX_ "Usage: %s(%s)", "re::regnames", "[all]");
+ croak_xs_usage(cv, "[all]");
rx = PL_curpm ? PM_GETRE(PL_curpm) : NULL;
dVAR;
dXSARGS;
REGEXP *re;
- PERL_UNUSED_ARG(cv);
if (items != 1)
- Perl_croak(aTHX_ "Usage: %s(%s)", "re::regexp_pattern", "sv");
+ croak_xs_usage(cv, "sv");
SP -= items;
REGEXP * rx;
U32 flags;
SV * ret;
- PERL_UNUSED_ARG(cv);
if (items != 2)
- Perl_croak(aTHX_ "Usage: Tie::Hash::NamedCapture::STORE($key, $flags)");
+ croak_xs_usage(cv, "$key, $flags");
rx = PL_curpm ? PM_GETRE(PL_curpm) : NULL;
dXSARGS;
REGEXP * rx;
U32 flags;
- PERL_UNUSED_ARG(cv);
if (items != 3)
- Perl_croak(aTHX_ "Usage: Tie::Hash::NamedCapture::STORE($key, $value, $flags)");
+ croak_xs_usage(cv, "$key, $value, $flags");
rx = PL_curpm ? PM_GETRE(PL_curpm) : NULL;
dXSARGS;
REGEXP * rx = PL_curpm ? PM_GETRE(PL_curpm) : NULL;
U32 flags;
- PERL_UNUSED_ARG(cv);
if (items != 2)
- Perl_croak(aTHX_ "Usage: Tie::Hash::NamedCapture::DELETE($key, $flags)");
+ croak_xs_usage(cv, "$key, $flags");
if (!rx)
Perl_croak(aTHX_ PL_no_modify);
dXSARGS;
REGEXP * rx;
U32 flags;
- PERL_UNUSED_ARG(cv);
if (items != 1)
- Perl_croak(aTHX_ "Usage: Tie::Hash::NamedCapture::CLEAR($flags)");
+ croak_xs_usage(cv, "$flags");
rx = PL_curpm ? PM_GETRE(PL_curpm) : NULL;
REGEXP * rx;
U32 flags;
SV * ret;
- PERL_UNUSED_ARG(cv);
if (items != 2)
- Perl_croak(aTHX_ "Usage: Tie::Hash::NamedCapture::EXISTS($key, $flags)");
+ croak_xs_usage(cv, "$key, $flags");
rx = PL_curpm ? PM_GETRE(PL_curpm) : NULL;
REGEXP * rx;
U32 flags;
SV * ret;
- PERL_UNUSED_ARG(cv);
if (items != 1)
- Perl_croak(aTHX_ "Usage: Tie::Hash::NamedCapture::FIRSTKEY()");
+ croak_xs_usage(cv, "");
rx = PL_curpm ? PM_GETRE(PL_curpm) : NULL;
REGEXP * rx;
U32 flags;
SV * ret;
- PERL_UNUSED_ARG(cv);
if (items != 2)
- Perl_croak(aTHX_ "Usage: Tie::Hash::NamedCapture::NEXTKEY($lastkey)");
+ croak_xs_usage(cv, "$lastkey");
rx = PL_curpm ? PM_GETRE(PL_curpm) : NULL;
REGEXP * rx;
U32 flags;
SV * ret;
- PERL_UNUSED_ARG(cv);
if (items != 1)
- Perl_croak(aTHX_ "Usage: Tie::Hash::NamedCapture::SCALAR()");
+ croak_xs_usage(cv, "");
rx = PL_curpm ? PM_GETRE(PL_curpm) : NULL;
{
dVAR;
dXSARGS;
- PERL_UNUSED_ARG(cv);
if (items != 0)
- Perl_croak(aTHX_ "Usage: Tie::Hash::NamedCapture::flags()");
+ croak_xs_usage(cv, "");
mXPUSHu(RXapif_ONE);
mXPUSHu(RXapif_ALL);