This is the mail archive of the guile@cygnus.com mailing list for the guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: latest port-line fix.



> I could see why you'd want the extra insurance test, but I'd be afraid
> of making the code self-inconsistent.  Someone might reason about
> what fgets can or should return based on the code in genio.c & then
> break the code in ioext.c, or might decide there's a bug in ioext.c &
> add the additional test, ...
> 
> Or do you have other reasons for the extra test?

At first I just put it in there on reflex, without thinking about it
much.  When I looked at your patch, I realized that the invariant you
mention was true, but I was still uncomfortable balancing the
correctness of scm_do_read_line on a promise to be maintained by any
number of port implementations.  So as of Monday, the code reads:


    char *
    scm_do_read_line (port, len)
	 SCM port;
	 int *len;
    {
      char *s;
      scm_sizet i;

      i = SCM_PTOBNUM (port);
      SCM_SYSCALL (s = (scm_ptobs[i].fgets) (port, len));

      /* We should never get an empty string.  Every line has a newline at
	 the end, except for the last one.  If the last line has no
	 newline and is empty, then that's just an ordinary EOF, and we
	 should have s == NULL.  But this seems obscure to me, so we check
	 this here, to protect ourselves from odd port implementations.  */
      if (s && *len <= 0)
	abort ();

      /* If we're not at EOF, and there was a newline at the end of the
	 string, increment the line counter.  */
      if (s && s[*len - 1] == '\n')
	SCM_INCLINE(port);

      return s;
    }

Never before has such a small piece of code received such careful,
loving attention. :)