On 19 Jan, [EMAIL PROTECTED] wrote:
> perl -V reported that my perl was not compiled for debugging, so I set DEBUGGING in
> Makefile.PL by adding "DEFINE => '-DDEBUGGING'". Sorry, I'm not that familiar with
> MakeMaker, but a look through the docs and a check of the resulting makefile made me
> think this is the way to do this.
Yah, that's fine.
> Now, it compiles, but fails to complete the tests
> (while it passes them successfully without that switch). The following message
>appears
> for all tests and seems to be essential:
>
> "Reference miscount in sv_replace() at blib/lib/Event.pm line 184."
Whoa! I've never seen that. Can you post the output from 'perl -V'?
Maybe I can try to reproduce the problem with exactly the same version
of perl...
> > Admittedly, it's nasty stuff. I hate memory leaks.
>
> Really nasty, I know. I appreciate your help.
Well, the following patch should track all of Event's dynamic memory, but
it sounds like I need to investigate the sv_replace() problem first.
==== //depot/D/Event/Event.xs#61 - /cache/D/Event/Event.xs ====
--- /tmp/tmp.2411.0 Wed Jan 19 11:08:56 2000
+++ /cache/D/Event/Event.xs Wed Jan 19 10:51:10 2000
@@ -96,8 +96,10 @@
#if DEBUGGING
# define EvNew(id, ptr, size, type) dbg_count_memory(id,1); New(0,ptr,size,type)
+# define EvFree(id, ptr) STMT_START { dbg_count_memory(id,-1); safefree(ptr); }
+STMT_END
#else
# define EvNew(x, ptr, size, type) New(0,ptr,size,type)
+# define EvFree(id, ptr) safefree(ptr)
#endif
static int ActiveWatchers=0; /* includes WaACTIVE + queued events */
==== //depot/D/Event/c/hook.c#5 - /cache/D/Event/c/hook.c ====
--- /tmp/tmp.2411.1 Wed Jan 19 11:08:56 2000
+++ /cache/D/Event/c/hook.c Wed Jan 19 10:40:07 2000
@@ -44,7 +44,7 @@
if (qcb->is_perl)
SvREFCNT_dec((SV*)qcb->callback);
PE_RING_DETACH(&qcb->ring);
- safefree(qcb);
+ EvFree(2, qcb);
}
static void pe_map_check(pe_ring *List)
==== //depot/D/Event/c/idle.c#18 - /cache/D/Event/c/idle.c ====
--- /tmp/tmp.2411.2 Wed Jan 19 11:08:56 2000
+++ /cache/D/Event/c/idle.c Wed Jan 19 10:46:57 2000
@@ -21,6 +21,7 @@
SvREFCNT_dec(ip->max_interval);
SvREFCNT_dec(ip->min_interval);
pe_watcher_dtor(ev);
+ EvFree(3, ev);
}
static void pe_idle_start(pe_watcher *ev, int repeating) {
==== //depot/D/Event/c/io.c#33 - /cache/D/Event/c/io.c ====
--- /tmp/tmp.2411.3 Wed Jan 19 11:08:56 2000
+++ /cache/D/Event/c/io.c Wed Jan 19 10:47:21 2000
@@ -29,6 +29,7 @@
PE_RING_DETACH(&ev->ioring);
SvREFCNT_dec(ev->handle);
pe_watcher_dtor(_ev);
+ EvFree(4, _ev);
}
static void pe_io_start(pe_watcher *_ev, int repeat) {
==== //depot/D/Event/c/signal.c#19 - /cache/D/Event/c/signal.c ====
--- /tmp/tmp.2411.4 Wed Jan 19 11:08:56 2000
+++ /cache/D/Event/c/signal.c Wed Jan 19 10:48:05 2000
@@ -41,6 +41,11 @@
return (pe_watcher*) ev;
}
+static void pe_signal_dtor(pe_watcher *ev) {
+ pe_watcher_dtor(ev);
+ EvFree(5, ev);
+}
+
static void pe_signal_start(pe_watcher *_ev, int repeat) {
pe_signal *ev = (pe_signal*) _ev;
int sig = ev->signal;
@@ -138,6 +143,7 @@
++sigp;
}
memcpy(vt, &pe_watcher_base_vtbl, sizeof(pe_watcher_base_vtbl));
+ vt->dtor = pe_signal_dtor;
vt->start = pe_signal_start;
vt->stop = pe_signal_stop;
pe_register_vtbl(vt, gv_stashpv("Event::signal",1), &event_vtbl);
==== //depot/D/Event/c/tied.c#16 - /cache/D/Event/c/tied.c ====
--- /tmp/tmp.2411.5 Wed Jan 19 11:08:56 2000
+++ /cache/D/Event/c/tied.c Wed Jan 19 10:46:25 2000
@@ -10,6 +10,11 @@
return (pe_watcher*) ev;
}
+static void pe_tied_dtor(pe_watcher *ev) {
+ pe_watcher_dtor(ev);
+ EvFree(6, ev);
+}
+
static void pe_tied_start(pe_watcher *ev, int repeat) {
HV *stash = SvSTASH(SvRV(ev->mysv));
GV *gv;
@@ -92,6 +97,7 @@
pe_watcher_vtbl *vt = &pe_tied_vtbl;
memcpy(vt, &pe_watcher_base_vtbl, sizeof(pe_watcher_base_vtbl));
vt->did_require = 1; /* otherwise tries to autoload Event::Event! */
+ vt->dtor = pe_tied_dtor;
vt->start = pe_tied_start;
vt->stop = pe_tied_stop;
vt->alarm = pe_tied_alarm;
==== //depot/D/Event/c/timer.c#19 - /cache/D/Event/c/timer.c ====
--- /tmp/tmp.2411.6 Wed Jan 19 11:08:56 2000
+++ /cache/D/Event/c/timer.c Wed Jan 19 10:48:25 2000
@@ -16,6 +16,7 @@
pe_timer *tm = (pe_timer*) ev;
SvREFCNT_dec(tm->interval);
pe_watcher_dtor(ev);
+ EvFree(7, ev);
}
static void pe_timer_start(pe_watcher *ev, int repeat) {
==== //depot/D/Event/c/typemap.c#23 - /cache/D/Event/c/typemap.c ====
--- /tmp/tmp.2411.7 Wed Jan 19 11:08:57 2000
+++ /cache/D/Event/c/typemap.c Wed Jan 19 11:01:14 2000
@@ -22,7 +22,7 @@
while ((mg = *mgp))
mgp = &mg->mg_moremagic;
- EvNew(8, mg, 1, MAGIC);
+ New(0, mg, 1, MAGIC);
Zero(mg, 1, MAGIC);
mg->mg_type = '~';
mg->mg_obj = (SV*) ptr; /* NOT refcnt'd */
==== //depot/D/Event/c/unix_io.c#24 - /cache/D/Event/c/unix_io.c ====
--- /tmp/tmp.2411.8 Wed Jan 19 11:08:57 2000
+++ /cache/D/Event/c/unix_io.c Wed Jan 19 10:40:29 2000
@@ -75,7 +75,7 @@
int ret;
if (pollMax < IOWatchCount) {
if (Pollfd)
- safefree(Pollfd);
+ EvFree(9, Pollfd);
pollMax = IOWatchCount+5;
EvNew(9, Pollfd, pollMax, struct pollfd);
IOWatch_OK = 0;
==== //depot/D/Event/c/var.c#18 - /cache/D/Event/c/var.c ====
--- /tmp/tmp.2411.9 Wed Jan 19 11:08:57 2000
+++ /cache/D/Event/c/var.c Wed Jan 19 11:01:30 2000
@@ -16,6 +16,7 @@
pe_var *wv = (pe_var *)ev;
SvREFCNT_dec(wv->variable);
pe_watcher_dtor(ev);
+ EvFree(10, ev);
}
static void pe_tracevar(pe_watcher *wa, SV *sv, int got) {
@@ -81,7 +82,7 @@
mg->mg_virtual = &PL_vtbl_uvar;
*mgp = mg;
- EvNew(12, ufp, 1, struct ufuncs);
+ EvNew(8, ufp, 1, struct ufuncs);
ufp->uf_val = ev->events & PE_R? tracevar_r : 0;
ufp->uf_set = ev->events & PE_W? tracevar_w : 0;
ufp->uf_index = (IV) ev;
@@ -119,8 +120,8 @@
*mgp = mg->mg_moremagic;
- safefree(mg->mg_ptr);
- safefree(mg);
+ EvFree(8, mg->mg_ptr);
+ EvFree(11, mg);
}
static void _var_restart(pe_watcher *ev) {
==== //depot/D/Event/c/watcher.c#31 - /cache/D/Event/c/watcher.c ====
--- /tmp/tmp.2411.10 Wed Jan 19 11:08:57 2000
+++ /cache/D/Event/c/watcher.c Wed Jan 19 10:45:24 2000
@@ -74,7 +74,7 @@
SvREFCNT_dec(wa->desc);
if (wa->stats)
Estat.dtor(wa->stats);
- safefree(wa);
+ /* safefree(wa); do it yourself */
}
/********************************** *******************************/
@@ -243,7 +243,7 @@
vt = &pe_watcher_base_vtbl;
vt->stash = 0;
vt->did_require = 0;
- vt->dtor = pe_watcher_dtor;
+ vt->dtor = 0;
vt->start = pe_watcher_nostart;
vt->stop = pe_watcher_nostop;
vt->alarm = pe_watcher_alarm;
--
"Never ascribe to malice that which can be explained by stupidity."
via, but not speaking for Deutsche Bank