[PHP-CVS] com php-src: Bug #46408: Fix double formatting for PostgreSQL bound parameters: NEWS Zend/zend_operators.c Zend/zend_operators.h ext/pgsql/pgsql.c ext/pgsql/tests/bug46408.phpt

2013-01-14 Thread Lars Strojny
Commit:92965b033afa098945d18080203de1595084d1ac
Author:Lars Strojny lstro...@php.net Mon, 14 Jan 2013 21:23:52 
+0100
Parents:   785e66adb536d40a26e4813e6b4ad96b2fdbef43
Branches:  PHP-5.5

Link:   
http://git.php.net/?p=php-src.git;a=commitdiff;h=92965b033afa098945d18080203de1595084d1ac

Log:
Bug #46408: Fix double formatting for PostgreSQL bound parameters

Bugs:
https://bugs.php.net/46408

Changed paths:
  M  NEWS
  M  Zend/zend_operators.c
  M  Zend/zend_operators.h
  M  ext/pgsql/pgsql.c
  A  ext/pgsql/tests/bug46408.phpt


Diff:
diff --git a/NEWS b/NEWS
index c31365e..74c1134 100644
--- a/NEWS
+++ b/NEWS
@@ -19,12 +19,16 @@ PHP 
   NEWS
 
 - cURL:
   . Added new functions curl_escape, curl_multi_setopt, curl_multi_strerror
-curl_pause, curl_reset, curl_share_close, curl_share_init, 
+curl_pause, curl_reset, curl_share_close, curl_share_init,
curl_share_setopt curl_strerror and curl_unescape. (Pierrick)
   . Addes new curl options CURLOPT_TELNETOPTIONS, CURLOPT_GSSAPI_DELEGATION,
 CURLOPT_ACCEPTTIMEOUT_MS, CURLOPT_SSL_OPTIONS, CURLOPT_TCP_KEEPALIVE,
CURLOPT_TCP_KEEPIDLE and CURLOPT_TCP_KEEPINTVL. (Pierrick)
 
+- pgsql:
+  . Bug #46408: Locale number format settings can cause pg_query_params to
+break with numerics. (asmecher, Lars)
+
 18 Dec 2012, PHP 5.5.0 Alpha 2
 
 - General improvements:
diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c
index bd9..274893c 100644
--- a/Zend/zend_operators.c
+++ b/Zend/zend_operators.c
@@ -572,6 +572,24 @@ ZEND_API void convert_to_boolean(zval *op) /* {{{ */
 }
 /* }}} */
 
+ZEND_API void _convert_to_cstring(zval *op ZEND_FILE_LINE_DC) /* {{{ */
+{
+   double dval;
+   switch (Z_TYPE_P(op)) {
+   case IS_DOUBLE: {
+   TSRMLS_FETCH();
+   dval = Z_DVAL_P(op);
+   Z_STRLEN_P(op) = zend_spprintf(Z_STRVAL_P(op), 0, 
%.*H, (int) EG(precision), dval);
+   /* %H already handles removing trailing zeros from the 
fractional part, yay */
+   break;
+   }
+   default:
+   return _convert_to_string(op);
+   }
+   Z_TYPE_P(op) = IS_STRING;
+}
+/* }}} */
+
 ZEND_API void _convert_to_string(zval *op ZEND_FILE_LINE_DC) /* {{{ */
 {
long lval;
diff --git a/Zend/zend_operators.h b/Zend/zend_operators.h
index d3f5e5a..20a5277 100644
--- a/Zend/zend_operators.h
+++ b/Zend/zend_operators.h
@@ -301,6 +301,7 @@ ZEND_API int increment_function(zval *op1);
 ZEND_API int decrement_function(zval *op2);
 
 ZEND_API void convert_scalar_to_number(zval *op TSRMLS_DC);
+ZEND_API void _convert_to_cstring(zval *op ZEND_FILE_LINE_DC);
 ZEND_API void _convert_to_string(zval *op ZEND_FILE_LINE_DC);
 ZEND_API void convert_to_long(zval *op);
 ZEND_API void convert_to_double(zval *op);
@@ -314,6 +315,7 @@ ZEND_API void multi_convert_to_double_ex(int argc, ...);
 ZEND_API void multi_convert_to_string_ex(int argc, ...);
 ZEND_API int add_char_to_string(zval *result, const zval *op1, const zval 
*op2);
 ZEND_API int add_string_to_string(zval *result, const zval *op1, const zval 
*op2);
+#define convert_to_cstring(op) if ((op)-type != IS_STRING) { 
_convert_to_cstring((op) ZEND_FILE_LINE_CC); }
 #define convert_to_string(op) if ((op)-type != IS_STRING) { 
