summaryrefslogtreecommitdiff
path: root/av.c
diff options
context:
space:
mode:
authorMalcolm Beattie <mbeattie@sable.ox.ac.uk>1997-05-25 21:19:38 +0000
committerMalcolm Beattie <mbeattie@sable.ox.ac.uk>1997-05-25 21:19:38 +0000
commit97fcbf9696d4cdc3d47f383b99d9840ccb39c616 (patch)
treedb7f5a92355aa3402f174a0065ca2542147c15ee /av.c
parentae77835f9b08444f73b593d4cdc0758132dbbf00 (diff)
downloadperl-97fcbf9696d4cdc3d47f383b99d9840ccb39c616.tar.gz
Fix up integration 5.003->5.004.
p4raw-id: //depot/perl@19
Diffstat (limited to 'av.c')
-rw-r--r--av.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/av.c b/av.c
index ca6f00a695..e3d341c361 100644
--- a/av.c
+++ b/av.c
@@ -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;