On Wed, Jan 19, 2000 at 04:00:03PM -0500, Joshua N Pritikin wrote:
> That's a cool test script.  It certainly appears to be failing to cancel
> watchers and refusing to exit.  I need to dust off my thinking cap...  :-)

I think I found the problem.  Try the attached patch over 0.58.  This
patches contains all the patches I've sent out today so you might need
to start over with a fresh copy of 0.58 unless you're a patch wizard.

-- 
"Does `competition' have an abstract purpose?"
       via, but not speaking for Deutsche Bank
==== //depot/D/Event/Event.xs#61 - /cache/D/Event/Event.xs ====
--- /tmp/tmp.3389.0     Wed Jan 19 16:54:44 2000
+++ /cache/D/Event/Event.xs     Wed Jan 19 11:45:47 2000
@@ -94,10 +94,12 @@
     MemoryCount[id] += cnt;
 }
 
-#if DEBUGGING
+#if EVENT_MEMORY_DEBUG
 #  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 */
@@ -309,7 +311,7 @@
 _memory_counters()
      PPCODE:
 {
-#ifdef DEBUGGING
+#ifdef EVENT_MEMORY_DEBUG
     int xx;
     for (xx=0; xx < MAX_MEMORYCOUNT; xx++)
        XPUSHs(sv_2mortal(newSViv(MemoryCount[xx])));
==== //depot/D/Event/c/hook.c#5 - /cache/D/Event/c/hook.c ====
--- /tmp/tmp.3389.1     Wed Jan 19 16:54:44 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.3389.2     Wed Jan 19 16:54:44 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.3389.3     Wed Jan 19 16:54:44 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/queue.c#28 - /cache/D/Event/c/queue.c ====
--- /tmp/tmp.3389.4     Wed Jan 19 16:54:44 2000
+++ /cache/D/Event/c/queue.c    Wed Jan 19 16:54:06 2000
@@ -149,6 +149,9 @@
 }
 
 static int one_event(double tm) {  /**INVOKE**/
+    /*if (SvIVX(DebugLevel) >= 4)
+      warn("Event: ActiveWatchers=%d\n", ActiveWatchers);*/
+
     pe_signal_asynccheck();
     if (!PE_RING_EMPTY(&AsyncCheck)) pe_map_check(&AsyncCheck);
 
==== //depot/D/Event/c/signal.c#19 - /cache/D/Event/c/signal.c ====
--- /tmp/tmp.3389.5     Wed Jan 19 16:54:44 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.3389.6     Wed Jan 19 16:54:44 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.3389.7     Wed Jan 19 16:54:44 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.3389.8     Wed Jan 19 16:54:44 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.3389.9     Wed Jan 19 16:54:45 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.3389.10    Wed Jan 19 16:54:45 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.3389.11    Wed Jan 19 16:54:45 2000
+++ /cache/D/Event/c/watcher.c  Wed Jan 19 16:51:41 2000
@@ -49,8 +49,8 @@
     pe_event *ev;
     while (!PE_RING_EMPTY(&wa->events)) {
        pe_ring *lk = wa->events.prev;
-       PE_RING_DETACH(lk);
        ev = (pe_event*) lk->self;
+       dequeEvent(ev);
        pe_event_release(ev);
     }
 }
@@ -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;
==== //depot/D/Event/lib/Event/EventAPI.h#37 - /cache/D/Event/lib/Event/EventAPI.h ====
--- /tmp/tmp.3389.12    Wed Jan 19 16:54:45 2000
+++ /cache/D/Event/lib/Event/EventAPI.h Wed Jan 19 16:47:42 2000
@@ -25,8 +25,8 @@
     IV running; /* SAVEINT */
     U32 flags;
     SV *desc;
-    pe_ring all;
-    pe_ring events;  /* queued events */
+    pe_ring all;       /* all watchers */
+    pe_ring events;    /* this watcher's queued events */
     HV *FALLBACK;
     I16 event_counter; /* refcnt? XXX */
     I16 prio;

Reply via email to