implement [NSMutableData+dataWithBytesNoCopy:length:freeWhenDone:]

This commit is contained in:
Richard Frith-Macdonald 2019-08-06 16:05:19 +01:00
parent 4a4da681dc
commit dce6a5a86a
2 changed files with 20 additions and 2 deletions

View file

@ -1,3 +1,8 @@
2019-08-06 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSData.m: Implement
[NSMutableData+dataWithBytesNoCopy:length:freeWhenDone]
2019-07-28 Fred Kiefer <fredkiefer@gmx.de>
* Source/NSByteCountFormatter.m: Fix to work in non fragile settings.

View file

@ -2178,6 +2178,19 @@ failure:
return AUTORELEASE(d);
}
+ (id) dataWithBytesNoCopy: (void*)aBuffer
length: (NSUInteger)bufferSize
freeWhenDone: (BOOL)shouldFree
{
NSData *d;
d = [mutableDataMalloc allocWithZone: NSDefaultMallocZone()];
d = [d initWithBytesNoCopy: aBuffer
length: bufferSize
freeWhenDone: shouldFree];
return AUTORELEASE(d);
}
/**
* New instance with buffer of given numBytes with length of valid data set
* to zero. Note that capacity will be automatically increased as necessary.
@ -3703,8 +3716,8 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
{
if (bufferSize > 0)
{
[NSException raise: NSInvalidArgumentException
format: @"[%@-initWithBytesNoCopy:length:freeWhenDone:] called with "
[NSException raise: NSInvalidArgumentException format:
@"[%@-initWithBytesNoCopy:length:freeWhenDone:] called with "
@"length but null bytes", NSStringFromClass([self class])];
}
self = [self initWithCapacity: bufferSize];