smart_str_alloc:错误:newlen未声明

时间:2014-08-28 09:04:08

标签: php-internals

我使用smart_str标头来获取简短的FastCGI脚本(与PHP无关),但无法正确使用smart_str_alloc。我的代码:

smart_str json = {0, 0, 0};
smart_str_alloc(&json, 1024 * 20, 0);

这会出错:

php_smart_str.h:72:37: error: ‘newlen’ undeclared (first use in this function)
  smart_str_alloc4((d), (n), (what), newlen)

smart_str_alloc4的宏是:

#define smart_str_alloc4(d, n, what, newlen) do {                   \
    if (!(d)->c) {                                                  \
        (d)->len = 0;                                               \
        newlen = (n);                                               \
        (d)->a = newlen < SMART_STR_START_SIZE                      \
                ? SMART_STR_START_SIZE                              \
                : newlen + SMART_STR_PREALLOC;                      \
        SMART_STR_DO_REALLOC(d, what);                              \
    } else {                                                        \
        newlen = (d)->len + (n);                                    \
        if (newlen >= (d)->a) {                                     \
            (d)->a = newlen + SMART_STR_PREALLOC;                   \
            SMART_STR_DO_REALLOC(d, what);                          \
        }                                                           \
    }                                                               \
} while (0)

newlen参数从smart_str_alloc定义传递,如下所示:

#define smart_str_alloc(d, n, what) \
    smart_str_alloc4((d), (n), (what), newlen)

有趣的是,在PHP源代码中,smart_str_alloc使用没有问题(来自json.c):

smart_str_alloc(buf, len+2, 0);

我错过了什么?

1 个答案:

答案 0 :(得分:0)

smart_str_alloc需要在其范围内定义变量newlen

size_t newlen;