Skip to content

Commit a5dde61

Browse files
committed
Convert some SPL Exceptions to normal Errors in spl_dllist.c
1 parent a06a94c commit a5dde61

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
@@ -778,7 +778,7 @@ SPL_METHOD(SplDoublyLinkedList, offsetGet)
778778
index = spl_offset_convert_to_long(zindex);
779779

780780
if (index < 0 || index >= intern->llist->count) {
781-
zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid or out of range", 0);
781+
zend_value_error("Offset invalid or out of range");
782782
RETURN_THROWS();
783783
}
784784

@@ -789,7 +789,8 @@ SPL_METHOD(SplDoublyLinkedList, offsetGet)
789789

790790
ZVAL_COPY_DEREF(return_value, value);
791791
} else {
792-
zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid", 0);
792+
zend_value_error("Offset invalid");
793+
RETURN_THROWS();
793794
}
794795
} /* }}} */
795796

@@ -817,7 +818,7 @@ SPL_METHOD(SplDoublyLinkedList, offsetSet)
817818
index = spl_offset_convert_to_long(zindex);
818819

819820
if (index < 0 || index >= intern->llist->count) {
820-
zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid or out of range", 0);
821+
zend_value_error("Offset invalid or out of range");
821822
RETURN_THROWS();
822823
}
823824

@@ -840,7 +841,7 @@ SPL_METHOD(SplDoublyLinkedList, offsetSet)
840841
}
841842
} else {
842843
zval_ptr_dtor(value);
843-
zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid", 0);
844+
zend_value_error("Offset invalid");
844845
RETURN_THROWS();
845846
}
846847
}
@@ -865,7 +866,7 @@ SPL_METHOD(SplDoublyLinkedList, offsetUnset)
865866
llist = intern->llist;
866867

867868
if (index < 0 || index >= intern->llist->count) {
868-
zend_throw_exception(spl_ce_OutOfRangeException, "Offset out of range", 0);
869+
zend_value_error("Offset out of range");
869870
RETURN_THROWS();
870871
}
871872

@@ -906,7 +907,7 @@ SPL_METHOD(SplDoublyLinkedList, offsetUnset)
906907

907908
SPL_LLIST_DELREF(element);
908909
} else {
909-
zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid", 0);
910+
zend_value_error("Offset invalid");
910911
RETURN_THROWS();
911912
}
912913
} /* }}} */
@@ -1293,7 +1294,7 @@ SPL_METHOD(SplDoublyLinkedList, add)
12931294
index = spl_offset_convert_to_long(zindex);
12941295

12951296
if (index < 0 || index > intern->llist->count) {
1296-
zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid or out of range", 0);
1297+
zend_value_error("Offset invalid or out of range");
12971298
RETURN_THROWS();
12981299
}
12991300

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)