Windows unit and SyncObjs unit clash

classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|

Windows unit and SyncObjs unit clash

Graeme Geldenhuys-2
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/
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Windows unit and SyncObjs unit clash

Michael Van Canneyt


On Wed, 26 Mar 2008, Graeme Geldenhuys wrote:

> 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.

>
> 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  -  [hidden email]
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Windows unit and SyncObjs unit clash

Graeme Geldenhuys-2
On 26/03/2008, Michael Van Canneyt <[hidden email]> wrote:
>
> Yes, use fully qualified names.
>
>  windows.tcriticalsection.
>  syncobjs.tcriticalsection.


That should work....


>  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/
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Windows unit and SyncObjs unit clash

Graeme Geldenhuys-2
In reply to this post by Michael Van Canneyt
On 26/03/2008, Michael Van Canneyt <[hidden email]> 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?


Regards,
  - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Windows unit and SyncObjs unit clash

Michael Van Canneyt


On Wed, 26 Mar 2008, Graeme Geldenhuys wrote:

> On 26/03/2008, Michael Van Canneyt <[hidden email]> 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.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Windows unit and SyncObjs unit clash

Marco van de Voort
> On Wed, 26 Mar 2008, Graeme Geldenhuys wrote:
>
> > On 26/03/2008, Michael Van Canneyt <[hidden email]> 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.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Windows unit and SyncObjs unit clash

Graeme Geldenhuys-2
On 26/03/2008, Marco van de Voort <[hidden email]> 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/
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Windows unit and SyncObjs unit clash

Pete Cervasio
On Wednesday 26 March 2008 08:51:53 Graeme Geldenhuys wrote:
> On 26/03/2008, Marco van de Voort <[hidden email]> 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.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Windows unit and SyncObjs unit clash

Joao Morais
In reply to this post by Marco van de Voort
Marco van de Voort wrote:

>> On Wed, 26 Mar 2008, Graeme Geldenhuys wrote:
>>
>>> On 26/03/2008, Michael Van Canneyt <[hidden email]> 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
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Windows unit and SyncObjs unit clash

Joao Morais
In reply to this post by Graeme Geldenhuys-2
Graeme Geldenhuys wrote:

>>  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

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Windows unit and SyncObjs unit clash

Graeme Geldenhuys-2
On 26/03/2008, Joao Morais <[hidden email]> 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/
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Windows unit and SyncObjs unit clash

Tomas Hajny
In reply to this post by Marco van de Voort
On Wed, March 26, 2008 14:43, Marco van de Voort wrote:

>> On Wed, 26 Mar 2008, Graeme Geldenhuys wrote:
>>
>> > On 26/03/2008, Michael Van Canneyt <[hidden email]> 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


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Windows unit and SyncObjs unit clash

Graeme Geldenhuys-2
On 27/03/2008, Tomas Hajny <[hidden email]> 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/
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Windows unit and SyncObjs unit clash

Marco van de Voort
In reply to this post by Tomas Hajny
> 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.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Windows unit and SyncObjs unit clash

Graeme Geldenhuys-2
On 27/03/2008, Marco van de Voort <[hidden email]> wrote:
>
> 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/
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal