-
Notifications
You must be signed in to change notification settings - Fork 194
Closed
Description
Execute this script cause system violation.
program sample2;
{$APPTYPE CONSOLE}
uses
System.SysUtils,
System.Math,
uPSCompiler,
uPSRuntime;
function ScriptOnUses(Sender: TPSPascalCompiler; const Name: AnsiString): Boolean;
begin
if Name = 'SYSTEM' then
begin
Sender.AddDelphiFunction('function SimpleRoundTo_Double(const o: Double; const Digits: Integer): Double');
Sender.AddDelphiFunction('function SimpleRoundTo_Extended(const o: Extended; const Digits: Integer): Extended');
Result := True;
end else
Result := False;
end;
procedure ExecuteScript(const Script: string);
var
Compiler: TPSPascalCompiler;
Exec: TPSExec;
{$IFDEF UNICODE}Data: AnsiString;{$ELSE}Data: string;{$ENDIF}
SimpleRoundTo_Double: function (const AValue: Double; const ADigit: TRoundToRange = -2): Double;
SimpleRoundTo_Extended: function (const AValue: Extended; const ADigit: TRoundToRange = -2): Extended;
begin
Compiler := TPSPascalCompiler.Create; // create an instance of the compiler.
Compiler.OnUses := ScriptOnUses; // assign the OnUses event.
if not Compiler.Compile(Script) then // Compile the Pascal script into bytecode.
begin
Compiler.Free;
Exit;
end;
Compiler.GetOutput(Data); // Save the output of the compiler in the string Data.
Compiler.Free; // After compiling the script, there is no need for the compiler anymore.
Exec := TPSExec.Create; // Create an instance of the executer.
SimpleRoundTo_Double := SimpleRoundTo;
SimpleRoundTo_Extended := SimpleRoundTo;
Exec.RegisterDelphiFunction(@SimpleRoundTo_Double, 'SimpleRoundTo_Double', cdRegister);
Exec.RegisterDelphiFunction(@SimpleRoundTo_Extended, 'SimpleRoundTo_Extended', cdRegister);
if not Exec.LoadData(Data) then // Load the data from the Data string.
begin
Exec.Free;
Exit;
end;
Exec.RunScript; // Run the script.
Exec.Free; // Free the executer.
end;
begin
ExecuteScript('begin SimpleRoundTo_Double(10, 1) end.'); // success
ExecuteScript('begin SimpleRoundTo_Extended(10, 1) end.'); // fail
end.I notice in InvokeCall.inc treat both double and extended data type similarly:
btDouble, btExtended: Arg := TValue.From(PDouble(fvar.dta)^);
...
btDouble, btExtended: pdouble(res.dta)^ := Double(Invoke(Address,Args,SysCalConv,TypeInfo(Double),False,IsConstr).AsExtended);
Metadata
Metadata
Assignees
Labels
No labels