[PATCH] ngx_str_set

Mons Anderson mons на cpan.org
Чт Май 20 15:10:41 MSD 2010


Предлагаю немного пропатчить ngx_str_set

простой пример, когда оригинальная версия работать не будет.

if (...) ngx_str_set(...);

или
if (...) ngx_str_set(...);
else ...;


тестовый пример, сравнивающий 2 подхода:

#include <stdio.h>

#ifdef CORRECT
#define test(a,b) do { printf("%s\n",a);printf("%s\n",b); } while (0)
#endif
#ifndef CORRECT
#define test(a,b) printf("%s\n",a);printf("%s\n",b)
#endif

int main () {
    test("visible 1.1","visible 1.2");
    if (0) test("invisible 2.1","invisible 2.2");
    return 0;
}

/**************************/

$ gcc -o test test.c && ./test
visible 1.1
visible 1.2
invisible 2.2

$ gcc -DCORRECT -o test test.c && ./test
visible 1.1
visible 1.2

при этом если у нас if/else, то с оригинальным вариантом все еще хуже:

/**************************/

#include <stdio.h>

#ifdef CORRECT
#define test(a,b) do { printf("%s\n",a);printf("%s\n",b); } while (0)
#endif
#ifndef CORRECT
#define test(a,b) printf("%s\n",a);printf("%s\n",b)
#endif

int main () {
    test("visible 1.1","visible 1.2");
    if (0) test("invisible 2.1","invisible 2.2");
    else test("visible 3.1","visible 3.2");
    return 0;
}

/**************************/

$ gcc -o test test.c && ./test
test.c: In function 'main':
test.c:13: error: expected expression before 'else'

$ gcc -DCORRECT -o test test.c && ./test
visible 1.1
visible 1.2
visible 3.1
visible 3.2


-- 
Mons Anderson aka Vladimir Perepelitsa
<mons на cpan.org> / #99779956 / quanth на irc.freenode.net
----------- следущая часть -----------
A non-text attachment was scrubbed...
Name: ngx_str_set-patch
Type: text/x-diff
Size: 742 bytes
Desc: отсутствует
URL: <http://nginx.org/pipermail/nginx-ru/attachments/20100520/b5fb62bb/attachment.diff>


Подробная информация о списке рассылки nginx-ru