Skip to content

Commit 22cafcb

Browse files
committed
Convert some SPL Exceptions to normal Errors in spl_dllist.c
1 parent 5bfb8a9 commit 22cafcb

14 files changed

+81
-95
lines changed

ext/spl/spl_dllist.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,7 @@ SPL_METHOD(SplDoublyLinkedList, offsetGet)
770770
spl_dllist_object *intern;
771771
spl_ptr_llist_element *element;
772772

773+
/* TODO Change this to int? */
773774
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &zindex) == FAILURE) {
774775
RETURN_THROWS();
775776
}
@@ -778,7 +779,7 @@ SPL_METHOD(SplDoublyLinkedList, offsetGet)
778779
index = spl_offset_convert_to_long(zindex);
779780

780781
if (index < 0 || index >= intern->llist->count) {
781-
zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid or out of range", 0);
782+
zend_argument_value_error(1, "is out of range");
782783
RETURN_THROWS();
783784
}
784785

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

790791
ZVAL_COPY_DEREF(return_value, value);
791792
} else {
792-
zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid", 0);
793+
zend_argument_value_error(1, "is invalid");
794+
RETURN_THROWS();
793795
}
794796
} /* }}} */
795797

@@ -817,7 +819,7 @@ SPL_METHOD(SplDoublyLinkedList, offsetSet)
817819
index = spl_offset_convert_to_long(zindex);
818820

819821
if (index < 0 || index >= intern->llist->count) {
820-
zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid or out of range", 0);
822+
zend_argument_value_error(1, "is out of range");
821823
RETURN_THROWS();
822824
}
823825

@@ -840,7 +842,7 @@ SPL_METHOD(SplDoublyLinkedList, offsetSet)
840842
}
841843
} else {
842844
zval_ptr_dtor(value);
843-
zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid", 0);
845+
zend_argument_value_error(1, "is invalid");
844846
RETURN_THROWS();
845847
}
846848
}
@@ -865,7 +867,7 @@ SPL_METHOD(SplDoublyLinkedList, offsetUnset)
865867
llist = intern->llist;
866868

867869
if (index < 0 || index >= intern->llist->count) {
868-
zend_throw_exception(spl_ce_OutOfRangeException, "Offset out of range", 0);
870+
zend_argument_value_error(1, "is out of range");
869871
RETURN_THROWS();
870872
}
871873

@@ -906,7 +908,7 @@ SPL_METHOD(SplDoublyLinkedList, offsetUnset)
906908

907909
SPL_LLIST_DELREF(element);
908910
} else {
909-
zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid", 0);
911+
zend_argument_value_error(1, "is invalid");
910912
RETURN_THROWS();
911913
}
912914
} /* }}} */
@@ -1209,6 +1211,7 @@ SPL_METHOD(SplDoublyLinkedList, unserialize)
12091211

12101212
error:
12111213
PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
1214+
/* TODO Convert to standard Error ? */
12121215
zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0, "Error at offset %zd of %zd bytes", ((char*)p - buf), buf_len);
12131216
RETURN_THROWS();
12141217

