* Guile 2.0.0 cannot open /dev/urandom
@ 2011-02-17 22:58 Martin Ward
2011-02-18 4:44 ` Mark Harig
2011-02-27 22:47 ` Andy Wingo
0 siblings, 2 replies; 4+ messages in thread
From: Martin Ward @ 2011-02-17 22:58 UTC (permalink / raw)
To: bug-guile
Guile 1.8.6 can open /dev/urandom (which I use for seeding a random
number generator):
% guile
guile> (open-input-file "/dev/urandom")
#<input: /dev/urandom 9>
guile>
But guile 2.0.0 gives this error:
~/Documents/guile-2.0.0/meta/guile
GNU Guile 2.0.0
Copyright (C) 1995-2011 Free Software Foundation, Inc.
Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
This program is free software, and you are welcome to redistribute it
under certain conditions; type `,show c' for details.
Enter `,help' for help.
scheme@(guile-user)> (open-input-file "/dev/urandom")
ERROR: In procedure open-file:
ERROR: In procedure fport_end_input: Invalid argument
Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue.
scheme@(guile-user) [1]> ,bt
0 (open-file "/dev/urandom" "r")
scheme@(guile-user) [1]>
--
Martin
STRL Reader in Software Engineering and Royal Society Industry Fellow
martin@gkc.org.uk http://www.cse.dmu.ac.uk/~mward/ Erdos number: 4
G.K.Chesterton web site: http://www.cse.dmu.ac.uk/~mward/gkc/
Mirrors: http://www.gkc.org.uk and http://www.gkc.org.uk/gkc
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Guile 2.0.0 cannot open /dev/urandom
2011-02-17 22:58 Guile 2.0.0 cannot open /dev/urandom Martin Ward
@ 2011-02-18 4:44 ` Mark Harig
2011-02-27 22:47 ` Andy Wingo
1 sibling, 0 replies; 4+ messages in thread
From: Mark Harig @ 2011-02-18 4:44 UTC (permalink / raw)
To: martin, bug-guile
On Thu, Feb 17, 2011 at 10:58:33PM +0000, Martin Ward wrote:
>
> Guile 1.8.6 can open /dev/urandom (which I use for seeding a random
> number generator):
>
> % guile
> guile> (open-input-file "/dev/urandom")
> #<input: /dev/urandom 9>
> guile>
>
> But guile 2.0.0 gives this error:
>
> ~/Documents/guile-2.0.0/meta/guile
> GNU Guile 2.0.0
> Copyright (C) 1995-2011 Free Software Foundation, Inc.
>
> Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
> This program is free software, and you are welcome to redistribute it
> under certain conditions; type `,show c' for details.
>
> Enter `,help' for help.
> scheme@(guile-user)> (open-input-file "/dev/urandom")
> ERROR: In procedure open-file:
> ERROR: In procedure fport_end_input: Invalid argument
>
> Entering a new prompt. Type `,bt' for a backtrace or `,q' to
continue.
> scheme@(guile-user) [1]> ,bt
> 0 (open-file "/dev/urandom" "r")
> scheme@(guile-user) [1]>
>
>
> --
As a work-around until the Guile developers can decide how
this is going to be handled, specifying that the file is to be opened
in read-only, binary mode works on bothGuile 2.0 and Guile 1.8.
This requires that you use `open-file' instead of `open-input-file':
$ guile
GNU Guile 2.0.0
Copyright (C) 1995-2011 Free Software Foundation, Inc.
Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
This program is free software, and you are welcome to redistribute it
under certain conditions; type `,show c' for details.
Enter `,help' for help.
scheme@(guile-user)> (open-file "/dev/urandom" "rb")
$1 = #<input: /dev/urandom 108>
scheme@(guile-user)> ,q
$ /usr/bin/guile
guile> (version)
"1.8.7"
guile> (open-file "/dev/urandom" "rb")
#<input: /dev/urandom 9>
guile>
The file, /dev/urandom, will then be opened in read-only
mode for both versions of Guile.
--
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Guile 2.0.0 cannot open /dev/urandom
2011-02-17 22:58 Guile 2.0.0 cannot open /dev/urandom Martin Ward
2011-02-18 4:44 ` Mark Harig
@ 2011-02-27 22:47 ` Andy Wingo
2011-03-03 11:57 ` Andy Wingo
1 sibling, 1 reply; 4+ messages in thread
From: Andy Wingo @ 2011-02-27 22:47 UTC (permalink / raw)
To: Martin Ward; +Cc: bug-guile, Mike Gran
Hi Martin,
On Thu 17 Feb 2011 23:58, Martin Ward <martin@gkc.org.uk> writes:
> scheme@(guile-user)> (open-input-file "/dev/urandom")
> ERROR: In procedure open-file:
> ERROR: In procedure fport_end_input: Invalid argument
Good catch!
The relevant part of the C backtrace is:
#22 0x00007ffff7cd83f6 in scm_syserror (subr=0x7ffff7d8008e "fport_end_input") at error.c:177
#23 0x00007ffff7ce174c in fport_end_input (port=<value optimized out>, offset=<value optimized out>) at fports.c:838
#24 0x00007ffff7ce1817 in fport_seek (port=<value optimized out>, offset=<value optimized out>,
whence=<value optimized out>) at fports.c:709
#25 0x00007ffff7d13d65 in scm_seek (fd_port=0x118cec0, offset=0x2, whence=<value optimized out>) at ports.c:1768
#26 0x00007ffff7d1f5a9 in scm_i_scan_for_encoding (port=0x118cec0) at read.c:1672
#27 0x00007ffff7ce250b in scm_open_file (filename=0x11659e0, mode=0x7676c0) at fports.c:463
It seems that Guile is scanning the first few lines of the file for a
"coding" declaration. This is because it is being opened in textual
mode; if you open with (open-file "/dev/urandom" "rb") you will probably
get what you want.
It should not be erroring out here. In fact the error appears to
proceed from an attempt to seek in the port after reading out the first
N bytes to scan them for a coding directive; hummm. Mike, it seems that
we should unget bytes onto the port instead of seeking; does that sound
right to you?
Martin, note that with Guile 1.8 and earlier, byte IO masquerading as
character IO was all you have. Now with 2.0 you really want to be
dealing with binary ports and bytevectors and such.
Thanks for the report,
Andy
--
http://wingolog.org/
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Guile 2.0.0 cannot open /dev/urandom
2011-02-27 22:47 ` Andy Wingo
@ 2011-03-03 11:57 ` Andy Wingo
0 siblings, 0 replies; 4+ messages in thread
From: Andy Wingo @ 2011-03-03 11:57 UTC (permalink / raw)
To: Martin Ward; +Cc: bug-guile, Mike Gran
Hi Martin,
On Sun 27 Feb 2011 23:47, Andy Wingo <wingo@pobox.com> writes:
> On Thu 17 Feb 2011 23:58, Martin Ward <martin@gkc.org.uk> writes:
>
>> scheme@(guile-user)> (open-input-file "/dev/urandom")
>> ERROR: In procedure open-file:
>> ERROR: In procedure fport_end_input: Invalid argument
>
> It seems that Guile is scanning the first few lines of the file for a
> "coding" declaration. This is because it is being opened in textual
> mode; if you open with (open-file "/dev/urandom" "rb") you will probably
> get what you want.
I have fixed the (open-input-file "/dev/urandom") case, by having the
coding: scan use the read buffer if possible, to avoid a seek. That
should catch all cases of interest.
Regards,
Andy
--
http://wingolog.org/
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-03-03 11:57 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-17 22:58 Guile 2.0.0 cannot open /dev/urandom Martin Ward
2011-02-18 4:44 ` Mark Harig
2011-02-27 22:47 ` Andy Wingo
2011-03-03 11:57 ` Andy Wingo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).