Skip to content

Commit a92af01

Browse files
committed
Merge remote-tracking branch 'upstream/master' into upstream/split_randomizer_method
2 parents ad4be80 + 395b6a9 commit a92af01

File tree

75 files changed

+2224
-480
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+2224
-480
lines changed

.github/actions/verify-generated-files/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ runs:
1212
build/gen_stub.php -f
1313
build/gen_stub.php --generate-optimizer-info
1414
ext/tokenizer/tokenizer_data_gen.php
15-
git add . -Nu && git diff --exit-code
15+
git add . -N && git diff --exit-code

EXTENSIONS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ STATUS: Working
427427
SINCE: 4.0.2
428428
-------------------------------------------------------------------------------
429429
EXTENSION: random
430-
PRIMARY MAINTAINER Go Kudo <zeriyoshi@gmail.com> (2022 - 2022)
430+
PRIMARY MAINTAINER Go Kudo <zeriyoshi@php.net> (2022 - 2022)
431431
Tim Düsterhus <timwolla@php.net> (2022 - 2022)
432432
MAINTENANCE: Maintained
433433
STATUS: Working

NEWS

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,24 @@ PHP NEWS
55
- Date:
66
. Fixed bug GH-8730 (DateTime::diff miscalculation is same time zone of
77
different type). (Derick)
8+
. Fixed bug GH-8964 (DateTime object comparison after applying delta less
9+
than 1 second). (Derick)
10+
. Fixed bug #75035 (Datetime fails to unserialize "extreme" dates).
11+
(Derick)
12+
. Fixed bug #80483 (DateTime Object with 5-digit year can't unserialized).
13+
(Derick)
814
. Fixed bug #81263 (Wrong result from DateTimeImmutable::diff). (Derick)
915

1016
- DBA:
1117
. Fixed LMDB driver memory leak on DB creation failure (Girgias)
1218

1319
- Random:
1420
. Fixed bug GH-9067 (random extension is not thread safe). (cmb)
21+
. Fixed bug GH-9055 (segmentation fault if user engine throws). (timwolla)
22+
. Fixed bug GH-9066 (signed integer overflow). (zeriyoshi)
23+
. Fixed bug GH-9083 (undefined behavior during shifting). (timwolla)
24+
. Fixed bug GH-9088, GH-9056 (incorrect expansion of bytes when
25+
generating uniform integers within a given range). (timwolla)
1526

1627
21 Jul 2022, PHP 8.2.0beta1
1728

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
Multiple calls to constructor are prevented after fiber terminated
3+
--FILE--
4+
<?php
5+
6+
$fiber = new Fiber(function () {
7+
return 123;
8+
});
9+
10+
var_dump($fiber->start());
11+
var_dump($fiber->getReturn());
12+
13+
$fiber->__construct(function () {
14+
return 321;
15+
});
16+
17+
?>
18+
--EXPECTF--
19+
NULL
20+
int(123)
21+
22+
Fatal error: Uncaught FiberError: Cannot call constructor twice in %scall-to-ctor-of-terminated-fiber.php:%d
23+
Stack trace:
24+
#0 %scall-to-ctor-of-terminated-fiber.php(%d): Fiber->__construct(Object(Closure))
25+
#1 {main}
26+
thrown in %scall-to-ctor-of-terminated-fiber.php on line %d
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
Multiple calls to constructor are prevented
3+
--FILE--
4+
<?php
5+
6+
$fiber = new Fiber(function () {
7+
return 123;
8+
});
9+
10+
$fiber->__construct(function () {
11+
return 321;
12+
});
13+
14+
?>
15+
--EXPECTF--
16+
Fatal error: Uncaught FiberError: Cannot call constructor twice in %smultiple-calls-to-ctor.php:%d
17+
Stack trace:
18+
#0 %smultiple-calls-to-ctor.php(%d): Fiber->__construct(Object(Closure))
19+
#1 {main}
20+
thrown in %smultiple-calls-to-ctor.php on line %d

Zend/tests/type_declarations/typed_properties_095.phpt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Typed properties in internal classes
33
--EXTENSIONS--
44
zend_test
5+
spl
56
--FILE--
67
<?php
78

