Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

use helper for converting from double to string, use _ex version of _…

…php_math_number_format_ex for PHP 5.4
  • Loading branch information...
commit 72a041c7f898c236f92c077dbb8af5b27dce9dc9 1 parent c1bc92b
@maxbeutel maxbeutel authored
Showing with 12 additions and 3 deletions.
  1. +2 −2 library.c
  2. +9 −0 library.h
  3. +1 −1  redis.c
View
4 library.c
@@ -259,7 +259,7 @@ redis_cmd_format_static(char **ret, char *keyword, char *format, ...) {
case 'f':
case 'F': {
double d = va_arg(ap, double);
- dbl_len = spprintf(&dbl_str, 0, "%.8f", d);
+ REDIS_DOUBLE_TO_STRING(dbl_str, dbl_len, d)
smart_str_append_long(&buf, dbl_len);
smart_str_appendl(&buf, _NL, sizeof(_NL) - 1);
smart_str_appendl(&buf, dbl_str, dbl_len);
@@ -327,7 +327,7 @@ redis_cmd_format(char **ret, char *format, ...) {
case 'F':
case 'f': {
double d = va_arg(ap, double);
- dbl_len = spprintf(&dbl_str, 0, "%.8f", d);
+ REDIS_DOUBLE_TO_STRING(dbl_str, dbl_len, d)
smart_str_append_long(&buf, dbl_len);
smart_str_appendl(&buf, _NL, sizeof(_NL) - 1);
smart_str_appendl(&buf, dbl_str, dbl_len);
View
9 library.h
@@ -42,3 +42,12 @@ redis_key_prefix(RedisSock *redis_sock, char **key, int *key_len TSRMLS_DC);
PHPAPI int
redis_unserialize(RedisSock *redis_sock, const char *val, int val_len, zval **return_value TSRMLS_DC);
+#if (PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION >= 4)
+# define REDIS_DOUBLE_TO_STRING(dbl_str, dbl_len, dbl) \
+ dbl_str = _php_math_number_format_ex(dbl, 8, (char*)'.', 0, NULL, 0); \
+ dbl_len = strlen(dbl_str);
+#else
+# define REDIS_DOUBLE_TO_STRING(dbl_str, dbl_len, dbl) \
+ dbl_str = _php_math_number_format(dbl, 8, '.', '\x00'); \
+ dbl_len = strlen(dbl_str);
+#endif
View
2  redis.c
@@ -3662,7 +3662,7 @@ PHP_METHOD(Redis, zAdd) {
/* add score */
score = Z_DVAL_P(z_args[i]);
- dbl_len = spprintf(&dbl_str, 0, "%.8f", score);
+ REDIS_DOUBLE_TO_STRING(dbl_str, dbl_len, score)
smart_str_appendc(&buf, '$');
smart_str_append_long(&buf, dbl_len);
smart_str_appendl(&buf, _NL, sizeof(_NL) - 1);
Please sign in to comment.
Something went wrong with that request. Please try again.