I've been looking into this and while I'm not sure what the problem is, I am going to rewrite part of the code to use some relevant run-time functions which became available in Lion. These functions allow for the graceful creation of blocks from functions and I hope will eliminate the iOS problem.
More to come,
Philip
On Jan 11, 2012, at 10:50 AM, ksjogo wrote:
> iOS has some cBlock issue at the moment too: http://groups.google.com/group/programming-nu/browse_thread/thread/b819d3e56cef2949
>
> ---
> Reply to this email directly or view it on GitHub:
> https://github.com/timburks/nu/issues/31#issuecomment-3449515
Making NuBlock a subclass of a obj-c block class (presumably NSMallocBlock) sounds a little hairy. Is that what MacRuby does?. Alternately, when Nu finds that the user is passing an object to a method expecting a block, it could see if the object implements a method (say -cBlock) and, if so, call that method and pass the return value instead of the original object.
Along with this, the (do ...) syntax could be extended to allow the user to input type information. If information is not included for any argument, id can be assumed, similar to declaring instance and class methods in nu. This info would then be used if the NuBlock were passed to a method expecting an obj-c block. That would avoid the complexity of using BridgeSupport while eliminating the separate cblock macro. To my mind, that seems the best solution.
Does MacRuby allow objc-blocks to be used as Ruby blocks? I don't see a lot of utility in this, though perhaps it could be useful. Are there any Cocoa or GCD methods that return objc-blocks?
-Philip
On Jan 11, 2012, at 11:41 AM, Sorin Ionescu wrote:
> Objective-C blocks are implemented through NSGlobalBlock, NSStackBlock, and NSMallocBlock. So why not have NuBlock extend the Objective-C block classes? Instead of bridging, you can just downcast and upcast between a NuBlock and an Objective-C block automatically.
>
> ---
> Reply to this email directly or view it on GitHub:
> https://github.com/timburks/nu/issues/31#issuecomment-3450354
Thanks,
Philip
On Feb 20, 2012, at 4:42 AM, jogo wrote:
> The automatic conversion with type info in do sounds great.
> Any success with the lion apis?
>
> --
> You received this message because you are subscribed to the Google Groups "Programming Nu" group.
> To post to this group, send email to program...@googlegroups.com.
> To unsubscribe from this group, send email to programming-n...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/programming-nu?hl=en.
>
Closure AllocationIt looks like Nu is using the old style, perhaps the closure allocation from libffi would help.
libffi
has changed how it deals with closures over time. Originally, closures had to be allocated by the calling code. This chunk of memory was then passed tolibffi
which did its thing. Afterwards, the client had to mark that code as executable. The version oflibffi
which ships with Mac OS X works this way. Newer versions oflibffi
encapsulate all of this in calls to allocate, prepare, and deallocate closures. This is what you'll get if you buildlibffi
from source, and it's what you can get on iOS.
Interesting post too:Due to iOS not supporting the creation of executable data, standard libffi closures don't work there. Landon Fuller has developed a fork of libffi that uses some crazy dirty tricks to work around this, and MABlockClosure works with this fork. This requires building a custom libffi, but iOS doesn't even offer libffi anyway, so this would be required either way.
Note that libffi closures on iOS are highly experimental and you should tread with caution. They have worked well in limited testing so far, but be prepared for trouble.
--
You received this message because you are subscribed to the Google Groups "Programming Nu" group.
To view this discussion on the web visit https://groups.google.com/d/msg/programming-nu/-/hlO_1PXRN7sJ.
git clone https://github.com/atgreen/libffi.git libffi
cd libffi
chmod +x generate-ios-source-and-headers.py
./generate-ios-source-and-headers.py
import the .xcodeproj into a iOS window template project with Nu.hm added
add a header search path for libffi/ios/includeIt will compile fine for iOS and Simulator.
void* funcPtr;
ffi_closure* closure = ffi_closure_alloc(sizeof(ffi_closure), &funcPtr);
ffi_prep_closure_loc(closure, cif, objc_calling_nu_block_handler, userdata, funcPtr);
return funcPtr;