Re: git: bf362c1b41c8 - main - kobj: convert KOBJOPLOOKUP() to returning pointer to function
Date: Fri, 20 Nov 2026 13:48:37 UTC
> On Nov 20, 2026, at 9:36 PM, Cy Schubert <Cy.Schubert@cschubert.com> wrote:
>
> In message <6b001ca8.17a65.140055b6@gitrepo.freebsd.org <mailto:6b001ca8.17a65.140055b6@gitrepo.freebsd.org>>, Zhenlei Huang
> writes:
>> The branch main has been updated by zlei:
>>
>> URL: https://cgit.FreeBSD.org/src/commit/?id=bf362c1b41c803c7320147b89915bd65
>> 88dd6071
>>
>> commit bf362c1b41c803c7320147b89915bd6588dd6071
>> Author: Elliott Mitchell <ehem+freebsd@m5p.com>
>> AuthorDate: 2025-01-10 00:45:05 +0000
>> Commit: Zhenlei Huang <zlei@FreeBSD.org>
>> CommitDate: 2026-11-20 10:09:02 +0000
>>
>> kobj: convert KOBJOPLOOKUP() to returning pointer to function
>>
>> 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.
>>
>> Reviewed by: zlei
>> MFC after: 2 weeks
>> Differential Revision: https://reviews.freebsd.org/D48408
>> ---
>> sys/sys/kobj.h | 20 ++++++++++----------
>> sys/tools/makeobjops.awk | 6 +++---
>> 2 files changed, 13 insertions(+), 13 deletions(-)
>>
>> diff --git a/sys/sys/kobj.h b/sys/sys/kobj.h
>> index 890ad1d39a13..3cdbf14d124c 100644
>> --- a/sys/sys/kobj.h
>> +++ b/sys/sys/kobj.h
>> @@ -247,30 +247,30 @@ extern u_int kobj_lookup_misses;
>> * slow way.
>> */
>> #ifdef KOBJ_STATS
>> -#define KOBJOPLOOKUP(OPS,OP) do { \
>> +#define KOBJOPLOOKUP(OBJ, OP) __extension__ ({ \
>> kobjop_desc_t _desc = &OP##_##desc; \
>> kobj_method_t **_cep = \
>> - &OPS->cache[_desc->id & (KOBJ_CACHE_SIZE-1)]; \
>> + &(OBJ)->ops->cache[_desc->id & (KOBJ_CACHE_SIZE-1)];\
>
> This has caused a number of errors as below as an example.
>
> --- aq_media.o ---
> In file included from /opt/src/git-src/sys/dev/aq/aq_media.c:43:
> In file included from /opt/src/git-src/sys/net/iflib.h:31:
> In file included from /opt/src/git-src/sys/sys/bus.h:893:
> ./device_if.h:115:2: error: no member named 'ops' in 'struct kobj_ops'
> 115 | KOBJOPLOOKUP(((kobj_t)dev)->ops, device_probe);
It appears that the generated file `device_if.h` is not re-generated after `sys/tools/makeobjops.awk`
been updated.
Can you please try this first,
```
make cleankernel
```
and then rebuild ?
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> /opt/src/git-src/sys/sys/kobj.h:267:14: note: expanded from macro
> 'KOBJOPLOOKUP'
> 267 | &(OBJ)->ops->cache[_desc->id & (KOBJ_CACHE_SIZE-1)];\
> | ~~~~~ ^
>
>
>> kobj_method_t *_ce = *_cep; \
>> if (_ce->desc != _desc) { \
>> - _ce = kobj_lookup_method(OPS->cls, \
>> + _ce = kobj_lookup_method((OBJ)->ops->cls, \
>> _cep, _desc); \
>> kobj_lookup_misses++; \
>> } else \
>> kobj_lookup_hits++; \
>> - _m = _ce->func; \
>> -} while (0)
>> + (OP##_t *)(_ce->func); \
>> +})
>> #else
>> -#define KOBJOPLOOKUP(OPS,OP) do { \
>> +#define KOBJOPLOOKUP(OBJ, OP) __extension__ ({ \
>> kobjop_desc_t _desc = &OP##_##desc; \
>> kobj_method_t **_cep = \
>> - &OPS->cache[_desc->id & (KOBJ_CACHE_SIZE-1)]; \
>> + &(OBJ)->ops->cache[_desc->id & (KOBJ_CACHE_SIZE-1)];\
>> kobj_method_t *_ce = *_cep; \
>> if (_ce->desc != _desc) \
>> - _ce = kobj_lookup_method(OPS->cls, \
>> + _ce = kobj_lookup_method((OBJ)->ops->cls, \
>> _cep, _desc); \
>> - _m = _ce->func; \
>> -} while (0)
>> + (OP##_t *)(_ce->func); \
>> +})
>> #endif
>>
>> kobj_method_t* kobj_lookup_method(kobj_class_t cls,
>> diff --git a/sys/tools/makeobjops.awk b/sys/tools/makeobjops.awk
>> index 522fb04ec4d1..f36a9166efbd 100644
>> --- a/sys/tools/makeobjops.awk
>> +++ b/sys/tools/makeobjops.awk
>> @@ -320,16 +320,16 @@ function handle_method (static, doc)
>> line_width, length(prototype)));
>> }
>> printh("{");
>> - printh("\tkobjop_t _m;");
>> + printh("\t" mname "_t *_m;");
>> if (ret != "void")
>> printh("\t" ret " rc;");
>> if (!static)
>> firstvar = "((kobj_t)" firstvar ")";
>> if (prolog != "")
>> printh(prolog);
>> - printh("\tKOBJOPLOOKUP(" firstvar "->ops, " mname ");");
>> + printh("\t_m = KOBJOPLOOKUP(" firstvar ", " mname ");");
>> rceq = (ret != "void") ? "rc = " : "";
>> - printh("\t" rceq "((" mname "_t *) _m)(" varname_list ");");
>> + printh("\t" rceq "(*_m)(" varname_list ");");
>> if (epilog != "")
>> printh(epilog);
>> if (ret != "void")
>>
>
>
> --
> Cheers,
> Cy Schubert <Cy.Schubert@cschubert.com <mailto:Cy.Schubert@cschubert.com>>
> FreeBSD UNIX: <cy@FreeBSD.org <mailto:cy@FreeBSD.org>> Web: https://FreeBSD.org <https://freebsd.org/>
> NTP: <cy@nwtime.org <mailto:cy@nwtime.org>> Web: https://nwtime.org <https://nwtime.org/>
>
> e**(i*pi)+1=0