From eed1edadb46981b9f2dc2443793d3750d3a77e99 Mon Sep 17 00:00:00 2001
From: Lars Kanis <kanis@comcard.de>
Date: Sat, 28 Jan 2012 19:33:16 +0100
Subject: [PATCH] Fix GC bug in FXAccelTable

The target objects stored in the accelerator table are currently
private. Therefore FXRbAccelTable::markfunc() doesn't mark them as used.
As a workaround the objects are additionally stored in @targets Hash.
---
 ext/fox16/markfuncs.cpp  |  1 +
 lib/fox16/accel_table.rb | 13 +++++++++++++
 2 files changed, 14 insertions(+)

diff --git a/ext/fox16/markfuncs.cpp b/ext/fox16/markfuncs.cpp
index bea3a48..464191b 100644
--- a/ext/fox16/markfuncs.cpp
+++ b/ext/fox16/markfuncs.cpp
@@ -42,6 +42,7 @@ static void delete_if_not_owned_by_app(BASECLASS* self,SUBCLASS*){
 
 // FIXME: How to get to the target objects stored in the accelerator
 // table? This is currently private (not protected) data for the class.
+// See workaround in lib/fox16/accel_table.rb.
 void FXRbAccelTable::markfunc(FXAccelTable* accelTable){
   FXRbObject::markfunc(accelTable);
   }
diff --git a/lib/fox16/accel_table.rb b/lib/fox16/accel_table.rb
index 410d4e2..0641aa4 100644
--- a/lib/fox16/accel_table.rb
+++ b/lib/fox16/accel_table.rb
@@ -64,7 +64,20 @@ module Fox
           end
         end
       end
+      # FIXME: The target objects stored in the accelerator table are currently
+      # private. Therefore FXRbAccelTable::markfunc() doesn't mark them as used.
+      # As a workaround the objects are additionally stored in @targets Hash.
+      @targets = {} unless instance_variable_defined?('@targets')
+      @targets[hotKey] = tgt
       addAccelOrig(hotKey, tgt, seldn, selup)
     end
+
+    alias removeAccelOrig removeAccel # :nodoc:
+
+    def removeAccel(hotKey)
+      @targets = {} unless instance_variable_defined?('@targets')
+      @targets.delete(hotKey)
+      removeAccelOrig(hotKey)
+    end
   end
 end
\ No newline at end of file
-- 
GitLab