_convert_to_string((op) ZEND_FILE_LINE_CC); }
 
 ZEND_API double zend_string_to_double(const char *number, zend_uint length);
diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c
index d01dda6..7ee838a 100644
--- a/ext/pgsql/pgsql.c
+++ b/ext/pgsql/pgsql.c
@@ -1736,7 +1736,7 @@ PHP_FUNCTION(pg_query_params)
} else {
zval tmp_val = **tmp;
zval_copy_ctor(tmp_val);
-   convert_to_string(tmp_val);
+   convert_to_cstring(tmp_val);
if (Z_TYPE(tmp_val) != IS_STRING) {
php_error_docref(NULL TSRMLS_CC, 
E_WARNING,Error converting parameter);
zval_dtor(tmp_val);
diff --git a/ext/pgsql/tests/bug46408.phpt b/ext/pgsql/tests/bug46408.phpt
new file mode 100644
index 000..8c72ba5
--- /dev/null
+++ b/ext/pgsql/tests/bug46408.phpt
@@ -0,0 +1,23 @@
+--TEST--
+Bug #46408 (Locale number format settings can cause pg_query_params to break 
with numerics)
+--SKIPIF--
+?php
+require_once('skipif.inc');
+?
+--FILE--
+?php
+
+require_once('config.inc');
+
+$dbh = pg_connect($conn_str);
+setlocale(LC_ALL, 'hr_HR.utf-8', 'hr_HR');
+echo 3.5.PHP_EOL;
+pg_query_params(SELECT $1::numeric, array(3.5));
+pg_close($dbh);
+
+echo Done.PHP_EOL;
+
+?
+--EXPECTF--
+3,5
+Done


--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-CVS] com php-src: Bug #46408: Fix double formatting for PostgreSQL bound parameters: NEWS Zend/zend_operators.c Zend/zend_operators.h ext/pgsql/pgsql.c ext/pgsql/tests/bug46408.phpt

2013-01-14 Thread Adam Harvey
On 15 January 2013 04:23, Lars Strojny lstro...@php.net wrote:
 diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c
 index bd9..274893c 100644
 --- a/Zend/zend_operators.c
 +++ b/Zend/zend_operators.c
 @@ -572,6 +572,24 @@ ZEND_API void convert_to_boolean(zval *op) /* {{{ */
  }
  /* }}} */

 +ZEND_API void _convert_to_cstring(zval *op ZEND_FILE_LINE_DC) /* {{{ */
 +{
 +   double dval;
 +   switch (Z_TYPE_P(op)) {
 +   case IS_DOUBLE: {
 +   TSRMLS_FETCH();
 +   dval = Z_DVAL_P(op);
 +   Z_STRLEN_P(op) = zend_spprintf(Z_STRVAL_P(op), 0, 
 %.*H, (int) EG(precision), dval);
 +   /* %H already handles removing trailing zeros from 
 the fractional part, yay */
 +   break;
 +   }
 +   default:
 +   return _convert_to_string(op);
 +   }
 +   Z_TYPE_P(op) = IS_STRING;
 +}
 +/* }}} */
 +
  ZEND_API void _convert_to_string(zval *op ZEND_FILE_LINE_DC) /* {{{ */
  {
 long lval;

This broke compilation — specifically, the default: code path. I've
opened https://github.com/php/php-src/pull/261 to fix this, if someone
with Zend karma would be so kind.

Thanks,

Adam

--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php