Sign in Join

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

Mailing lists / fpc-pascal / 2008-03

Windows unit and SyncObjs unit clash

15 messages · 6 people · –

Reply by email Subscribe to this list Your subscription

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

Graeme Geldenhuys

Hi,

I've noticed this ages ago and found a work-around, but never reported it. I hit the same error again today and thought this time I would mention it.

In tiOPF we have some IFDEF's for the 'Windows' unit. Some units also use the 'SyncObjs' unit for critical section handling. If 'SyncObjs' unit appears before the 'Windows' unit, our code fails to compile with a error referring to the TCriticalSection class.

Does anybody know about this? Is there any permanent fix to that FPC doesn't depend on specific order in uses clause?

I'm now using FPC 2.2.0, but this issue has been around since 2.0.2.

------------[ copy ]------------------
C:\Programming\tiOPF2\Source\Core\tiUtils.pas(3491,13) Error: Unknown record field identifier "ENTER"

C:\Programming\tiOPF2\Source\Core\tiUtils.pas(3491,18) Error: Illegal expression
C:\Programming\tiOPF2\Source\Core\tiUtils.pas(3497,15) Error: Unknown
record field identifier "LEAVE"
C:\Programming\tiOPF2\Source\Core\tiUtils.pas(3497,20) Error: Illegal expression
C:\Programming\tiOPF2\Source\Core\tiUtils.pas(3503,13) Error: Unknown
record field identifier "ENTER"
C:\Programming\tiOPF2\Source\Core\tiUtils.pas(3503,18) Error: Illegal expression
C:\Programming\tiOPF2\Source\Core\tiUtils.pas(3509,15) Error: Unknown
record field identifier "LEAVE"
C:\Programming\tiOPF2\Source\Core\tiUtils.pas(3509,20) Error: Illegal expression
C:\Programming\tiOPF2\Source\Core\tiUtils.pas(3526,32) Error: Unknown
record field identifier "CREATE"
C:\Programming\tiOPF2\Source\Core\tiUtils.pas(3532,13) Error: Unknown
record field identifier "FREE"
C:\Programming\tiOPF2\Source\Core\tiUtils.pas(3532,17) Error: Illegal expression
C:\Programming\tiOPF2\Source\Core\tiUtils.pas(3544,13) Error: Unknown
record field identifier "ENTER"
C:\Programming\tiOPF2\Source\Core\tiUtils.pas(3544,18) Error: Illegal expression
C:\Programming\tiOPF2\Source\Core\tiUtils.pas(3548,15) Error: Unknown
record field identifier "LEAVE"
C:\Programming\tiOPF2\Source\Core\tiUtils.pas(3548,20) Error: Illegal expression
C:\Programming\tiOPF2\Source\Core\tiUtils.pas(3560,13) Error: Unknown
record field identifier "ENTER"
C:\Programming\tiOPF2\Source\Core\tiUtils.pas(3560,18) Error: Illegal expression
C:\Programming\tiOPF2\Source\Core\tiUtils.pas(3564,15) Error: Unknown
record field identifier "LEAVE"
C:\Programming\tiOPF2\Source\Core\tiUtils.pas(3564,20) Error: Illegal expression

C:\Programming\tiOPF2\Source\Core\tiUtils.pas(3569) Fatal: There were 19 errors compiling module, stopping

------------[ end ]-------------------

And here is an example of where the cursor lands to show the error...

function TtiMultiReadExclusiveWriteSynchronizer.LockForRead: boolean;
begin
  FCritSect.Enter;          // <<<<<<<<<  Cursor showing error
  try
    result:= CanLockForRead;
    if Result then
      Inc(FReadCount);
  finally
    FCritSect.Leave;
  end;
end;

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Michael Van Canneyt
to Graeme Geldenhuys
Graeme Geldenhuys wrote 13 lines
Hi, I've noticed this ages ago and found a work-around, but never reported it. I hit the same error again today and thought this time I would mention it. In tiOPF we have some IFDEF's for the 'Windows' unit. Some units also use the 'SyncObjs' unit for critical section handling. If 'SyncObjs' unit appears before the 'Windows' unit, our code fails to compile with a error referring to the TCriticalSection class. Does anybody know about this? Is there any permanent fix to that FPC doesn't depend on specific order in uses clause?

