/*
 * This file was generated automatically by ExtUtils::ParseXS version 2.21 from the
 * contents of Util.xs. Do not edit this file, edit Util.xs instead.
 *
 *	ANY CHANGES MADE HERE WILL BE LOST! 
 *
 */

#line 1 "Util.xs"
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"


#line 16 "Util.c"
#ifndef PERL_UNUSED_VAR
#  define PERL_UNUSED_VAR(var) if (0) var = var
#endif

#ifndef PERL_ARGS_ASSERT_CROAK_XS_USAGE
#define PERL_ARGS_ASSERT_CROAK_XS_USAGE assert(cv); assert(params)

/* prototype to pass -Wmissing-prototypes */
STATIC void
S_croak_xs_usage(pTHX_ const CV *const cv, const char *const params);

STATIC void
S_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(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(0x%"UVxf")(%s)", PTR2UV(cv), params);
    }
}
#undef  PERL_ARGS_ASSERT_CROAK_XS_USAGE

#ifdef PERL_IMPLICIT_CONTEXT
#define croak_xs_usage(a,b)	S_croak_xs_usage(aTHX_ a,b)
#else
#define croak_xs_usage		S_croak_xs_usage
#endif

#endif

/* NOTE: the prototype of newXSproto() is different in versions of perls,
 * so we define a portable version of newXSproto()
 */
#ifdef newXS_flags
#define newXSproto_portable(name, c_impl, file, proto) newXS_flags(name, c_impl, file, proto, 0)
#else
#define newXSproto_portable(name, c_impl, file, proto) (PL_Sv=(SV*)newXS(name, c_impl, file), sv_setpv(PL_Sv, proto), (CV*)PL_Sv)
#endif /* !defined(newXS_flags) */

#line 68 "Util.c"

XS(XS_Hash__Util_all_keys); /* prototype to pass -Wmissing-prototypes */
XS(XS_Hash__Util_all_keys)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    if (items != 3)
       croak_xs_usage(cv,  "hash, keys, placeholder");
    {
	SV*	hash = ST(0);
	SV*	keys = ST(1);
	SV*	placeholder = ST(2);
#line 16 "Util.xs"
	AV* av_k;
        AV* av_p;
        HV* hv;
        SV *key;
        HE *he;
#line 90 "Util.c"
	SV *	RETVAL;
#line 22 "Util.xs"
	if (!SvROK(hash) || SvTYPE(SvRV(hash)) != SVt_PVHV)
	   croak("First argument to all_keys() must be an HASH reference");
	if (!SvROK(keys) || SvTYPE(SvRV(keys)) != SVt_PVAV)
	   croak("Second argument to all_keys() must be an ARRAY reference");
        if (!SvROK(placeholder) || SvTYPE(SvRV(placeholder)) != SVt_PVAV)
	   croak("Third argument to all_keys() must be an ARRAY reference");

	hv = (HV*)SvRV(hash);
	av_k = (AV*)SvRV(keys);
	av_p = (AV*)SvRV(placeholder);

        av_clear(av_k);
        av_clear(av_p);

        (void)hv_iterinit(hv);
	while((he = hv_iternext_flags(hv, HV_ITERNEXT_WANTPLACEHOLDERS))!= NULL) {
	    key=hv_iterkeysv(he);
            if (HeVAL(he) == &PL_sv_placeholder) {
                SvREFCNT_inc(key);
	        av_push(av_p, key);
            } else {
                SvREFCNT_inc(key);
	        av_push(av_k, key);
            }
        }
        RETVAL=hash;
#line 119 "Util.c"
    }
    XSRETURN(1);
}


XS(XS_Hash__Util_hidden_ref_keys); /* prototype to pass -Wmissing-prototypes */
XS(XS_Hash__Util_hidden_ref_keys)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    if (items != 1)
       croak_xs_usage(cv,  "hash");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	SV*	hash = ST(0);
#line 54 "Util.xs"
        HV* hv;
        SV *key;
        HE *he;
#line 143 "Util.c"
#line 58 "Util.xs"
	if (!SvROK(hash) || SvTYPE(SvRV(hash)) != SVt_PVHV)
	   croak("First argument to hidden_keys() must be an HASH reference");

	hv = (HV*)SvRV(hash);

        (void)hv_iterinit(hv);
	while((he = hv_iternext_flags(hv, HV_ITERNEXT_WANTPLACEHOLDERS))!= NULL) {
	    key=hv_iterkeysv(he);
            if (HeVAL(he) == &PL_sv_placeholder) {
                XPUSHs( key );
            }
        }
#line 157 "Util.c"
	PUTBACK;
	return;
    }
}


XS(XS_Hash__Util_legal_ref_keys); /* prototype to pass -Wmissing-prototypes */
XS(XS_Hash__Util_legal_ref_keys)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    if (items != 1)
       croak_xs_usage(cv,  "hash");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	SV*	hash = ST(0);
#line 75 "Util.xs"
        HV* hv;
        SV *key;
        HE *he;
#line 182 "Util.c"
#line 79 "Util.xs"
	if (!SvROK(hash) || SvTYPE(SvRV(hash)) != SVt_PVHV)
	   croak("First argument to legal_keys() must be an HASH reference");

	hv = (HV*)SvRV(hash);

        (void)hv_iterinit(hv);
	while((he = hv_iternext_flags(hv, HV_ITERNEXT_WANTPLACEHOLDERS))!= NULL) {
	    key=hv_iterkeysv(he);
            XPUSHs( key );
        }
#line 194 "Util.c"
	PUTBACK;
	return;
    }
}


XS(XS_Hash__Util_hv_store); /* prototype to pass -Wmissing-prototypes */
XS(XS_Hash__Util_hv_store)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    if (items != 3)
       croak_xs_usage(cv,  "hvref, key, val");
    {
	SV*	hvref = ST(0);
	SV*	key = ST(1);
	SV*	val = ST(2);
#line 97 "Util.xs"
	HV* hv;
#line 217 "Util.c"
#line 99 "Util.xs"
    {
	if (!SvROK(hvref) || SvTYPE(SvRV(hvref)) != SVt_PVHV)
	   croak("First argument to hv_store() must be a hash reference");
	hv = (HV*)SvRV(hvref);
        SvREFCNT_inc(val);
	if (!hv_store_ent(hv, key, val, 0)) {
	    SvREFCNT_dec(val);
	    XSRETURN_NO;
	} else {
	    XSRETURN_YES;
	}
    }
#line 231 "Util.c"
    }
    XSRETURN_EMPTY;
}

#ifdef __cplusplus
extern "C"
#endif
XS(boot_Hash__Util); /* prototype to pass -Wmissing-prototypes */
XS(boot_Hash__Util)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
#if (PERL_REVISION == 5 && PERL_VERSION < 9)
    char* file = __FILE__;
#else
    const char* file = __FILE__;
#endif

    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(items); /* -W */
    XS_VERSION_BOOTCHECK ;

        (void)newXSproto_portable("Hash::Util::all_keys", XS_Hash__Util_all_keys, file, "\\%\\@\\@");
        (void)newXS("Hash::Util::hidden_ref_keys", XS_Hash__Util_hidden_ref_keys, file);
        (void)newXS("Hash::Util::legal_ref_keys", XS_Hash__Util_legal_ref_keys, file);
        (void)newXSproto_portable("Hash::Util::hv_store", XS_Hash__Util_hv_store, file, "\\%$$");
#if (PERL_REVISION == 5 && PERL_VERSION >= 9)
  if (PL_unitcheckav)
       call_list(PL_scopestack_ix, PL_unitcheckav);
#endif
    XSRETURN_YES;
}

