gnustep-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: textview / test storage string copy problem


From: Fred Kiefer
Subject: Re: textview / test storage string copy problem
Date: Wed, 18 Jan 2012 22:28:28 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:9.0) Gecko/20111220 Thunderbird/9.0

On 18.01.2012 12:57, Riccardo Mottola wrote:
Hi,

On 01/18/2012 11:20 AM, Dr. H. Nikolaus Schaller wrote:
Here:

http://www.gnustep.org/resources/OpenStepSpec/ApplicationKit/Classes/NSCell.html


• - (void)setStringValue:(NSString *)aString Sets the NSCell's value
to a copy of aString.

So you should find out why it does not set the value to a copy.
Ok, maybe my patch is wrong, I can take it out. The problem could be
indeed NSCell.. I see it does:

line 335

id newContents;

ASSIGN (_object_value, object);

if (_formatter == nil)
{
if (object == nil || [object isKindOfClass: [NSString class]] == YES)
{
newContents = object;
_cell.contents_is_attributed_string = NO;
_cell.has_valid_object_value = YES;
}
<....>

ASSIGN (_contents, newContents);

I see no "copy" method here, perhaps the fix is as simple as
newContents = [NSString stringWithString: (NSString*)object)];


stringWithString should be fine if our own gnustep doc is correct:

+ (id) *stringWithString:* (NSString
<http://www.gnustep.org/resources/documentation/Developer/Base/Reference/NSString.html#class$NSString>*)aString;

*Availability:* MacOS-X 10.0.0


Create a copy of aString.

We should rather use the copy method (followed by autorelease, of course) as this will optimise away the most common case that we are dealing with a non-mutable string here . And we also should try to handle the other cases as well., not just the one where we don't have a formatter and are dealing with an NSString.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]