matt-kempster / m2c

A MIPS and PowerPC decompiler.
GNU General Public License v3.0
396 stars 48 forks source link

Fix `M2C_ERROR` when the message contains a comma #258

Closed ribbanya closed 1 year ago

ribbanya commented 1 year ago

Uses a variadic macro to ensure valid C syntax.

An alternative approach would be to emit either strings or comments within the macro, rather than unescaped C.

simonlindholm commented 1 year ago

Downside of this is that IDO doesn't support .... Another alternative is to emit M2C_ERROR((message)); could also choose to change syntax only in valid-syntax mode and/or when the message contains a comma. Not sure what alternative I like best here...

ribbanya commented 1 year ago

What do you think about wrapping the M2C_ERROR emissions (as in, the format strings) in a function, which wraps the message in a comment?

def m2c_error(err):
    return f"M2C_ERROR(/* {err} */)"
simonlindholm commented 1 year ago

M2C_ERROR emission is already localized into a function:

    def format(self, fmt: Formatter) -> str:
        if self.desc is not None:
            return f"M2C_ERROR({self.desc})"
        return "M2C_ERROR()"

I think I'm fine going with the comment syntax

simonlindholm commented 1 year ago

Just make sure to run ./run_tests.py --overwrite to update test expectations, and I can merge tomorrow

ribbanya commented 1 year ago

Okay, I don't have a local setup of any of the tested projects, so I'll have to do that first.

Oh wait, you can just not specify a project.