2014-08-28 134 views
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); 

我缺少什麼?

回答

0

smart_str_alloc需要定義的變量newlen在它的範圍:

size_t newlen;