﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc	difficulty
999	Unit ports uses read-string! from unit extras, causing errors (segfaults) in programs that only (use ports)	sjamaan	felix winkelmann	"On IRC, user ""szablica"" pointed out that the following program will cause a segfault when run in compiled mode:

{{{
#!scm
(use ports)

(define (read-file-contents filename)
  (call-with-output-string
    (lambda (result-string)
      (call-with-input-file
        filename
        (lambda (source-file)
          (copy-port source-file result-string))))))

(display (read-file-contents ""/etc/hosts""))
}}}

If you run it with a Chicken built with DEBUGBUILD=1, you'll get a decent error message:

{{{
Error: unbound variable: read-string!

        Call history:

        foo.scm:11: read-file-contents    
        foo.scm:4: call-with-output-string        
        foo.scm:6: call-with-input-file   
        foo.scm:9: copy-port            <--
}}}

It works fine from csi.  The reason this doesn't work is that {{{read-string!}}} is provded by unit extras, but ports doesn't depend on it.  Simply adding {{{(uses extras)}}} to the declarations causes the problem to go away, but AFAICT, this is iffy: extras already declares {{{(uses ports)}}} so this would mean we've introduced a circular dependency.

I think such implicit dependencies could be easily prevented by converting core to use proper modules, and getting rid of the ""unit"" concept, but I don't know if that's feasible."	defect	closed	major	someday	core libraries	4.8.x	fixed			
