我为一个简短的FastCGI脚本使用了smart_str头文件(与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)从smart_str_alloc定义中传递的newlen参数如下所示:
#define smart_str_alloc(d, n, what) \
smart_str_alloc4((d), (n), (what), newlen)有趣的是,在PHP源代码中,(来自json.c)使用smart_str_alloc是没有问题的:
smart_str_alloc(buf, len+2, 0);我遗漏了什么?
发布于 2014-08-28 17:08:25
宏smart_str_alloc需要在其作用域中定义一个变量newlen:
size_t newlen;https://stackoverflow.com/questions/25544848
复制相似问题