Skip to content

Commit 930ce56

Browse files
committed
Merge branch 'pull-request/54' into php7
* pull-request/54: Use serialize_precision when encoding double values yaml_parse_file_002.phpt: Fix expectations for PHP 8.0.0beta1 test-all.sh: Exclude PHP 7.0.x
2 parents 334613b + 0503632 commit 930ce56

13 files changed

+108
-36
lines changed

dev-tools/test-all.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
rm .rbenv-version 2>/dev/null
44

5-
VERSIONS=$(phpenv versions --bare | grep -E '^(7|8|master)')
5+
VERSIONS=$(phpenv versions --bare | grep -E '^(7.[^0]|8|master)' | sort -V)
66
SCRIPT_DIR=$(dirname $0)
77

88
for v in $VERSIONS; do

emit.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -387,22 +387,20 @@ static int y_write_double(
387387
yaml_event_t event;
388388
int omit_tag = 0;
389389
int status;
390-
char *res = { 0 };
391-
size_t res_size;
390+
char res[PHP_DOUBLE_MAX_LENGTH];
392391

393392
if (NULL == tag) {
394393
tag = (yaml_char_t *) YAML_FLOAT_TAG;
395394
omit_tag = 1;
396395
}
397396

398-
res_size = snprintf(res, 0, "%f", Z_DVAL_P(data));
399-
res = (char*) emalloc(res_size + 1);
400-
snprintf(res, res_size + 1, "%f", Z_DVAL_P(data));
397+
// Bug 79866: let PHP determine output precision
398+
php_gcvt(Z_DVAL_P(data), (int)PG(serialize_precision), '.', 'E', res);
401399

402400
status = yaml_scalar_event_initialize(&event, NULL, tag,
403401
(yaml_char_t *) res, strlen(res),
404402
omit_tag, omit_tag, YAML_PLAIN_SCALAR_STYLE);
405-
efree(res);
403+
406404
if (!status) {
407405
y_event_init_failed(&event);
408406
return FAILURE;

package.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
<license uri="http://www.opensource.org/licenses/mit-license.php">MIT</license>
3333
<notes>
3434
Bugs Fixed:
35+
- #79866 Use serialize_precision when encoding double values (bd808)
36+
- yaml_parse_file_002.phpt: Fix expectations for PHP 8.0.0beta1 (bd808)
3537
- Remove use of call_user_function_ex() for compat with PHP 8.0.0a2 (andypost)
3638
- Adjust test values for compat with 32bit platforms (bd808)
3739
- Fix memory leaks (cmb69)
@@ -73,6 +75,7 @@
7375
<file role="test" name="bug_77720.phpt" />
7476
<file role="test" name="bug_79494.phpt" />
7577
<file role="test" name="bug_79567.phpt" />
78+
<file role="test" name="bug_79866.phpt" />
7679
<file role="test" name="bug_parsing_alias.phpt" />
7780
<file role="test" name="yaml_001.phpt" />
7881
<file role="test" name="yaml_002.phpt" />

tests/bug_61923.phpt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Test PECL bug #61923
33
--SKIPIF--
44
<?php if(!extension_loaded('yaml')) die('skip yaml n/a'); ?>
5+
--INI--
6+
serialize_precision=-1
57
--FILE--
68
<?php
79
$yaml_code = <<<YAML
@@ -71,7 +73,7 @@ array(2) {
7173
float(67997.00037)
7274
}
7375
}
74-
string(162) "---
76+
string(161) "---
7577
strings:
7678
- "1:0"
7779
- "0:1"
@@ -89,6 +91,6 @@ numbers:
8991
- -3600
9092
- 1
9193
- 1
92-
- 67997.000370
94+
- 67997.00037
9395
...
9496
"

tests/bug_76309.phpt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Test PECL bug #76309
33
--SKIPIF--
44
<?php if(!extension_loaded('yaml')) die('skip yaml n/a'); ?>
5+
--INI--
6+
serialize_precision=-1
57
--FILE--
68
<?php
79
echo yaml_emit([
@@ -20,7 +22,7 @@ a: "1.0"
2022
b: "2."
2123
c: "3"
2224
d: .
23-
e: 1.000000
24-
f: 2.000000
25+
e: 1
26+
f: 2
2527
g: 3
2628
...

tests/bug_79494.phpt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Test PECL bug #74949
33
--SKIPIF--
44
<?php if(!extension_loaded('yaml')) die('skip yaml n/a'); ?>
5+
--INI--
6+
serialize_precision=-1
57
--FILE--
68
<?php
79
$data = array (
@@ -26,9 +28,9 @@ print yaml_emit($data);
2628
---
2729
audio:
2830
audioEnabled:
29-
- 13231778%s
31+
- %r(132317787432502136|1\.3231778743250214E\+17)%r
3032
- 0
3133
eveampGain:
32-
- 13231683%s
33-
- 0.250000
34+
- %r(132316833510704299|1\.323168335107043E\+17)%r
35+
- 0.25
3436
...

tests/bug_79866.phpt

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
--TEST--
2+
Test PECL bug #79866
3+
--SKIPIF--
4+
<?php if(!extension_loaded('yaml')) die('skip yaml n/a'); ?>
5+
--INI--
6+
precision=14
7+
serialize_precision=-1
8+
--FILE--
9+
<?php
10+
$floats = [
11+
"0" => 0,
12+
"1" => 1,
13+
"-1" => -1,
14+
"2." => 2.,
15+
"2.0" => 2.0,
16+
"2.00" => 2.00,
17+
"2.000" => 2.000,
18+
"0.123456789" => 0.123456789,
19+
"-0.123456789" => -0.123456789,
20+
"2.3e6" => 2.3e6,
21+
"-2.3e6" => -2.3e6,
22+
"2.3e-6" => 2.3e-6,
23+
"-2.3e-6" => -2.3e-6,
24+
"INF" => INF,
25+
"NAN" => NAN,
26+
"0.000021" => 0.000021,
27+
];
28+
29+
foreach( $floats as $idx => $float ) {
30+
$float = floatval($float);
31+
ob_start();
32+
echo $float;
33+
$native = ob_get_clean();
34+
35+
$expect = "--- {$native}\n...\n";
36+
$got = yaml_emit($float);
37+
if ( $got !== $expect ) {
38+
echo "== FAIL! ${idx} ==\n";
39+
echo "expected:\n{$expect}\n";
40+
echo "got:{$got}\n";
41+
}
42+
}
43+
?>
44+
--EXPECT--

tests/yaml_emit_001.phpt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
yaml_emit - scalars
33
--SKIPIF--
44
<?php if(!extension_loaded('yaml')) die('skip yaml n/a'); ?>
5+
--INI--
6+
serialize_precision=-1
57
--FILE--
68
<?php
79
var_dump(yaml_emit(null));
@@ -57,10 +59,10 @@ string(11) "--- 10
5759
string(12) "--- -10
5860
...
5961
"
60-
string(19) "--- 123.456000
62+
string(16) "--- 123.456
6163
...
6264
"
63-
string(20) "--- -123.456000
65+
string(17) "--- -123.456
6466
...
6567
"
6668
string(14) "--- "yes"

tests/yaml_emit_002.phpt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
yaml_emit - sequences
33
--SKIPIF--
44
<?php if(!extension_loaded('yaml')) die('skip yaml n/a'); ?>
5+
--INI--
6+
serialize_precision=-1
57
--FILE--
68
<?php
79
$str = <<<EOD
@@ -65,14 +67,14 @@ var_dump(yaml_emit(array()));
6567
?>
6668
--EXPECT--
6769
=== Array of scalars ===
68-
string(610) "---
70+
string(604) "---
6971
- ~
7072
- true
7173
- false
7274
- 10
7375
- -10
74-
- 123.456000
75-
- -123.456000
76+
- 123.456
77+
- -123.456
7678
- "yes"
7779
- "no"
7880
- "~"

tests/yaml_emit_003.phpt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
yaml_emit - mappings
33
--SKIPIF--
44
<?php if(!extension_loaded('yaml')) die('skip yaml n/a'); ?>
5+
--INI--
6+
serialize_precision=-1
57
--FILE--
68
<?php
79
$addr = array(
@@ -41,7 +43,7 @@ $invoice = array (
4143
var_dump(yaml_emit($invoice));
4244
?>
4345
--EXPECT--
44-
string(628) "---
46+
string(620) "---
4547
invoice: 34843
4648
date: 980208000
4749
bill-to:
@@ -73,8 +75,8 @@ product:
7375
quantity: 1
7476
description: Super Hoop
7577
price: 2392
76-
tax: 251.420000
77-
total: 4443.520000
78+
tax: 251.42
79+
total: 4443.52
7880
comments: Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.
7981
...
8082
"

0 commit comments

Comments
 (0)