Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 19 Nov 2012 10:44:00 -0800
From:      mdf@FreeBSD.org
To:        Navdeep Parhar <np@freebsd.org>
Cc:        Gleb Smirnoff <glebius@freebsd.org>, Andre Oppermann <andre@freebsd.org>, src-committers@freebsd.org, svn-src-user@freebsd.org
Subject:   Re: svn commit: r243215 - user/andre/tcp_workqueue/sys/sys
Message-ID:  <CAMBSHm-RUKkm%2BsaLMA9xwrB-L3Hauiy2SHf-Z3RoFMyX6S-ysA@mail.gmail.com>
In-Reply-To: <50AA7773.1050401@FreeBSD.org>
References:  <201211181217.qAICH7aH021497@svn.freebsd.org> <20121119114510.GQ38060@FreeBSD.org> <50AA3529.2030300@freebsd.org> <CAMBSHm_eu-z6fuxTL2bdavQeBjOcE1zvS5h4itGa%2BP%2BiQhqrrA@mail.gmail.com> <50AA76CD.3070904@freebsd.org> <50AA7773.1050401@FreeBSD.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Nov 19, 2012 at 10:16 AM, Navdeep Parhar <np@freebsd.org> wrote:
> On 11/19/12 10:13, Andre Oppermann wrote:
>> On 19.11.2012 18:01, mdf@FreeBSD.org wrote:
>>> On Mon, Nov 19, 2012 at 5:33 AM, Andre Oppermann <andre@freebsd.org>
>>> wrote:
>>>> On 19.11.2012 12:45, Gleb Smirnoff wrote:
>>>>>
>>>>> On Sun, Nov 18, 2012 at 12:17:07PM +0000, Andre Oppermann wrote:
>>>>> A> Author: andre
>>>>> A> Date: Sun Nov 18 12:17:07 2012
>>>>> A> New Revision: 243215
>>>>> A> URL: http://svnweb.freebsd.org/changeset/base/243215
>>>>> A>
>>>>> A> Log:
>>>>> A>   Add mtodo(m, o, t) macro taking an additional offset into
>>>>> A>   the mbuf data section before the casting to type 't'.
>>>>>
>>>>> IMHO, argument order of (m, t, o) is more intuitive, since
>>>>> matches order of mtod().
>>>>
>>>>
>>>> Yes, but that looks rather horrible and counter-intuitive:
>>>>
>>>>   th = mtodo(m, struct tcphdr *, 20);
>>>>
>>>> vs.
>>>>
>>>>   th = mtodo(m, 20, struct tcphdr *);
>>>>
>>>> Reads m->m_data at offset 20 is struct tcphdr.
>>>>
>>>> Naming it mtood() wasn't convincing either. ;-)
>>>
>>> Why a cast at all?  Perpetuating the mistake of mtod()'s casting isn't
>>> necessary.  mtod() can't be fixed for source reasons, but the new one
>>> doesn't need to cast.  Since C automatically casts from void * to any
>>> other pointer, the code gets shorter (usually) too:
>>>
>>> th = mtodo(m, 20);
>>
>> m->m_data is caddr_t which is "char *"
>
> No matter what it is you can always cast it to void * before returning,
> instead of having the caller supply the type.

Right, this is what I meant.  Instead of a parameter to cast to, just
return void *.  Let the caller cast, or not, as needed.  It's a
simpler macro that way.

Cheers,
matthew



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAMBSHm-RUKkm%2BsaLMA9xwrB-L3Hauiy2SHf-Z3RoFMyX6S-ysA>