On Sat, Nov 5, 2022 at 5:10 PM R. Diez <rdiezmail-open...@yahoo.de> wrote: > > Hi all: > > In file src/helper/command.h , "struct command", there are these 2 members: > > command_handler_t handler; > Jim_CmdProc *jim_handler; > > OpenOCD commands seem to use the one or the other. What is the difference? If > one preferable?
Hi, thanks for asking it; it gives me the opportunity to post something more. .jim_handler are commands written in the native way of JimTCL code. .handler are OpenOCD commands, where OpenOCD adds the needed wrapper to run them in JimTCL They are equivalent and sometimes writing a simple command looks even easier in JIM's way than in OpenOCD way, but: - to write JIM commands you need to understand how to handle JIM object, which is not always trivial; - JIM objects are sometimes freed automatically, sometimes have to be freed with a specific function call; - JIM functions return JIM_OK or JIM_ERR, and we are getting mad with some case where these values are incorrectly mixed with ERROR_OK and the other OpenOCD ERROR_xxx codes; It's already some time that I'm thinking about this and I end up counting them to have a better view. We have today, in OpenOCD, 687 .handler vs only 98 .jim_handler. After v0.12.0 I will drop nds32 and, with it, 14 .jim_handler will be gone! So only 84 remain! I'm really considering converting all the JIM commands to OpenOCD commands and dropping this ambiguity completely. This would solve the point above, plus it should decrease a little the total size of OpenOCD, not only reducing the size of the struct command but also removing some code (with related complexity) to support this dual way. Another worm in my head asks me to go further and encapsulate in a single file all the code that depends on JimTCL, to better control it and not expose it to every user, again for the point mentioned above. Said that, while I would prefer seeing new commands as handler, for the time being I will not stop anyone from adding jim_handler commands. Regards, Antonio