Skip to content

Commit 4f70713

Browse files
committed
Convert some SPL Exceptions to normal Errors in spl_dllist.c
1 parent 99b3efb commit 4f70713

12 files changed

+68
-83
lines changed

ext/spl/spl_dllist.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ SPL_METHOD(SplDoublyLinkedList, offsetGet)
782782
index = spl_offset_convert_to_long(zindex);
783783

784784
if (index < 0 || index >= intern->llist->count) {
785-
zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid or out of range", 0);
785+
zend_value_error("Offset invalid or out of range");
786786
RETURN_THROWS();
787787
}
788788

@@ -793,7 +793,8 @@ SPL_METHOD(SplDoublyLinkedList, offsetGet)
793793

794794
ZVAL_COPY_DEREF(return_value, value);
795795
} else {
796-
zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid", 0);
796+
zend_value_error("Offset invalid");
797+
RETURN_THROWS();
797798
}
798799
} /* }}} */
799800

@@ -821,7 +822,7 @@ SPL_METHOD(SplDoublyLinkedList, offsetSet)
821822
index = spl_offset_convert_to_long(zindex);
822823

823824
if (index < 0 || index >= intern->llist->count) {
824-
zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid or out of range", 0);
825+
zend_value_error("Offset invalid or out of range");
825826
RETURN_THROWS();
826827
}
827828

@@ -844,7 +845,7 @@ SPL_METHOD(SplDoublyLinkedList, offsetSet)
844845
}
845846
} else {
846847
zval_ptr_dtor(value);
847-
zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid", 0);
848+
zend_value_error("Offset invalid");
848849
RETURN_THROWS();
849850
}
850851
}
@@ -869,7 +870,7 @@ SPL_METHOD(SplDoublyLinkedList, offsetUnset)
869870
llist = intern->llist;
870871

871872
if (index < 0 || index >= intern->llist->count) {
872-
zend_throw_exception(spl_ce_OutOfRangeException, "Offset out of range", 0);
873+
zend_value_error("Offset out of range");
873874
RETURN_THROWS();
874875
}
875876

@@ -910,7 +911,7 @@ SPL_METHOD(SplDoublyLinkedList, offsetUnset)
910911

911912
SPL_LLIST_DELREF(element);
912913
} else {
913-
zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid", 0);
914+
zend_value_error("Offset invalid");
914915
RETURN_THROWS();
915916
}
916917
} /* }}} */
@@ -1296,7 +1297,7 @@ SPL_METHOD(SplDoublyLinkedList, add)
12961297
index = spl_offset_convert_to_long(zindex);
12971298

12981299
if (index < 0 || index > intern->llist->count) {
1299-
zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid or out of range", 0);
1300+
zend_value_error("Offset invalid or out of range");
13001301
RETURN_THROWS();
13011302
}
13021303

ext/spl/tests/SplDoublyLinkedList_add_invalid_offset.phpt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ Check that SplDoublyLinkedList::add throws an exception with an invalid offset a
33
--FILE--
44
<?php
55
try {
6-
$dll = new SplDoublyLinkedList();
7-
var_dump($dll->add(12,'Offset 12 should not exist'));
8-
} catch (OutOfRangeException $e) {
9-
echo "Exception: ".$e->getMessage()."\n";
6+
$dll = new SplDoublyLinkedList();
7+
var_dump($dll->add(12,'Offset 12 should not exist'));
8+
} catch (\ValueError $e) {
9+
echo $e->getMessage()."\n";
1010
}
1111
?>
1212
--EXPECT--
13-
Exception: Offset invalid or out of range
13+
Offset invalid or out of range

ext/spl/tests/SplDoublyLinkedList_add_null_offset.phpt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ Check that SplDoublyLinkedList::add throws an exception with an invalid offset a
33
--FILE--
44
<?php
55
try {
6-
$dll = new SplDoublyLinkedList();
7-
var_dump($dll->add(NULL,2));
8-
} catch (OutOfRangeException $e) {
9-
echo "Exception: ".$e->getMessage()."\n";
6+
$dll = new SplDoublyLinkedList();
7+
var_dump($dll->add(NULL,2));
8+
} catch (\ValueError $e) {
9+
echo $e->getMessage()."\n";
1010
}
1111
?>
1212
--EXPECT--
13-
Exception: Offset invalid or out of range
13+
Offset invalid or out of range

ext/spl/tests/SplDoublyLinkedList_offsetGet_param_array.phpt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ PHPNW Test Fest 2009 - Jordan Hatch
77

88
$array = new SplDoublyLinkedList( );
99

10-
$get = $array->offsetGet( array( 'fail' ) );
10+
try {
11+
$array->offsetGet( array( 'fail' ) );
12+
} catch(\ValueError $e) {
13+
echo $e->getMessage();
14+
}
1115

1216
?>
13-
--EXPECTF--
14-
Fatal error: Uncaught OutOfRangeException: Offset invalid or out of range in %s
15-
Stack trace:
16-
#0 %s
17-
#1 {main}
18-
thrown in %s on line %d
17+
--EXPECT--
18+
Offset invalid or out of range

ext/spl/tests/SplDoublyLinkedList_offsetGet_param_string.phpt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ PHPNW Test Fest 2009 - Jordan Hatch
77

88
$array = new SplDoublyLinkedList( );
99

10-
$get = $array->offsetGet( 'fail' );
10+
try {
11+
$array->offsetGet( 'fail' );
12+
} catch(\ValueError $e) {
13+
echo $e->getMessage();
14+
}
1115

