Hi all,

I have some problems with WPO. When the unit in the attached example is compiled for the third time, the compiler crashes while writing the WPO-information to the ppu.

This is because the a tobjectdef which has been added to the WPO-list with classes which are created has been freed.

I am not sure what happens exactly, and I was not able to generate a simpler example. But my guess is that there is a method in which an instance of the class is created. Then there are no calls to this method so the method is removed. (and with this method the it's symtable with the type-definition. This is the part that I do not really understand) The reference to the type is still in the WPO-table, so when it is written to file, the system collapses.

The attached patch fixes the problem, but I doubt that the fix is correct. (Especially when a class is created in multiple places. My patch will remove the classtype from the list with created classes, regardless the count.)

Besides that, I just discovered that the patch breaks cycling of the compiler. But it is wrong anyway...

Can someone help me out?

Regards,

Joost.
Index: symdef.pas
===================================================================
--- symdef.pas	(revision 43306)
+++ symdef.pas	(working copy)
@@ -523,6 +523,7 @@
           function search_enumerator_current: tsym; override;
           { WPO }
           procedure register_created_object_type;override;
+          procedure deregister_created_object_type;
           procedure register_maybe_created_object_type;
           procedure register_created_classref_type;
           procedure register_vmt_call(index:longint);
@@ -7231,6 +7232,7 @@
 
     destructor tobjectdef.destroy;
       begin
+         deregister_created_object_type();
          if assigned(symtable) then
            begin
              symtable.free;
@@ -7939,6 +7941,12 @@
       end;
 
 
+    procedure tobjectdef.deregister_created_object_type;
+      begin
+        current_module.wpoinfo.removecreatedobjtype(self);
+      end;
+
+
     procedure tobjectdef.register_maybe_created_object_type;
       begin
         { if we know it has been created for sure, no need
Index: wpobase.pas
===================================================================
--- wpobase.pas	(revision 43306)
+++ wpobase.pas	(working copy)
@@ -168,6 +168,7 @@
     property calledvmtentries: tfphashlist read fcalledvmtentries;
 
     procedure addcreatedobjtype(def: tdef);
+    procedure removecreatedobjtype(def: tdef);
     procedure addcreatedobjtypeforclassref(def: tdef);
     procedure addmaybecreatedbyclassref(def: tdef);
     procedure addcalledvmtentry(def: tdef; index: longint);
@@ -412,6 +413,12 @@
     end;
 
 
+  procedure tunitwpoinfobase.removecreatedobjtype(def: tdef);
+    begin
+      fcreatedobjtypes.remove(def);
+    end;
+
+
   procedure tunitwpoinfobase.addcreatedobjtypeforclassref(def: tdef);
     begin
       fcreatedclassrefobjtypes.add(def);

Attachment: bug_test.tgz
Description: application/compressed-tar

_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to