Summary: read(char[]) and write(char[]) note 64bit
           Product: D
           Version: D1 & D2
          Platform: All
        OS/Version: Linux
            Status: NEW
          Severity: major
          Priority: P2
         Component: Phobos

--- Comment #0 from Daniel Gibson <> 2010-10-06 09:07:08 
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
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
( - 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.


Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to