【问题标题】:smart_str_alloc: error: newlen undeclaredsmart_str_alloc: 错误: newlen 未声明
【发布时间】:2014-10-22 01:58:53
【问题描述】:

我将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);

我错过了什么?

【问题讨论】:

    标签: php-internals


    【解决方案1】:

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

    size_t newlen;
    

    【讨论】:

      猜你喜欢
      • 2015-02-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-28
      • 1970-01-01
      • 2013-08-21
      • 1970-01-01
      相关资源
      最近更新 更多