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 starting newline in demangled func name #3502

Merged
merged 3 commits into from
Oct 6, 2023

Conversation

ItsDrike
Copy link
Contributor

@ItsDrike ItsDrike commented Oct 5, 2023

Describe your PR, what does it fix/add?

When searching for a Hyprland fucntion with findFunctionsByName, the returned vector of matches contain demangled names, which always seem to be prefixed with a newline.

static const auto CREATE_GROUP_METHODS = HyprlandAPI::findFunctionsByName(PHANDLE, "createGroup");
for (auto& method : CREATE_GROUP_METHODS) {
    if (method.demangled == "\nCWindow::createGroup()") {
        g_pOriginalCreateGroup = (voidFunctionT)method.address;
    }
}

Notice the if (method.demangled == "\nCWindow::createGroup()") . There's no reason this should be the case, the newline character shouldn't be there. (tested with "createGroup", "destroyGroup", "getNodeFromWindow" fucntions).


From what I understand, this was caused by this lambda function:

auto demangledFromID = [&](size_t id) -> std::string {
size_t pos = 0;
size_t count = 0;
while (count < id) {
pos++;
pos = SYMBOLSDEMANGLED.find('\n', pos);
if (pos == std::string::npos)
return "";
count++;
}
return SYMBOLSDEMANGLED.substr(pos, SYMBOLSDEMANGLED.find('\n', pos + 1) - pos);
};

Which is supposed to return the contents of nth line, by finding positions of \n characters, returning a substring from that pos to next newline.

However the pos variable was set to the position of last newline, so it's included too. Instead, it should probably just be pos + 1 to skip that newline char.

Is there anything you want to mention? (unchecked code, possible bugs, found problems, breaking compatibility, etc.)

No

Is it ready for merging, or does it need work?

Ready to be merged.

src/plugins/PluginAPI.cpp Outdated Show resolved Hide resolved
src/plugins/PluginAPI.cpp Outdated Show resolved Hide resolved
Copy link
Member

@vaxerski vaxerski left a comment

Choose a reason for hiding this comment

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

lgtm

@vaxerski vaxerski merged commit 1afb00a into hyprwm:main Oct 6, 2023
@ItsDrike ItsDrike deleted the remove-demangled-newline branch October 6, 2023 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants