issue-#167 endless loop in DevBrowser for cyclic pointer typ
- Josef Templ
- Posts: 2047
- Joined: Tue Sep 17, 2013 6:50 am
issue-#167 endless loop in DevBrowser for cyclic pointer typ
I have created issue https://redmine.blackboxframework.org/issues/167 for fixing an endless loop
when showing the interface of the following kind of type definition:
TYPE T* = POINTER TO ARRAY OF T;
This is a legal (cyclic) type definition. The compiler handles it correctly.
Only DevBrowser fails to show the interface.
The fix is in the check (DevBrowser.IsHook) for "Kernel.Hook" types, which are invisible by default.
Cycles need to be detected in such a case and this is done by using an auxiliary variable that points to the beginning
of the type structure. Since cycles need a named type structure, they always start with the beginning and thereby include the beginning.
See diffs at https://redmine.blackboxframework.org/p ... ebd3883a8d.
- Josef
when showing the interface of the following kind of type definition:
TYPE T* = POINTER TO ARRAY OF T;
This is a legal (cyclic) type definition. The compiler handles it correctly.
Only DevBrowser fails to show the interface.
The fix is in the check (DevBrowser.IsHook) for "Kernel.Hook" types, which are invisible by default.
Cycles need to be detected in such a case and this is done by using an auxiliary variable that points to the beginning
of the type structure. Since cycles need a named type structure, they always start with the beginning and thereby include the beginning.
See diffs at https://redmine.blackboxframework.org/p ... ebd3883a8d.
- Josef
Re: issue-#167 endless loop in DevBrowser for cyclic pointer
Your fixup is ok, I have tested it;
luowy
luowy
- Josef Templ
- Posts: 2047
- Joined: Tue Sep 17, 2013 6:50 am
Re: issue-#167 endless loop in DevBrowser for cyclic pointer
Thanks for testing.
In the meantime, however, I found another cycle that is still not detected.
More precisely, it is detected for S, but not for T.
TYPE S* = POINTER TO ARRAY OF S;
TYPE T* = POINTER TO ARRAY OF S;
That means checking for t0 is not sufficient.
- Josef
In the meantime, however, I found another cycle that is still not detected.
More precisely, it is detected for S, but not for T.
TYPE S* = POINTER TO ARRAY OF S;
TYPE T* = POINTER TO ARRAY OF S;
That means checking for t0 is not sufficient.
- Josef
Re: issue-#167 endless loop in DevBrowser for cyclic pointer
add one line
luowy
Code: Select all
PROCEDURE IsHook(typ: DevCPT.Struct): BOOLEAN;
VAR t0: DevCPT.Struct;
BEGIN
t0 := typ;
WHILE ((typ.form = pointer) OR (typ.form = comp)) & (typ.BaseTyp # NIL) & (typ.BaseTyp # t0) DO
IF typ.form = pointer THEN t0:=typ END;
typ := typ.BaseTyp
END;
RETURN (DevCPT.glbMods[typ.mno].name^ = "Kernel") & (typ.strobj.name^ = "Hook^")
END IsHook;
- Josef Templ
- Posts: 2047
- Joined: Tue Sep 17, 2013 6:50 am
Re: issue-#167 endless loop in DevBrowser for cyclic pointer
This does not work for
TYPE U* = POINTER TO ARRAY OF POINTER TO ARRAY OF U;
I see two possibilities:
1. increment a counter within the loop and when the counter reaches a limit (for example 100) assume that it is a cycle and terminate the loop.
2. treat arrays differently, i.e. assume that the base type of an array is never a hook or something like that.
- Josef
TYPE U* = POINTER TO ARRAY OF POINTER TO ARRAY OF U;
I see two possibilities:
1. increment a counter within the loop and when the counter reaches a limit (for example 100) assume that it is a cycle and terminate the loop.
2. treat arrays differently, i.e. assume that the base type of an array is never a hook or something like that.
- Josef
- Josef Templ
- Posts: 2047
- Joined: Tue Sep 17, 2013 6:50 am
Re: issue-#167 endless loop in DevBrowser for cyclic pointer
I have now committed version 1, a counter up to 100.
Note that this is not time critical because it is only relevant in exotic cases.
See diffs at https://redmine.blackboxframework.org/p ... c7f2704da1.
- Josef
Note that this is not time critical because it is only relevant in exotic cases.
See diffs at https://redmine.blackboxframework.org/p ... c7f2704da1.
- Josef
Re: issue-#167 endless loop in DevBrowser for cyclic pointer
I think the second choice is goog enough for this procedure's function.
- Josef Templ
- Posts: 2047
- Joined: Tue Sep 17, 2013 6:50 am
Re: issue-#167 endless loop in DevBrowser for cyclic pointer
It looked to me more complicated.luowy wrote:I think the second choice is goog enough for this procedure's function.
The "counter" version is very easy to implement and understand.
It does not have any possibility for a loophole, I believe, and it has the same behavior as before.
Only if there are more than 100(!) base types a Kernel.Hook could be missed and displayed when showing the interface.
This is the trade off.
- Josef
Re: issue-#167 endless loop in DevBrowser for cyclic pointer
though The following code accept all your previous examples, but I'm afraid that your next example will defeat it;
so I agree with you,the counter guard is easy and good enough;
luowy
so I agree with you,the counter guard is easy and good enough;
Code: Select all
PROCEDURE IsHook(typ: DevCPT.Struct): BOOLEAN;
VAR t0: DevCPT.Struct;
BEGIN
t0 := typ;
WHILE ((typ.form = pointer) OR (typ.form = comp)) & (typ.BaseTyp # NIL) & (typ.BaseTyp # t0) DO
IF (typ.form = pointer)&(typ.strobj.name^ # '')) THEN t0:=typ END;
typ := typ.BaseTyp
END;
RETURN (DevCPT.glbMods[typ.mno].name^ = "Kernel") & (typ.strobj.name^ = "Hook^")
END IsHook;
- Josef Templ
- Posts: 2047
- Joined: Tue Sep 17, 2013 6:50 am
Re: issue-#167 endless loop in DevBrowser for cyclic pointer
Right you are, luowy. Here is the example:-)luowy wrote:though The following code accept all your previous examples, but I'm afraid that your next example will defeat it;
so I agree with you,the counter guard is easy and good enough;
luowy
Code: Select all
TYPE S* = POINTER TO ARRAY OF T;
TYPE T* = POINTER TO ARRAY OF S;