Re: [fpc-pascal] using Interfaces in descendant classes 2.6.4 vs 3.x

2017-11-03 Thread Graeme Geldenhuys

On 2017-11-03 23:52, Graeme Geldenhuys wrote:

Attached is a sample application reproducing the problem. Compile the
program with FPC 2.6.4 and everything works. Compile it with FPC 3.x and
no interface reference is ever returned.



Yet more testing. Now I've managed to get it to work in all FPC 
versions. Yeah!!!


If I change my class that does interface delegation to the following syntax:

   TClassA = class(TObject, ICmdLine)
   private
FCmdLineParams: TCmdLineImpl;
function GetCmdLineParamsInterface: TCmdLineImpl;
property ChildDelegate: TCmdLineImpl read GetCmdLineParamsInterface 
implements ICmdLine;

   public
 destructor Destroy; override;
   end;


Then it works. Note I changed the function and property definitions.

Still strange that FPC 2.6.4 worked in my prior example and FPC 3.x not. 
I also didn't see any "User Changes" on the wiki about this changed 
behaviour of Interface Delegation.


Regards,
  Graeme

--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

My public PGP key:  http://tinyurl.com/graeme-pgp
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] using Interfaces in descendant classes 2.6.4 vs 3.x

2017-11-03 Thread Graeme Geldenhuys
Attached is a sample application reproducing the problem. Compile the 
program with FPC 2.6.4 and everything works. Compile it with FPC 3.x and 
no interface reference is ever returned.


Sample output:


===[ compiled with FPC 3.0.0, 3.0.2, 3.0.4 and 3.1.1]
[tmp]$ ./project1
TClassA: ICmdLine interface is not supported!
TClassB: ICmdLine interface is not supported!
TClassC: ICmdLine interface is not supported!


===[ compiled with FPC 2.6.4]
[tmp]$ ./project1
TCmdLineImpl: ICmdLine.MyProc implementation
TCmdLineImpl: ICmdLine.MyProc implementation
TCmdLineImpl: ICmdLine.MyProc implementation



I did some further testing. In the attached project I have a dedicated 
class that implements the interface, then another class that implements 
the interface using interface delegation.  If I change the sample code 
and NOT use interface delegation, but let TClassA directly implement the 
ICmdLine interface, then everything works.


But developers shouldn't need to be forced to do this. FPC support 
interface delegation and the real interface is a lot more complex to 
implement than the very simplified attached example. The nail in the 
coffin is that it used to work in FPC 2.6.4, but is now broken in FPC 3.x



Regards,
  Graeme

--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

My public PGP key:  http://tinyurl.com/graeme-pgp
program project1;

{$mode objfpc}{$H+}
{$interfaces corba}

uses
  Classes, SysUtils;

type
   ICmdLine = interface
   ['{1D27F8F3-C0EE-11E7-87C3-C86000E37EB0}']
 procedure MyProc;
   end;

   // class implementing the interface
   TCmdLineImpl = class(TObject, ICmdLine)
  procedure MyProc;
   end;

   // class implementing the interface via interface delegation
   TClassA = class(TObject, ICmdLine)
   private
FCmdLineParams: TCmdLineImpl;
functionGetCmdLineParamsInterface: ICmdLine;
propertyCmdLineParams: ICmdLine read GetCmdLineParamsInterface implements ICmdLine;
   public
 destructor Destroy; override;
   end;

TClassB = class(TClassA);

TClassC = class(TClassB);



function TClassA.GetCmdLineParamsInterface: ICmdLine;
begin
  if not Assigned(FCmdLineParams) then
FCmdLineParams := TCmdLineImpl.Create;
  Result := FCmdLineParams; // compiler does an implicit: FCmdLineParams as TCmdLineImpl
end;

destructor TClassA.Destroy;
begin
  FreeAndNil(FCmdLineParams);
  inherited Destroy;
end;

{ TCmdLineImpl }

procedure TCmdLineImpl.MyProc;
begin
  writeln(ClassName + ': ICmdLine.MyProc implementation');
end;

var
  c: ICmdLine;
  objA: TClassA;
  objB: TClassB;
  objC: TClassC;
begin
  objA := TClassA.Create;
  try
if Supports(objA, ICmdLine, c) then
  c.MyProc
else
  writeln('TClassA: ICmdLine interface is not supported!');
  finally
FreeAndNil(objA);
  end;

  objB := TClassB.Create;
  try
if Supports(objB, ICmdLine, c) then
  c.MyProc
else
  writeln('TClassB: ICmdLine interface is not supported!');
  finally
FreeAndNil(objB);
  end;

  objC := TClassC.Create;
  try
if Supports(objC, ICmdLine, c) then
  c.MyProc
