-
-
Notifications
You must be signed in to change notification settings - Fork 339
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 global variables from GNU z80 disassembler #4343
Conversation
librz/arch/isa_gnu/z80/expressions.c
Outdated
static void printerr(int error, const char *fmt, ...) { | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this empty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, in the original code it was also empty but there was code in its body guarded under an #if 0
preprocessor directive. I saw there was no good reason to keep maintaining that code since it's essentially comments, and I deleted it.
This function in some sense "deserves" deletion anyway because it's not following the same general approach to error reporting followed in the rest of the project, it prints directly to stderr and uses a weird va_list
type to manipulate variadic arguments. I leave it empty instead of completely removing it because other functions in expression.c
use it a lot, I plan to replace it with multiple functions or by writing to an error buffer in the state structure in a future PR. I didn't do any of this in this PR because it's already massive as it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome job.
something is wrong when you compile it. |
a6eb8e7
to
d203f7c
Compare
Yeah very sorry for that. I previously blamed it on the original code but it turns out that I did remove a few I moved the function |
if |
6a4d738
to
813ca1d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so much better.
813ca1d
to
8a642a6
Compare
Your checklist for this pull request
Detailed description
This change removes global variables from librz\arch\isa_gnu\z80. This is a fairly massive change, so sorry in advance for any reviewer, most of the diff is trivial.
The global variables that were removed were shared state that multiple functions in the file could modify, this is in essence the "OO" pattern, the functions that modified the variables were "methods" that operated on the same implicit "object". This pattern were made explicit by moving the variables into a structure, and all the functions were changed so that they accept a pointer to the structure as the first argument. The function that instantiates the structure is the one that starts the assembly process,
assemble
. This function outlives all other functions, ensuring the pointer it passes to the others is valid.In addition to that change, several minor cleanups were also made:
Dead code, presumably added for debugging, was removed (see: the variable
cont
)Dead code branching on the value of the variable
define_macro
was removed, since the variable has one value that no other code modifies.Dead code that was nested under an
#if 0
preprocessor directive. The function that used to contain this code is now empty, to be removed in a future cleanup (it's an error logging function that was presumably useful in the original context of the code)More cleanups to this file is later needed, to remove the function
printerr
and to free the memory returned bystrdup
in the initialization ofz80buffer
.Test plan
No new functionality was added so no new tests are necessary. The branch builds and all the tests in db/asm/z80 pass.
Closing issues
...