[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: _Block_object_assign crash
From: |
lorenb |
Subject: |
Re: _Block_object_assign crash |
Date: |
Tue, 28 Jun 2011 09:39:10 -0700 (PDT) |
After some sleep, it's clear that example was pretty dumb. I think I have a better one, that *should* work (and does on OS X), but segfaults on Linux.
OS X:
2011-06-28 12:31:09.512 a.out[17451:903] a: x = test string
2011-06-28 12:31:09.514 a.out[17451:903] b: x = test string
2011-06-28 12:31:09.514 a.out[17451:903] -1-
2011-06-28 12:31:09.515 a.out[17451:903] -2-
2011-06-28 12:31:09.516 a.out[17451:903] -3-
2011-06-28 12:31:09.516 a.out[17451:903] -4-
Linux:
2011-06-28 12:31:29.527 a.out[25272] a: x = test string
2011-06-28 12:31:29.529 a.out[25272] b: x = test string
2011-06-28 12:31:29.529 a.out[25272] -1-
2011-06-28 12:31:29.529 a.out[25272] -2-
Segmentation fault
the code below. two blocks both reference the same __block variable, which is declared inside yet another block. runs fine, but crashes on teardown. Apologies if this is the wrong place to post this - if so is there a better place?
int main(int argc, char *argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
void (^master)(VoidBlock*, VoidBlock*) = Block_copy(^(VoidBlock *a_out, VoidBlock *b_out) {
__block id x = nil;
*a_out = Block_copy(^{
x = [[NSString stringWithString:@"test string"] retain];
NSLog(@"a: x = %@", x);
});
*b_out = Block_copy(^{
NSLog(@"b: x = %@", x);
[x release];
});
});
VoidBlock a;
VoidBlock b;
master(&a, &b);
a();
b();
NSLog(@"-1-");
Block_release(a);
NSLog(@"-2-");
Block_release(b);
NSLog(@"-3-");
Block_release(master);
NSLog(@"-4-");
[pool drain];
return 0;
}
View this message in context: Re: _Block_object_assign crash
Sent from the GNUstep - Dev mailing list archive at Nabble.com.