[Rubycocoa-devel 564] Re: rubycocoa 0.9 questions and confusions

Back to archive index

Laurent Sansonetti lsans****@apple*****
Fri Jan 5 08:53:25 JST 2007


Hi Jean-Pierre :)

On Jan 5, 2007, at 12:13 AM, jeanp****@gmail***** wrote:

> hi hi -
>
> continuing on from my earlier investigations posted to the rubycocoa- 
> talk list, i installed rubycocoa 0.9 from source and gave it a  
> whirl. i've run into a few oddities that i thought i'd ask about.
>
> [1] for some reason, i can't seem to compile objC code into a bundle  
> and require it in ruby *unless* i name the bundle client.bundle. i  
> have attached a little sample project, if you run rake it'll build  
> 'client.bundle ' from the provided source and if you run helper.rb  
> it'll just print out a quick debug line after requiring the built  
> bundle. strangely enough, if i name the bundle something other than  
> 'client.bundle' and require it in helper.rb, it gives me a load  
> error on the require:
>
>     LoadError: Failed to lookup Init function ./schoolkid.bundle
>
> exactly the same code, just using a different bundle name...
>

In fact, all Ruby bundles should have an Init function that  
initializes the bundle (you can leave it empty if you want), that has  
the following prototype:

    void Init_XXX(void);

(where XXX is the name of the bundle).

If you do not conform to this rule you will get this LoadError  
exception :)

See the "Writing Ruby in C" chapter of the pickaxe for more details:

http://www.rubycentral.com/book/ext_ruby.html

> [2] is rubycocoa doing some sort of memory management on allocated  
> objC objects? i thought with 0.5 that if i allocated and initialized  
> an objC derived object that i'd also need to release it, but with  
> 0.9, doing so causes a segfault.
>
>   kid = OSX::SchoolKid.alloc.init
>   kid.release
>
>
> /Library/Frameworks/RubyCocoa.framework/Versions/A/Resources/ruby/ 
> osx/objc/oc_import.rb:170: [BUG] Segmentation fault
> ruby 1.8.5 (2006-08-25) [i686-darwin8.8.1]
>
> when running rubycocoa from irb and alloc/init'ing objects then  
> releasing them, i get a bus error:
> /Library/Frameworks/RubyCocoa.framework/Versions/A/Resources/ruby/ 
> osx/objc/oc_wrapper.rb:46: [BUG] Bus Error
> ruby 1.8.5 (2006-08-25) [i686-darwin8.8.1]
>
> zsh: abort      irb

Oh you should never do retain/release/autorelease from RubyCocoa.  
RubyCocoa maintains the Objective-C objects for you.

However it shouldn't segfault, IIRC on the stable branch retain/ 
release/autorelease messages were simply ignored, we should do the  
same there.

> [3] should i be able to override objC methods in ruby? if i have  
> some objC class:
>   @interface SchoolKid : NSObject {
>   }
>   - (NSString *)saySomething;
>   @end
>
>   @implementation SchoolKid
>   - (NSString *)saySomething {
>       return @"sorry, I am quiet";
>   }
>   @end
>
> and try to reopen the class in ruby to override a method, nothing  
> happens:
>   class OSX::SchoolKid
>     def saySomething
>       puts "hi"
>     end
>   end
>
> but i can subclass and override:
>   class OtherKid < OSX::SchoolKid
>     def saySomething
>       puts "halllo"
>     end
>   end

Actually there is no way to override a method without subclassing. We  
might want to provide this though (it shouldn't be hard to do).

> ns_overrides seems to have disappeared, is there a proper way to do  
> this? (i'm trying to mock objC objects in ruby).

Yes, ns_overrides is no longer necessary.

> [4] is OSX.ns_import no longer required?

Yes, ns_import is also no longer necessary.

HTH :)
Laurent



More information about the Rubycocoa-devel mailing list
Back to archive index