[plt-scheme] ports, make-srcloc and recursive reads
At Mon, 23 Apr 2007 22:20:49 -0400 (EDT), Dimitris Vyzovitis wrote:
> On Mon, 23 Apr 2007, Dimitris Vyzovitis wrote:
>
> > On Tue, 24 Apr 2007, Matthew Flatt wrote:
> >
> > > Is there some other way that this shows up, though?
> >
> > Not that I have seen.
>
> port-next-location is defined like this [portfun.c]:
> static Scheme_Object *port_next_location(int argc, Scheme_Object *argv[])
> {
> Scheme_Object *a[3];
> long line, col, pos;
>
> if (!SCHEME_INPUT_PORTP(argv[0]) && !SCHEME_OUTPUT_PORTP(argv[0]))
> scheme_wrong_type("port-next-location", "port", 0, argc, argv);
>
> scheme_tell_all(argv[0], &line, &col, &pos);
>
> a[0] = ((line < 0) ? scheme_false : scheme_make_integer_value(line));
> a[1] = ((col < 0) ? scheme_false : scheme_make_integer_value(col));
> a[2] = ((pos < 0) ? scheme_false : scheme_make_integer_value(pos+1));
>
> return scheme_values(3, a);
> }
>
> So it can conceivably be triggered by ports that have 0s at line/col/pos
> in plain reads.
The `line' result reported by scheme_tell_all() should never be 0; the
line counter is initialized to 1 when line counting is on.
The `col' result can be 0, but column counting starts from 0.
The `pos' result can be 0 (because it's easier to count from 0
internally), but 1 is added for the (external) result.
So, while it's a bit tricky, I think it works out at this level.
Thanks,
Matthew