diff options
author | Nicholas Clark <nick@ccl4.org> | 2002-04-16 23:22:41 +0100 |
---|---|---|
committer | Jarkko Hietaniemi <jhi@iki.fi> | 2002-04-16 22:05:07 +0000 |
commit | fe7bca907fe77f091cc40c458c768c0db469e921 (patch) | |
tree | 2fea22add731aa2ab7449ce62dcf2bb69f3b6b15 | |
parent | 16537909412fc4f9eac20f6fc9a1b80bddb3cdd5 (diff) | |
download | perl-fe7bca907fe77f091cc40c458c768c0db469e921.tar.gz |
Re: Unbalanced string table refcount (was: perl@15930)
Message-ID: <20020416212241.GA315@Bagpuss.unfortu.net>
p4raw-id: //depot/perl@15958
-rw-r--r-- | embed.fnc | 2 | ||||
-rw-r--r-- | global.sym | 1 | ||||
-rw-r--r-- | hv.c | 24 | ||||
-rw-r--r-- | universal.c | 13 |
4 files changed, 32 insertions, 8 deletions
@@ -278,7 +278,7 @@ Apd |char* |hv_iterkey |HE* entry|I32* retlen Apd |SV* |hv_iterkeysv |HE* entry Apd |HE* |hv_iternext |HV* tb Apd |SV* |hv_iternextsv |HV* hv|char** key|I32* retlen -ApM |HE* |hv_iternext_flags|HV* tb|I32 flags +ApMd |HE* |hv_iternext_flags|HV* tb|I32 flags Apd |SV* |hv_iterval |HV* tb|HE* entry Ap |void |hv_ksplit |HV* hv|IV newmax Apd |void |hv_magic |HV* hv|GV* gv|int how diff --git a/global.sym b/global.sym index cc4d2a164a..dec0480c38 100644 --- a/global.sym +++ b/global.sym @@ -208,6 +208,7 @@ Perl_is_utf8_string Perl_is_utf8_alnum Perl_is_utf8_alnumc Perl_is_utf8_idfirst +Perl_is_utf8_idcont Perl_is_utf8_alpha Perl_is_utf8_ascii Perl_is_utf8_space @@ -1758,6 +1758,14 @@ Perl_hv_iterinit(pTHX_ HV *hv) Returns entries from a hash iterator. See C<hv_iterinit>. +You may call C<hv_delete> or C<hv_delete_ent> on the hash entry that the +iterator currently points to, without losing your place or invalidating your +iterator. Note that in this case the current entry is deleted from the hash +with your iterator holding the last reference to it. Your iterator is flagged +to free the entry on the next call to C<hv_iternext>, so you must not discard +your iterator immediately else the entry will leak - call C<hv_iternext> to +trigger the resource deallocation. + =cut */ @@ -1768,11 +1776,19 @@ Perl_hv_iternext(pTHX_ HV *hv) } /* -XXX=for apidoc hv_iternext - -Returns entries from a hash iterator. See C<hv_iterinit>. +=for apidoc hv_iternext_flags + +Returns entries from a hash iterator. See C<hv_iterinit> and C<hv_iternext>. +The C<flags> value will normally be zero; if HV_ITERNEXT_WANTPLACEHOLDERS is +set the placeholders keys (for restricted hashes) will be returned in addition +to normal keys. By default placeholders are automatically skipped over. +Currently a placeholder is implemented with a value that is literally +<&Perl_sv_undef> (a regular C<undef> value is a normal read-write SV for which +C<!SvOK> is false). Note that the implementation of placeholders and +restricted hashes may change, and the implementation currently is +insufficiently abstracted for any change to be tidy. -XXX=cut +=cut */ HE * diff --git a/universal.c b/universal.c index 550ea4dfee..926d1c349d 100644 --- a/universal.c +++ b/universal.c @@ -520,9 +520,16 @@ XS(XS_Internals_hv_clear_placehold) I32 riter = HvRITER(hv); HE *eiter = HvEITER(hv); hv_iterinit(hv); - while (items - && (entry - = hv_iternext_flags(hv, HV_ITERNEXT_WANTPLACEHOLDERS))) { + /* This may look suboptimal with the items *after* the iternext, but + it's quite deliberate. We only get here with items==0 if we've + just deleted the last placeholder in the hash. If we've just done + that then it means that the hash is in lazy delete mode, and the + HE is now only referenced in our iterator. If we just quit the loop + and discarded our iterator then the HE leaks. So we do the && the + other way to ensure iternext is called just one more time, which + has the side effect of triggering the lazy delete. */ + while ((entry = hv_iternext_flags(hv, HV_ITERNEXT_WANTPLACEHOLDERS)) + && items) { SV *val = hv_iterval(hv, entry); if (val == &PL_sv_undef) { |