Block_copy and friends

Hello,

I am using clang on linux to compile some code I wrote which uses blocks. Whenever I invoke the Block_copy() function, however, I get warnings because (presumably) there is no prototype and so a default return type of int is assumed:

llvm/Release/bin/clang -fblocks -O3 -c -o bin/interval.o Intervals/interval.c
Intervals/interval.c:446:37: warning: incompatible integer to pointer conversion passing 'int',
      expected 'void *'
                        interval_task_t startTask = task(Block_copy(blk), TASK_COPIED_BLOCK_TAG);
                                                         ^~~~~~~~~~~~~~~
1 diagnostic generated.

On the Mac, I #include <Block.h> to make such warnings go away (or use Objective-C and fire a copy message). However, that header file doesn't seem to be included in the clang sources anywhere. How can I make this work?

I apologize if this is the wrong list for this question, but it seemed the most appropriate from what I saw on the web page. I looked around on google for references to Block_copy(), but didn't find much.

The code in question is publicly available at <http://github.com/nikomatsakiseth/eth-intervals-c >, if needed.

Thanks!

Niko

Niko Matsakis wrote:

On the Mac, I #include <Block.h> to make such warnings go away (or use Objective-C and fire a copy message). However, that header file doesn't seem to be included in the clang sources anywhere. How can I make this work?
  

I believe the runtime for blocks is in LLVM's compiler-rt subproject.

http://compiler-rt.llvm.org/

Sebastian

You can eliminate the warning on Linux by including the declarations yourself:

void *_Block_copy(const void *aBlock);
void _Block_release(const void *aBlock);

But you need the block's runtime library on linux which I don't think it is available yet.

- Fariborz

Yes, it's available as part of the compiler-rt LLVM top-level project

I don't know if LLVM's blocks runtime works on non-Darwin platforms yet, but the Étoilé ObjectiveC2 framework[1] and the GNUstep Objective-C runtime[1] both include support for blocks (based on the same code. The Étoilé framework provides most of the features that are missing from the GCC Objective-C runtime as an optional framework). We've been using blocks with this code on Linux, FreeBSD, and Solaris since May.

You can build these with GNUstep Make, or just copy the (MIT licensed) blocks.* files into your project.

David

[1] svn://svn.gna.org/svn/etoile/trunk/Etoile/Frameworks/ObjectiveC2
[2] svn://svn.gna.org/svn/gnustep/libs/libobjc2/trunk

-- Sent from my Apple II

I don't know if LLVM's blocks runtime works on non-Darwin platforms yet, but the Étoilé ObjectiveC2 framework[1] and the GNUstep Objective-C runtime[1] both include support for blocks (based on the same code. The Étoilé framework provides most of the features that are missing from the GCC Objective-C runtime as an optional framework). We've been using blocks with this code on Linux, FreeBSD, and Solaris since May.

You can build these with GNUstep Make, or just copy the (MIT licensed) blocks.* files into your project.

David

[1] svn://svn.gna.org/svn/etoile/trunk/Etoile/Frameworks/ObjectiveC2
[2] svn://svn.gna.org/svn/gnustep/libs/libobjc2/trunk

-- Sent from my Apple II

Great, thanks to all for the valuable advice!

Niko