unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* port-for-each vs lazy sweep
@ 2007-08-19  1:22 Kevin Ryde
  2007-08-20  8:42 ` Ludovic Courtès
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Kevin Ryde @ 2007-08-19  1:22 UTC (permalink / raw)
  To: guile-devel

I've struck, in 1.8, port-for-each passing a freed cell to its iterator
func.  Eg. "guile -s foo.scm" on

    (define lst '())
    (gc) (gc) (gc)
    (make-list 1000)
    (open-input-file "/etc/passwd")
    (make-list 1000)
    (open-input-file "/etc/passwd")
    (make-list 1000)
    (open-input-file "/etc/passwd")
    (make-list 1000)
    (open-input-file "/etc/passwd")

    (gc)

    (port-for-each (lambda (port)
                     (set! lst (cons port lst))))
    (gc) (gc) (gc)

    (display lst) (newline)

gives

    (#<freed cell 0xb7c3bd20; GC missed a reference> #<freed cell 0xb7c3ed78; GC missed a reference> #<freed cell 0xb7c41558; GC missed a reference> #<input: port-weak.scm 5> #<output: standard error /dev/pts/2> #<output: standard output /dev/pts/2> #<input: standard input /dev/pts/2> #<input-output: string 805d030> #<output: string 805cf70>)


I suspect the opened ports are correctly found to be unused and left
unmarked by the gc, but they remain in the port table.  port-for-each
then passes them to its func and a little later the sweep gets to them
and they turn into freed cells.  (I noticed this when printing ports
from within port-for-each as a diagnostic.)

I suppose either port-for-each should ignore ports which are unmarked
and unswept; or the gc should sweep the port table entries immediately
instead of lazily.  Neither sounds pretty, but the latter might be safer
than letting zombies remain in the port table.  I suspect for instance
`flush-all' could suffer the same problem if it does a callback to a
soft port flush function (or a C code ptob flush func if that somehow
provoked some sweeping).

(This got me wondering why there's a port table anyway, instead of
independent objects with say a weak hash table for the "list of all
ports" needed by port-for-each and flush-all.  Historical reasons I
suppose.)


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2007-10-27 15:07 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-19  1:22 port-for-each vs lazy sweep Kevin Ryde
2007-08-20  8:42 ` Ludovic Courtès
2007-08-21  0:30   ` Kevin Ryde
2007-08-23  0:32     ` Kevin Ryde
2007-08-23  7:25       ` Ludovic Courtès
2007-08-25 18:57 ` Han-Wen Nienhuys
2007-08-25 22:20 ` Han-Wen Nienhuys
2007-08-26 17:04   ` Ludovic Courtès
2007-08-26 17:16     ` Han-Wen Nienhuys
2007-08-26 17:36       ` Ludovic Courtès
2007-08-26 18:06     ` Han-Wen Nienhuys
2007-09-03 17:20       ` Ludovic Courtès
2007-09-03 19:34         ` Han-Wen Nienhuys
2007-09-04  9:08         ` Ludovic Courtès
2007-10-01 20:23         ` Ludovic Courtès
2007-10-27 15:07           ` Ludovic Courtès

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).