lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <59A7652D-BB6A-47BF-B916-4A79459DC226@mac.com>
Date:	Sat, 2 Dec 2006 15:53:48 -0500
From:	Kyle Moffett <mrmacman_g4@....com>
To:	Al Viro <viro@....linux.org.uk>
Cc:	Linus Torvalds <torvalds@...l.org>, linux-arch@...r.kernel.org,
	LKML Kernel <linux-kernel@...r.kernel.org>
Subject: Re: [RFC] timers, pointers to functions and type safety

On Dec 02, 2006, at 07:42:51, Al Viro wrote:
> On Sat, Dec 02, 2006 at 04:23:32AM -0500, Kyle Moffett wrote:
>> On Dec 01, 2006, at 12:21:49, Al Viro wrote:
>>> And that's where it gets interesting.  It would be very nice to  
>>> get to
>>> the following situation:
>>>  * callbacks are void (*)(void *)
>>>  * data is void *
>>>  * instances can take void * or pointer to object type
>>>  * a macro SETUP_TIMER(timer, func, data) sets callback and data  
>>> and checks if func(data) would be valid.
>>
>> This is where a very limited form of C++ templates would do  
>> nicely; you could define something like the following:
>>
>> template <typename T>
>> static inline void setup_timer(struct timer_list *timer,
>> 		void (*function)(T *), T *data)
>> {
>> 	timer->function = (void (*)(void *))function;
>> 	timer->data = (void *)data;
>> 	init_timer(timer);
>> }
>>
>> Any attempts to call it with mismatched "function" and "data"  
>> arguments would display an "Unable to find matching template"  
>> error from the compiler.
>>
>> Unfortunately you can't get simple templated functions without  
>> opening the whole barrel of monkeys involved with C++ support;
>
> Fortunately, you can get all checks done by gcc without involving C+ 
> + (or related flamewars).  See original post for a way to do it in  
> a macro and for fsck sake, leave gcc@....gnu.org out of it

Oh, I'm sorry I totally missed the CC of gcc@....gnu.org.  My point  
was just that while it _could_ be done with GCC and some ugly macros,  
a basic form of C++ templates usually produces much nicer and more  
descriptive error messages (leaving out all the reasons C++ isn't  
usable in the kernel for the sake of academic discussion).  The  
template syntax is also a bit more descriptive than is the macro  
syntax for achieving the same thing.

Cheers,
Kyle Moffett

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