@@ -1262,8 +1265,7 @@ SPL_METHOD(SplDoublyLinkedList, __unserialize) {
12621265
if (!flags_zv || !storage_zv || !members_zv ||
12631266
Z_TYPE_P(flags_zv) != IS_LONG || Z_TYPE_P(storage_zv) != IS_ARRAY ||
12641267
Z_TYPE_P(members_zv) != IS_ARRAY) {
1265-
zend_throw_exception(spl_ce_UnexpectedValueException,
1266-
"Incomplete or ill-typed serialization data", 0);
1268+
zend_throw_error(NULL, "Incomplete or ill-typed serialization data");
12671269
RETURN_THROWS();
12681270
}
12691271

@@ -1293,7 +1295,7 @@ SPL_METHOD(SplDoublyLinkedList, add)
12931295
index = spl_offset_convert_to_long(zindex);
12941296

12951297
if (index < 0 || index > intern->llist->count) {
1296-
zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid or out of range", 0);
1298+
zend_argument_value_error(1, "is out of range");
12971299
RETURN_THROWS();
12981300
}
12991301

@@ -1357,7 +1359,7 @@ zend_object_iterator *spl_dllist_get_iterator(zend_class_entry *ce, zval *object
13571359
spl_dllist_object *dllist_object = Z_SPLDLLIST_P(object);
13581360

13591361
if (by_ref) {
1360-
zend_throw_exception(spl_ce_RuntimeException, "An iterator cannot be used with foreach by reference", 0);
1362+
zend_throw_error(NULL, "An iterator cannot be used with foreach by reference");
13611363
return NULL;
13621364
}
13631365

ext/spl/tests/SPLDoublyLinkedList_iterate_by_reference.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ try {
1717
$value *= $value;
1818
echo $value, PHP_EOL;
1919
}
20-
} catch (Exception $e) {
20+
} catch (\Error $e) {
2121
echo $e->getMessage(), PHP_EOL;
2222
}
2323

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+
SplDoublyLinkedList::add(): Argument #1 ($index) is 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+
SplDoublyLinkedList::add(): Argument #1 ($index) is 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+
SplDoublyLinkedList::offsetGet(): Argument #1 ($index) is 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+
SplDoublyLinkedList::offsetGet(): Argument #1 ($index) is out of range

ext/spl/tests/SplDoublyLinkedList_offsetUnset_greater_than_elements.phpt

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,12 @@ $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
?>
2421
--EXPECT--
25-
Offset out of range
22+
SplDoublyLinkedList::offsetUnset(): Argument #1 ($index) is out of range

ext/spl/tests/SplDoublyLinkedList_offsetUnset_negative-parameter.phpt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ PHPNW Testfest 2009 - Paul Court ( [email protected] )
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--
23-
Offset out of range
22+
SplDoublyLinkedList::offsetUnset(): Argument #1 ($index) is out of range

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ PHPNW Testfest 2009 - Paul Court ( [email protected] )
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--
23-
Offset out of range
22+
SplDoublyLinkedList::offsetUnset(): Argument #1 ($index) is 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+
SplDoublyLinkedList::offsetSet(): Argument #1 ($index) is out of range

ext/spl/tests/bug71735.phpt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ 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--
13-
Offset invalid or out of range
13+
SplDoublyLinkedList::offsetSet(): Argument #1 ($index) is out of range

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+
SplDoublyLinkedList::offsetGet(): Argument #1 ($index) is out of range
5848
int(1)
59-
Exception: Offset invalid or out of range
49+
SplDoublyLinkedList::offsetGet(): Argument #1 ($index) is 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+
SplDoublyLinkedList::add(): Argument #1 ($index) is out of range
3535
7
3636
7
3737
6

ext/spl/tests/unserialize_errors.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,25 +59,25 @@ echo "SplDoublyLinkedList:\n";
5959

6060
try {
6161
unserialize('O:19:"SplDoublyLinkedList":0:{}');
62-
} catch (Exception $e) {
62+
} catch (Error $e) {
6363
echo $e->getMessage(), "\n";
6464
}
6565

6666
try {
6767
unserialize('O:19:"SplDoublyLinkedList":3:{i:0;b:1;i:1;a:0:{}i:2;a:0:{}}');
68-
} catch (Exception $e) {
68+
} catch (Error $e) {
6969
echo $e->getMessage(), "\n";
7070
}
7171

7272
try {
7373
unserialize('O:19:"SplDoublyLinkedList":3:{i:0;i:0;i:1;a:0:{}i:2;i:0;}');
74-
} catch (Exception $e) {
74+
} catch (Error $e) {
7575
echo $e->getMessage(), "\n";
7676
}
7777

7878
try {
7979
unserialize('O:19:"SplDoublyLinkedList":3:{i:0;i:0;i:1;i:0;i:2;a:0:{}}');
80-
} catch (Exception $e) {
80+
} catch (Error $e) {
8181
echo $e->getMessage(), "\n";
8282
}
8383

0 commit comments

Comments
 (0)