grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Handlers


From: Vesa Jääskeläinen
Subject: Re: Handlers
Date: Sat, 30 Aug 2008 17:55:19 +0300
User-agent: Thunderbird 2.0.0.16 (Windows/20080708)

Marco Gerards wrote:
> Vesa Jääskeläinen <address@hidden> writes:
> 
>> Marco Gerards wrote:
>>> If I knew a better way, I would have used it.  I think the
>>> alternatives will all end up in either code duplication or a loss of
>>> type safety that now is at least present through warnings.  But please
>>> understand that you only have to use the macros, not change them :-)
>>>
>>> Suggestions are welcome.
>> Hi,
>>
>> Well... How about something like this?
> 
> This code does not describe structs with function pointers but structs
> with data.  Furthermore, you made it very generic while you do need
> casts.  For example, you have a generic iterate function.  Except for
> the macros, this code is not too different.  But I used the macros to
> glue the list code to the other code of GRUB, which is what you left
> out.  But this is the essence of the discussion.
> 
>> It only requires one cast and no macros at all.
> 
> My code also contained generic code in kern/handler.c like your code.
> I have added the macros to avoid casts.  This code will not work
> directly in GRUB 2 for filesystems or whatever.  You need to cast at
> some points, or even quite often.  And that is *exactly* what I would
> like to avoid.

Hi,

But your code does the cast too :)... its just hidden inside macro
magic... Or did you lost track of it already as it was hidden ;) ;)

If you just paste code for GRUB_HANDLER_CREATE_C inside .c file we are
pretty much in the same functionality.

If we want to nitpick somewhere, your code assumes iterate makes a call
to int (*hook) (const grub_handler_t handler) where as actual function
pointer is something else.

Anyway... my point is. Do not hide code behind macros :). It just makes
life much harder when you are debugging or reading the code as you do
not see what is happening (and can even confuse debugger). You can do
generic register / unregister / iterate handling but keep it simple
stupid in code to make it easier to use in the end.

Thats my 2 cents on the issue.

Thanks,
Vesa Jääskeläinen





reply via email to

[Prev in Thread] Current Thread [Next in Thread]