DWScript icon indicating copy to clipboard operation
DWScript copied to clipboard

IsCompilation failed on Lazarus under Windows

Open Molochnik opened this issue 1 year ago • 9 comments

There is a lot of small errors during compilation under Lazarus Windows, I started to correct them but have no idea how long it'll take to correct them all so I dropped it for now.

Molochnik avatar May 18 '24 09:05 Molochnik

Yes, I had a go at it a couple years ago, but a major stumbling block was that FreePascal RTL doesn't fully support UnicodeString Variants, and the the RTL only has partial support for UnicodeString. This leads to a lot of glitching and test case failures. The issue is not solvable in the FPC RTL without breaking a lot of existing LCL code assumptions.

Only long term solution would probably be to implement a "DWSVariant" from scratch for FPC, so DWScript can get a Delphi-compatible Variant behavior under FPC, but this is a major undertaking with dubious benefits. Alternatively, it's possible to compile with UTF8Strings, which FPC Variants support, but this would fork the DWScript variant into a new dialect with incompatible behaviors.

EricGrange avatar Jun 06 '24 05:06 EricGrange

Yes I see, different strings implementation on FPC and Delphi can cause a lot of pain. All right no problem, I don't think it's worth the time. BTW I placed some issues on the bitbucket.org.

Molochnik avatar Jun 07 '24 09:06 Molochnik

BTW I placed some issues on the bitbucket.org

The bitbucket issue tracker is broken; You are probably the only one who can see the issues you posted.

andersmelander avatar Jun 07 '24 09:06 andersmelander

:) didnt know that. So here are the issues: Delphi 11.3,

1) dwsRTTIExposer.pas (805)

tkEnumeration : if asType.Handle=TypeInfo(Boolean) then info.Value:=value.AsBoolean else info.Value:=value.AsInt64;

AsInt64here causes error, if you replace it with AsVariant it works.

  1. when exposing a method like this

procedure TSomeClass.DecodeActions(const sActions: string; var Actions: TArray);

if you place here out instead of var the script always gets an empty array. Var works fine.

  1. The similar problem exists with enumeration parameters, but on the contrary, var doesn't return a changed value but out works fine

procedure TSomeClass.DecodeActions(const sActions: string; var Action: TSomeEnumeration);

  1. I have got different behavior on Linux and Windows while exposing methods with array parameters like in 2. dwsRTTIExposer.pas (881)

DynArraySetLength(PPointer(Result.GetReferenceToRawData)^, Result.TypeInfo, 1, @LLen)

The code causes range check error on Linux, while on Windows does not.

If you need to provide some tests I can do that. The 4) issue is the most essential

Molochnik avatar Jun 07 '24 10:06 Molochnik

Yes, I saw your Issue on Bitbucket, but when trying to access it, I just get a 403 "under review" error.

For your 1, do you have an example of the Delphi-side code that triggers the issue ?

For 4, I do not have access to Linux for Delphi to test on :/

EricGrange avatar Jun 07 '24 15:06 EricGrange

  1. Looks like the first problem is related to properties. Delphi code:
type
TSomeClass //class to be exposed   
.....
private
    FTestEnum: TSomeEnumeration;
published 
    property TestEnum: TSomeEnumeration read FTestEnum write FTestEnum;
    function TestFunc2(ATestEnum: TSomeEnumeration ): Boolean;
end;
var
   SomeClass :TSomeClass;//object to be exposed

Script code

var
   TestEnum: TSomeEnumeration
SomeClass.TestFunc2(TestEnum);//works fine with internal variable
SomeClass.TestFunc2(SomeClass.TestEnum);//invalid class typecast with exposed property

  1. As per Linux I can offer you the remote access to my PC where you can test it

Molochnik avatar Jun 07 '24 21:06 Molochnik

I have committed a test case in Test/URTTIExposeTests.pas based on your above snippet, but can't reproduce the issue (Delphi 12 / Win64). Does the test reproduce the issue on your side or do you have extra details that could help reproduce ?

EricGrange avatar Jun 13 '24 14:06 EricGrange

thanks I will try to reproduce the issue on your test case and let you know

Molochnik avatar Jun 14 '24 15:06 Molochnik

Yes I found why you didn't get the error.

  1. I tried to compile your test but failed to find TestUtils.pas, so I copied your code to my test unit and changed it to produce the error
  2. My test is more complicated than yours. I expose not only TClassWithEnumeration but also the var c:TClassWithEnumeration; like that: FUnit.ExposeInstanceToUnit('c', 'TClassWithEnumeration', c); and the script will be like that (c is not created but exposed):
c.TestFunc(seOne);//fine
c.TestFunc(c.EnumField);//bad



Molochnik avatar Jun 14 '24 21:06 Molochnik

Hi Eric, I found some weird issue when exposing arrays. When you pass such property to another exposed method the script runs extremely slow and speed falls down exponentially with increasing size of the array (actually not very large) for example passing 10000 elements takes around 10 seconds of running when the program does absolutely nothing useful. 20000 elements takes around 40 seconds.

type
  TTestScript = class
  private
    FResponseStream: TArray<Int64>;
  published
    property ResponseStream read FResponseStream write FResponseStream;
    procedure Test;
    procedure Test2(const ar:TArray<Int64>);
  end;

implementation
procedure TTestScript.Test;
begin
  SetLength(FResponseStream,10000);
end;

procedure TTestScript.Test2(const ar:TArray<Int64>);
begin
end;

Calling test and then test2 in the script when passing the ResponseStream to it causes the program to work very slow.

Molochnik avatar Jul 23 '24 17:07 Molochnik

I managed to work around using variant properties instead of arrays. It works now fast on Windows. But on Linux I have got another problem - all array parameters of exposed class method cause a huge number of range check errors when Delphi tries to call the method from the script

Molochnik avatar Jul 27 '24 03:07 Molochnik

Eric, I have made a test project, so this one can be closed

Molochnik avatar Jul 27 '24 07:07 Molochnik