<div class="gmail_quote">On Sat, Mar 20, 2010 at 2:44 PM, Matthew Mondor <span dir="ltr"><<a href="mailto:mm_lists@pulsar-zone.net">mm_lists@pulsar-zone.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
With CVS HEAD ECL, I noticed that if I create a stream over an FD using<br>
ecl_make_stream_from_fd() in smm_io mode, segmentation faults occur for<br>
si:file-stream-fd, si::set-buffering-mode as well as read-char. </blockquote><div><br></div><div>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.</div>
<div><br></div><div>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:</div><div><br></div><div>(ffi::clines "#include <fcntl.h>")</div>
<div><br></div><div>(defun make-stream (filename)</div><div>  (let ((f (namestring filename)))</div><div>    (ffi:c-inline (f) (:object) :object "</div><div>{</div><div><span class="Apple-tab-span" style="white-space:pre">   </span>mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;</div>
<div><span class="Apple-tab-span" style="white-space:pre">      </span>cl_object file = #0;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>int fd = open(file->base_string.self, O_RDONLY, mode);</div>
<div><span class="Apple-tab-span" style="white-space:pre">      </span>printf(\"%d %s\", fd, file->base_string.self);</div><div><span class="Apple-tab-span" style="white-space:pre">  </span>@(return) = ecl_make_stream_from_fd(file, fd, smm_io,</div>
<div>                                            8, 0, @:default);</div><div>}"</div><div>                  :one-liner nil)))</div><div><br></div><div>Replacing smm_io with smm_input fixes the problem here. </div></div>
<br>-- <br>Instituto de Física Fundamental, CSIC<br>c/ Serrano, 113b, Madrid 28006 (Spain) <br><a href="http://tream.dreamhosters.com">http://tream.dreamhosters.com</a><br>