0

I'm using the smart_str headers for a short FastCGI script (not related to PHP), but can't use smart_str_alloc correctly. My code:

smart_str json = {0, 0, 0};
smart_str_alloc(&json, 1024 * 20, 0);

This gives error:

php_smart_str.h:72:37: error: ‘newlen’ undeclared (first use in this function)
  smart_str_alloc4((d), (n), (what), newlen)

And the macro for smart_str_alloc4 is:

#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)

The newlen argument is passed from the smart_str_alloc definition like so:

#define smart_str_alloc(d, n, what) \
    smart_str_alloc4((d), (n), (what), newlen)

Funny thing is, in the PHP source code, smart_str_alloc is used without problem (from json.c):

smart_str_alloc(buf, len+2, 0);

What am I missing?

Olle Härstedt
  • 3,799
  • 1
  • 24
  • 57

1 Answers1

0

The macro smart_str_alloc needs a defined variable newlen in it's scope:

size_t newlen;
Olle Härstedt
  • 3,799
  • 1
  • 24
  • 57