cvs commit: ponie/perl perl.c

[email protected] (Nicholas Clark) 10 May 2005 15:10:39 -0000
Newsgroups perl.ponie.changes
Message-ID <[email protected]>
cvsuser     05/05/10 08:10:39

  Modified:    perl     perl.c
  Log:
  Clean up the symbol table at global destruction time.
  
  Revision  Changes    Path
  1.29      +40 -0     ponie/perl/perl.c
  
  Index: perl.c
  ===================================================================
  RCS file: /cvs/public/ponie/perl/perl.c,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- perl.c	6 May 2005 09:56:05 -0000	1.28
  +++ perl.c	10 May 2005 15:10:38 -0000	1.29
  @@ -455,6 +455,35 @@
   =cut
   */
   
  +void
  +S_perl_clear_symtable(pTHX_ HV *stash) {
  +  HE* entry;
  +
  +  if (SvRMAGICAL(stash)) {
  +      assert (!mg_find((SV*)stash, PERL_MAGIC_tied));
  +  }
  +
  +  hv_iterinit(stash);
  +  while ((entry = hv_iternext(stash))) {
  +      SV *val = HeVAL(entry);
  +      HeVAL(entry) = &PL_sv_placeholder;
  +
  +      if (isGV(val)) {
  +	  STRLEN len = GvNAMELEN(val);
  +	  const char *name = GvNAME(val);
  +
  +	  /* name =~ /::$/;  */
  +	  if (name && --len && name[len] == ':' && name[len-1] == ':') {
  +	      HV *substash = GvHV(val);
  +
  +	      if (substash)
  +		  S_perl_clear_symtable(aTHX_ substash);
  +	  }
  +      }
  +      SvREFCNT_dec(val);
  +  }
  +}
  +
   int
   perl_destruct(pTHXx)
   {
  @@ -816,6 +845,7 @@
   
       hv = PL_defstash;
       PL_defstash = 0;
  +    S_perl_clear_symtable(aTHX_ hv);
       SvREFCNT_dec(hv);
       SvREFCNT_dec(PL_curstname);
       PL_curstname = Nullsv;
  @@ -4904,3 +4934,13 @@
       sv_chop(PL_e_script, nl);
       return 1;
   }
  +
  +/*
  + * Local variables:
  + * c-indentation-style: bsd
  + * c-basic-offset: 4
  + * indent-tabs-mode: t
  + * End:
  + *
  + * vim: shiftwidth=4:
  +*/