@@ -70,6 +71,8 @@ object(_ZendTestClass)#1 (3) {
7071
}
7172
["classUnionProp"]=>
7273
NULL
74+
["classIntersectionProp"]=>
75+
uninitialized(Traversable&Countable)
7376
["readonlyProp"]=>
7477
uninitialized(int)
7578
}
@@ -84,6 +87,8 @@ object(Test)#4 (3) {
8487
}
8588
["classUnionProp"]=>
8689
NULL
90+
["classIntersectionProp"]=>
91+
uninitialized(Traversable&Countable)
8792
["readonlyProp"]=>
8893
uninitialized(int)
8994
}

Zend/zend_fibers.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -647,12 +647,23 @@ static HashTable *zend_fiber_object_gc(zend_object *object, zval **table, int *n
647647

648648
ZEND_METHOD(Fiber, __construct)
649649
{
650-
zend_fiber *fiber = (zend_fiber *) Z_OBJ_P(ZEND_THIS);
650+
zend_fcall_info fci;
651+
zend_fcall_info_cache fcc;
651652

652653
ZEND_PARSE_PARAMETERS_START(1, 1)
653-
Z_PARAM_FUNC(fiber->fci, fiber->fci_cache)
654+
Z_PARAM_FUNC(fci, fcc)
654655
ZEND_PARSE_PARAMETERS_END();
655656

657+
zend_fiber *fiber = (zend_fiber *) Z_OBJ_P(ZEND_THIS);
658+
659+
if (UNEXPECTED(fiber->context.status != ZEND_FIBER_STATUS_INIT || Z_TYPE(fiber->fci.function_name) != IS_UNDEF)) {
660+
zend_throw_error(zend_ce_fiber_error, "Cannot call constructor twice");
661+
RETURN_THROWS();
662+
}
663+
664+
fiber->fci = fci;
665+
fiber->fci_cache = fcc;
666+
656667
// Keep a reference to closures or callable objects while the fiber is running.
657668
Z_TRY_ADDREF(fiber->fci.function_name);
658669
}

Zend/zend_types.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,9 @@ typedef struct {
280280
#define ZEND_TYPE_INIT_UNION(ptr, extra_flags) \
281281
{ (void *) (ptr), (_ZEND_TYPE_LIST_BIT|_ZEND_TYPE_UNION_BIT) | (extra_flags) }
282282

283+
#define ZEND_TYPE_INIT_INTERSECTION(ptr, extra_flags) \
284+
{ (void *) (ptr), (_ZEND_TYPE_LIST_BIT|_ZEND_TYPE_INTERSECTION_BIT) | (extra_flags) }
285+
283286
#define ZEND_TYPE_INIT_CLASS(class_name, allow_null, extra_flags) \
284287
ZEND_TYPE_INIT_PTR(class_name, _ZEND_TYPE_NAME_BIT, allow_null, extra_flags)
285288

azure-pipelines.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ jobs:
4444
parameters:
4545
configurationName: I386_RELEASE_ZTS
4646
configurationParameters: '--disable-debug --enable-zts'
47+
- template: azure/msan_job.yml
48+
parameters:
49+
configurationName: DEBUG_ZTS_MSAN
50+
configurationParameters: '--enable-debug --enable-zts'
51+
runTestsParameters: --msan
52+
timeoutInMinutes: 90
4753
- template: azure/community_job.yml
4854
parameters:
4955
configurationName: COMMUNITY

build/gen_stub.php

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use PhpParser\PrettyPrinterAbstract;
1616

1717
error_reporting(E_ALL);
18-
ini_set("precision", "17");
18+
ini_set("precision", "-1");
1919

2020
const PHP_70_VERSION_ID = 70000;
2121
const PHP_80_VERSION_ID = 80000;
@@ -548,23 +548,26 @@ public function equals(SimpleType $other): bool {
548548
class Type {
549549
/** @var SimpleType[] */
550550
public $types;
551+
/** @var bool */
552+
public $isIntersection = false;
551553

552554
public static function fromNode(Node $node): Type {
553-
if ($node instanceof Node\UnionType) {
555+
if ($node instanceof Node\UnionType || $node instanceof Node\IntersectionType) {
554556
$nestedTypeObjects = array_map(['Type', 'fromNode'], $node->types);
555557
$types = [];
556558
foreach ($nestedTypeObjects as $typeObject) {
557559
array_push($types, ...$typeObject->types);
558560
}
559-
return new Type($types);
561+
return new Type($types, ($node instanceof Node\IntersectionType));
560562
}
561563

562564
if ($node instanceof Node\NullableType) {
563565
return new Type(
564566
[
565567
...Type::fromNode($node->type)->types,
566568
SimpleType::null(),
567-
]
569+
],
570+
false
568571
);
569572
}
570573

@@ -573,18 +576,20 @@ public static function fromNode(Node $node): Type {
573576
[
574577
SimpleType::fromString("Traversable"),
575578
ArrayType::createGenericArray(),
576-
]
579+
],
580+
false
577581
);
578582
}
579583

580-
return new Type([SimpleType::fromNode($node)]);
584+
return new Type([SimpleType::fromNode($node)], false);
581585
}
582586

583587
public static function fromString(string $typeString): self {
584588
$typeString .= "|";
585589
$simpleTypes = [];
586590
$simpleTypeOffset = 0;
587591
$inArray = false;
592+
$isIntersection = false;
588593

589594
$typeStringLength = strlen($typeString);
590595
for ($i = 0; $i < $typeStringLength; $i++) {
@@ -604,7 +609,8 @@ public static function fromString(string $typeString): self {
604609
continue;
605610
}
606611

607-
if ($char === "|") {
612+
if ($char === "|" || $char === "&") {
613+
$isIntersection = ($char === "&");
608614
$simpleTypeName = trim(substr($typeString, $simpleTypeOffset, $i - $simpleTypeOffset));
609615

610616
$simpleTypes[] = SimpleType::fromString($simpleTypeName);
@@ -613,14 +619,15 @@ public static function fromString(string $typeString): self {
613619
}
614620
}
615621

616-
return new Type($simpleTypes);
622+
return new Type($simpleTypes, $isIntersection);
617623
}
618624

619625
/**
620626
* @param SimpleType[] $types
621627
*/
622-
private function __construct(array $types) {
628+
private function __construct(array $types, bool $isIntersection) {
623629
$this->types = $types;
630+
$this->isIntersection = $isIntersection;
624631
}
625632

626633
public function isScalar(): bool {
@@ -650,7 +657,8 @@ public function getWithoutNull(): Type {
650657
function(SimpleType $type) {
651658
return !$type->isNull();
652659
}
653-
)
660+
),
661+
false
654662
);
655663
}
656664

@@ -683,6 +691,7 @@ public function toOptimizerTypeMask(): string {
683691
$optimizerTypes = [];
684692

685693
foreach ($this->types as $type) {
694+
// TODO Support for toOptimizerMask for intersection
686695
$optimizerTypes[] = $type->toOptimizerTypeMask();
687696
}
688697

@@ -711,8 +720,9 @@ public function toOptimizerTypeMaskForArrayValue(): string {
711720

712721
public function getTypeForDoc(DOMDocument $doc): DOMElement {
713722
if (count($this->types) > 1) {
723+
$typeSort = $this->isIntersection ? "intersection" : "union";
714724
$typeElement = $doc->createElement('type');
715-
$typeElement->setAttribute("class", "union");
725+
$typeElement->setAttribute("class", $typeSort);
716726

717727
foreach ($this->types as $type) {
718728
$unionTypeElement = $doc->createElement('type', $type->name);
@@ -755,7 +765,8 @@ public function __toString() {
755765
return 'mixed';
756766
}
757767

758-
return implode('|', array_map(
768+
$char = $this->isIntersection ? '&' : '|';
769+
return implode($char, array_map(
759770
function ($type) { return $type->name; },
760771
$this->types)
761772
);
@@ -2237,7 +2248,11 @@ public function getDeclaration(iterable $allConstInfos): string {
22372248

22382249
$typeMaskCode = $this->type->toArginfoType()->toTypeMask();
22392250

2240-
$code .= "\tzend_type property_{$propertyName}_type = ZEND_TYPE_INIT_UNION(property_{$propertyName}_type_list, $typeMaskCode);\n";
2251+
if ($this->type->isIntersection) {
2252+
$code .= "\tzend_type property_{$propertyName}_type = ZEND_TYPE_INIT_INTERSECTION(property_{$propertyName}_type_list, $typeMaskCode);\n";
2253+
} else {
2254+
$code .= "\tzend_type property_{$propertyName}_type = ZEND_TYPE_INIT_UNION(property_{$propertyName}_type_list, $typeMaskCode);\n";
2255+
}
22412256
$typeCode = "property_{$propertyName}_type";
22422257
} else {
22432258
$escapedClassName = $arginfoType->classTypes[0]->toEscapedName();

ext/date/lib/interval.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -405,12 +405,21 @@ timelib_time *timelib_sub_wall(timelib_time *old_time, timelib_rel_time *interva
405405
timelib_update_ts(t, NULL);
406406
}
407407

408-
do_range_limit(0, 1000000, 1000000, &interval->us, &interval->s);
409-
t->sse -= bias * timelib_hms_to_seconds(interval->h, interval->i, interval->s);
410-
timelib_update_from_sse(t);
411-
t->us -= interval->us * bias;
412-
if (bias == -1 && interval->us > 0) {
413-
t->sse++;
408+
if (interval->us == 0) {
409+
t->sse -= bias * timelib_hms_to_seconds(interval->h, interval->i, interval->s);
410+
timelib_update_from_sse(t);
411+
} else {
412+
timelib_rel_time *temp_interval = timelib_rel_time_clone(interval);
413+
414+
do_range_limit(0, 1000000, 1000000, &temp_interval->us, &temp_interval->s);
415+
t->sse -= bias * timelib_hms_to_seconds(temp_interval->h, temp_interval->i, temp_interval->s);
416+
timelib_update_from_sse(t);
417+
t->us -= temp_interval->us * bias;
418+
419+
timelib_do_normalize(t);
420+
timelib_update_ts(t, NULL);
421+
422+
timelib_rel_time_dtor(temp_interval);
414423
}
415424
timelib_do_normalize(t);
416425
}

ext/date/lib/parse_date.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Generated by re2c 0.15.3 on Sun Jun 26 17:34:01 2022 */
1+
/* Generated by re2c 0.15.3 on Fri Jul 22 15:29:55 2022 */
22
#line 1 "ext/date/lib/parse_date.re"
33
/*
44
* The MIT License (MIT)
@@ -26004,7 +26004,7 @@ timelib_time *timelib_strtotime(const char *s, size_t len, timelib_error_contain
2600426004
add_pbf_error(s, TIMELIB_ERR_UNEXPECTED_DATA, "Unexpected data found.", string, begin); \
2600526005
}
2600626006
#define TIMELIB_CHECK_SIGNED_NUMBER \
26007-
if (strchr("-0123456789", *ptr) == NULL) \
26007+
if (strchr("+-0123456789", *ptr) == NULL) \
2600826008
{ \
2600926009
add_pbf_error(s, TIMELIB_ERR_UNEXPECTED_DATA, "Unexpected data found.", string, begin); \
2601026010
}
@@ -26079,6 +26079,8 @@ static const timelib_format_specifier default_format_map[] = {
2607926079
{' ', TIMELIB_FORMAT_WHITESPACE},
2608026080
{'y', TIMELIB_FORMAT_YEAR_TWO_DIGIT},
2608126081
{'Y', TIMELIB_FORMAT_YEAR_FOUR_DIGIT},
26082+
{'x', TIMELIB_FORMAT_YEAR_EXPANDED},
26083+
{'X', TIMELIB_FORMAT_YEAR_EXPANDED},
2608226084
{'\0', TIMELIB_FORMAT_END}
2608326085
};
2608426086

@@ -26265,6 +26267,15 @@ timelib_time *timelib_parse_from_format_with_map(const char *format, const char
2626526267
break;
2626626268
}
2626726269

26270+
s->time->have_date = 1;
26271+
break;
26272+
case TIMELIB_FORMAT_YEAR_EXPANDED: /* optional symbol, followed by up to 19 digits */
26273+
TIMELIB_CHECK_SIGNED_NUMBER;
26274+
if ((s->time->y = timelib_get_signed_nr(s, &ptr, 19)) == TIMELIB_UNSET) {
26275+
add_pbf_error(s, TIMELIB_ERR_NO_FOUR_DIGIT_YEAR, "An expanded digit year could not be found", string, begin);
26276+
break;
26277+
}
26278+
2626826279
s->time->have_date = 1;
2626926280
break;
2627026281
case TIMELIB_FORMAT_HOUR_TWO_DIGIT_12_MAX: /* two digit hour, without leading zero */

0 commit comments

Comments
 (0)