else
  writeln('TClassC: ICmdLine interface is not supported!');
  finally
FreeAndNil(objC);
  end;
end.

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] using Interfaces in descendant classes 2.6.4 vs 3.x

2017-11-03 Thread Graeme Geldenhuys


On 2017-11-03 23:09, Graeme Geldenhuys wrote:

I looked at the wiki and the FPC 3.x "User Changes" pages and the only
reference to Interface changes is this.
  
http://wiki.freepascal.org/User_Changes_3.0.0#Classes_implementing_forward-declared_interfaces




Please note that I'm not using Interface Forward Declarations in my 
code. The interface definition is fully defined in a separate unit, and 
that unit is referenced in the uses clause (interface section of the 
unit) where TBaseApplication is defined.


So I highly doubt my issue is related to the above URL's topic.


Regards,
  Graeme

--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

My public PGP key:  http://tinyurl.com/graeme-pgp
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] using Interfaces in descendant classes 2.6.4 vs 3.x

2017-11-03 Thread Graeme Geldenhuys

Hi,

Some of my programs were last compiled with FPC 2.6.4, and there I used 
Corba-style Interfaces without a problem. I've now recompiled those 
projects with FPC 3.0.4 and the program immediately crashes.


Debugging I found that I was trying to use a interface reference, but 
forgot to check if it was nil or not. I've fixed the code, but the issue 
is still not resolved. The class in question DOES implement the 
interface, but FPC 3.x always returns nil, whereas FPC 2.6.4 correctly 
returns a Interface reference.


The class hierarchy is as follows...

 TBaseApplication = class(TObject, ICmdLineParams);
   |
 TX11Application = class(TBaseApplication)
   |
 TfpgApplication = class(TX11Application)

In my applications I only work with a TfpgApplication instance. If the 
interface is fully implemented in TBaseApplication, why does FPC 3.x 
_always_ report that TfpgApplication doesn't support the ICmdLineParams?



My code looks as follows:

var
  cmd: ICmdLineParams;
begin
  if Supports(fpgApplication, ICmdLineParams, cmd) then
  begin
if cmd.HasOption('n', 'newinstance') then
  MainProc
else if not AnotherInstance then
  MainProc;
  end
  else
  begin
 // ICmdLineParams interface is not supported
  end;


I looked at the wiki and the FPC 3.x "User Changes" pages and the only 
reference to Interface changes is this.



http://wiki.freepascal.org/User_Changes_3.0.0#Classes_implementing_forward-declared_interfaces

The wiki is very vague with what it means. Either way, I don't consider 
my code wrong. I'm using a class hierarchy and the base class does 
implement the Interface in question fully, so why does FPC 3.x think it 
doesn't? Bottom line, is this a FPC bug and how to I change my code to 
work until the bug can be fixed?



Regards,
  Graeme

--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

My public PGP key:  http://tinyurl.com/graeme-pgp
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] fcl-passrc: in which line a TPasElement ends?

2017-11-03 Thread Michael Van Canneyt



On Fri, 3 Nov 2017, Michael Fuchs wrote:


Sorry, some message were not sent to list, my fault:


Am 03.11.2017 um 14:132 schrieb Michael Van Canneyt:

Are there plans for a support in future? Or can you give me some 
advices how I can implement this by myself? I'm afraid I am an

absolutly newbie in this part of of the FCL.>

There are no plans to support this. I can't even imagine what you
would need this for ?

I try to write a small tool for code analysis. I need for example to
discover the line length of methods.


In this case, you can probably simply use

TPasTreeContainer.FinishScope

to record the end of the method.

Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] fcl-passrc: in which line a TPasElement ends?

2017-11-03 Thread Michael Fuchs
Sorry, some message were not sent to list, my fault:


Am 03.11.2017 um 14:132 schrieb Michael Van Canneyt:

>> Are there plans for a support in future? Or can you give me some 
>> advices how I can implement this by myself? I'm afraid I am an
>> absolutly newbie in this part of of the FCL.>
> There are no plans to support this. I can't even imagine what you
> would need this for ?
I try to write a small tool for code analysis. I need for example to
discover the line length of methods.


> To implement this, you would need to heavily modify one of procedure
> TPasParser.ParseDeclarations(Declarations: TPasDeclarations); or
> function ParseType(Parent: TPasElement; const NamePos:
> TPasSourcePos; const TypeName: String = ''; Full: Boolean = false;
> GenericArgs: TFPList = nil): TPasType;
> 
> depending on what you need

g
Michael
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] fcl-passrc: in which line a TPasElement ends?

2017-11-03 Thread Michael Van Canneyt



On Fri, 3 Nov 2017, Michael Fuchs wrote:


