From: Michael Wallner Date: Fri, 19 Apr 2013 08:33:25 +0000 (+0200) Subject: better type handling for bool/double params X-Git-Tag: v0.2.0~5 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=6a0af039bb4c00c2489cbd63f94f63966c9a28b3;p=m6w6%2Fext-pq better type handling for bool/double params --- diff --git a/src/php_pq_misc.c b/src/php_pq_misc.c index c1f8333..2438182 100644 --- a/src/php_pq_misc.c +++ b/src/php_pq_misc.c @@ -86,21 +86,37 @@ static int apply_to_param(void *p TSRMLS_DC, int argc, va_list argv, zend_hash_k params = (char ***) va_arg(argv, char ***); zdtor = (HashTable *) va_arg(argv, HashTable *); - if (Z_TYPE_PP(zparam) == IS_NULL) { + switch (Z_TYPE_PP(zparam)) { + case IS_NULL: **params = NULL; ++*params; - } else { - if (Z_TYPE_PP(zparam) != IS_STRING) { - convert_to_string_ex(zparam); - } + break; + + case IS_BOOL: + **params = Z_BVAL_PP(zparam) ? "t" : "f"; + ++*params; + break; + + case IS_DOUBLE: + SEPARATE_ZVAL(zparam); + Z_TYPE_PP(zparam) = IS_STRING; + Z_STRLEN_PP(zparam) = spprintf(&Z_STRVAL_PP(zparam), 0, "%F", Z_DVAL_PP((zval **)p)); + /* no break */ + default: + convert_to_string_ex(zparam); + /* no break */ + + case IS_STRING: **params = Z_STRVAL_PP(zparam); ++*params; if (*zparam != *(zval **)p) { zend_hash_next_index_insert(zdtor, zparam, sizeof(zval *), NULL); } + break; } + return ZEND_HASH_APPLY_KEEP; }