Yes, use fully qualified names.

windows.tcriticalsection.
syncobjs.tcriticalsection.

For lower level stuff, you should use TRTLCriticalSection, never TCriticalSection.

It has the advantage of being portable.

I'm surprised you actually use the windows unit. That is Evil(tm).

Michael.

Show quoted text 98 lines
I'm now using FPC 2.2.0, but this issue has been around since 2.0.2. ------------[ copy ]------------------ C:\Programming\tiOPF2\Source\Core\tiUtils.pas(3491,13) Error: Unknown record field identifier "ENTER" C:\Programming\tiOPF2\Source\Core\tiUtils.pas(3491,18) Error: Illegal expression C:\Programming\tiOPF2\Source\Core\tiUtils.pas(3497,15) Error: Unknown record field identifier "LEAVE" C:\Programming\tiOPF2\Source\Core\tiUtils.pas(3497,20) Error: Illegal expression C:\Programming\tiOPF2\Source\Core\tiUtils.pas(3503,13) Error: Unknown record field identifier "ENTER" C:\Programming\tiOPF2\Source\Core\tiUtils.pas(3503,18) Error: Illegal expression C:\Programming\tiOPF2\Source\Core\tiUtils.pas(3509,15) Error: Unknown record field identifier "LEAVE" C:\Programming\tiOPF2\Source\Core\tiUtils.pas(3509,20) Error: Illegal expression C:\Programming\tiOPF2\Source\Core\tiUtils.pas(3526,32) Error: Unknown record field identifier "CREATE" C:\Programming\tiOPF2\Source\Core\tiUtils.pas(3532,13) Error: Unknown record field identifier "FREE" C:\Programming\tiOPF2\Source\Core\tiUtils.pas(3532,17) Error: Illegal expression C:\Programming\tiOPF2\Source\Core\tiUtils.pas(3544,13) Error: Unknown record field identifier "ENTER" C:\Programming\tiOPF2\Source\Core\tiUtils.pas(3544,18) Error: Illegal expression C:\Programming\tiOPF2\Source\Core\tiUtils.pas(3548,15) Error: Unknown record field identifier "LEAVE" C:\Programming\tiOPF2\Source\Core\tiUtils.pas(3548,20) Error: Illegal expression C:\Programming\tiOPF2\Source\Core\tiUtils.pas(3560,13) Error: Unknown record field identifier "ENTER" C:\Programming\tiOPF2\Source\Core\tiUtils.pas(3560,18) Error: Illegal expression C:\Programming\tiOPF2\Source\Core\tiUtils.pas(3564,15) Error: Unknown record field identifier "LEAVE" C:\Programming\tiOPF2\Source\Core\tiUtils.pas(3564,20) Error: Illegal expression C:\Programming\tiOPF2\Source\Core\tiUtils.pas(3569) Fatal: There were 19 errors compiling module, stopping ------------[ end ]------------------- And here is an example of where the cursor lands to show the error... function TtiMultiReadExclusiveWriteSynchronizer.LockForRead: boolean; begin FCritSect.Enter; // <<<<<<<<< Cursor showing error try result:= CanLockForRead; if Result then Inc(FReadCount); finally FCritSect.Leave; end; end; Regards, - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net/fpgui/ _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Graeme Geldenhuys
to Michael Van Canneyt
Michael Van Canneyt wrote 5 lines
Yes, use fully qualified names. windows.tcriticalsection. syncobjs.tcriticalsection.

That should work....

Show quoted text 5 lines
For lower level stuff, you should use TRTLCriticalSection, never TCriticalSection. It has the advantage of being portable. I'm surprised you actually use the windows unit. That is Evil(tm).

