Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2008-01

TBits class bug?

5 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Giuliano Colla

While porting the Delphi Kylix CLX library to fpc, I had errors related to Tbits class. Simply lifting the Delphi implementation into the code solved the problems.

A quick investigations shows that at least the Size property has a different meaning.
While Delphi reports the actual number of allocated bits (i.e. 1-2-3 etc) FPC reports a fixed value of 31 for 1 to 32 bits allocated, and then 63, and so on:

{bits.inc}
function TBits.getSize : longint;
begin
    result := (FSize shl BITSHIFT) - 1;
end;

It seems to me that, besides not being Delphi compatible, this is also wrong, because the actual available space size is (FSize shl BITSHIFT) not decreased by one.

However FPC implementation makes inconsistent the values returned from OpenBit with those obtained reading Size.

Do I miss some point?

Giuliano

Giuliano Colla Whenever people agree with me, I always feel I must be wrong (O. Wilde)

Reply by email

Marco van de Voort
to Giuliano Colla
However FPC implementation makes inconsistent the values returned from OpenBit with those obtained reading Size. Do I miss some point?

I can imagine bits being allocated in words to avoid endianess problems. So it could be a deliberate deviation for portabilities sake.

Reply by email

Michael Van Canneyt
to Giuliano Colla: Marco van de Voort ha scritto: That the implementation needs to be different to support…
Giuliano Colla wrote 23 lines
Marco van de Voort ha scritto: > > However FPC implementation makes inconsistent the values returned from > > OpenBit with those obtained reading Size. > > > > Do I miss some point? > > I can imagine bits being allocated in words to avoid endianess problems. So > it could be a deliberate deviation for portabilities sake. That the implementation needs to be different to support different platforms I can understand. Delphi implementation uses asm code which make it i386 specific. What I find harder to swallow is that a size of 31 is reported, when the allocated size is 1 and the available size is 32. Current implementation makes it impossible to detect if an OpenBit has actually created a grow of the bitlist or not, which is necessary if the bitlist is used to keep track of other objects being allocated. If nobody else is taking care of the matter, as I have a test case ready, I could try and fix TBits implementation, in oder to keep portability but to provide self-consistency, and submit a patch.

Please submit a patch to me. I'll review and apply it.

Michael.

Reply by email

Giuliano Colla
to Marco van de Voort: I can imagine bits being allocated in words to avoid endianess problems. So it could be a…

Marco van de Voort ha scritto:

Show quoted text 7 lines
> However FPC implementation makes inconsistent the values returned from > OpenBit with those obtained reading Size. > > Do I miss some point? I can imagine bits being allocated in words to avoid endianess problems. So it could be a deliberate deviation for portabilities sake.

That the implementation needs to be different to support different platforms I can understand. Delphi implementation uses asm code which make it i386 specific.

What I find harder to swallow is that a size of 31 is reported, when the allocated size is 1 and the available size is 32.

Current implementation makes it impossible to detect if an OpenBit has actually created a grow of the bitlist or not, which is necessary if the bitlist is used to keep track of other objects being allocated.

If nobody else is taking care of the matter, as I have a test case ready, I could try and fix TBits implementation, in oder to keep portability but to provide self-consistency, and submit a patch.

Kind regards,

Giuliano

Giuliano Colla Whenever people agree with me, I always feel I must be wrong (O. Wilde)

Reply by email