bugGNUstep - Bugs: bug #25572, NSSavePanel/NSOpenPanel return an...

Group
 
 

bug #25572: NSSavePanel/NSOpenPanel return an instance variable instead of object copy

Submitter:  Riccardo Mottola <rmottola>
Submitted:  Thu 12 Feb 2009 11:47:50 PM UTC
   
 
Category:  Gui/AppKit Severity:  3 - Normal
Item Group:  Bug Status:  Fixed
Privacy:  Public Assigned to:  None
Open/Closed:  Closed
* Mandatory Fields

Add a New Comment Rich Markup
   

Mon 16 Feb 2009 07:46:50 AM UTC, comment #2: 

Yes, the application is at fault to begin with, also it gets the singleton panel twice, which while it should be allowed, is inefficient because it resets everything, still it should be possible.

If your implementation is more efficient than mine go for it.

Riccardo Mottola <rmottola>
Group Member
Sat 14 Feb 2009 09:43:55 PM UTC, comment #1: 

GNUstep really should be doing more copying when setting or returning instance variables. This is out of question. Your specific solution may not the the most efficient one. I will probably replace
return [NSString stringWithString:_directory];
with
return AUTORELEASE([_directory copy]);

Here immutable subclasses of NSString may decide to not copy themselves and in your case a new object is created every time.

On the other hand your application is also at fault, it relies on the fact that an object returned by a method will stay around. This is never guarrantied, you always need to retain objects yourself, when you need to use them later on.

Fred Kiefer <FredKiefer>
Group Member
Thu 12 Feb 2009 11:47:50 PM UTC, original submission:  

debugging the reason of easydiff Crashing while opening the second file to compare, I traced it to a problem with [NSSavePanel directory]. That method returns just the instance variable _directory.

Since the second time the shared instance of the panel is gotten the internal variable gets ASSIGNed, the original object returned the first time gets released, and thus gets invalid.

even if this could be worked around in several ways in the applicatioin, I consider ths behaviour unexpected. I thus run the following test on the mac:

{
NSOpenPanel *panel;
NSString *dir;

panel = [NSOpenPanel openPanel];
dir = nil;
[panel runModalForDirectory: dir file:nil types:nil];
dir = [panel directory];
panel = [NSOpenPanel openPanel];
[panel runModalForDirectory: dir file:nil types:nil];
NSLog(@"dir: %@", dir);
NSLog(@"file: %@", [[panel filenames] objectAtIndex:0]);

}

and it works fine. thus I think gnustep should return an autoreleaed copy of the directory string.

Riccardo Mottola <rmottola>
Group Member

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by FredKiefer (Posted a comment)
  • -email is unavailable- added by rmottola (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2009-02-13 rmottola StatusNone Fixed
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-caa5.
    Corresponding source code