Page 1 of 2

issue-#167 endless loop in DevBrowser for cyclic pointer typ

Posted: Mon Jul 24, 2017 1:03 pm
by Josef Templ
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

Re: issue-#167 endless loop in DevBrowser for cyclic pointer

Posted: Wed Jul 26, 2017 2:41 am
by luowy
Your fixup is ok, I have tested it;

luowy

Re: issue-#167 endless loop in DevBrowser for cyclic pointer

Posted: Wed Jul 26, 2017 3:18 am
by Josef Templ
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

Re: issue-#167 endless loop in DevBrowser for cyclic pointer

Posted: Wed Jul 26, 2017 5:34 am
by luowy
add one line

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;
luowy

Re: issue-#167 endless loop in DevBrowser for cyclic pointer

Posted: Wed Jul 26, 2017 7:27 am
by Josef Templ
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

Re: issue-#167 endless loop in DevBrowser for cyclic pointer

Posted: Wed Jul 26, 2017 7:46 am
by Josef Templ
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

Re: issue-#167 endless loop in DevBrowser for cyclic pointer

Posted: Wed Jul 26, 2017 8:47 am
by luowy
I think the second choice is goog enough for this procedure's function.

Re: issue-#167 endless loop in DevBrowser for cyclic pointer

Posted: Wed Jul 26, 2017 9:37 am
by Josef Templ
luowy wrote:I think the second choice is goog enough for this procedure's function.
It looked to me more complicated.
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

Posted: Wed Jul 26, 2017 3:11 pm
by luowy
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;

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;
luowy

Re: issue-#167 endless loop in DevBrowser for cyclic pointer

Posted: Wed Jul 26, 2017 3:55 pm
by Josef Templ
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
Right you are, luowy. Here is the example:-)

Code: Select all

TYPE S* = POINTER TO ARRAY OF T;
TYPE T* = POINTER TO ARRAY OF S;
- Josef