[Lazarus] TRTLCriticalSection

2014-02-25 Thread Antonio Fortuny

Hi Folks.

Lazarus 1.0.2, FPC 2.6.2, Win32 and Linux x86_64
Something goes wrong with TRTRCriticalSection. There is a difference
between Windows and Linux.
In a program which will run on Win32 and Linux x86_64, using threads and
all this stuff I need to protect some code from multi-threading access.
One critical section looks enough to do the job.
So i code this in Win32 and Linux:

Interface uses clause is:
uses
  {$IFDEF LINUX}
  CThreads,
  {$ENDIF}
  syncobjs,
  {$IFDEF MSWINDOWS}
  windows,
  {$ENDIF}
  {$IFDEF LINUX}
  LCLIntf,
  {$ENDIF}
  Classes,
  IdContext,
  uSimplelogger,
  sitacom,
  MessageQ,
  autoupdateTCPthread,
  sqldb,
  SysUtils;
FIniCriticalSection: TRTLCriticalSection;
...
InitializeCriticalSection(FIniCriticalSection); -
compilation error
...
EnterCriticalSection(FIniCriticalSection);
try
... do a lot of things
finally
LeaveCriticalSection(FIniCriticalSection);
end
...

On the above line marked as compilation error the compiler complains
with the message
autoupdateserverthread.pas(255,48) Error: Call by var for arg no. 1 has
to match exactly: Got TRTLCriticalSection expected QWord
*winapi.inc*(650,11) Hint: Found declaration:
InitializeCriticalSection(var QWord);
winapi ??? Why on Linux ?
No way to get rid of this compilation error
In Win32 the program compiles and runs without errors.

Some help would be appreciated.

Antonio.




---
Ce courrier électronique ne contient aucun virus ou logiciel malveillant parce 
que la protection avast! Antivirus est active.
http://www.avast.com
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TRTLCriticalSection

2014-02-25 Thread patspiper

On 25/02/14 12:22, Antonio Fortuny wrote:

Hi Folks.

Lazarus 1.0.2, FPC 2.6.2, Win32 and Linux x86_64


That's an old Lazarus version. Did you test with the most recent one?

Something goes wrong with TRTRCriticalSection. There is a difference 
between Windows and Linux.
In a program which will run on Win32 and Linux x86_64, using threads 
and all this stuff I need to protect some code from multi-threading 
access.

One critical section looks enough to do the job.
So i code this in Win32 and Linux:

Interface uses clause is:
uses
  {$IFDEF LINUX}
  CThreads,
  {$ENDIF}
  syncobjs,
  {$IFDEF MSWINDOWS}
  windows,
  {$ENDIF}
  {$IFDEF LINUX}
  LCLIntf,
  {$ENDIF}
  Classes,
  IdContext,
  uSimplelogger,
  sitacom,
  MessageQ,
  autoupdateTCPthread,
  sqldb,
  SysUtils;
FIniCriticalSection: TRTLCriticalSection;
...
InitializeCriticalSection(FIniCriticalSection); - 
compilation error

...
EnterCriticalSection(FIniCriticalSection);
try
... do a lot of things
finally
LeaveCriticalSection(FIniCriticalSection);
end
...

On the above line marked as compilation error the compiler complains 
with the message
autoupdateserverthread.pas(255,48) Error: Call by var for arg no. 1 
has to match exactly: Got TRTLCriticalSection expected QWord


Try putting syncobjs after LCLIntf in the uses section.

What you're seeing may be related to bug report 
http://bugs.freepascal.org/view.php?id=25187


*winapi.inc*(650,11) Hint: Found declaration: 
InitializeCriticalSection(var QWord);

winapi ??? Why on Linux ?
No way to get rid of this compilation error
In Win32 the program compiles and runs without errors.

Some help would be appreciated.


This is odd. What is the output of View/IDE Internals/About FPC and 
About IDE?


