Re: elog() proposal
От | Mike Mascari |
---|---|
Тема | Re: elog() proposal |
Дата | |
Msg-id | 3C7768FB.91E6C6D8@mascari.com обсуждение исходный текст |
Ответ на | Re: elog() proposal (Bruce Momjian <pgman@candle.pha.pa.us>) |
Список | pgsql-hackers |
Tom Lane wrote: > > Bruce Momjian <pgman@candle.pha.pa.us> writes: > > OK, so elog(ERROR, ...) and PGError(msg, ...) would be the same. Makes > > sense. Should we consider hiding these in macros so they really still > > call elog(ERROR, ...) for backward compatiblity? > > I would love to make them macros, but I don't know a portable way to > create macros with variable numbers of arguments. Do you feel like > writing double parens? > > PGERROR((msg, ...)) I'm not sure about complete portability, but the trick that I use works under both Linux/gcc and Windows/Visual C++. It is something like this: #define elog mkError(__FILE__, __LINE__) I then have the following prototypes: ---- typedef void (*throwError_ptr) (const char *message, ...); throwError_ptr mkError(const char *file, int line); void throwError(const char *message, ...); ----- The implementation looks like: throwError_ptr mkError(const char *file, int line) { sprintf(global_message, "File: %s\nLine: %i\n", file, line);return (throwError) } void throwError(const char *message, ...) { va_list arg_ptr;char buffer[MAX_MESSAGE]; va_start(arg_ptr, message);vsnprintf(buffer, sizeof(buffer), message, arg_ptr);va_end(arg_ptr); fprintf(stderr, "Error: %s\n%s", global_message, message); } ----- So, I can write: ... if (i < 0) { elog("Illegal index specified: %i", i); } ... which becomes mkError(__FILE__, __LINE__) ("Illegal index specified: %i", i); Shouldn't that be portable? Mike Mascari mascarm@mascari.com
В списке pgsql-hackers по дате отправления: