#include <stdio.h>
#include <Block_private.h>
int AssignCalled = 0;
int DisposeCalled = 0;
void _Block_object_assign(void *destAddr, const void *object, const int isWeak) {
AssignCalled = 1;
}
void _Block_object_dispose(const void *object, const int isWeak) {
DisposeCalled = 1;
}
struct MyStruct {
long isa;
long field;
};
typedef struct MyStruct *__attribute__((NSObject)) MyStruct_t;
int main(int argc, char *argv[]) {
struct MyStruct X;
MyStruct_t xp = (MyStruct_t)&X;
xp->field = 10;
void (^myBlock)(void) = ^{ printf("field is %ld\n", xp->field); };
struct Block_layout *bl = (struct Block_layout *)(void *)myBlock;
if ((bl->flags & BLOCK_HAS_DESCRIPTOR) != BLOCK_HAS_DESCRIPTOR) {
printf("using old runtime layout!\n");
return 1;
}
if ((bl->flags & BLOCK_HAS_COPY_DISPOSE) != BLOCK_HAS_COPY_DISPOSE) {
printf("no copy dispose!!!!\n");
return 1;
}
long destBuffer[256];
bl->descriptor->copy(destBuffer, bl);
bl->descriptor->dispose(bl);
if (AssignCalled == 0) {
printf("did not call assign helper!\n");
return 1;
}
if (DisposeCalled == 0) {
printf("did not call dispose helper\n");
return 1;
}
printf("%s: Success!\n", argv[0]);
return 0;
}