Stephano
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TRTLCriticalSection

2014-02-25 Thread Mattias Gaertner
On Tue, 25 Feb 2014 11:22:57 +0100
Antonio Fortuny a.fort...@sitasoftware.lu wrote:

[...] 
  FIniCriticalSection: TRTLCriticalSection;
  ...
  InitializeCriticalSection(FIniCriticalSection); - 
 compilation error

A TRTLCriticalSection is initialized with
InitCriticalSection from the system unit.


Mattias

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TRTLCriticalSection

2014-02-25 Thread Sven Barth

Am 25.02.2014 11:22, schrieb Antonio Fortuny:

Hi Folks.

Lazarus 1.0.2, FPC 2.6.2, Win32 and Linux x86_64
Something goes wrong with TRTRCriticalSection. There is a difference 
between Windows and Linux.
In a program which will run on Win32 and Linux x86_64, using threads 
and all this stuff I need to protect some code from multi-threading 
access.

One critical section looks enough to do the job.
So i code this in Win32 and Linux:


[snip]
On the above line marked as compilation error the compiler complains 
with the message
autoupdateserverthread.pas(255,48) Error: Call by var for arg no. 1 
has to match exactly: Got TRTLCriticalSection expected QWord
*winapi.inc*(650,11) Hint: Found declaration: 
InitializeCriticalSection(var QWord);

winapi ??? Why on Linux ?
No way to get rid of this compilation error
In Win32 the program compiles and runs without errors.

Some help would be appreciated.
The function for initializing a TRTLCriticalSection is 
InitCriticalSection, not InitializeCriticalSection. If you wouldn't use 
the Windows unit you'd have seen this error on Windows as well.


@Michael: maybe we should add a seealso for the 
Init-/Enter-/Leave-/DoneCriticalSection functions to the documentation 
of the TRTLCriticalSection type.


Regards,
Sven
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TRTLCriticalSection

2014-02-25 Thread Michael Van Canneyt



On Tue, 25 Feb 2014, Sven Barth wrote:


Am 25.02.2014 11:22, schrieb Antonio Fortuny:
  Hi Folks.

  Lazarus 1.0.2, FPC 2.6.2, Win32 and Linux x86_64
  Something goes wrong with TRTRCriticalSection. There is a difference 
between Windows and
  Linux.
  In a program which will run on Win32 and Linux x86_64, using threads and 
all this stuff I
  need to protect some code from multi-threading access.
  One critical section looks enough to do the job.
  So i code this in Win32 and Linux:

[snip]
  On the above line marked as compilation error the compiler complains with 
the message
  autoupdateserverthread.pas(255,48) Error: Call by var for arg no. 1 has 
to match exactly:
  Got TRTLCriticalSection expected QWord
  winapi.inc(650,11) Hint: Found declaration: InitializeCriticalSection(var 
QWord);
  winapi ??? Why on Linux ?
  No way to get rid of this compilation error
  In Win32 the program compiles and runs without errors.

  Some help would be appreciated.

The function for initializing a TRTLCriticalSection is InitCriticalSection, not
InitializeCriticalSection. If you wouldn't use the Windows unit you'd have seen 
this error on Windows
as well.

@Michael: maybe we should add a seealso for the 
Init-/Enter-/Leave-/DoneCriticalSection functions to
the documentation of the TRTLCriticalSection type.


Will do.

Michael.


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TRTLCriticalSection

2014-02-25 Thread Antonio Fortuny


Le 25/02/2014 12:04, Sven Barth a écrit :

Am 25.02.2014 11:22, schrieb Antonio Fortuny:

Hi Folks.

Lazarus 1.0.2, FPC 2.6.2, Win32 and Linux x86_64
Something goes wrong with TRTRCriticalSection. There is a difference 
between Windows and Linux.
In a program which will run on Win32 and Linux x86_64, using threads 
and all this stuff I need to protect some code from multi-threading 
access.

