www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5001] New: std.stream read(char[]) and write(char[]) note 64bit safe

http://d.puremagic.com/issues/show_bug.cgi?id=5001

           Summary: std.stream read(char[]) and write(char[]) note 64bit
                    safe
           Product: D
           Version: D1 & D2
          Platform: All
        OS/Version: Linux
            Status: NEW
          Severity: major
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: metalcaedes gmail.com



PDT ---
As mentioned in the NG[1], OutputStreams write(char[]) and write(wchar[]), that
write "a string, together with its length", are not 64bit safe, because they
write first the length as a size_t (which is uint on x86 und ulong on amd64
afaik).
This means that you can't use write(char[]) to write into a file on a x86
system (or a 32bit executable on an amd64 system) and later read that file on
an amd64 system. Also consider SocketStream.. you can't use
SocketStream.write(char[]) to communicate between a x86 and an amd64 box (when
an 64bit executable is used an the latter).
This could easily be fixed by using uint or ulong instead of size_t on all
platforms. (uint is probably ok, Java even uses short in a similar method
(java.io.DataOutput.writeUTF() - never use this, it's no real UTF-8)). 

Unfortunately the libphobos of GDC (that already supports 64bit targets) has
been using size_t for ages, so in D1 it should *maybe* stay like that to avoid
breaking compatibility.
On the other hand, probably no GDC user who thinks at least a bit
cross-platform uses write(char[]) anyway, so it might suffice to use uint so
it's compatible with existing 32bit binaries from DMD.

But at least for D2/phobos2 write( (w)char[] ) should either use uint or ulong,
but not size_t.

Of course read( (w)char[] ) needs to be updated as well.


[1]
http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=118413

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 06 2010