Work on copy of command to avoid side effect from tokenization#23
Work on copy of command to avoid side effect from tokenization#23tobiasfrejo wants to merge 4 commits intospaceinventor:masterfrom
Conversation
kivkiv12345
left a comment
There was a problem hiding this comment.
Good catch!
Before merging however, I'm wondering if we should introduce a verbose argument to control the new "executing" printf.
I don't now much about how this function will be used, but I imagine that the print may become tedious.
On that thought, I should mention that this function is quite divisive. I defend its inclusion, but I can't promise it will stick around.
Another thing, PyCSH has the CLEANUP_FREE macro (from "utils.h"), which I prefer to use for pointers that should be freed when they fall out of scope.
It's not too important on cmd_cpy here, since there aren't any guard clauses where we can forget to free it.
0dfeebc to
2984894
Compare
|
You are right about the printf potentially being tedious. That was just used for debugging, so I have simply removed it now, and also added the CLEANUP_FREE for good measure. As a defense for keeping the function, I see it as a way to call CSH commands that has not been implemented as Python functions, which we might use in DISCO for automating calls to our own libraries and not having to implement them in Python as well. |
|
To my dismay, GCC is overly strict about the types of cleanup routines. So using CLEANUP_FREE instead of CLEANUP_STR to free a char* will issue a warning, even though they both call free(). |
Due to tokenization of the parsed command in
slash_execute, the string gets mutated on execution.Example:
prints
b'node\x0012'instead of the expectedb'node 12'This is resolved here by copying the command string before it is passed to the
slash_executeC function.