On Sat, Mar 20, 2010 at 2:44 PM, Matthew Mondor <mm_lists@pulsar-zone.net> wrote:
With CVS HEAD ECL, I noticed that if I create a stream over an FD using
ecl_make_stream_from_fd() in smm_io mode, segmentation faults occur for
si:file-stream-fd, si::set-buffering-mode as well as read-char. 

Most likely fdopen() is failing and the resulting stream is in a bogus state. I have added an error message to ecl_make_stream_from_fd() to signal that problem.

A candidate for failure is when you create a file descriptor with one mode and try to fdopen() it with a different mode, as in the following tiny example:

(ffi::clines "#include <fcntl.h>")

(defun make-stream (filename)
  (let ((f (namestring filename)))
    (ffi:c-inline (f) (:object) :object "
mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
cl_object file = #0;
int fd = open(file->base_string.self, O_RDONLY, mode);
printf(\"%d %s\", fd, file->base_string.self);
@(return) = ecl_make_stream_from_fd(file, fd, smm_io,
                                            8, 0, @:default);
                  :one-liner nil)))

Replacing smm_io with smm_input fixes the problem here. 

Instituto de Física Fundamental, CSIC
c/ Serrano, 113b, Madrid 28006 (Spain)