Re: [idea] request_module(const char *fmt, ...);

From: Pauline Middelink (middelink@polyware.nl)
Date: Sat Jan 15 2000 - 04:10:39 EST


On Fri, Jan 14, 2000 at 01:16:53PM +0100, willy tarreau wrote:
> Hi guys,
>
> I think I have a solution to the variable-length macro
> :
>
> if you define an empty macro for request_module, this
> line :
>
> request_module("blah","blah2","foobar");
>
> will be converted to :
>
> ("blah","blah2","foobar");
>
> which is treated by the compiler as useless code and
> will no even generate one byte of code.
But gives a warning?

Better to do it like this:

-------------------
#include <stdio.h>
#include <errno.h>
#include <stdarg.h>

#ifndef ENABLE
#define request_module(fmt,rest...) ({-EINVAL;})
#else
int request_module(char* fmt, ...)
{
        char buf[1024];
        va_list ap;
        va_start(ap,fmt);
        vsprintf(buf,fmt,ap);
        va_end(ap);

        return 0;
}
#endif
--------------------

When enable is off, request_module resolves to a nice constant
value, which may or may not be used in the an if() construct.
If enabled, we build the proper string and do the old
request_module() thing

However, this still implies a recompile of all files containing
CONFIG_KMOD...
(Which I frankly dont care about; it happens to infreqently to
worry about)

    Met vriendelijke groet,
        Pauline Middelink

-- 
PGP Key fingerprint = DE 6B D0 D9 19 AD A7 A0  58 A3 06 9D B6 34 39 E2
For more details look at my website http://www.polyware.nl/~middelink

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



This archive was generated by hypermail 2b29 : Sat Jan 15 2000 - 21:00:26 EST