Skip to content

Commit

Permalink
fix to support non-local access with PCALL
Browse files Browse the repository at this point in the history
  • Loading branch information
Rochus Keller committed May 15, 2022
1 parent f1ddf7c commit 1873061
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 19 deletions.
2 changes: 1 addition & 1 deletion ObxIde2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3378,7 +3378,7 @@ int main(int argc, char *argv[])
a.setOrganizationName("[email protected]");
a.setOrganizationDomain("github.com/rochus-keller/Oberon");
a.setApplicationName("Oberon+ IDE (Mono)");
a.setApplicationVersion("0.9.71");
a.setApplicationVersion("0.9.72");
a.setStyle("Fusion");
QFontDatabase::addApplicationFont(":/font/DejaVuSansMono.ttf"); // "DejaVu Sans Mono"

Expand Down
4 changes: 3 additions & 1 deletion ObxValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -683,10 +683,12 @@ struct ValidatorImp : public AstVisitor
ProcType* pt = cast<ProcType*>(t1);
if( pt->d_return.isNull() )
{
// checkValidRhs(args->d_args[1].data()); // forbids non-local access
ArgExpr tmp = *args;
tmp.d_sub = args->d_args[1].data();
tmp.d_args.pop_front();
tmp.d_args.pop_front();
checkCallArgs(pt,&tmp);
checkCallArgs(pt,&tmp); // PCALL is transparent; this is the actual call
}else
error( args->d_args[1]->d_loc, Validator::tr("function procedures are not supported by PCALL"));
}else // td can be null, e.g. when calling new(ptr) as second argument
Expand Down
48 changes: 31 additions & 17 deletions testcases/ObxTests/Pcall2.obx
Original file line number Diff line number Diff line change
@@ -1,23 +1,37 @@
module Pcall2
type Exception = record end
proc Print(IN str: array of char)
var e: pointer to Exception

proc Sub()
type Exception = record end

proc Print(IN str: array of char)
var e: pointer to Exception
begin
i := 33
println(str)
new(e)
raise(e)
println("this should not be printed")
end Print

var
res: pointer to anyrec
i: integer

begin
println(str)
new(e)
raise(e)
println("this is printed")
end Print
var
res: pointer to anyrec
i := 22
pcall(res, Print, "Hello World")
case res of
| Exception: println("got Exception")
| anyrec: println("got anyrec")
| nil: println("all ok")
else
println("unknown exception")
end
println(i) // CLR prints 33, C prints 22
end Sub

begin
pcall(res, Print, "Hello World")
case res of
| Exception: println("got Exception")
| anyrec: println("got anyrec")
else
println("no or unknown exception")
end

Sub();

end Pcall2

0 comments on commit 1873061

Please sign in to comment.