This makes KOBJOPLOOKUP() rather more suitable for purposes outside
the macros generated by makeobjops.awk. Of note other callers can
lookup the function on their parent class and call that explicitly.
Details
Diff Detail
- Repository
- rG FreeBSD src repository
- Lint
Lint Not Applicable - Unit
Tests Not Applicable
Event Timeline
The change seems fine at a glance, but I'm not very familiar with this code.
For the commit description: I'm not convinced the conversion to compound expressions is the interesting point. IMO that's just the implementation. It's changing the API from assigning to a tkobjop_t _m internally to returning an <OP>_t that's interesting.
| sys/sys/kobj.h | ||
|---|---|---|
| 250 | IIRC we need to spell it __extension__ ({ to avoid breaking... something. | |
| sys/sys/kobj.h | ||
|---|---|---|
| 250 | Eh, we don't include that in other places (at least it's not something I'm aware of) | |
| sys/sys/kobj.h | ||
|---|---|---|
| 250 | 49 uses in sys/; I suspect it's only a requirement for the userland warning set, but it'd be nice to be consistent. | |
Updating as per current comments, add extension, minor title adjustment. Remove a now unnecessary cast from makeobjsops.awk's output.
One more comment and possible adjustment. I don't like the KOBJOPLOOKUP name. I think the original author was thinking (KOBJOP)(LOOKUP), but I believe the more common parsing is (KOBJ)(OP)(LOOKUP). KOBJLOOKUPOP or KOBJLOOKUP seem better since the is it is looking up an OP (function pointer) on a KOBJ, not looking up a KOBJOP in some global table.
I didn't find any uses of KOBJOPLOOKUP other than those generated by makeobjsop.awk, but there could be some outside the FreeBSD repository. I'm also unsure whether KOBJOPLOOKUP() is meant strictly for makeobjsops.awk files, versus simply being an undocumented useful macro.
If anyone is wondering, the value is KOBJOPLOOKUP() is quite helpful for places which want to use kobj, but existing things won't match well. One such place is sys/x86/isa/clock.c:attimer_attach(). If x86 was converted to kobj, the setting of i8254_pending = needs adjustment and KOBJOPLOOKUP() with function pointer return works well. This is also handy for calling a parent class's version of a function after device-variant work is done.
5 days is on the short side for expecting secondary reviews, but I notice many member second-round reviews happen faster than that.
Minor tweak. The ->ops gets added by all observed callers so far, so seems best to move it into the macro. Slight adjustment to parentheses.
The change looks good to me. I do not have strong opinion on __extension__ . There're already lots of macro definition without __extension__.
| sys/tools/makeobjops.awk | ||
|---|---|---|
| 332 | ||
I've got one more tweak to the version in my tree, I rename KOBJOPLOOKUP to KOBJ_LOOKUP_METHOD. The reason being most users will want the caching lookup, rather than directly calling kobj_lookup_method().
This has been looking for a committer for a while. Just need to know what hand-off method you prefer. Patch attached to e-mail? Branch on a repository?
| sys/tools/makeobjops.awk | ||
|---|---|---|
| 332 | The parentheses were previously needed due to "_m" being cast to the function type. Whereas this moves the cast inside KOBJOPLOOKUP() since other callers will pretty well always want the correct type. | |
I plan to commit this in few days. Any objection ?
| sys/tools/makeobjops.awk | ||
|---|---|---|
| 332 | The _m is declared as function pointer. When calling the referenced function, _m(args) is perfect valid, but (*_m)(args) can make the intention clear. | |