mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 09:04:13 +00:00
Merge pull request #213 from madsmtm/patch-1
Fix `NSData` `initWithBytesNoCopy:length:deallocator:`
This commit is contained in:
commit
f958c37c15
2 changed files with 6 additions and 0 deletions
|
@ -3548,6 +3548,8 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
|
|||
}
|
||||
|
||||
GSClassSwizzle(self, dataBlock);
|
||||
bytes = buf;
|
||||
length = len;
|
||||
ASSIGN(deallocator, (id)deallocBlock);
|
||||
return self;
|
||||
}
|
||||
|
|
|
@ -89,6 +89,8 @@ int main()
|
|||
deallocator: ^(void* bytes, NSUInteger length) {
|
||||
called++;
|
||||
}];
|
||||
PASS([immutable length] == 4, "Length set");
|
||||
PASS([immutable bytes] == stackBuf, "Bytes set");
|
||||
PASS_RUNS([immutable release]; immutable = nil;,
|
||||
"No free() error with custom deallocator");
|
||||
PASS(called == 1, "Deallocator block called");
|
||||
|
@ -102,6 +104,8 @@ int main()
|
|||
called++;
|
||||
}
|
||||
];
|
||||
PASS([mutable length] == 4, "Length set");
|
||||
PASS([mutable bytes] == buf, "Bytes set");
|
||||
PASS_RUNS([mutable release]; mutable = nil;,
|
||||
"No free() error with custom deallocator on mutable data");
|
||||
PASS(called == 2, "Deallocator block called on -dealloc of mutable data");
|
||||
|
|
Loading…
Reference in a new issue