One critical section looks enough to do the job.
So i code this in Win32 and Linux:


[snip]
On the above line marked as compilation error the compiler complains 
with the message
autoupdateserverthread.pas(255,48) Error: Call by var for arg no. 1 
has to match exactly: Got TRTLCriticalSection expected QWord
*winapi.inc*(650,11) Hint: Found declaration: 
InitializeCriticalSection(var QWord);

winapi ??? Why on Linux ?
No way to get rid of this compilation error
In Win32 the program compiles and runs without errors.

Some help would be appreciated.
The function for initializing a TRTLCriticalSection is 
InitCriticalSection, not InitializeCriticalSection. If you wouldn't 
use the Windows unit you'd have seen this error on Windows as well.
The windows unit is used in the Win32 box (look at the conditional uses 
clause)


Antonio;


@Michael: maybe we should add a seealso for the 
Init-/Enter-/Leave-/DoneCriticalSection functions to the documentation 
of the TRTLCriticalSection type.


Regards,
Sven


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus




---
Ce courrier électronique ne contient aucun virus ou logiciel malveillant parce 
que la protection avast! Antivirus est active.
http://www.avast.com



--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TRTLCriticalSection

2014-02-25 Thread patspiper

On 25/02/14 12:56, Mattias Gaertner wrote:

On Tue, 25 Feb 2014 11:22:57 +0100
Antonio Fortuny a.fort...@sitasoftware.lu wrote:


[...]
  FIniCriticalSection: TRTLCriticalSection;
  ...
  InitializeCriticalSection(FIniCriticalSection); -
compilation error

A TRTLCriticalSection is initialized with
InitCriticalSection from the system unit.


I didn't notice that difference. But what about 
http://bugs.freepascal.org/view.php?id=25187 ?


LCLIntf's (winapi.h) EnterCriticalsection(TCriticalSection) always takes 
precedence in compilation although codetools show it defined in 
threadh.inc: EnterCriticalsection(TRTLCriticalSection).


Stephano

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TRTLCriticalSection

2014-02-25 Thread Sven Barth

Am 25.02.2014 12:14, schrieb Antonio Fortuny:


Le 25/02/2014 12:04, Sven Barth a écrit :

Am 25.02.2014 11:22, schrieb Antonio Fortuny:

Some help would be appreciated.
The function for initializing a TRTLCriticalSection is 
InitCriticalSection, not InitializeCriticalSection. If you wouldn't 
use the Windows unit you'd have seen this error on Windows as well.
The windows unit is used in the Win32 box (look at the conditional 
uses clause)
Yes, nevertheless you would get the same error as on Linux if you would 
*not* use the Windows unit on Win32. Because on Windows 
TRTLCriticalSection is the same as the Windows CRITICAL_SECTION thus 
InitializeCriticalSection will happily take an TRTLCriticalSection as 
argument. However on Linux TRTLCriticalSection is defined differently. 
That Lazarus additionally declared a different TCriticalSection and 
InitializeCriticalSection does not help of course... :/


Regards,
Sven

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TRTLCriticalSection

2014-02-25 Thread Mattias Gaertner
On Tue, 25 Feb 2014 13:22:41 +0200
patspiper patspi...@gmail.com wrote:

[...]
 LCLIntf's (winapi.h) EnterCriticalsection(TCriticalSection) always takes 
 precedence in compilation although codetools show it defined in 
 threadh.inc: EnterCriticalsection(TRTLCriticalSection).

The compiler is very strict and requires the overload keyword for
multiple functions with the same name in various units.
Codetools allows to see all overloads, no matter if the overload
keyword is missing. It depends on the context if this is a feature or a
bug.


Mattias

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TRTLCriticalSection

2014-02-25 Thread Mattias Gaertner
On Tue, 25 Feb 2014 13:22:41 +0200
patspiper patspi...@gmail.com wrote:

