]> git.eshelyaron.com Git - emacs.git/commitdiff
* nsmenu.m (Popdown_data): New struct.
authorJan Djärv <jan.h.d@swipnet.se>
Sun, 22 Jul 2012 16:35:15 +0000 (18:35 +0200)
committerJan Djärv <jan.h.d@swipnet.se>
Sun, 22 Jul 2012 16:35:15 +0000 (18:35 +0200)
(pop_down_menu): p->pointer is Popdown_data.  Release the pool and
free Popdown_data.
(ns_popup_dialog): Use NSAutoreleasePool and pass it to pop_down_menu.
(initWithContentRect): Make imgView and contentView non-static
and autorelease them.  Also autorelease img and matrix.
(dealloc): Remove (Bug#1995-05-29T20:16:10Z!kwzh@gnu.org).

src/ChangeLog
src/nsmenu.m

index f689cc20ee02bae5d88390b44160232c8f3582c3..b89bfc412989cda10e8ecc7cfcd6a24a434f5de7 100644 (file)
@@ -1,3 +1,13 @@
+2012-07-22  Jan Djärv  <jan.h.d@swipnet.se>
+
+       * nsmenu.m (Popdown_data): New struct.
+       (pop_down_menu): p->pointer is Popdown_data.  Release the pool and
+       free Popdown_data.
+       (ns_popup_dialog): Use NSAutoreleasePool and pass it to pop_down_menu.
+       (initWithContentRect): Make imgView and contentView non-static
+       and autorelease them.  Also autorelease img and matrix (Bug#12005).
+       (dealloc): Remove (Bug#12005).
+
 2012-07-22  Dmitry Antipov  <dmantipov@yandex.ru>
 
        Adjust consing_since_gc when objects are explicitly freed.
index c919f350c6ca99471139faeacacb81b014799db3..d5b5f4b7526460c79239d1173244f2315f62eb37 100644 (file)
@@ -1349,20 +1349,33 @@ update_frame_tool_bar (FRAME_PTR f)
 
    ========================================================================== */
 
+struct Popdown_data
+{
+  NSAutoreleasePool *pool;
+  EmacsDialogPanel *dialog;
+};
 
 static Lisp_Object
 pop_down_menu (Lisp_Object arg)
 {
   struct Lisp_Save_Value *p = XSAVE_VALUE (arg);
+  struct Popdown_data *unwind_data = (struct Popdown_data *) p->pointer;
+
+  BLOCK_INPUT;
   if (popup_activated_flag)
     {
+      EmacsDialogPanel *panel = unwind_data->dialog;
       popup_activated_flag = 0;
-      BLOCK_INPUT;
       [NSApp endModalSession: popupSession];
-      [((EmacsDialogPanel *) (p->pointer)) close];
+
+      [panel close];
+      [unwind_data->pool release];
       [[FRAME_NS_VIEW (SELECTED_FRAME ()) window] makeKeyWindow];
-      UNBLOCK_INPUT;
     }
+
+  xfree (unwind_data);
+  UNBLOCK_INPUT;
+
   return Qnil;
 }
 
@@ -1375,6 +1388,7 @@ ns_popup_dialog (Lisp_Object position, Lisp_Object contents, Lisp_Object header)
   struct frame *f;
   NSPoint p;
   BOOL isQ;
+  NSAutoreleasePool *pool;
 
   NSTRACE (x-popup-dialog);
 
@@ -1429,15 +1443,23 @@ ns_popup_dialog (Lisp_Object position, Lisp_Object contents, Lisp_Object header)
     contents = Fcons (title, Fcons (Fcons (build_string ("Ok"), Qt), Qnil));
 
   BLOCK_INPUT;
+  pool = [[NSAutoreleasePool alloc] init];
   dialog = [[EmacsDialogPanel alloc] initFromContents: contents
                                            isQuestion: isQ];
+
   {
     ptrdiff_t specpdl_count = SPECPDL_INDEX ();
-    record_unwind_protect (pop_down_menu, make_save_value (dialog, 0));
+    struct Popdown_data *unwind_data = xmalloc (sizeof (*unwind_data));
+
+    unwind_data->pool = pool;
+    unwind_data->dialog = dialog;
+    
+    record_unwind_protect (pop_down_menu, make_save_value (unwind_data, 0));
     popup_activated_flag = 1;
     tem = [dialog runDialogAt: p];
     unbind_to (specpdl_count, Qnil);  /* calls pop_down_menu */
   }
+
   UNBLOCK_INPUT;
 
   return tem;
@@ -1475,24 +1497,22 @@ ns_popup_dialog (Lisp_Object position, Lisp_Object contents, Lisp_Object header)
   NSSize spacing = {SPACER, SPACER};
   NSRect area;
   id cell;
-  static NSImageView *imgView;
-  static FlippedView *contentView;
-
-  if (imgView == nil)
-    {
-      NSImage *img;
-      area.origin.x   = 3*SPACER;
-      area.origin.y   = 2*SPACER;
-      area.size.width = ICONSIZE;
-      area.size.height= ICONSIZE;
-      img = [[NSImage imageNamed: @"NSApplicationIcon"] copy];
-      [img setScalesWhenResized: YES];
-      [img setSize: NSMakeSize (ICONSIZE, ICONSIZE)];
-      imgView = [[NSImageView alloc] initWithFrame: area];
-      [imgView setImage: img];
-      [imgView setEditable: NO];
-      [img release];
-    }
+  NSImageView *imgView;
+  FlippedView *contentView;
+  NSImage *img;
+
+  area.origin.x   = 3*SPACER;
+  area.origin.y   = 2*SPACER;
+  area.size.width = ICONSIZE;
+  area.size.height= ICONSIZE;
+  img = [[NSImage imageNamed: @"NSApplicationIcon"] copy];
+  [img setScalesWhenResized: YES];
+  [img setSize: NSMakeSize (ICONSIZE, ICONSIZE)];
+  imgView = [[NSImageView alloc] initWithFrame: area];
+  [imgView setImage: img];
+  [imgView setEditable: NO];
+  [img autorelease];
+  [imgView autorelease];
 
   aStyle = NSTitledWindowMask;
   flag = YES;
@@ -1501,6 +1521,8 @@ ns_popup_dialog (Lisp_Object position, Lisp_Object contents, Lisp_Object header)
   [super initWithContentRect: contentRect styleMask: aStyle
                      backing: backingType defer: flag];
   contentView = [[FlippedView alloc] initWithFrame: [[self contentView] frame]];
+  [contentView autorelease];
+
   [self setContentView: contentView];
 
   [[self contentView] setAutoresizesSubviews: YES];
@@ -1551,12 +1573,12 @@ ns_popup_dialog (Lisp_Object position, Lisp_Object contents, Lisp_Object header)
                                  prototype: cell
                               numberOfRows: 0
                            numberOfColumns: 1];
-  [[self contentView] addSubview: matrix];
-  [matrix release];
   [matrix setFrameOrigin: NSMakePoint (area.origin.x,
                                       area.origin.y + (TEXTHEIGHT+3*SPACER))];
   [matrix setIntercellSpacing: spacing];
+  [matrix autorelease];
 
+  [[self contentView] addSubview: matrix];
   [self setOneShot: YES];
   [self setReleasedWhenClosed: YES];
   [self setHidesOnDeactivate: YES];
@@ -1735,12 +1757,6 @@ void process_dialog (id window, Lisp_Object list)
 }
 
 
-- (void)dealloc
-{
-  { [super dealloc]; return; };
-}
-
-
 - (Lisp_Object)runDialogAt: (NSPoint)p
 {
   NSInteger ret;