http://llvm.org/bugs/show_bug.cgi?id=19321

            Bug ID: 19321
           Summary: __attribute__((cleanup)) does not respect __block
                    qualifier
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]
    Classification: Unclassified

The following simple test program:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <Block.h>

typedef int (^block_t)(void);

static void freestr(char **s)
{
    if (s)
    {
        printf("Freeing block: %s\n", *s);
        free(*s);
        *s = 0;
    }
}

block_t getCounter(char *name)
{
    __attribute__((cleanup(freestr)))
    __block char *n = strdup(name);
    __block int c=0;
    return Block_copy(^()
    {
        printf("%s called %d times\n", n, ++c);
        return c;
    });
}

int main(void)
{
    block_t counter = getCounter("A counter");
    counter();
    counter();
    counter();
    counter();
    Block_release(counter);
    return 0;
}

When run, produces:

Freeing block: A counter
(null) called 1 times
(null) called 2 times
(null) called 3 times
(null) called 4 times

The lifetime of the bound variable is the lifetime of the block, but the
cleanup code runs sooner.  The analogous C++ example (an object with a
destructor) runs correctly.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to