diff options
author | Malcolm Beattie <mbeattie@sable.ox.ac.uk> | 1997-05-25 21:19:38 +0000 |
---|---|---|
committer | Malcolm Beattie <mbeattie@sable.ox.ac.uk> | 1997-05-25 21:19:38 +0000 |
commit | 97fcbf9696d4cdc3d47f383b99d9840ccb39c616 (patch) | |
tree | db7f5a92355aa3402f174a0065ca2542147c15ee /av.c | |
parent | ae77835f9b08444f73b593d4cdc0758132dbbf00 (diff) | |
download | perl-97fcbf9696d4cdc3d47f383b99d9840ccb39c616.tar.gz |
Fix up integration 5.003->5.004.
p4raw-id: //depot/perl@19
Diffstat (limited to 'av.c')
-rw-r--r-- | av.c | 78 |
1 files changed, 78 insertions, 0 deletions
@@ -507,6 +507,35 @@ I32 lval; } SV** +avhv_fetch_ent(av, keysv, lval, hash) +AV *av; +SV *keysv; +I32 lval; +U32 hash; +{ + SV **keys, **indsvp; + HE *he; + I32 ind; + + keys = av_fetch(av, 0, FALSE); + if (!keys || !SvROK(*keys) || SvTYPE(SvRV(*keys)) != SVt_PVHV) + croak("Can't coerce array into hash"); + he = hv_fetch_ent((HV*)SvRV(*keys), keysv, FALSE, hash); + if (he) { + ind = SvIV(HeVAL(he)); + if (ind < 1) + croak("Bad index while coercing array into hash"); + } else { + if (!lval) + return 0; + + ind = AvFILL(av) + 1; + hv_store_ent((HV*)SvRV(*keys), keysv, newSViv(ind), 0); + } + return av_fetch(av, ind, lval); +} + +SV** avhv_store(av, key, klen, val, hash) AV *av; char *key; @@ -533,6 +562,20 @@ U32 hash; } bool +avhv_exists_ent(av, keysv, hash) +AV *av; +SV *keysv; +U32 hash; +{ + SV **keys; + + keys = av_fetch(av, 0, FALSE); + if (!keys || !SvROK(*keys) || SvTYPE(SvRV(*keys)) != SVt_PVHV) + croak("Can't coerce array into hash"); + return hv_exists_ent((HV*)SvRV(*keys), keysv, hash); +} + +bool avhv_exists(av, key, klen) AV *av; char *key; @@ -581,6 +624,41 @@ I32 flags; return sv; } +/* avhv_delete_ent leaks. Caller can re-index and compress if so desired. */ +SV * +avhv_delete_ent(av, keysv, flags, hash) +AV *av; +SV *keysv; +I32 flags; +U32 hash; +{ + SV **keys; + SV *sv; + SV **svp; + I32 ind; + + keys = av_fetch(av, 0, FALSE); + if (!keys || !SvROK(*keys) || SvTYPE(SvRV(*keys)) != SVt_PVHV) + croak("Can't coerce array into hash"); + sv = hv_delete_ent((HV*)SvRV(*keys), keysv, 0, hash); + if (!sv) + return Nullsv; + ind = SvIV(sv); + if (ind < 1) + croak("Bad index while coercing array into hash"); + svp = av_fetch(av, ind, FALSE); + if (!svp) + return Nullsv; + if (flags & G_DISCARD) { + sv = Nullsv; + SvREFCNT_dec(*svp); + } else { + sv = sv_2mortal(*svp); + } + *svp = &sv_undef; + return sv; +} + I32 avhv_iterinit(av) AV *av; |