dstep icon indicating copy to clipboard operation
dstep copied to clipboard

Clang blocks are incorrectly translated to function pointers

Open jacob-carlborg opened this issue 6 years ago • 6 comments

The following code with Clang blocks [1]:

void(^CXCursorVisitorBlock)(void);

Is translated to:

extern (C):

extern __gshared void function () CXCursorVisitorBlock;

Which is not correct since D doesn't support Clang blocks. Either this should be treated as any other code that DStep cannot translate or it needs to be translated to something like this:

https://github.com/dlang/druntime/pull/1582/files#diff-28995e23585af2d8309ff0d8cdc6228c

[1] https://clang.llvm.org/docs/BlockLanguageSpec.html

jacob-carlborg avatar Jul 03 '17 15:07 jacob-carlborg

How does any other code that DStep cannot translate is treated? Can't we just ignore the blocks?

ciechowoj avatar Aug 26 '17 20:08 ciechowoj

How does any other code that DStep cannot translate is treated?

Either it's skipped or in some cases <unimplemented> is outputted.

Can't we just ignore the blocks?

Yes. Eventually we could translate them. See [1] for how to interface with blocks.

[1] https://github.com/dlang/druntime/pull/1582

jacob-carlborg avatar Aug 26 '17 21:08 jacob-carlborg

We would need to include the file with the structure representing the block along with the output files...

ciechowoj avatar Aug 26 '17 21:08 ciechowoj

Yeah, I haven't figure out yet the best way to deal with that.

jacob-carlborg avatar Aug 26 '17 21:08 jacob-carlborg

I think we could emit additional file with name something like dstep.d and import it from the translated one, in dstep.d there would be required code.

Another idea is to generate separate Block structure with unique name for every file that contains blocks...

ciechowoj avatar Aug 26 '17 22:08 ciechowoj

Another idea is to generate separate Block structure with unique name for every file that contains blocks...

Not sure if that would work. The user need to create a block and pass it to the the function. It also need to be easy to work with blocks from separate bindings.

jacob-carlborg avatar Aug 28 '17 12:08 jacob-carlborg