0
我正在使用smart_str
標題作爲簡短的FastCGI腳本(與PHP無關),但無法正確使用smart_str_alloc
。我的代碼:smart_str_alloc:錯誤:newlen未聲明
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);
我缺少什麼?