【发布时间】: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