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?


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;
+         deregister_created_object_type();
          if assigned(symtable) then
@@ -7939,6 +7941,12 @@
+    procedure tobjectdef.deregister_created_object_type;
+      begin
+        current_module.wpoinfo.removecreatedobjtype(self);
+      end;
     procedure tobjectdef.register_maybe_created_object_type;
         { 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 @@
+  procedure tunitwpoinfobase.removecreatedobjtype(def: tdef);
+    begin
+      fcreatedobjtypes.remove(def);
+    end;
   procedure tunitwpoinfobase.addcreatedobjtypeforclassref(def: tdef);

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

fpc-devel maillist  -  fpc-devel@lists.freepascal.org

Reply via email to