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

Remove GSFakeNSMenuItem class #7

Merged

Conversation

williameveretteggplant
Copy link
Contributor

This class doesn't appear to do anything but serve as a pass-through for the original object, so why not just use that?

This class doesn't appear to do anything but serve as a pass-through for the original object, so why not just use that?
@williameveretteggplant williameveretteggplant changed the title Draft: Remove GSFakeNSMenuItem class Remove GSFakeNSMenuItem class Oct 25, 2024
@@ -151,7 +71,7 @@ void initialize_lock()
}

// find all subitems for the given items...
HMENU r_build_menu_for_itemmap(NSMenu *menu, BOOL asPopUp, BOOL fakeItem, NSMapTable *itemMap)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a great idea to rename the variable fakeItem to notPullDown (or something similar) as this value is initially set to ![cell pullsDown]in displayPopUpMenu (line 554). But I'd suggest we update the name throughout, i.e. rename the fake variable in displayPopUpMenu and any other method that may use that name?

@qmfrederik
Copy link
Contributor

Left a comment, LGTM otherwise. @rfm @fredkiefer @gcasa - any thoughts?

@fredkiefer
Copy link
Member

I am not familiar with this theme. If popup menus still work with your change, this sounds like a simplification that we should use. But @gcasa should decide.

@gcasa
Copy link
Member

gcasa commented Oct 26, 2024

I agree with @fredkiefer. Please test pop up menus. If that works then the change is acceptable

@gcasa
Copy link
Member

gcasa commented Oct 27, 2024

I am going to spin up a fresh windows install to test this. I need to do this anyway. I will report back once that is done. Thanks.

@@ -271,11 +191,15 @@ HMENU r_build_menu_for_itemmap(NSMenu *menu, BOOL asPopUp, BOOL fakeItem, NSMapT
{
flags = MF_STRING;
s = menu_tag++;
if(fakeItem)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gcasa @fredkiefer These lines were actually causing GSFakeMenuItems to replace NSMenuItems in memory leading to crashes when you clicked on a pop up.

item = [[GSFakeNSMenuItem alloc] initWithItem: item];
AUTORELEASE(item);
}
if (([item action] == NULL || [item target] == nil) && notPullDown && asPopUp)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gcasa @fredkiefer Once the GSFakeMenuItems were removed we were able to click on pop ups but they were inoperable because there was no action set on them. This change here populates the action.

@qmfrederik
Copy link
Contributor

@fredkiefer As @johnathan-becker mentioned, we are seeing crashes when invoking pop ups with the current implementation, and this PR fixes those crashes. So yes, we've tested this change.

@gcasa Is there any additional testing you would like to perform?

@gcasa
Copy link
Member

gcasa commented Oct 30, 2024

@fredkiefer As @johnathan-becker mentioned, we are seeing crashes when invoking pop ups with the current implementation, and this PR fixes those crashes. So yes, we've tested this change.

@gcasa Is there any additional testing you would like to perform?

I haven't had a chance to test this with the latest msys2. If this works for you, then that's fine. I see no issue based on looking at the code, so go ahead and merge this change.

@qmfrederik qmfrederik merged commit bd1fd5a into gnustep:master Oct 30, 2024
3 checks passed
@fredkiefer
Copy link
Member

According to Riccardo this change broke NSPopupButtons. It was either the pulldown or the popup version, I am not sure. In that case the displayed value won't be adjusted to the selected on. It would be great if you find a fix for that, or we will have to revert this change.

@qmfrederik
Copy link
Contributor

@fredkiefer We're tracking a couple of issues with NSPopupButtons which we're planning to address (so stay tuned for more PRs 😄). That said, without this PR, we were seeing crashes (at least when building on Windows with libobjc2 & clang), so this PR was not just a code cleanup issue, it also addressed crashes.

@qmfrederik
Copy link
Contributor

So, I spent some more time digging into this crash.

I believe this is crash is caused by how message forwarding works when using libobjc2 on mingw-w64. [GSFakeNSMenuItem forwardingTargetForSelector] correctly returns the underlying NSMenuItem, and from what I can see gs_objc_proxy_lookup also returns the correct value. However, by the time objc_msgSend invokes the selector on the target object (i.e. the actual NSMenuItem object instead of the initial GSFakeMenuItem object), the value of self is wrong (interestingly, from what I could see, *self actually returns the correct value).

If, in GSFFInvocation.m, in the load method, you comment out the objc_proxy_lookup = gs_objc_proxy_lookup; line, everything works as expected.

Not really sure what's going on here, but looks like there's either a bug in libobjc2 or in how libobjc2 and libs-base interact.

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

Successfully merging this pull request may close these issues.

5 participants