2 Copyright (c) 1995,1996-1998 Nick Ing-Simmons. All rights reserved.
3 This program is free software; you can redistribute it and/or
4 modify it under the same terms as Perl itself.
11 typedef long used_proc _((void *,SV *,long));
12 typedef struct hash_s *hash_ptr;
15 #define sv_dump(sv) PerlIO_printf(PerlIO_stderr(), "\n")
20 static hash_ptr pile = NULL;
23 LangDumpVec(char *who, int count, SV **data)
26 PerlIO_printf(PerlIO_stderr(), "%s (%d):\n", who, count);
27 for (i = 0; i < count; i++)
32 PerlIO_printf(PerlIO_stderr(), "%2d ", i);
45 lookup(hash_ptr *ht, SV *sv, void *tag)
46 {unsigned hash = ((unsigned long) sv) % MAX_HASH;
47 hash_ptr p = ht[hash];
60 p = (hash_ptr) malloc(sizeof(struct hash_s));
72 for (sva = PL_sv_arenaroot; sva; sva = (SV *) SvANY(sva))
75 SV *svend = &sva[SvREFCNT(sva)];
78 if (SvROK(sv) && ((IV) SvANY(sv)) & 1)
80 warn("Odd SvANY for %p @ %p[%d]",sv,sva,(sv-sva));
89 sv_apply_to_used(p, proc,n)
95 for (sva = PL_sv_arenaroot; sva; sva = (SV *) SvANY(sva))
98 SV *svend = &sva[SvREFCNT(sva)];
102 if (SvTYPE(sv) != SVTYPEMASK)
104 n = (*proc) (p, sv, n);
112 static char old[] = "old";
113 static char new[] = "new";
126 note_used(hash_ptr **x)
129 Newz(603, ht, MAX_HASH, hash_ptr);
131 return sv_apply_to_used(ht, note_sv, 0);
135 check_sv(void *p, SV *sv, long hwm)
137 char *state = lookup(p,sv,new);
140 fprintf(stderr,"%s %p : ", state ? state : new, sv);
147 find_object(void *p, SV *sv, long count)
158 check_used(hash_ptr **x)
162 croak("Please call Devel::Check::NoteSV() before calling Devel::Check::CheckSV()");
164 long count = sv_apply_to_used(ht, check_sv, 0);
166 for (i = 0; i < MAX_HASH; i++)
174 LangDumpVec(t->tag ? t->tag : "NUL",1,&t->sv);
186 add_to_AV(void *p, SV *sv, long av)
188 char *state = lookup(p,sv,new);
192 SV* sv_ptr = newSViv((IV)sv);
193 note_sv(p,sv_ptr,0); /* tricky: avoid that the newly created SV is also counted... */
194 av_push((AV*)av, sv_ptr);
196 av_push((AV*)av, SvREFCNT_inc(sv));
199 return av; /* pass over */
202 MODULE = Devel::Leak PACKAGE = Devel::Leak
208 hash_ptr * obj = NO_INIT
211 RETVAL = note_used(&obj);
222 RETVAL = check_used(&obj);
232 RETVAL = sv_apply_to_used(NULL, find_object, 0);
248 note_sv(ht,RETVAL,0); /* tricky: avoid that the newly created AV is also counted... */
249 sv_apply_to_used(ht, add_to_AV, (long)RETVAL); /* misuse long for pointer --- should be always large enough */
250 sv_2mortal((SV*)RETVAL);