Unintended keybinding of a custom command

Custom command I created got assigned to a key without me specifying it. I am trying to get new functionality using the code found in goto_next_jump and goto_first_jump, so I duplicated one of them to begin the work:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
CUSTOM_COMMAND_SIG(sq_goto_next_jump)
CUSTOM_DOC("Meaningful documentation.")
{
    Heap *heap = &global_heap;
    
    Locked_Jump_State jump_state = get_locked_jump_state(app, heap);
    if (jump_state.view != 0){
        i64 cursor_position = view_get_cursor_pos(app, jump_state.view);
        Buffer_Cursor cursor = view_compute_cursor(app, jump_state.view, seek_pos(cursor_position));
        i64 line = get_line_from_list(app, jump_state.list, jump_state.list_index);
        if (line <= cursor.line){
            jump_state.list_index += 1;
        }
        goto_next_filtered_jump(app, jump_state.list, jump_state.view, jump_state.list_index, 1, true, true);
    }
}


I noticed that both my new function as well as the original goto_next_jump are bound to the same key, even though I didn't change anything apart from copying the code and changing the command signature.

Edited by Sokus on Reason: Initial post
If you use the command lister (default is Alt + x) does it list a keybinding for sq_goto_next_jump ?

Are you sure both functions are called ? Did you set a breakpoint in each to confirm it ?

Could you post the entire custom layer so we can try it out (code and/or dll + binding file ) ?
The command lister did list sq_goto_next_jump, although it surprised me it was already bound to a key.

Unfortunately I didn't step into the code, although feel free to look at the source code - sq_goto_next_jump is at the very bottom if I remember correctly (it is blocked by #if 0).
I didn't touch anything from Ryan's custom layer (apart from config.4coder, bindings.4coder and adding the include with my code).
There is also build.bat, but be careful because it overwrites the .dll in the root folder.

Edited by Sokus on Reason: Added info
What is the structure of your 4coder folder and custom code folder.

I tried to compile your code, but ran into an issue where the code compiles, but if I remove your file from the folder and compile, your functions are still listed in the command lister, but sq_goto_next_jump never shows up, which confuses me a lot because the generated metadata file seems correct. I'll try to figure it out tomorrow, but I suppose it could be another consequence of the issue you where seeing. I assume that at some point you had a bindings for sq_goto_next_jump and that there is some file that are correctly regenerated. But since I don't understand the build problem it's just a guess.
My file structure looks like this:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
4coder (root folder)
  custom
    4coder_sokus
      ryan's source/header files
      4coder_sokus.cpp
      ...
      (basically everything from my github repository)
    bin
    ...
    other folders/4coder custom layer source and header files
  4ed.exe
  ...
  other folders/config/bindings/.dll


I tried what you said - I checked whether sq_goto_next_jump is listed, deleted 4coder_sokus.cpp from the folder and commented out #include "4coder_sokus.cpp" in ryan's 4coder_fleury.cpp, recompiled and I had a different outcome - none of my sq_ functions were listed. They re-appeared when I pasted the source file back in and uncommented the include.

I don't know if my folder structure is "right", I know that I could place the 4coder_sokus folder in the root directory and run the exe with -U 4coder_sokus argument, but it had some drawbacks as well (that could probably be solved if I knew more than one argument option).
Okay, I played with it a bit more and sq_goto_next_jump works just as the original, I created a jump list and used it from the Command Lister and it moved me. Not sure how bindings work, but when I press the shortcut I am not getting moved twice.

Another thing I did is I looked into build.bat and deleted the release argument and to my surprise the issue no longer occurrs (sq_goto_next_jump is not getting bound to a key). Maybe it has something to do with optimisation? Those functions look exactly the same, it could be that the issue will solve itself once I modify one of them.
[offtopic] I worked around my build issue by moving the 4coder folder to a different hard drive. This issue confuses me a lot because what seemed to happen was 4coder using a deleted dll (even with no custom dll in the folder it's working somehow), and not using the new one, which doesn't make any sense to me. If anybody as an idea on how such a thing can happen I'd like to know (this is probably a Windows issue, not a 4coder issue).

EDIT: There was a custom layer dll at the root of the hard drive (from a previous build where the custom code wasn't in the correct folder) that was always loaded instead of the new dll at the correct location (which I don't believe is the default behavior of LoadLibrary).[/offtopic]

I was able to reproduce the issue. I think that it's caused by the optimizer seeing that sq_goto_next_jump and goto_next_jump contains the exact same code, and so both functions names points to the same memory address and use the same code (not a copy, the exact same bytes in memory). When I added a breakpoint to sq_goto_next_jump and stepped in it with RemedyBG, it alternated between the two functions source.

4coder probably shows a bindings to sq_goto_next_jump because is uses the function pointer to identify the entry in the list (it's a guess I didn't actually checked the code), and as both function have the same function pointer, binding one shows the bindings for both. You may want report that on the 4coder github or 4coder discord even if it's not clear if it's a bug.

Edited by Simon Anciaux on Reason: offtopic solved