Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning about block being passed to objective-c method incorrectly #13

Open
ferrous26 opened this issue Aug 6, 2011 · 6 comments
Open
Labels

Comments

@ferrous26
Copy link
Member

You can trigger this by resizing a window.

Need to track this down and fix it...

@ferrous26
Copy link
Member Author

Turns out this is an interesting bug.

If you get a back trace at the point of warning (replace the warning in dispatcher.cpp with an exception), then you can see the problem is that HotCocoa::LayoutView#setFrameSize is being called with a block.

If you fiddle with the block a bit you can also see that the block being passed to #setFrameSize is the block passed to the application constructor:

application name: 'App' do |app|
  puts "I'm the culprit!"
end

I'm not sure why that block is being passed to the method and so I don't know how to fix this...

ferrous26 added a commit that referenced this issue Aug 28, 2011
Not a proper fix, I'll have to get deeper into the guts of the layout manager first. I
plan to do that when I start on an auto-layout backed manager for HotCocoa.
@ferrous26
Copy link
Member Author

I've got a work around for the time being, I'll have to look into it more when I'm not tired...

@bultacorick
Copy link

Actually, I think it is a proper fix. According to PragProg Programming Ruby 1.9 :

"If no parameters (and no parentheses) are passed to super, the original method's parameters will be passed; otherwise, the parameters to super will be passed"

Of course, finding this in the source is left as an exercise for the reader.

@ferrous26
Copy link
Member Author

I think perhaps I am confusing myself on what this issue really is. Technically this bug is about getting rid of the warning, which I have done, but I also want to understand why the block was getting passed to that method in the first place and fix that as well.

@bultacorick
Copy link

I'm don't think there's a bug here.

I start by assuming the behavior of super is consistent from Ruby to
MacRuby and is correctly described in the "Programming Ruby 1.9" book (2
big assumptions on my part).

The full text is:

"Within the body of a method, a call to super acts just like a call to that
original method, except that the search for a method body starts in the
superclass of the object that was found to contain the original method. If
no parameters (an no parentheses) are passed to super, the original
methods's parameters will be passed; otherwise, the parameters to super
will be passed."

I follow that with your comment that what you see being passed to super
(when called with no parens) is the block that was passed to the
application constructor.

Is it possible the app itself is the superclass of your object?

Rick

On Fri, Dec 30, 2011 at 9:38 PM, Mark Rada <
[email protected]

wrote:

I think perhaps I am confusing myself on what this issue really is.
Technically this bug is about getting rid of the warning, which I have
done, but I also want to understand why the block was getting passed to
that method in the first place and fix that as well.


Reply to this email directly or view it on GitHub:
#13 (comment)

@ferrous26
Copy link
Member Author

Yes, MacRuby's behaviour for super should match Ruby's. However, my problem is not how the superclass is getting the block, but how HotCocoa::LayoutView#setFrameSize is getting the block in the first place.

As in my example, the specific block that is getting passed has been traced to be the block passed to the NSApplication constructor, but if you trace through the constructor (in mapper.rb), you see the block is passed to the NSApplication mappings#handle_blockmethod, and then the block will be yielded to and then that's it, it should not be called again. However, objects created in the context of that block, such as a window with buttons, are still around after the block is done being executed, so I think the block sticks around in memory not being garbage collected. In short, that block is never passed toHotCocoa::LayoutView#setFrameSize` by HotCocoa code.

HotCocoa::LayoutView#setFrameSize is called by the Cocoa runtime when the window gets resized, so where is the block being pulled from? I think this is a MacRuby bug, but I still have to investigate more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants