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

User avatar
Josef Templ
Posts: 2047
Joined: Tue Sep 17, 2013 6:50 am

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

Post 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
luowy
Posts: 234
Joined: Mon Oct 20, 2014 12:52 pm

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

Post by luowy »

Your fixup is ok, I have tested it;

luowy
User avatar
Josef Templ
Posts: 2047
Joined: Tue Sep 17, 2013 6:50 am

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

Post 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
luowy
Posts: 234
Joined: Mon Oct 20, 2014 12:52 pm

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

Post 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
User avatar
Josef Templ
Posts: 2047
Joined: Tue Sep 17, 2013 6:50 am

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

Post 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
User avatar
Josef Templ
Posts: 2047
Joined: Tue Sep 17, 2013 6:50 am

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

Post 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
luowy
Posts: 234
Joined: Mon Oct 20, 2014 12:52 pm

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

Post by luowy »

I think the second choice is goog enough for this procedure's function.
User avatar
Josef Templ
Posts: 2047
Joined: Tue Sep 17, 2013 6:50 am

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

Post 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
luowy
Posts: 234
Joined: Mon Oct 20, 2014 12:52 pm

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

Post 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
User avatar
Josef Templ
Posts: 2047
Joined: Tue Sep 17, 2013 6:50 am

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

Post 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
Post Reply