set 'free' flag for inline strings and comment it

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@22969 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2006-05-22 10:09:34 +00:00
parent d531b5e572
commit 599ebcbe16
2 changed files with 23 additions and 19 deletions

View file

@ -1,9 +1,12 @@
2006-05-22 Richard Frith-Macdonald <rfm@gnu.org> 2006-05-22 Richard Frith-Macdonald <rfm@gnu.org>
Fix longstanding NSSerialiser deserialisation problem ... is not * Source/NSSerializer.m: Fix longstanding deserialisation problem ...
retaining cross-referenced items... which is not a problem unless is not retaining cross-referenced items... which is not a problem unless
the item happens to be a dictionary key which is copied/released the item happens to be a dictionary key which is copied/released
when the corresponding value is added to the dictionary. when the corresponding value is added to the dictionary.
* Source/GSString.m: Make sure inline strings have 'free' flag set and
add comments to say we use it to indicate ownership of buffer rather
than whether to free the data. Maybe we should change the flag name?
2006-05-20 Richard Frith-Macdonald <rfm@gnu.org> 2006-05-20 Richard Frith-Macdonald <rfm@gnu.org>

View file

@ -29,7 +29,8 @@
You should have received a copy of the GNU Library General Public You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA. Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02111 USA.
*/ */
#include "config.h" #include "config.h"
@ -572,7 +573,7 @@ fixBOM(unsigned char **bytes, unsigned *length, BOOL *shouldFree,
me->_contents.c = (unsigned char*)&((GSCInlineString*)me)[1]; me->_contents.c = (unsigned char*)&((GSCInlineString*)me)[1];
me->_count = length; me->_count = length;
me->_flags.wide = 0; me->_flags.wide = 0;
me->_flags.free = 0; me->_flags.free = 1; // Ignored on dealloc, but means we own buffer
while (length-- > 0) while (length-- > 0)
{ {
me->_contents.c[length] = ((unichar*)chars)[length]; me->_contents.c[length] = ((unichar*)chars)[length];
@ -687,7 +688,7 @@ fixBOM(unsigned char **bytes, unsigned *length, BOOL *shouldFree,
me->_contents.u = (unichar*)&((GSUnicodeInlineString*)me)[1]; me->_contents.u = (unichar*)&((GSUnicodeInlineString*)me)[1];
me->_count = f._count; me->_count = f._count;
me->_flags.wide = 1; me->_flags.wide = 1;
me->_flags.free = 1; me->_flags.free = 1; // Ignored on dealloc, but means we own buffer
memcpy(me->_contents.u, f._contents.u, f._count*sizeof(unichar)); memcpy(me->_contents.u, f._contents.u, f._count*sizeof(unichar));
} }
else else
@ -697,7 +698,7 @@ fixBOM(unsigned char **bytes, unsigned *length, BOOL *shouldFree,
me->_contents.c = (unsigned char*)&((GSCInlineString*)me)[1]; me->_contents.c = (unsigned char*)&((GSCInlineString*)me)[1];
me->_count = f._count; me->_count = f._count;
me->_flags.wide = 0; me->_flags.wide = 0;
me->_flags.free = 1; me->_flags.free = 1; // Ignored on dealloc, but means we own buffer
memcpy(me->_contents.c, f._contents.c, f._count); memcpy(me->_contents.c, f._contents.c, f._count);
} }
@ -744,7 +745,7 @@ fixBOM(unsigned char **bytes, unsigned *length, BOOL *shouldFree,
me->_contents.c = (unsigned char*)&((GSCInlineString*)me)[1]; me->_contents.c = (unsigned char*)&((GSCInlineString*)me)[1];
me->_count = length; me->_count = length;
me->_flags.wide = 0; me->_flags.wide = 0;
me->_flags.free = 1; me->_flags.free = 1; // Ignored on dealloc, but means we own buffer
memcpy(me->_contents.c, ((GSStr)string)->_contents.c, length); memcpy(me->_contents.c, ((GSStr)string)->_contents.c, length);
} }
else if (GSObjCIsKindOf(c, GSUnicodeStringClass) == YES else if (GSObjCIsKindOf(c, GSUnicodeStringClass) == YES
@ -759,7 +760,7 @@ fixBOM(unsigned char **bytes, unsigned *length, BOOL *shouldFree,
me->_contents.u = (unichar*)&((GSUnicodeInlineString*)me)[1]; me->_contents.u = (unichar*)&((GSUnicodeInlineString*)me)[1];
me->_count = length; me->_count = length;
me->_flags.wide = 1; me->_flags.wide = 1;
me->_flags.free = 1; me->_flags.free = 1; // Ignored on dealloc, but means we own buffer
memcpy(me->_contents.u, ((GSStr)string)->_contents.u, memcpy(me->_contents.u, ((GSStr)string)->_contents.u,
length*sizeof(unichar)); length*sizeof(unichar));
} }
@ -774,7 +775,7 @@ fixBOM(unsigned char **bytes, unsigned *length, BOOL *shouldFree,
me->_contents.u = (unichar*)&((GSUnicodeInlineString*)me)[1]; me->_contents.u = (unichar*)&((GSUnicodeInlineString*)me)[1];
me->_count = length; me->_count = length;
me->_flags.wide = 1; me->_flags.wide = 1;
me->_flags.free = 1; me->_flags.free = 1; // Ignored on dealloc, but means we own buffer
[string getCharacters: me->_contents.u]; [string getCharacters: me->_contents.u];
} }
return (id)me; return (id)me;
@ -2920,7 +2921,7 @@ agree, create a new GSCInlineString otherwise.
o->_count = _count; o->_count = _count;
memcpy(o->_contents.c, _contents.c, _count); memcpy(o->_contents.c, _contents.c, _count);
o->_flags.wide = 0; o->_flags.wide = 0;
o->_flags.free = 0; o->_flags.free = 1; // Ignored on dealloc, but means we own buffer
return (id)o; return (id)o;
} }
else else
@ -2972,7 +2973,7 @@ agree, create a new GSCInlineString otherwise.
o->_count = _count; o->_count = _count;
memcpy(o->_contents.c, _contents.c, _count); memcpy(o->_contents.c, _contents.c, _count);
o->_flags.wide = 0; o->_flags.wide = 0;
o->_flags.free = 0; o->_flags.free = 1; // Ignored on dealloc, but means we own buffer
return (id)o; return (id)o;
} }
@ -3231,7 +3232,7 @@ agree, create a new GSUnicodeInlineString otherwise.
o->_count = _count; o->_count = _count;
memcpy(o->_contents.u, _contents.u, _count * sizeof(unichar)); memcpy(o->_contents.u, _contents.u, _count * sizeof(unichar));
o->_flags.wide = 1; o->_flags.wide = 1;
o->_flags.free = 0; o->_flags.free = 1; // Ignored on dealloc, but means we own buffer
return (id)o; return (id)o;
} }
else else
@ -3284,7 +3285,7 @@ agree, create a new GSUnicodeInlineString otherwise.
o->_count = _count; o->_count = _count;
memcpy(o->_contents.u, _contents.u, _count * sizeof(unichar)); memcpy(o->_contents.u, _contents.u, _count * sizeof(unichar));
o->_flags.wide = 1; o->_flags.wide = 1;
o->_flags.free = 0; o->_flags.free = 1; // Ignored on dealloc, but means we own buffer
return (id)o; return (id)o;
} }
@ -3403,7 +3404,7 @@ agree, create a new GSUnicodeInlineString otherwise.
o->_count = _count; o->_count = _count;
memcpy(o->_contents.u, _contents.u, _count * sizeof(unichar)); memcpy(o->_contents.u, _contents.u, _count * sizeof(unichar));
o->_flags.wide = 1; o->_flags.wide = 1;
o->_flags.free = 0; o->_flags.free = 1; // Ignored on dealloc, but means we own buffer
return (id)o; return (id)o;
} }
else else
@ -3417,7 +3418,7 @@ agree, create a new GSUnicodeInlineString otherwise.
o->_count = _count; o->_count = _count;
memcpy(o->_contents.c, _contents.c, _count); memcpy(o->_contents.c, _contents.c, _count);
o->_flags.wide = 0; o->_flags.wide = 0;
o->_flags.free = 0; o->_flags.free = 1; // Ignored on dealloc, but means we own buffer
return (id)o; return (id)o;
} }
} }
@ -4139,7 +4140,7 @@ agree, create a new GSUnicodeInlineString otherwise.
memcpy(o->_contents.u, _contents.u + aRange.location, memcpy(o->_contents.u, _contents.u + aRange.location,
aRange.length * sizeof(unichar)); aRange.length * sizeof(unichar));
o->_flags.wide = 1; o->_flags.wide = 1;
o->_flags.free = 0; o->_flags.free = 1; // Ignored on dealloc, but means we own buffer
return AUTORELEASE((id)o); return AUTORELEASE((id)o);
} }
else else
@ -4154,7 +4155,7 @@ agree, create a new GSUnicodeInlineString otherwise.
o->_count = aRange.length; o->_count = aRange.length;
memcpy(o->_contents.c, _contents.c + aRange.location, aRange.length); memcpy(o->_contents.c, _contents.c + aRange.location, aRange.length);
o->_flags.wide = 0; o->_flags.wide = 0;
o->_flags.free = 0; o->_flags.free = 1; // Ignored on dealloc, but means we own buffer
return AUTORELEASE((id)o); return AUTORELEASE((id)o);
} }
} }
@ -4176,7 +4177,7 @@ agree, create a new GSUnicodeInlineString otherwise.
memcpy(o->_contents.u, _contents.u + aRange.location, memcpy(o->_contents.u, _contents.u + aRange.location,
aRange.length * sizeof(unichar)); aRange.length * sizeof(unichar));
o->_flags.wide = 1; o->_flags.wide = 1;
o->_flags.free = 0; o->_flags.free = 1; // Ignored on dealloc, but means we own buffer
return AUTORELEASE((id)o); return AUTORELEASE((id)o);
} }
else else
@ -4191,7 +4192,7 @@ agree, create a new GSUnicodeInlineString otherwise.
o->_count = aRange.length; o->_count = aRange.length;
memcpy(o->_contents.c, _contents.c + aRange.location, aRange.length); memcpy(o->_contents.c, _contents.c + aRange.location, aRange.length);
o->_flags.wide = 0; o->_flags.wide = 0;
o->_flags.free = 0; o->_flags.free = 1; // Ignored on dealloc, but means we own buffer
return AUTORELEASE((id)o); return AUTORELEASE((id)o);
} }
} }