BUG?: HP-UX 10.20 and IO#gets followed by IO#puts 
Author Message
 BUG?: HP-UX 10.20 and IO#gets followed by IO#puts

S>  I get the following behavior for Ruby 1.6.1,1.6.2 and 1.6.3
S> on HP-UX 10.20. Could someone running HP-UX 11 check it?

 Seems normal for me :-)))

 Try to add

S> [derby]:cat /tmp/a.txt
S> line 1
S> [derby]:/mnt/ruby162/bin > ./irb
S> irb(main):001:0> f = File.new("/tmp/a.txt","r+")
S> #<File:0x400deef8>
S> irb(main):002:0> f.gets
S> "line 1\n"

                    f.seek 0, IO::SEEK_CUR

S> irb(main):003:0> f.puts("line 2")
S> nil
S> irb(main):004:0> f.close
S> nil
S> irb(main):005:0> exit

 and look if you have the good result.

Guy Decoux



Mon, 22 Sep 2003 19:47:02 GMT  
 BUG?: HP-UX 10.20 and IO#gets followed by IO#puts
Hi,
 I get the following behavior for Ruby 1.6.1,1.6.2 and 1.6.3
on HP-UX 10.20. Could someone running HP-UX 11 check it?
I checked it on Win NT ( see below ) and the results there
seem OK.

[derby]:cat /tmp/a.txt
line 1
[derby]:/mnt/ruby162/bin > ./irb
irb(main):001:0> f = File.new("/tmp/a.txt","r+")
#<File:0x400deef8>
irb(main):002:0> f.gets
"line 1\n"
irb(main):003:0> f.puts("line 2")
nil
irb(main):004:0> f.close
nil
irb(main):005:0> exit

[derby]:/mnt/ruby162/bin >cat /tmp/a.txt

line 1
line 1
line 2

On Windows ( Ruby 1.6.2 )

C:\ruby\bin>type c:\temp\a.txt
line 1

C:\ruby\bin>./irb
irb(main):001:0> f = File.new("c:/temp/a.txt","r+")
#<File:0xa016bf8>
irb(main):002:0> f.gets
"line 1\n"
irb(main):003:0> f.puts("line 2")
nil
irb(main):004:0> f.close
nil
irb(main):005:0> exit

C:\ruby\bin>type c:\temp\a.txt
line 1

line 2



Mon, 22 Sep 2003 19:22:03 GMT  
 BUG?: HP-UX 10.20 and IO#gets followed by IO#puts

S> If it's normal, though, why are the results different on HP-UX and NT?

 Does NT follow a standard ? :-)

 More seriously, look at fopen(3) and particulary at this paragraph (it's
 from Solaris but probably you have the same on HP-UX)

     When a file is opened with update mode (+ as the  second  or
     third character in the mode argument), both input and output
     may be performed on the associated stream.  However,  output
     must   not   be   directly  followed  by  input  without  an
     intervening call to fflush(3S)  or  to  a  file  positioning
     function ( fseek(3S), fsetpos(3S) or rewind( 3S)), and input
                                                        ^^^^^^^^
     must not be directly followed by output without an interven-
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     ing  call  to  a file positioning function, unless the input
     operation encounters end-of-file.

 In your case, if you add "f.eof?" it will work, because in this case it
 will encounters end-of-file

 I think this is required by ANSI-C (not really sure)

Guy Decoux



Mon, 22 Sep 2003 20:01:01 GMT  
 BUG?: HP-UX 10.20 and IO#gets followed by IO#puts
Thanks, Guy.

Quote:
>  Seems normal for me :-)))

If it's normal, though, why are the results different on HP-UX and NT?

Quote:

>  Try to add

> S> [derby]:cat /tmp/a.txt
> S> line 1
> S> [derby]:/mnt/ruby162/bin > ./irb
> S> irb(main):001:0> f = File.new("/tmp/a.txt","r+")
> S> #<File:0x400deef8>
> S> irb(main):002:0> f.gets
> S> "line 1\n"

>                     f.seek 0, IO::SEEK_CUR

Yes, now it works fine, but I don't understand why "line 1" appears
twice without IO#seek.

Barry



Mon, 22 Sep 2003 19:54:45 GMT  
 BUG?: HP-UX 10.20 and IO#gets followed by IO#puts

Quote:
>      When a file is opened with update mode (+ as the  second  or
>      third character in the mode argument), both input and output
>      may be performed on the associated stream.  However,  output
>      must   not   be   directly  followed  by  input  without  an
>      intervening call to fflush(3S)  or  to  a  file  positioning
>      function ( fseek(3S), fsetpos(3S) or rewind( 3S)), and input
>                                                         ^^^^^^^^
>      must not be directly followed by output without an interven-
>      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>      ing  call  to  a file positioning function, unless the input
>      operation encounters end-of-file.

OK, at least the Unix case is clear now. Thanks again.

Barry



Mon, 22 Sep 2003 20:06:33 GMT  
 BUG?: HP-UX 10.20 and IO#gets followed by IO#puts

Quote:


> S> If it's normal, though, why are the results different on HP-UX and NT?

>  Does NT follow a standard ? :-)

In this case though Ruby is abstracting the underlying calls, so I'd
hope for identical output on the two systems.

Dave



Mon, 22 Sep 2003 20:35:17 GMT  
 BUG?: HP-UX 10.20 and IO#gets followed by IO#puts
Hi,

In message "[ruby-talk:13512] Re: BUG?: HP-UX 10.20 and IO#gets followed  by IO#puts"

|In this case though Ruby is abstracting the underlying calls, so I'd
|hope for identical output on the two systems.

I'm considering vague possibility of throwing stdio away from Ruby,
like Tcl's channel system.

                                                        matz.



Mon, 22 Sep 2003 22:11:28 GMT  
 BUG?: HP-UX 10.20 and IO#gets followed by IO#puts

Quote:



> > S> If it's normal, though, why are the results different on HP-UX and NT?
> >  Does NT follow a standard ? :-)

> In this case though Ruby is abstracting the underlying calls, so I'd
> hope for identical output on the two systems.

Well, if Ruby abstracts the underlying calls such that the Ruby's IO
contract is basically the same as POSIX's IO contract, and if POSIX says a
certain sequence of operations (eg: a read followed immediately by a
write) is undefined, then it does not matter whether two systems behave
differently when you do that, because you aren't supposed to do that in
the first place.

Now whether we want Ruby IO to follow POSIX semantics is a good question.

Btw, if you want Ruby to have its own buffering, that's what I started
doing in MetaRuby's IOMixin, but I didn't finish it. The reason I'm doing
it in the first place is that I can't rely on <stdio.h> buffering because
it only works on real filehandles.

matju



Tue, 23 Sep 2003 13:22:50 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. BUG: Tcl Unix Notifier in 7.6 with HP/UX 10.20 and DCE library

2. Chicken 0.990 on HP PA-RISC HP-UX 10.20

3. HP-UX Fortran, derived data types and list directed IO

4. BUG? IO.seek conflicts with IO.sysread

5. Scheme for HP-UX 10.20

6. VRML97 viewer for hp-ux 10.20?

7. ObjectAda 7.1, HP-UX 10.20, Oracle 7.X, and Intersolv's ODBC drivers

8. G77 for HP-UX 10.20

9. HP-UX 10.20/Procobol 4.0 Problem

10. FW: Problems running Make command for Python 2.2.1 on HP-UX 10.20

11. FW: Installing Python on an HP-UX 10.20 workstation

12. problems building 2.1.1 on HP-UX 10.20

 

 
Powered by phpBB® Forum Software