The code in question is the tiOPF project which is shared with Delphi & FPC users. They (Delphi users) are all out of luck with the cross-platform abilities of FPC, so we have to use what both compilers support. For Delphi, that would be the 'Windows' unit.

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Graeme Geldenhuys
to Michael Van Canneyt: Yes, use fully qualified names. windows.tcriticalsection. syncobjs.tcriticalsection. For…
Michael Van Canneyt wrote 5 lines
Yes, use fully qualified names. windows.tcriticalsection. syncobjs.tcriticalsection.

Why doesn't Delphi compiler complain about it? A quick search revealed that Delphi's Windows.pas unit doesn't contain a TCriticalSection type definition, so why does FPC's Windows.pas unit? Why must FPC have two TCriticalSection type definitions?

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Michael Van Canneyt
to Graeme Geldenhuys
Graeme Geldenhuys wrote 12 lines
On 26/03/2008, Michael Van Canneyt wrote: > > Yes, use fully qualified names. > > windows.tcriticalsection. > syncobjs.tcriticalsection. Why doesn't Delphi compiler complain about it? A quick search revealed that Delphi's Windows.pas unit doesn't contain a TCriticalSection type definition, so why does FPC's Windows.pas unit? Why must FPC have two TCriticalSection type definitions?

It was translated automatically with the h2pas tool, probably with the -t option, which prepends a T to all types. For backwards compatibility we cannot revert this.

Michael.

Marco van de Voort
to Michael Van Canneyt
Show quoted text 18 lines
On Wed, 26 Mar 2008, Graeme Geldenhuys wrote: > On 26/03/2008, Michael Van Canneyt wrote: > > > > Yes, use fully qualified names. > > > > windows.tcriticalsection. > > syncobjs.tcriticalsection. > > > Why doesn't Delphi compiler complain about it? A quick search > revealed that Delphi's Windows.pas unit doesn't contain a > TCriticalSection type definition, so why does FPC's Windows.pas unit? > Why must FPC have two TCriticalSection type definitions? It was translated automatically with the h2pas tool, probably with the -t option, which prepends a T to all types. For backwards compatibility we cannot revert this.

Hmm, didn't older (<6) versions simply have this, and did synobjs get introduced later? In that case, if Delphi can break compat, so can we.

Graeme Geldenhuys
to Marco van de Voort
Marco van de Voort wrote
Hmm, didn't older (<6) versions simply have this, and did synobjs get introduced later? In that case, if Delphi can break compat, so can we.

I think I still have my copy of Delphi 5 lying around. If I can find it, I'll see if TCriticalSection is in that Windows unit and if SyncObjs unit existed in v5.

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Pete Cervasio
to Graeme Geldenhuys
Graeme Geldenhuys wrote 7 lines
On 26/03/2008, Marco van de Voort wrote: > Hmm, didn't older (<6) versions simply have this, and did synobjs get > introduced later? In that case, if Delphi can break compat, so can we. I think I still have my copy of Delphi 5 lying around. If I can find it, I'll see if TCriticalSection is in that Windows unit and if SyncObjs unit existed in v5.

Hi, Graeme.

I've got D5 installed under Wine here, and the only thing found when grepping for tcriticalsection in the ./Source/Rtl/Win directory is the function "SetCriticalSectionSpinCount".

The SyncObjs unit does exist in D5.

~/.wine/drive_c/Program Files/Borland/Delphi5 $ find . -iname 'syncobj*' ./Lib/Debug/syncobjs.dcu
./Lib/syncobjs.dcu
./Source/Vcl/syncobjs.pas

Best regards,
Pete C.

Joao Morais
to Marco van de Voort: Hmm, didn't older (<6) versions simply have this, and did synobjs get introduced later?…
Marco van de Voort wrote 18 lines
> On Wed, 26 Mar 2008, Graeme Geldenhuys wrote: > >> On 26/03/2008, Michael Van Canneyt wrote: >>> Yes, use fully qualified names. >>> >>> windows.tcriticalsection. >>> syncobjs.tcriticalsection. >> >> Why doesn't Delphi compiler complain about it? A quick search >> revealed that Delphi's Windows.pas unit doesn't contain a >> TCriticalSection type definition, so why does FPC's Windows.pas unit? >> Why must FPC have two TCriticalSection type definitions? > It was translated automatically with the h2pas tool, probably with the -t > option, which prepends a T to all types. For backwards compatibility we > cannot revert this. Hmm, didn't older (<6) versions simply have this, and did synobjs get introduced later? In that case, if Delphi can break compat, so can we.