1216
?>
13-
--EXPECTF--
14-
Fatal error: Uncaught OutOfRangeException: Offset invalid or out of range in %s
15-
Stack trace:
16-
#0 %s
17-
#1 {main}
18-
thrown in %s on line %d
17+
--EXPECT--
18+
Offset invalid or out of range

ext/spl/tests/SplDoublyLinkedList_offsetUnset_greater_than_elements.phpt

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,10 @@ $ll->push('2');
1111
$ll->push('3');
1212

1313
try {
14-
15-
$ll->offsetUnset($ll->count() + 1);
16-
17-
var_dump($ll);
18-
19-
} catch(Exception $e) {
20-
echo $e->getMessage();
14+
$ll->offsetUnset($ll->count() + 1);
15+
var_dump($ll);
16+
} catch(\ValueError $e) {
17+
echo $e->getMessage();
2118
}
2219

2320
?>

ext/spl/tests/SplDoublyLinkedList_offsetUnset_negative-parameter.phpt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ PHPNW Testfest 2009 - Paul Court ( g@rgoyle.com )
1212
$dll->push(2);
1313
$dll->push(3);
1414

15-
try {
16-
$dll->offsetUnset(-1);
17-
}
18-
catch (Exception $e) {
19-
echo $e->getMessage() . "\n";
20-
}
15+
try {
16+
$dll->offsetUnset(-1);
17+
} catch (\ValueError $e) {
18+
echo $e->getMessage() . "\n";
19+
}
2120
?>
2221
--EXPECT--
2322
Offset out of range

ext/spl/tests/SplDoublyLinkedList_offsetUnset_parameter-larger-num-elements.phpt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ PHPNW Testfest 2009 - Paul Court ( g@rgoyle.com )
1212
$dll->push(2);
1313
$dll->push(3);
1414

15-
try {
16-
$dll->offsetUnset(3);
17-
}
18-
catch (Exception $e) {
19-
echo $e->getMessage() . "\n";
20-
}
15+
try {
16+
$dll->offsetUnset(3);
17+
} catch (\ValueError $e) {
18+
echo $e->getMessage() . "\n";
19+
}
2120
?>
2221
--EXPECT--
2322
Offset out of range

ext/spl/tests/bug46160.phpt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22
Bug #46160 (SPL - Memory leak when exception is throwed in offsetSet method)
33
--FILE--
44
<?php
5-
65
try {
7-
$x = new splqueue;
8-
$x->offsetSet(0, 0);
9-
} catch (Exception $e) { }
10-
6+
$x = new splqueue;
7+
$x->offsetSet(0, 0);
8+
} catch (\ValueError $e) {
9+
echo $e->getMessage()."\n";
10+
}
1111
?>
12-
DONE
1312
--EXPECT--
14-
DONE
13+
Offset invalid or out of range

ext/spl/tests/bug71735.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ Bug #71735 (Double-free in SplDoublyLinkedList::offsetSet)
33
--FILE--
44
<?php
55
try {
6-
$var_1=new SplStack();
7-
$var_1->offsetSet(100,new DateTime('2000-01-01'));
8-
} catch(OutOfRangeException $e) {
9-
print $e->getMessage()."\n";
6+
$var_1=new SplStack();
7+
$var_1->offsetSet(100,new DateTime('2000-01-01'));
8+
} catch(\ValueError $e) {
9+
print $e->getMessage()."\n";
1010
}
1111
?>
1212
--EXPECT--

ext/spl/tests/dllist_006.phpt

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,20 @@ echo "Unsetting..\n";
1919
var_dump($a[2]);
2020
unset($a[2]);
2121
var_dump($a[2]);
22-
23-
24-
try {
25-
var_dump($a["1"]);
26-
} catch (OutOfRangeException $e) {
27-
echo "Exception: ".$e->getMessage()."\n";
28-
}
22+
var_dump($a["1"]);
2923

3024
try {
3125
var_dump($a["a"]);
32-
} catch (OutOfRangeException $e) {
33-
echo "Exception: ".$e->getMessage()."\n";
26+
} catch (\ValueError $e) {
27+
echo $e->getMessage()."\n";
3428
}
3529

36-
try {
37-
var_dump($a["0"]);
38-
} catch (OutOfRangeException $e) {
39-
echo "Exception: ".$e->getMessage()."\n";
40-
}
30+
var_dump($a["0"]);
4131

4232
try {
4333
var_dump($a["9"]);
44-
} catch (OutOfRangeException $e) {
45-
echo "Exception: ".$e->getMessage()."\n";
34+
} catch (\ValueError $e) {
35+
echo $e->getMessage()."\n";
4636
}
4737
?>
4838
--EXPECT--
@@ -54,6 +44,6 @@ Unsetting..
5444
int(3)
5545
int(4)
5646
int(2)
57-
Exception: Offset invalid or out of range
47+
Offset invalid or out of range
5848
int(1)
59-
Exception: Offset invalid or out of range
49+
Offset invalid or out of range

ext/spl/tests/dllist_013.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ SPL: DoublyLinkedList: insert operations
55
$dll = new SplDoublyLinkedList();
66
// errors
77
try {
8-
$dll->add(2,5);
9-
} catch (OutOfRangeException $e) {
10-
echo "Exception: ".$e->getMessage()."\n";
8+
$dll->add(2,5);
9+
} catch (\ValueError $e) {
10+
echo $e->getMessage()."\n";
1111
}
1212

1313
$dll->add(0,6); // 6
@@ -31,7 +31,7 @@ echo $dll->pop()."\n";
3131
echo $dll->pop()."\n";
3232
?>
3333
--EXPECT--
34-
Exception: Offset invalid or out of range
34+
Offset invalid or out of range
3535
7
3636
7
3737
6

0 commit comments

Comments
 (0)