comparison mac/dw.m @ 1582:728778634933

Performed a more thorough audit of functions on Mac that require local pools. Added macros to these functions to hopefully reduce or eliminate leaks in apps that are threaded and perform GUI functions on secondary threads. _dw_pool_drain() is still available to drain the main thread pool, but enclosing the functions in these macros should reduce the objects accumulating in the thread's main pool.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 26 Jan 2012 05:26:40 +0000
parents a51397ea24bf
children 021d2966f84d
comparison
equal deleted inserted replaced
1581:a80ec948c3eb 1582:728778634933
5229 { 5229 {
5230 NSColor *color = [[NSColor colorWithDeviceRed: DW_RED_VALUE(value)/255.0 green: DW_GREEN_VALUE(value)/255.0 blue: DW_BLUE_VALUE(value)/255.0 alpha: 1] retain]; 5230 NSColor *color = [[NSColor colorWithDeviceRed: DW_RED_VALUE(value)/255.0 green: DW_GREEN_VALUE(value)/255.0 blue: DW_BLUE_VALUE(value)/255.0 alpha: 1] retain];
5231 /* Create the Color Chooser Dialog class. */ 5231 /* Create the Color Chooser Dialog class. */
5232 static DWColorChoose *colorDlg = nil; 5232 static DWColorChoose *colorDlg = nil;
5233 DWDialog *dialog; 5233 DWDialog *dialog;
5234 DW_LOCAL_POOL_IN;
5234 5235
5235 if(colorDlg) 5236 if(colorDlg)
5236 { 5237 {
5237 dialog = [colorDlg dialog]; 5238 dialog = [colorDlg dialog];
5238 /* If someone is already waiting just return */ 5239 /* If someone is already waiting just return */
5239 if(dialog) 5240 if(dialog)
5240 { 5241 {
5242 DW_LOCAL_POOL_OUT;
5241 return value; 5243 return value;
5242 } 5244 }
5243 } 5245 }
5244 else 5246 else
5245 { 5247 {
5261 /* Figure out the value of what they returned */ 5263 /* Figure out the value of what they returned */
5262 CGFloat red, green, blue; 5264 CGFloat red, green, blue;
5263 [color getRed:&red green:&green blue:&blue alpha:NULL]; 5265 [color getRed:&red green:&green blue:&blue alpha:NULL];
5264 [color release]; 5266 [color release];
5265 value = DW_RGB((int)(red * 255), (int)(green *255), (int)(blue *255)); 5267 value = DW_RGB((int)(red * 255), (int)(green *255), (int)(blue *255));
5268 DW_LOCAL_POOL_OUT;
5266 return value; 5269 return value;
5267 } 5270 }
5268 5271
5269 /* Draw a point on a window (preferably a render window). 5272 /* Draw a point on a window (preferably a render window).
5270 * Parameters: 5273 * Parameters:
5822 { 5825 {
5823 int _locked_by_me = FALSE; 5826 int _locked_by_me = FALSE;
5824 DW_MUTEX_LOCK; 5827 DW_MUTEX_LOCK;
5825 DWTree *tree = handle; 5828 DWTree *tree = handle;
5826 NSMutableArray *array = (NSMutableArray *)item; 5829 NSMutableArray *array = (NSMutableArray *)item;
5830 DW_LOCAL_POOL_IN;
5831
5827 if(title) 5832 if(title)
5828 { 5833 {
5829 NSString *oldstr = [array objectAtIndex:1]; 5834 NSString *oldstr = [array objectAtIndex:1];
5830 NSString *nstr = [[NSString stringWithUTF8String:title] retain]; 5835 NSString *nstr = [[NSString stringWithUTF8String:title] retain];
5831 [array replaceObjectAtIndex:1 withObject:nstr]; 5836 [array replaceObjectAtIndex:1 withObject:nstr];
5834 if(icon) 5839 if(icon)
5835 { 5840 {
5836 [array replaceObjectAtIndex:0 withObject:icon]; 5841 [array replaceObjectAtIndex:0 withObject:icon];
5837 } 5842 }
5838 [tree reloadData]; 5843 [tree reloadData];
5844 DW_LOCAL_POOL_OUT;
5839 DW_MUTEX_UNLOCK; 5845 DW_MUTEX_UNLOCK;
5840 } 5846 }
5841 5847
5842 /* 5848 /*
5843 * Sets the item data of a tree item. 5849 * Sets the item data of a tree item.
6530 * text: Text usually returned by dw_container_query(). 6536 * text: Text usually returned by dw_container_query().
6531 */ 6537 */
6532 void API dw_container_cursor(HWND handle, char *text) 6538 void API dw_container_cursor(HWND handle, char *text)
6533 { 6539 {
6534 int _locked_by_me = FALSE; 6540 int _locked_by_me = FALSE;
6541 DW_LOCAL_POOL_IN;
6535 DW_MUTEX_LOCK; 6542 DW_MUTEX_LOCK;
6536 DWContainer *cont = handle; 6543 DWContainer *cont = handle;
6537 char *thistext; 6544 char *thistext;
6538 int x, count = (int)[cont numberOfRowsInTableView:cont]; 6545 int x, count = (int)[cont numberOfRowsInTableView:cont];
6539 int textcomp = DW_POINTER_TO_INT(dw_window_get_data(handle, "_dw_textcomp")); 6546 int textcomp = DW_POINTER_TO_INT(dw_window_get_data(handle, "_dw_textcomp"));
6548 6555
6549 [cont selectRowIndexes:selected byExtendingSelection:YES]; 6556 [cont selectRowIndexes:selected byExtendingSelection:YES];
6550 [selected release]; 6557 [selected release];
6551 [cont scrollRowToVisible:x]; 6558 [cont scrollRowToVisible:x];
6552 DW_MUTEX_UNLOCK; 6559 DW_MUTEX_UNLOCK;
6560 DW_LOCAL_POOL_OUT;
6553 return; 6561 return;
6554 } 6562 }
6555 } 6563 }
6556 DW_MUTEX_UNLOCK; 6564 DW_MUTEX_UNLOCK;
6565 DW_LOCAL_POOL_OUT;
6557 } 6566 }
6558 6567
6559 /* 6568 /*
6560 * Deletes the item with the text speficied. 6569 * Deletes the item with the text speficied.
6561 * Parameters: 6570 * Parameters:
6628 * icon: Icon handle that was used with dw_taskbar_insert(). 6637 * icon: Icon handle that was used with dw_taskbar_insert().
6629 */ 6638 */
6630 void API dw_taskbar_delete(HWND handle, HICN icon) 6639 void API dw_taskbar_delete(HWND handle, HICN icon)
6631 { 6640 {
6632 NSStatusItem *item = dw_window_get_data(handle, "_dw_taskbar"); 6641 NSStatusItem *item = dw_window_get_data(handle, "_dw_taskbar");
6642 DW_LOCAL_POOL_IN;
6633 [item release]; 6643 [item release];
6644 DW_LOCAL_POOL_OUT;
6634 } 6645 }
6635 6646
6636 /* 6647 /*
6637 * Obtains an icon from a module (or header in GTK). 6648 * Obtains an icon from a module (or header in GTK).
6638 * Parameters: 6649 * Parameters:
6691 * handle: Handle to icon returned by dw_icon_load(). 6702 * handle: Handle to icon returned by dw_icon_load().
6692 */ 6703 */
6693 void API dw_icon_free(HICN handle) 6704 void API dw_icon_free(HICN handle)
6694 { 6705 {
6695 NSImage *image = handle; 6706 NSImage *image = handle;
6707 DW_LOCAL_POOL_IN;
6696 [image release]; 6708 [image release];
6709 DW_LOCAL_POOL_OUT;
6697 } 6710 }
6698 6711
6699 /* 6712 /*
6700 * Create a new MDI Frame to be packed. 6713 * Create a new MDI Frame to be packed.
6701 * Parameters: 6714 * Parameters:
7095 { 7108 {
7096 NSFont *font = _dw_font_by_name(fontname); 7109 NSFont *font = _dw_font_by_name(fontname);
7097 7110
7098 if(font) 7111 if(font)
7099 { 7112 {
7113 DW_LOCAL_POOL_IN;
7100 NSFont *oldfont = pixmap->font; 7114 NSFont *oldfont = pixmap->font;
7101 [font retain]; 7115 [font retain];
7102 pixmap->font = font; 7116 pixmap->font = font;
7103 if(oldfont) 7117 if(oldfont)
7104 [oldfont release]; 7118 [oldfont release];
7119 DW_LOCAL_POOL_OUT;
7105 return DW_ERROR_NONE; 7120 return DW_ERROR_NONE;
7106 } 7121 }
7107 } 7122 }
7108 return DW_ERROR_GENERAL; 7123 return DW_ERROR_GENERAL;
7109 } 7124 }
7118 { 7133 {
7119 if(pixmap) 7134 if(pixmap)
7120 { 7135 {
7121 NSBitmapImageRep *image = (NSBitmapImageRep *)pixmap->image; 7136 NSBitmapImageRep *image = (NSBitmapImageRep *)pixmap->image;
7122 NSFont *font = pixmap->font; 7137 NSFont *font = pixmap->font;
7138 DW_LOCAL_POOL_IN;
7123 [image release]; 7139 [image release];
7124 [font release]; 7140 [font release];
7125 free(pixmap); 7141 free(pixmap);
7142 DW_LOCAL_POOL_OUT;
7126 } 7143 }
7127 } 7144 }
7128 7145
7129 /* 7146 /*
7130 * Copies from one item to another. 7147 * Copies from one item to another.
7235 void dw_calendar_set_date(HWND handle, unsigned int year, unsigned int month, unsigned int day) 7252 void dw_calendar_set_date(HWND handle, unsigned int year, unsigned int month, unsigned int day)
7236 { 7253 {
7237 DWCalendar *calendar = handle; 7254 DWCalendar *calendar = handle;
7238 NSDate *date; 7255 NSDate *date;
7239 char buffer[101]; 7256 char buffer[101];
7257 DW_LOCAL_POOL_IN;
7240 7258
7241 snprintf(buffer, 100, "%04d-%02d-%02d 00:00:00 +0600", year, month, day); 7259 snprintf(buffer, 100, "%04d-%02d-%02d 00:00:00 +0600", year, month, day);
7242 7260
7243 date = [[NSDate alloc] initWithString:[ NSString stringWithUTF8String:buffer ]]; 7261 date = [[NSDate alloc] initWithString:[ NSString stringWithUTF8String:buffer ]];
7244 [calendar setDateValue:date]; 7262 [calendar setDateValue:date];
7245 [date release]; 7263 [date release];
7264 DW_LOCAL_POOL_OUT;
7246 } 7265 }
7247 7266
7248 /* 7267 /*
7249 * Gets the position of a splitbar (pecentage). 7268 * Gets the position of a splitbar (pecentage).
7250 * Parameters: 7269 * Parameters:
7251 * handle: The handle to the splitbar returned by dw_splitbar_new(). 7270 * handle: The handle to the splitbar returned by dw_splitbar_new().
7252 */ 7271 */
7253 void dw_calendar_get_date(HWND handle, unsigned int *year, unsigned int *month, unsigned int *day) 7272 void dw_calendar_get_date(HWND handle, unsigned int *year, unsigned int *month, unsigned int *day)
7254 { 7273 {
7255 DWCalendar *calendar = handle; 7274 DWCalendar *calendar = handle;
7275 DW_LOCAL_POOL_IN;
7256 NSDate *date = [calendar dateValue]; 7276 NSDate *date = [calendar dateValue];
7257 NSDateFormatter *df = [[NSDateFormatter alloc] init]; 7277 NSDateFormatter *df = [[NSDateFormatter alloc] init];
7258 [df setDateStyle:NSDateFormatterShortStyle]; 7278 [df setDateStyle:NSDateFormatterShortStyle];
7259 NSString *nstr = [df stringFromDate:date]; 7279 NSString *nstr = [df stringFromDate:date];
7260 sscanf([ nstr UTF8String ], "%d/%d/%d", month, day, year); 7280 sscanf([ nstr UTF8String ], "%d/%d/%d", month, day, year);
7265 else if(*year < 100) 7285 else if(*year < 100)
7266 { 7286 {
7267 *year += 1900; 7287 *year += 1900;
7268 } 7288 }
7269 [df release]; 7289 [df release];
7290 DW_LOCAL_POOL_OUT;
7270 } 7291 }
7271 7292
7272 /* 7293 /*
7273 * Causes the embedded HTML widget to take action. 7294 * Causes the embedded HTML widget to take action.
7274 * Parameters: 7295 * Parameters:
7414 * menu: Handle of a menu. 7435 * menu: Handle of a menu.
7415 */ 7436 */
7416 void API dw_menu_destroy(HMENUI *menu) 7437 void API dw_menu_destroy(HMENUI *menu)
7417 { 7438 {
7418 NSMenu *thismenu = *menu; 7439 NSMenu *thismenu = *menu;
7440 DW_LOCAL_POOL_IN;
7419 [thismenu release]; 7441 [thismenu release];
7442 DW_LOCAL_POOL_OUT;
7420 } 7443 }
7421 7444
7422 /* 7445 /*
7423 * Pops up a context menu at given x and y coordinates. 7446 * Pops up a context menu at given x and y coordinates.
7424 * Parameters: 7447 * Parameters:
7676 */ 7699 */
7677 void API dw_notebook_page_destroy(HWND handle, unsigned int pageid) 7700 void API dw_notebook_page_destroy(HWND handle, unsigned int pageid)
7678 { 7701 {
7679 DWNotebook *notebook = handle; 7702 DWNotebook *notebook = handle;
7680 DWNotebookPage *notepage = _notepage_from_id(notebook, pageid); 7703 DWNotebookPage *notepage = _notepage_from_id(notebook, pageid);
7704 DW_LOCAL_POOL_IN;
7681 7705
7682 if(notepage != nil) 7706 if(notepage != nil)
7683 { 7707 {
7684 [notebook removeTabViewItem:notepage]; 7708 [notebook removeTabViewItem:notepage];
7685 } 7709 }
7710 DW_LOCAL_POOL_OUT;
7686 } 7711 }
7687 7712
7688 /* 7713 /*
7689 * Queries the currently visible page ID. 7714 * Queries the currently visible page ID.
7690 * Parameters: 7715 * Parameters:
8385 * handle: The window handle to destroy. 8410 * handle: The window handle to destroy.
8386 */ 8411 */
8387 int API dw_window_destroy(HWND handle) 8412 int API dw_window_destroy(HWND handle)
8388 { 8413 {
8389 int _locked_by_me = FALSE; 8414 int _locked_by_me = FALSE;
8415 DW_LOCAL_POOL_IN;
8390 DW_MUTEX_LOCK; 8416 DW_MUTEX_LOCK;
8391 id object = handle; 8417 id object = handle;
8392 8418
8393 /* Handle destroying a top-level window */ 8419 /* Handle destroying a top-level window */
8394 if([ object isKindOfClass:[ NSWindow class ] ]) 8420 if([ object isKindOfClass:[ NSWindow class ] ])
8431 } 8457 }
8432 8458
8433 if(index == -1) 8459 if(index == -1)
8434 { 8460 {
8435 DW_MUTEX_UNLOCK; 8461 DW_MUTEX_UNLOCK;
8462 DW_LOCAL_POOL_OUT;
8436 return 0; 8463 return 0;
8437 } 8464 }
8438 8465
8439 [object removeFromSuperview]; 8466 [object removeFromSuperview];
8440 8467
8454 free(thisitem); 8481 free(thisitem);
8455 thisbox->count--; 8482 thisbox->count--;
8456 } 8483 }
8457 } 8484 }
8458 DW_MUTEX_UNLOCK; 8485 DW_MUTEX_UNLOCK;
8486 DW_LOCAL_POOL_OUT;
8459 return 0; 8487 return 0;
8460 } 8488 }
8461 8489
8462 /* 8490 /*
8463 * Gets the text used for a given window. 8491 * Gets the text used for a given window.
10549 UInt32 start, end; 10577 UInt32 start, end;
10550 10578
10551 if(!p) 10579 if(!p)
10552 return result; 10580 return result;
10553 10581
10582 DW_LOCAL_POOL_IN;
10583
10554 /* Figure out the printer/paper size */ 10584 /* Figure out the printer/paper size */
10555 pi = p->pi; 10585 pi = p->pi;
10556 size = [pi paperSize]; 10586 size = [pi paperSize];
10557 10587
10558 /* Get the page range */ 10588 /* Get the page range */
10619 [flipped release]; 10649 [flipped release];
10620 dw_pixmap_destroy(pixmap); 10650 dw_pixmap_destroy(pixmap);
10621 dw_pixmap_destroy(pixmap2); 10651 dw_pixmap_destroy(pixmap2);
10622 free(p); 10652 free(p);
10623 [iv release]; 10653 [iv release];
10654 DW_LOCAL_POOL_OUT;
10624 return result; 10655 return result;
10625 } 10656 }
10626 10657
10627 /* 10658 /*
10628 * Cancels the print job, typically called from a draw page callback. 10659 * Cancels the print job, typically called from a draw page callback.