ron minnich wrote:
> In general I'd like to avoid weak symbols, what purpose is being
> served by them here?
>> ron
>It avoids the need to add an empty function to every single mainboard
not supporting the feature yet, in order to avoid compilation breakage
of those boards.
Carl-Daniel mentioned that weak symbols make the code harder to follow.
In a classic C sense that may not wrong, but since we're modelling
components, what happens is that we have a slightly object oriented
approach and some "constructors" are being overloaded, while others stay
empty.
We do a similar thing with the device functions in many places.. "If
there's a subsystem vendor/device id function for that device, execute
it, otherwise execute the default function" is harder to follow than
just "If there's an ACPI create function for that board, execute it"
To show an example, look at this:
What we have today:
/* Set the subsystem vendor and device id for mainboard devices */
ops = ops_pci(dev);
if (dev->on_mainboard && ops && ops->set_subsystem) {
ops->set_subsystem(dev,
MAINBOARD_PCI_SUBSYSTEM_VENDOR_ID,
MAINBOARD_PCI_SUBSYSTEM_DEVICE_ID);
}
Here's on the other hand, how filo uses weak symbols:
void __attribute__((weak)) platform_reboot(void);
if (platform_reboot)
platform_reboot();
else
printf("Rebooting not supported.\n");
which looks very familiar, does it? Oh, and a fix of the else case/error
message would potentially fix 50 boards without requiring 50 small hunks
of patches.
I'm no big fan of empty dummy function for everyone to fix compilation.
Are they considered better than weak symbols as a method of controlling
code flow and readability? They're sure not some overly clever code, so
it hopefully won't become dangerous.
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it." – Brian W. Kernighan
One thing I wonder though, do we want to call weak symbols
unconditionally, as in Rudolf's code? No if() clause catches the case
that the symbol isn't there. In a test program that call would segfault
a user space program here.
Stefan
--
coresystems GmbH • Brahmsstr. 16 • D-79104 Freiburg i. Br.
Tel.: +49 761 7668825 • Fax: +49 761 7664613
Email: info at coresystems.de • http://www.coresystems.de/
Registergericht: Amtsgericht Freiburg • HRB 7656
Geschäftsführer: Stefan Reinauer • Ust-IdNr.: DE245674866