Hi,

a question to TPasElement of fcl-passrc:

To get the line in which the element starts I use the public
SourceLinenumber field. But how do I get the last line of this element?


Currently this is not supported.

Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] fcl-passrc: in which line a TPasElement ends?

2017-11-03 Thread Michael Fuchs
Hi,

a question to TPasElement of fcl-passrc:

To get the line in which the element starts I use the public
SourceLinenumber field. But how do I get the last line of this element?

g
Michael
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] cpu_relax() in freepascal

2017-11-03 Thread Matias Vara
Hi and thanks for the answers,

This feature seems to be a compiler intrinsic at least in the Intel C
> compiler. We don't have anything similar, so you have to fall back either
> to an asm procedure or a line of inline assembler. The compiler is also
> not doing an optimization similar to this. Free Pascal's inline assembler
> supports the PAUSE instruction though.
>
>
good to know that.


> But unless you plan to use this in a multithreaded spinloop because you're
> loading multiple cores of the CPU, it's better to let the operating system
> handle the wait. This instruction is certainly not the way to fix a "my
> app uses 100% CPU" scenario, just saying.
>
> Charlie


I am currently investigating the use of this instruction in my kernel. I
have wait-loops when accessing shared resources in a multicore system so
that could be a place to use it.
Also, I have situations in which the core just spends time in a loop so
this instruction may help to reduce energy consumption.  All this work is
however very experimental.


Matias
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] cpu_relax() in freepascal

2017-11-03 Thread Karoly Balogh (Charlie/SGR)
Hi,

On Fri, 3 Nov 2017, Matias Vara wrote:

> Hello,  I think it would be better if I put my question in context. In
> order to tell the processor that we are in a loop, the pause instruction
> could be used (also I think the "rep nop" produces the same opcode).
> This tells the processor that we are in a loop so it improves the access
> to the cache and the branching mechanism. My question is if the compiler
> is doing any improvement of this kind in a loop or I should write my own
> "pause" procedure/macro. For more info
>
> https://software.intel.com/en-us/articles/benefitting-power-and-performance-sleep-loops

This feature seems to be a compiler intrinsic at least in the Intel C
compiler. We don't have anything similar, so you have to fall back either
to an asm procedure or a line of inline assembler. The compiler is also
not doing an optimization similar to this. Free Pascal's inline assembler
supports the PAUSE instruction though.

But unless you plan to use this in a multithreaded spinloop because you're
loading multiple cores of the CPU, it's better to let the operating system
handle the wait. This instruction is certainly not the way to fix a "my
app uses 100% CPU" scenario, just saying.

Charlie___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] cpu_relax() in freepascal

2017-11-03 Thread Adriaan van Os



I want to implement the cpu_relax() function in order to use it
inside loops. However before, I would like to know if the fpc
compiler is doing an optimization of this kind.


I don't think one would you use that "inside a loop" or "to improve branching" but rather inside a 
wait-loop where constant polling, without regular pausing, keeps the processor unnecessarily busy. 
The operating system has calls for that purpose (e.g. usleep, see 
). That is not up to the compiler.


Regards,

Adriaan van Os

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] cpu_relax() in freepascal

2017-11-03 Thread Matias Vara
Hello,

I think it would be better if I put my question in context. In order to
tell the processor that we are in a loop, the pause instruction could be
used (also I think the "rep nop" produces the same opcode). This tells the
processor that we are in a loop so it improves the access to the cache and
the branching mechanism. My question is if the compiler is doing any
improvement of this kind in a loop or I should write my own "pause"
procedure/macro. For more info
https://software.intel.com/en-us/articles/benefitting-power-and-performance-sleep-loops

Cheers!

2017-10-29 16:59 GMT+01:00 Matias Vara :

> Hello everyone,
>
> I want to implement the cpu_relax() function in order to use it inside
> loops. However before, I would like to know if the fpc compiler is doing an
> optimization of this kind.
>
> Kinds regards, Matias.
>
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] FPC install on windows with limited rights

2017-11-03 Thread Martok
Am 02.11.2017 um 21:00 schrieb Graeme Geldenhuys:
> The FPC team really should consider releasing a Windows binary zip 
> release too. It really wouldn't be any extra effort as they already prep 
> everything for Inno Setup, so a simply ZIP command is all that would be 
> needed.

In case you don't need a release version (or the other way around, want a trunk
version), you may also want to have a look at my ~weekly snapshots at
. They're all just plain 7zip
archives, and a .cmd to create the fpc.cfg. The directory structure is the same
as from the installer, so you can mix & match.


-- 
Regards,
Martok

Ceterum censeo b32079 esse sanandam.

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal