Re: [fpc-pascal] LZMA Algorithm fails on 64bit
> Does anyone know why the code fails to work? Not really, but at least the following is will be evaluated differently on 32 and 64 bit platforms: > > ### > ~~~ > CodeSequence [-1-]: > - > > var inStream:TBufferedFS; >outStream:TBufferedFS; >decoder: TLZMADecoder; >properties:array[0..4] of byte; >filesize,outSize:Int64; >i: Integer; >v: byte; > const propertiessize=5; > begin > if not FileExists(ipkfile) then Exception.Create('IPK file does not > exists!'); > > try > inStream:=TBufferedFS.Create(ipkfile, fmOpenRead or fmShareDenyNone); > try > outStream:=TBufferedFS.Create(workdir+'ipktar.tar', fmCreate); > > decoder:=TLZMADecoder.Create; > inStream.position:=0; >with decoder do >begin > if inStream.read(properties, propertiesSize) <> propertiesSize then > raise Exception.Create('input .lzma file is too short'); > if not SetDecoderProperties(properties) then > raise Exception.Create('Incorrect stream properties'); > > outSize := 0; > for i := 0 to 7 do > begin > v := inStream.ReadByte; > if v < 0 then >raise Exception.Create('Can''t read stream size'); > outSize := outSize or v shl (8 * i); v is a byte, i is a longint (integer in Delphi mode). Outsize is an int64. On a 32 bit platform, "v shl (8 * i)" will be evaluated as 32 bit. This means that the upper 32 bits of the result of that expression will be discarded before the "or" operation is performed. On a 64 bit platform, that entire expression will be evaluated using 64 bit arithmetic. Jonas___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] LZMA Algorithm fails on 64bit
On Sat, 23 Jan 2010 14:19:23 +0100, Jonas Maebe wrote: >> Does anyone know why the code fails to work? > > Not really, but at least the following is will be evaluated differently on > 32 and 64 bit platforms: > > [...] > v is a byte, i is a longint (integer in Delphi mode). Outsize is an int64. > > On a 32 bit platform, "v shl (8 * i)" will be evaluated as 32 bit. This > means that the upper 32 bits of the result of that expression will be > discarded before the "or" operation is performed. On a 64 bit platform, > that entire expression will be evaluated using 64 bit arithmetic. > Hi! Maybe the is the reason why it fails, cause the compression does not do operations like this. How do I have to change the expression to make it work on 32bit and 64bit? Thanks! Matthias ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] LZMA Algorithm fails on 64bit
On 23 Jan 2010, at 15:12, Matthias Klumpp wrote: > On Sat, 23 Jan 2010 14:19:23 +0100, Jonas Maebe > wrote: >>> Does anyone know why the code fails to work? >> >> Not really, but at least the following is will be evaluated differently >> on 32 and 64 bit platforms: >> >> [...] >> v is a byte, i is a longint (integer in Delphi mode). Outsize is an >> int64. >> >> On a 32 bit platform, "v shl (8 * i)" will be evaluated as 32 bit. This >> means that the upper 32 bits of the result of that expression will be >> discarded before the "or" operation is performed. On a 64 bit platform, >> that entire expression will be evaluated using 64 bit arithmetic. >> > Hi! > Maybe the is the reason why it fails, cause the compression does not do > operations like this. How do I have to change the expression to make it > work on 32bit and 64bit? I think the code there is currently actually only correct on 64 bit platforms and wrong on 32 bit platforms: it seems that it should read an int64 in little endian format and converts it on-the-fly to the native endianess, but that currently only happens correctly on 64 bit platforms. I was also wrong about what it does on 32 bit platforms, because that depends on the used architecture. On PowerPC, it will indeed throw away the upper 32 bits as I described above. On i386, it will however result in something like "v shl ((8 *i) and 31)". I don't think there is a quick fix. Someone who knows what is going on has to go through it and properly fix it. Hacking the code you posted will only result in hiding a bug, and you will probably still get more errors elsewhere. Jonas___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] RTTI Bug or something else i did wrong...
i did rewrote the whole program, and the bug vanished... so i cannot recreate the problem in a test case... (?) sorry about the inconvenience... ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal