[LLVMbugs] [Bug 19321] New: __attribute__((cleanup)) does not respect __block qualifier
    bugzilla-daemon at llvm.org 
    bugzilla-daemon at llvm.org
       
    Thu Apr  3 04:00:28 PDT 2014
    
    
  
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: unassignedbugs at nondot.org
          Reporter: csdavec at swan.ac.uk
                CC: llvmbugs at cs.uiuc.edu
    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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20140403/0c1b1329/attachment.html>
    
    
More information about the llvm-bugs
mailing list