D5 has Windows.TRTLCriticalSection, and SyncObjs.TCriticalSection which encapsulates a TRLTCriticalSection.

Joao Morais
Joao Morais
to Graeme Geldenhuys: That should work.... The code in question is the tiOPF project which is shared with Delphi
Graeme Geldenhuys wrote 10 lines
> For lower level stuff, you should use TRTLCriticalSection, never TCriticalSection. > > It has the advantage of being portable. > > I'm surprised you actually use the windows unit. That is Evil(tm). The code in question is the tiOPF project which is shared with Delphi & FPC users. They (Delphi users) are all out of luck with the cross-platform abilities of FPC, so we have to use what both compilers support. For Delphi, that would be the 'Windows' unit.

What about use uses Windows under ifndef fpc?

Joao Morais
Graeme Geldenhuys
to Joao Morais
Joao Morais wrote
What about use uses Windows under ifndef fpc?

That will work for some units, but not all of them. Some units reference things in Windows unit not related to Critical Section, but I am definitely going to give this a try and see how far it takes me.

Thanks for the suggestion.

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Tomas Hajny
to Marco van de Voort: Hmm, didn't older (<6) versions simply have this, and did synobjs get introduced later?…
Marco van de Voort wrote 22 lines
> On Wed, 26 Mar 2008, Graeme Geldenhuys wrote: > > > On 26/03/2008, Michael Van Canneyt wrote: > > > > > > Yes, use fully qualified names. > > > > > > windows.tcriticalsection. > > > syncobjs.tcriticalsection. > > > > > > Why doesn't Delphi compiler complain about it? A quick search > > revealed that Delphi's Windows.pas unit doesn't contain a > > TCriticalSection type definition, so why does FPC's Windows.pas unit? > > Why must FPC have two TCriticalSection type definitions? > > It was translated automatically with the h2pas tool, probably with the > -t > option, which prepends a T to all types. For backwards compatibility we > cannot revert this. Hmm, didn't older (<6) versions simply have this, and did synobjs get introduced later? In that case, if Delphi can break compat, so can we.

Maybe we could mark the declaration in unit Windows deprecated and later remove in 2.5.x (or whatever that becomes)?

Tomas

Graeme Geldenhuys
to Tomas Hajny
Tomas Hajny wrote
Maybe we could mark the declaration in unit Windows deprecated and later remove in 2.5.x (or whatever that becomes)?

I think this would be a good idea. It makes no sense having two TCriticalSection definitions. Plus it's much harder to maintain code shared between the Delphi and FPC compiler.

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Marco van de Voort
to Tomas Hajny: Maybe we could mark the declaration in unit Windows deprecated and later remove in 2.5.x…
Show quoted text 6 lines
On Wed, March 26, 2008 14:43, Marco van de Voort wrote: > Hmm, didn't older (<6) versions simply have this, and did synobjs get > introduced later? In that case, if Delphi can break compat, so can we. Maybe we could mark the declaration in unit Windows deprecated and later remove in 2.5.x (or whatever that becomes)?

Yes and no, that would be the last resort solution yes, but I think here direct Delphi compat _and_ platform independance should weigh heavier than a misplaced backwards compability for which we have no indications.

So my final opinion would be: change it in 2.2.2 in 1st half 2008, not in 2.6 in first half 2011 or so.

Graeme Geldenhuys
to Marco van de Voort
Marco van de Voort wrote 7 lines
Yes and no, that would be the last resort solution yes, but I think here direct Delphi compat _and_ platform independence should weigh heavier than a misplaced backwards compability for which we have no indications. So my final opinion would be: change it in 2.2.2 in 1st half 2008, not in 2.6 in first half 2011 or so.

That would be much preferred by me as well, but I don't carry any weight in pushing such FPC decisions.

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/