[Toybox] [PATCH] bc.c: deobfuscation of bc_lib

Oliver Webb aquahobbyist at proton.me
Tue Feb 27 12:26:50 PST 2024


On Tuesday, February 27th, 2024 at 14:00, Mouse <mouse at Rodents-Montreal.ORG> wrote:
> > And also, bc_program_stdin_name never changes from "<stdin>" so
> > there's no reason to make it a variable
> 
> 
> Well, I haven't read all the context. But I would say that there is at
> least potentially reason to leave it as a variable even if it's never
> changed: namely, future-proofing. If someone wants to change it in the
> future, it's significantly easier to change one variable initialization
> than to chase down everywhere that string is hardwired and check that
> each one actually is referring to the same thing.

While code flexibility is a good thing. I have to wonder what
would prompt the change of bc_program_stdin_name. The only reason I could
think of was internationalization, we already have a ton of English text in
bc.c in the form of help text, keyword names, error messages, etc.

> (It's easy to find
> all strings that say <stdin>. It's less easy to verify that each of
> those is actually talking about the semantic bc_program_stdin_name
> refers to.)

The only time the string "<stdin>" appears in bc.c is the declaration for
bc_program_stdin_name.

> If it were performance-critical enough that the cost of dereferencing a
> variable were significant (and, for that small a difference, if it were
> under my umbrella I'd want to see measurements), then it might be worth
> doing. While, as I say, I haven't checked in detail, I suspect that is
> not the case here.

The compiler does liveness analysis and puts the variable in section .rodata,
Although I can't confirm that since I haven't looked at the symbol table.
There isn't any tangible benefit to this as far as code speed goes. But it makes the code
easier to understand (not having to check what bc_program_stdin_name is if you don't know already).
It could be a preprocessor macro if there really is a need for it. But I don't see one

""Hiding numbers that are used just once into defines to put them out of
sight does not really help readability." - Pavel Machek"
- cleanup.html

> /~\ The ASCII Mouse
> \ / Ribbon Campaign
> X Against HTML mouse at rodents-montreal.org
> / \ Email! 7D C8 61 52 5D E7 2D 39 4E F1 31 3E E8 B3 27 4B

-   Oliver Webb <aquahobbyist at proton.me>


More information about the Toybox mailing list