[...]
 LCLIntf's (winapi.h) EnterCriticalsection(TCriticalSection) always takes 
 precedence in compilation although codetools show it defined in 
 threadh.inc: EnterCriticalsection(TRTLCriticalSection).

I added overload to LCL Enter/LeaveCriticalSection. So you don't need
to bother with unit order.

Mattias

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TRTLCriticalSection

2014-02-25 Thread Antonio Fortuny

Now I get it working on both platforms.

Use InitCriticalSection and DoneCriticalsection (thanks Mattias)
Using  system.EnterCriticalSection and system.LeaveCriticalSection 
solves all the compilation problems and runs (thanks all)


Thanks again

Antonio.

---
Ce courrier électronique ne contient aucun virus ou logiciel malveillant parce 
que la protection avast! Antivirus est active.
http://www.avast.com



--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TRTLCriticalSection

2014-02-25 Thread Mattias Gaertner
On Tue, 25 Feb 2014 12:46:43 +0100
Sven Barth pascaldra...@googlemail.com wrote:

 Am 25.02.2014 12:14, schrieb Antonio Fortuny:
 
  Le 25/02/2014 12:04, Sven Barth a écrit :
  Am 25.02.2014 11:22, schrieb Antonio Fortuny:
  Some help would be appreciated.
  The function for initializing a TRTLCriticalSection is 
  InitCriticalSection, not InitializeCriticalSection. If you wouldn't 
  use the Windows unit you'd have seen this error on Windows as well.
  The windows unit is used in the Win32 box (look at the conditional 
  uses clause)
 Yes, nevertheless you would get the same error as on Linux if you would 
 *not* use the Windows unit on Win32. Because on Windows 
 TRTLCriticalSection is the same as the Windows CRITICAL_SECTION thus 
 InitializeCriticalSection will happily take an TRTLCriticalSection as 
 argument. However on Linux TRTLCriticalSection is defined differently. 
 That Lazarus additionally declared a different TCriticalSection and 
 InitializeCriticalSection does not help of course... :/

This uses the widgetsets critical sections.

I personally am satisfied with the RTL one.

Mattias

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TRTLCriticalSection

2014-02-25 Thread patspiper

On 25/02/14 13:57, Mattias Gaertner wrote:

On Tue, 25 Feb 2014 13:22:41 +0200
patspiper patspi...@gmail.com wrote:


[...]
LCLIntf's (winapi.h) EnterCriticalsection(TCriticalSection) always takes
precedence in compilation although codetools show it defined in
threadh.inc: EnterCriticalsection(TRTLCriticalSection).

I added overload to LCL Enter/LeaveCriticalSection. So you don't need
to bother with unit order.


Thanks.

I closed the bug report.

Stephano

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TRTLCriticalSection

2013-12-01 Thread patspiper

On 29/11/13 13:32, Michael Van Canneyt wrote:



On Fri, 29 Nov 2013, Antonio Fortuny wrote:


Hi Folks.

On Linux x86_°64 Opensuse, Lazarus 1.0.12, FPC 2.6.2
Could anyone tell me why the next line
  EnterCriticalSection(CS);
with the following compiler error:
/home/sources/production/lib/usimplelogger.pas(180,27) Error: Call by 
var for arg no. 1 has to match exactly: Got Pointer

expected QWord  :-\
with somewhere before the declaration:
var
  CS: TRTLCriticalSection;

whilst in threadh.inc the is:
procedure EnterCriticalsection(var cs : TRTLCriticalSection);

which is pointed to when Ctrl-Left Click on the source unit word: 
EnterCriticalSection


With same Lazarus/FPC into Win32 Vista no compiler error and runs OK


What does TRTLCriticalSection point to ? There are multiple 
definitions floating around, make sure you are taking the one from the 
system unit:


var
   CS: system.TRTLCriticalSection;
http://bugs.freepascal.org/view.php?id=25187 makes debugging this 
particular issue worse.


Stephano

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus