From 19b757dacd224c1e70ad3452c5f9d9b69141ddf1 Mon Sep 17 00:00:00 2001 From: Rasmus Lerdorf Date: Mon, 2 Jan 2017 22:30:28 -0800 Subject: Fix opcache test dependencies --- ext/opcache/tests/basic_logging.phpt | 1 + ext/opcache/tests/issue0115.phpt | 16 ++++++++-------- ext/opcache/tests/issue0149.phpt | 4 ++-- ext/opcache/tests/log_verbosity_bug.phpt | 1 + 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/ext/opcache/tests/basic_logging.phpt b/ext/opcache/tests/basic_logging.phpt index c62ea039a5..4a571b5b93 100644 --- a/ext/opcache/tests/basic_logging.phpt +++ b/ext/opcache/tests/basic_logging.phpt @@ -7,6 +7,7 @@ outputs the correct logging at the highest log_verbosity_level --INI-- opcache.enable=1 opcache.enable_cli=1 +opcache.file_cache_only=0 opcache.log_verbosity_level=4 --SKIPIF-- diff --git a/ext/opcache/tests/issue0115.phpt b/ext/opcache/tests/issue0115.phpt index 0dfdd9f0eb..26d99080eb 100644 --- a/ext/opcache/tests/issue0115.phpt +++ b/ext/opcache/tests/issue0115.phpt @@ -16,28 +16,28 @@ require "phar://this/index.php"; __HALT_COMPILER(); ?>'; $p = new Phar(__DIR__ . '/issue0115_1.phar.php', 0, 'this'); $p['index.php'] = 'setStub($stub); unset($p); $p = new Phar(__DIR__ . '/issue0115_2.phar.php', 0, 'this'); $p['index.php'] = 'setStub($stub); unset($p); include "php_cli_server.inc"; -php_cli_server_start('-d opcache.enable=1 -d opcache.enable_cli=1'); +php_cli_server_start('-d opcache.enable=1 -d opcache.enable_cli=1 -d extension=phar.'.PHP_SHLIB_SUFFIX); echo file_get_contents('http://' . PHP_CLI_SERVER_ADDRESS . '/issue0115_1.phar.php'); echo file_get_contents('http://' . PHP_CLI_SERVER_ADDRESS . '/issue0115_2.phar.php'); ?> --CLEAN-- - diff --git a/ext/opcache/tests/issue0149.phpt b/ext/opcache/tests/issue0149.phpt index 8c7f1bb7e0..ba57623fce 100644 --- a/ext/opcache/tests/issue0149.phpt +++ b/ext/opcache/tests/issue0149.phpt @@ -20,13 +20,13 @@ $p->setStub($stub); unset($p); include "php_cli_server.inc"; -php_cli_server_start('-d opcache.enable=1 -d opcache.enable_cli=1'); +php_cli_server_start('-d opcache.enable=1 -d opcache.enable_cli=1 -d extension=phar.'.PHP_SHLIB_SUFFIX); echo file_get_contents('http://' . PHP_CLI_SERVER_ADDRESS . '/issue0149.phar.php'); echo file_get_contents('http://' . PHP_CLI_SERVER_ADDRESS . '/issue0149.phar.php'); echo file_get_contents('http://' . PHP_CLI_SERVER_ADDRESS . '/issue0149.phar.php'); ?> --CLEAN-- - --EXPECT-- diff --git a/ext/opcache/tests/log_verbosity_bug.phpt b/ext/opcache/tests/log_verbosity_bug.phpt index 725b8889f4..2e5d7a9add 100644 --- a/ext/opcache/tests/log_verbosity_bug.phpt +++ b/ext/opcache/tests/log_verbosity_bug.phpt @@ -7,6 +7,7 @@ The process should die regardless of the log_verbosity_level. --INI-- opcache.enable=1 opcache.enable_cli=1 +opcache.file_cache_only=0 opcache.memory_consumption=999999999 opcache.log_verbosity_level=-1 --SKIPIF-- -- cgit v1.2.1 From ff4e330eae7aa2550c483d480cb98054e251da55 Mon Sep 17 00:00:00 2001 From: Joe Watkins Date: Tue, 3 Jan 2017 10:48:42 +0000 Subject: Merge branch 'pull-request/1905' * pull-request/1905: pack()/unpack() for Big Endian float/double and Little Endian float/double --- ext/standard/pack.c | 214 +++++++++++++++++- ext/standard/tests/strings/pack_float.phpt | 312 +++++++++++++++++++++++++++ ext/standard/tests/strings/unpack_error.phpt | 4 +- 3 files changed, 519 insertions(+), 11 deletions(-) create mode 100644 ext/standard/tests/strings/pack_float.phpt diff --git a/ext/standard/pack.c b/ext/standard/pack.c index a24ee69ad2..1184717993 100644 --- a/ext/standard/pack.c +++ b/ext/standard/pack.c @@ -104,8 +104,132 @@ static void php_pack(zval *val, size_t size, int *map, char *output) } /* }}} */ +/* {{{ php_pack_reverse_int32 + */ +inline uint32_t php_pack_reverse_int32(uint32_t arg) +{ + uint32_t result; + result = ((arg & 0xFF) << 24) | ((arg & 0xFF00) << 8) | ((arg >> 8) & 0xFF00) | ((arg >> 24) & 0xFF); + + return result; +} +/* }}} */ + +/* {{{ php_pack + */ +inline uint64_t php_pack_reverse_int64(uint64_t arg) +{ + union Swap64 { + uint64_t i; + uint32_t ul[2]; + } tmp, result; + tmp.i = arg; + result.ul[0] = php_pack_reverse_int32(tmp.ul[1]); + result.ul[1] = php_pack_reverse_int32(tmp.ul[0]); + + return result.i; +} +/* }}} */ + +/* {{{ php_pack_copy_float + */ +static void php_pack_copy_float(int is_little_endian, void * dst, float f) +{ + union Copy32 { + float f; + uint32_t i; + } m; + m.f = f; + +#ifdef WORDS_BIGENDIAN + if (is_little_endian) { + m.i = php_pack_reverse_int32(m.i); + } +#else /* WORDS_BIGENDIAN */ + if (!is_little_endian) { + m.i = php_pack_reverse_int32(m.i); + } +#endif /* WORDS_BIGENDIAN */ + + memcpy(dst, &m.f, sizeof(float)); +} +/* }}} */ + +/* {{{ php_pack_copy_double + */ +static void php_pack_copy_double(int is_little_endian, void * dst, double d) +{ + union Copy64 { + double d; + uint64_t i; + } m; + m.d = d; + +#ifdef WORDS_BIGENDIAN + if (is_little_endian) { + m.i = php_pack_reverse_int64(m.i); + } +#else /* WORDS_BIGENDIAN */ + if (!is_little_endian) { + m.i = php_pack_reverse_int64(m.i); + } +#endif /* WORDS_BIGENDIAN */ + + memcpy(dst, &m.d, sizeof(double)); +} +/* }}} */ + +/* {{{ php_pack_parse_float + */ +static float php_pack_parse_float(int is_little_endian, void * src) +{ + union Copy32 { + float f; + uint32_t i; + } m; + memcpy(&m.i, src, sizeof(float)); + +#ifdef WORDS_BIGENDIAN + if (is_little_endian) { + m.i = php_pack_reverse_int32(m.i); + } +#else /* WORDS_BIGENDIAN */ + if (!is_little_endian) { + m.i = php_pack_reverse_int32(m.i); + } +#endif /* WORDS_BIGENDIAN */ + + return m.f; +} +/* }}} */ + +/* {{{ php_pack_parse_double + */ +static double php_pack_parse_double(int is_little_endian, void * src) +{ + union Copy64 { + double d; + uint64_t i; + } m; + memcpy(&m.i, src, sizeof(double)); + +#ifdef WORDS_BIGENDIAN + if (is_little_endian) { + m.i = php_pack_reverse_int64(m.i); + } +#else /* WORDS_BIGENDIAN */ + if (!is_little_endian) { + m.i = php_pack_reverse_int64(m.i); + } +#endif /* WORDS_BIGENDIAN */ + + return m.d; +} +/* }}} */ + /* pack() idea stolen from Perl (implemented formats behave the same as there except J and P) * Implemented formats are Z, A, a, h, H, c, C, s, S, i, I, l, L, n, N, q, Q, J, P, f, d, x, X, @. + * Added g, G for little endian float and big endian float, added e, E for little endian double and big endian double. */ /* {{{ proto string pack(string format, mixed arg1 [, mixed arg2 [, mixed ...]]) Takes one or more arguments and packs them into a binary string according to the format argument */ @@ -215,8 +339,12 @@ PHP_FUNCTION(pack) case 'N': case 'v': case 'V': - case 'f': - case 'd': + case 'f': /* float */ + case 'g': /* little endian float */ + case 'G': /* big endian float */ + case 'd': /* double */ + case 'e': /* little endian double */ + case 'E': /* big endian double */ if (arg < 0) { arg = num_args - currentarg; } @@ -294,11 +422,15 @@ PHP_FUNCTION(pack) break; #endif - case 'f': + case 'f': /* float */ + case 'g': /* little endian float */ + case 'G': /* big endian float */ INC_OUTPUTPOS(arg,sizeof(float)) break; - case 'd': + case 'd': /* double */ + case 'e': /* little endian double */ + case 'E': /* big endian double */ INC_OUTPUTPOS(arg,sizeof(double)) break; @@ -473,6 +605,26 @@ PHP_FUNCTION(pack) } break; } + + case 'g': { + /* pack little endian float */ + while (arg-- > 0) { + float v = (float) zval_get_double(&argv[currentarg++]); + php_pack_copy_float(1, &ZSTR_VAL(output)[outputpos], v); + outputpos += sizeof(v); + } + + break; + } + case 'G': { + /* pack big endian float */ + while (arg-- > 0) { + float v = (float) zval_get_double(&argv[currentarg++]); + php_pack_copy_float(0, &ZSTR_VAL(output)[outputpos], v); + outputpos += sizeof(v); + } + break; + } case 'd': { while (arg-- > 0) { @@ -482,6 +634,26 @@ PHP_FUNCTION(pack) } break; } + + case 'e': { + /* pack little endian double */ + while (arg-- > 0) { + double v = (double) zval_get_double(&argv[currentarg++]); + php_pack_copy_double(1, &ZSTR_VAL(output)[outputpos], v); + outputpos += sizeof(v); + } + break; + } + + case 'E': { + /* pack big endian double */ + while (arg-- > 0) { + double v = (double) zval_get_double(&argv[currentarg++]); + php_pack_copy_double(0, &ZSTR_VAL(output)[outputpos], v); + outputpos += sizeof(v); + } + break; + } case 'x': memset(&ZSTR_VAL(output)[outputpos], '\0', arg); @@ -542,6 +714,7 @@ static zend_long php_unpack(char *data, size_t size, int issigned, int *map) * Numeric pack types will return numbers, a and A will return strings, * f and d will return doubles. * Implemented formats are Z, A, a, h, H, c, C, s, S, i, I, l, L, n, N, q, Q, J, P, f, d, x, X, @. + * Added g, G for little endian float and big endian float, added e, E for little endian double and big endian double. */ /* {{{ proto array unpack(string format, string input) Unpack binary string into named array elements according to format argument */ @@ -673,11 +846,15 @@ PHP_FUNCTION(unpack) /* Use sizeof(float) bytes of input */ case 'f': + case 'g': + case 'G': size = sizeof(float); break; /* Use sizeof(double) bytes of input */ case 'd': + case 'e': + case 'E': size = sizeof(double); break; @@ -933,18 +1110,37 @@ PHP_FUNCTION(unpack) } #endif - case 'f': { + case 'f': /* float */ + case 'g': /* little endian float*/ + case 'G': /* big endian float*/ + { float v; - memcpy(&v, &input[inputpos], sizeof(float)); + if (type == 'g') { + v = php_pack_parse_float(1, &input[inputpos]); + } else if (type == 'G') { + v = php_pack_parse_float(0, &input[inputpos]); + } else { + memcpy(&v, &input[inputpos], sizeof(float)); + } + add_assoc_double(return_value, n, (double)v); break; } + - case 'd': { + case 'd': /* double */ + case 'e': /* little endian float */ + case 'E': /* big endian float */ + { double v; - - memcpy(&v, &input[inputpos], sizeof(double)); + if (type == 'e') { + v = php_pack_parse_double(1, &input[inputpos]); + } else if (type == 'E') { + v = php_pack_parse_double(0, &input[inputpos]); + } else { + memcpy(&v, &input[inputpos], sizeof(double)); + } add_assoc_double(return_value, n, v); break; } diff --git a/ext/standard/tests/strings/pack_float.phpt b/ext/standard/tests/strings/pack_float.phpt new file mode 100644 index 0000000000..088b508bc0 --- /dev/null +++ b/ext/standard/tests/strings/pack_float.phpt @@ -0,0 +1,312 @@ +--TEST-- +pack()/unpack(): float/double tests +--FILE-- + +--EXPECTF-- +string(6) "pack e" +string(16) "0000000000000000" +string(16) "0000000000000000" +string(16) "0000000000000000" +string(16) "0000000000000000" +string(16) "0000000000000000" +string(16) "000000000000f03f" +string(16) "000000000000f03f" +string(16) "0080e03779c34143" +string(16) "4a6ade0d65ebe23f" +string(16) "e1639d31956ae543" +string(16) "000000000000f0bf" +string(16) "000000000000f0bf" +string(16) "0080e03779c341c3" +string(16) "4a6ade0d65ebe2bf" +string(16) "e1639d31956ae5c3" +string(6) "pack E" +string(16) "0000000000000000" +string(16) "0000000000000000" +string(16) "0000000000000000" +string(16) "0000000000000000" +string(16) "0000000000000000" +string(16) "3ff0000000000000" +string(16) "3ff0000000000000" +string(16) "4341c37937e08000" +string(16) "3fe2eb650dde6a4a" +string(16) "43e56a95319d63e1" +string(16) "bff0000000000000" +string(16) "bff0000000000000" +string(16) "c341c37937e08000" +string(16) "bfe2eb650dde6a4a" +string(16) "c3e56a95319d63e1" +string(6) "pack g" +string(8) "00000000" +string(8) "00000000" +string(8) "00000000" +string(8) "00000000" +string(8) "00000000" +string(8) "0000803f" +string(8) "0000803f" +string(8) "ca1b0e5a" +string(8) "285b173f" +string(8) "aa542b5f" +string(8) "000080bf" +string(8) "000080bf" +string(8) "ca1b0eda" +string(8) "285b17bf" +string(8) "aa542bdf" +string(6) "pack G" +string(8) "00000000" +string(8) "00000000" +string(8) "00000000" +string(8) "00000000" +string(8) "00000000" +string(8) "3f800000" +string(8) "3f800000" +string(8) "5a0e1bca" +string(8) "3f175b28" +string(8) "5f2b54aa" +string(8) "bf800000" +string(8) "bf800000" +string(8) "da0e1bca" +string(8) "bf175b28" +string(8) "df2b54aa" +string(8) "unpack e" +array(1) { + [1]=> + float(0) +} +array(1) { + [1]=> + float(1) +} +array(1) { + [1]=> + float(1.0E+16) +} +array(1) { + [1]=> + float(0.59123470982315) +} +array(1) { + [1]=> + float(-1) +} +array(1) { + [1]=> + float(-1.0E+16) +} +array(1) { + [1]=> + float(-0.59123470982315) +} +array(1) { + [1]=> + float(-1.2345678901235E+19) +} +string(8) "unpack E" +array(1) { + [1]=> + float(1) +} +array(1) { + [1]=> + float(1.0E+16) +} +array(1) { + [1]=> + float(0.59123470982315) +} +array(1) { + [1]=> + float(1.2345678901235E+19) +} +array(1) { + [1]=> + float(-1) +} +array(1) { + [1]=> + float(-1.0E+16) +} +array(1) { + [1]=> + float(-0.59123470982315) +} +array(1) { + [1]=> + float(-1.2345678901235E+19) +} +string(8) "unpack g" +array(1) { + [1]=> + float(1) +} +array(1) { + [1]=> + float(1.0000000272564E+16) +} +array(1) { + [1]=> + float(0.59123468399048) +} +array(1) { + [1]=> + float(1.2345679395506E+19) +} +array(1) { + [1]=> + float(-1) +} +array(1) { + [1]=> + float(-1.0000000272564E+16) +} +array(1) { + [1]=> + float(-0.59123468399048) +} +array(1) { + [1]=> + float(-1.2345679395506E+19) +} +string(8) "unpack G" +array(1) { + [1]=> + float(1) +} +array(1) { + [1]=> + float(1.0000000272564E+16) +} +array(1) { + [1]=> + float(0.59123468399048) +} +array(1) { + [1]=> + float(1.2345679395506E+19) +} +array(1) { + [1]=> + float(-1) +} +array(1) { + [1]=> + float(-1.0000000272564E+16) +} +array(1) { + [1]=> + float(-0.59123468399048) +} +array(1) { + [1]=> + float(-1.2345679395506E+19) +} diff --git a/ext/standard/tests/strings/unpack_error.phpt b/ext/standard/tests/strings/unpack_error.phpt index 1ef97ccbaf..75496512b7 100644 --- a/ext/standard/tests/strings/unpack_error.phpt +++ b/ext/standard/tests/strings/unpack_error.phpt @@ -19,7 +19,7 @@ var_dump(unpack("I", pack("I", 65534), $extra_arg)); echo "\n-- Testing unpack() function with invalid format character --\n"; $extra_arg = 10; -var_dump(unpack("G", pack("I", 65534))); +var_dump(unpack("B", pack("I", 65534))); ?> ===DONE=== --EXPECTF-- @@ -37,6 +37,6 @@ NULL -- Testing unpack() function with invalid format character -- -Warning: unpack(): Invalid format type G in %s on line %d +Warning: unpack(): Invalid format type B in %s on line %d bool(false) ===DONE=== -- cgit v1.2.1 From cfd6e1484283f9d693e457320e6a0d82422b9b33 Mon Sep 17 00:00:00 2001 From: Vince Date: Tue, 8 Nov 2016 14:23:04 -0800 Subject: Fix Bug #73462 - Persistent connections don't set $connect_errno Persistent connections skipped resetting $connect_error and $connect_errno values This adds the "clear error" line to persistent connections for consistency --- NEWS | 4 ++++ ext/mysqli/mysqli_nonapi.c | 4 ++++ ext/mysqli/tests/bug73462.phpt | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 ext/mysqli/tests/bug73462.phpt diff --git a/NEWS b/NEWS index 8711158387..26376b694d 100644 --- a/NEWS +++ b/NEWS @@ -17,6 +17,10 @@ PHP NEWS - DOM: . Fixed bug #67474 (getElementsByTagNameNS filter on default ns). (aboks) +- Mysqli: + . Fixed bug #73462 (Persistent connections don't set $connect_errno). + (darkain) + - Mysqlnd: . Fixed issue with decoding BIT columns when having more than one rows in the result set. 7.0+ problem. (Andrey) diff --git a/ext/mysqli/mysqli_nonapi.c b/ext/mysqli/mysqli_nonapi.c index 49db7bbfe6..1c25fafba3 100644 --- a/ext/mysqli/mysqli_nonapi.c +++ b/ext/mysqli/mysqli_nonapi.c @@ -183,6 +183,10 @@ void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_real_conne mysqlnd_restart_psession(mysql->mysql); #endif MyG(num_active_persistent)++; + + /* clear error */ + php_mysqli_set_error(mysql_errno(mysql->mysql), (char *) mysql_error(mysql->mysql)); + goto end; } else { mysqli_close(mysql->mysql, MYSQLI_CLOSE_IMPLICIT); diff --git a/ext/mysqli/tests/bug73462.phpt b/ext/mysqli/tests/bug73462.phpt new file mode 100644 index 0000000000..6de73761f4 --- /dev/null +++ b/ext/mysqli/tests/bug73462.phpt @@ -0,0 +1,41 @@ +--TEST-- +Bug #73462 (Persistent connections don't set $connect_errno) +--SKIPIF-- + +--FILE-- +query("SHOW STATUS LIKE 'Connections'"); + $c1 = $result->fetch_row(); + $result->free(); + $mysql_1->close(); + + /* Failed connection to invalid host */ + $mysql_2 = @new mysqli(' !!! invalid !!! ', $user, $passwd, $db); + @$mysql_2->close(); + + /* Re-use persistent connection */ + $mysql_3 = new mysqli('p:'.$host, $user, $passwd, $db); + $error = mysqli_connect_errno(); + $result = $mysql_3->query("SHOW STATUS LIKE 'Connections'"); + $c3 = $result->fetch_row(); + $result->free(); + $mysql_3->close(); + + if (end($c1) !== end($c3)) + printf("[001] Expected '%d' got '%d'.\n", end($c1), end($c3)); + + if ($error !== 0) + printf("[002] Expected '0' got '%d'.\n", $error); + + print "done!"; +?> +--EXPECTF-- +done! -- cgit v1.2.1 From b3889d4b20aaec16ceb89fe64e42de7c464e20e1 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 3 Jan 2017 12:16:35 +0100 Subject: Fix build --- ext/standard/pack.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/standard/pack.c b/ext/standard/pack.c index 1184717993..34d3139863 100644 --- a/ext/standard/pack.c +++ b/ext/standard/pack.c @@ -106,7 +106,7 @@ static void php_pack(zval *val, size_t size, int *map, char *output) /* {{{ php_pack_reverse_int32 */ -inline uint32_t php_pack_reverse_int32(uint32_t arg) +static inline uint32_t php_pack_reverse_int32(uint32_t arg) { uint32_t result; result = ((arg & 0xFF) << 24) | ((arg & 0xFF00) << 8) | ((arg >> 8) & 0xFF00) | ((arg >> 24) & 0xFF); @@ -117,7 +117,7 @@ inline uint32_t php_pack_reverse_int32(uint32_t arg) /* {{{ php_pack */ -inline uint64_t php_pack_reverse_int64(uint64_t arg) +static inline uint64_t php_pack_reverse_int64(uint64_t arg) { union Swap64 { uint64_t i; -- cgit v1.2.1