<html>
<head>
<base href="http://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - __attribute__((cleanup)) does not respect __block qualifier"
href="http://llvm.org/bugs/show_bug.cgi?id=19321">19321</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>__attribute__((cleanup)) does not respect __block qualifier
</td>
</tr>
<tr>
<th>Product</th>
<td>new-bugs
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>new bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>csdavec@swan.ac.uk
</td>
</tr>
<tr>
<th>CC</th>
<td>llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>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.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>