Merge pull request #213 from madsmtm/patch-1

Fix `NSData` `initWithBytesNoCopy:length:deallocator:`
This commit is contained in:
Fred Kiefer 2021-10-29 12:00:08 +02:00 committed by GitHub
commit f958c37c15
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 0 deletions

View file

@ -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;
}

View file

@ -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");