@@ -241,26 +241,26 @@ static void from_zval_write_aggregation(const zval *container,
241
241
zval * elem ;
242
242
243
243
if (Z_TYPE_P (container ) != IS_ARRAY ) {
244
- do_from_zval_err (ctx , "%s" , "expected an array here" );
244
+ zend_type_error ("Expected array" );
245
+ return ;
245
246
}
246
247
247
248
for (descr = descriptors ; descr -> name != NULL && !ctx -> err .has_error ; descr ++ ) {
248
249
if ((elem = zend_hash_str_find (Z_ARRVAL_P (container ),
249
250
descr -> name , descr -> name_size - 1 )) != NULL ) {
250
251
251
252
if (descr -> from_zval == NULL ) {
252
- do_from_zval_err (ctx , "No information on how to convert value "
253
- "of key '%s'" , descr -> name );
254
- break ;
253
+ zend_value_error ("Impossible to convert value of key '%s'" , descr -> name );
254
+ return ;
255
255
}
256
256
257
257
zend_llist_add_element (& ctx -> keys , (void * )& descr -> name );
258
258
descr -> from_zval (elem , ((char * )structure ) + descr -> field_offset , ctx );
259
259
zend_llist_remove_tail (& ctx -> keys );
260
260
261
261
} else if (descr -> required ) {
262
- do_from_zval_err ( ctx , "The key '%s' is required" , descr -> name );
263
- break ;
262
+ zend_value_error ( "The key '%s' is required" , descr -> name );
263
+ return ;
264
264
}
265
265
}
266
266
}
@@ -339,15 +339,13 @@ static zend_long from_zval_integer_common(const zval *arr_value, ser_context *ct
339
339
}
340
340
341
341
/* if we get here, we don't have a numeric string */
342
- do_from_zval_err (ctx , "expected an integer, but got a non numeric "
343
- "string (possibly from a converted object): '%s'" , Z_STRVAL_P (arr_value ));
344
- break ;
342
+ zend_type_error ("Expected an integer, received a non numeric string: '%s'" , Z_STRVAL_P (arr_value ));
343
+ return ret ;
345
344
}
346
345
347
346
default :
348
- do_from_zval_err (ctx , "%s" , "expected an integer, either of a PHP "
349
- "integer type or of a convertible type" );
350
- break ;
347
+ zend_type_error ("Expected an integer" );
348
+ return ret ;
351
349
}
352
350
353
351
zval_ptr_dtor (& lzval );
@@ -365,8 +363,7 @@ void from_zval_write_int(const zval *arr_value, char *field, ser_context *ctx)
365
363
}
366
364
367
365
if (lval > INT_MAX || lval < INT_MIN ) {
368
- do_from_zval_err (ctx , "%s" , "given PHP integer is out of bounds "
369
- "for a native int" );
366
+ zend_value_error ("Provided PHP integer is out of bounds for a native int" );
370
367
return ;
371
368
}
372
369
@@ -384,8 +381,7 @@ static void from_zval_write_uint32(const zval *arr_value, char *field, ser_conte
384
381
}
385
382
386
383
if (sizeof (zend_long ) > sizeof (uint32_t ) && (lval < 0 || lval > 0xFFFFFFFF )) {
387
- do_from_zval_err (ctx , "%s" , "given PHP integer is out of bounds "
388
- "for an unsigned 32-bit integer" );
384
+ zend_value_error ("Provided PHP integer is out of bounds for an unsigned 32-bit integer" );
389
385
return ;
390
386
}
391
387
@@ -403,8 +399,7 @@ static void from_zval_write_net_uint16(const zval *arr_value, char *field, ser_c
403
399
}
404
400
405
401
if (lval < 0 || lval > 0xFFFF ) {
406
- do_from_zval_err (ctx , "%s" , "given PHP integer is out of bounds "
407
- "for an unsigned 16-bit integer" );
402
+ zend_value_error ("Provided PHP integer is out of bounds for an unsigned 16-bit integer" );
408
403
return ;
409
404
}
410
405
@@ -422,8 +417,7 @@ static void from_zval_write_sa_family(const zval *arr_value, char *field, ser_co
422
417
}
423
418
424
419
if (lval < 0 || lval > (sa_family_t )- 1 ) { /* sa_family_t is unsigned */
425
- do_from_zval_err (ctx , "%s" , "given PHP integer is out of bounds "
426
- "for a sa_family_t value" );
420
+ zend_value_error ("Provided PHP integer is out of bounds for a sa_family_t value" );
427
421
return ;
428
422
}
429
423
@@ -443,8 +437,7 @@ static void from_zval_write_pid_t(const zval *arr_value, char *field, ser_contex
443
437
}
444
438
445
439
if (lval < 0 || (pid_t )lval != lval ) { /* pid_t is signed */
446
- do_from_zval_err (ctx , "%s" , "given PHP integer is out of bounds "
447
- "for a pid_t value" );
440
+ zend_value_error ("Provided PHP integer is out of bounds for a pid_t value" );
448
441
return ;
449
442
}
450
443
@@ -464,14 +457,12 @@ static void from_zval_write_uid_t(const zval *arr_value, char *field, ser_contex
464
457
/* uid_t can be signed or unsigned (generally unsigned) */
465
458
if ((uid_t )- 1 > (uid_t )0 ) {
466
459
if (sizeof (zend_long ) > sizeof (uid_t ) && (lval < 0 || (uid_t )lval != lval )) {
467
- do_from_zval_err (ctx , "%s" , "given PHP integer is out of bounds "
468
- "for a uid_t value" );
460
+ zend_value_error ("Provided PHP integer is out of bounds for a uid_t value" );
469
461
return ;
470
462
}
471
463
} else {
472
464
if (sizeof (zend_long ) > sizeof (uid_t ) && (uid_t )lval != lval ) {
473
- do_from_zval_err (ctx , "%s" , "given PHP integer is out of bounds "
474
- "for a uid_t value" );
465
+ zend_value_error ("Provided PHP integer is out of bounds for a uid_t value" );
475
466
return ;
476
467
}
477
468
}
@@ -546,6 +537,7 @@ static void from_zval_write_sin_addr(const zval *zaddr_str, char *inaddr, ser_co
546
537
memcpy (inaddr , & saddr .sin_addr , sizeof saddr .sin_addr );
547
538
} else {
548
539
/* error already emitted, but let's emit another more relevant */
540
+ /* TODO Convert to ValueError? */
549
541
do_from_zval_err (ctx , "could not resolve address '%s' to get an AF_INET "
550
542
"address" , ZSTR_VAL (addr_str ));
551
543
}
@@ -562,8 +554,7 @@ static void to_zval_read_sin_addr(const char *data, zval *zv, res_context *ctx)
562
554
ZVAL_NEW_STR (zv , str );
563
555
564
556
if (inet_ntop (AF_INET , addr , Z_STRVAL_P (zv ), size ) == NULL ) {
565
- do_to_zval_err (ctx , "could not convert IPv4 address to string "
566
- "(errno %d)" , errno );
557
+ zend_value_error ("Could not convert IPv4 address to string (errno %d)" , errno );
567
558
return ;
568
559
}
569
560
@@ -596,6 +587,7 @@ static void from_zval_write_sin6_addr(const zval *zaddr_str, char *addr6, ser_co
596
587
memcpy (addr6 , & saddr6 .sin6_addr , sizeof saddr6 .sin6_addr );
597
588
} else {
598
589
/* error already emitted, but let's emit another more relevant */
590
+ /* TODO Convert to ValueError? */
599
591
do_from_zval_err (ctx , "could not resolve address '%s' to get an AF_INET6 "
600
592
"address" , Z_STRVAL_P (zaddr_str ));
601
593
}
@@ -613,8 +605,7 @@ static void to_zval_read_sin6_addr(const char *data, zval *zv, res_context *ctx)
613
605
ZVAL_NEW_STR (zv , str );
614
606
615
607
if (inet_ntop (AF_INET6 , addr , Z_STRVAL_P (zv ), size ) == NULL ) {
616
- do_to_zval_err (ctx , "could not convert IPv6 address to string "
617
- "(errno %d)" , errno );
608
+ zend_value_error ("Could not convert IPv6 address to string (errno %d)" , errno );
618
609
return ;
619
610
}
620
611
@@ -648,13 +639,12 @@ static void from_zval_write_sun_path(const zval *path, char *sockaddr_un_c, ser_
648
639
* this is not required, at least on linux for abstract paths. It also
649
640
* assumes that the path is not empty */
650
641
if (ZSTR_LEN (path_str ) == 0 ) {
651
- do_from_zval_err ( ctx , "%s" , "the path is cannot be empty" );
642
+ zend_value_error ( "The path cannot be empty" );
652
643
zend_tmp_string_release (tmp_path_str );
653
644
return ;
654
645
}
655
646
if (ZSTR_LEN (path_str ) >= sizeof (saddr -> sun_path )) {
656
- do_from_zval_err (ctx , "the path is too long, the maximum permitted "
657
- "length is %zd" , sizeof (saddr -> sun_path ) - 1 );
647
+ zend_value_error ("The path is too long, maximum permitted length is %zd" , sizeof (saddr -> sun_path ) - 1 );
658
648
zend_tmp_string_release (tmp_path_str );
659
649
return ;
660
650
}
@@ -670,7 +660,7 @@ static void to_zval_read_sun_path(const char *data, zval *zv, res_context *ctx)
670
660
671
661
nul_pos = memchr (& saddr -> sun_path , '\0' , sizeof (saddr -> sun_path ));
672
662
if (nul_pos == NULL ) {
673
- do_to_zval_err ( ctx , "could not find a NUL in the path" );
663
+ zend_value_error ( "Could not find a NUL in the path" );
674
664
return ;
675
665
}
676
666
@@ -702,7 +692,8 @@ static void from_zval_write_sockaddr_aux(const zval *container,
702
692
* sockaddr_len = 0 ;
703
693
704
694
if (Z_TYPE_P (container ) != IS_ARRAY ) {
705
- do_from_zval_err (ctx , "%s" , "expected an array here" );
695
+ /* TODO improve error message? */
696
+ zend_type_error ("Expected array" );
706
697
return ;
707
698
}
708
699
@@ -865,16 +856,15 @@ static void from_zval_write_control(const zval *arr,
865
856
866
857
entry = get_ancillary_reg_entry (level , type );
867
858
if (entry == NULL ) {
868
- do_from_zval_err (ctx , "cmsghdr with level %d and type %d not supported" ,
869
- level , type );
859
+ zend_value_error ("cmsghdr with level %d and type %d not supported" , level , type );
870
860
return ;
871
861
}
872
862
873
863
if (entry -> calc_space ) {
874
864
zval * data_elem ;
875
865
/* arr must be an array at this point */
876
866
if ((data_elem = zend_hash_str_find (Z_ARRVAL_P (arr ), "data" , sizeof ("data" ) - 1 )) == NULL ) {
877
- do_from_zval_err ( ctx , "cmsghdr should have a 'data' element here" );
867
+ zend_value_error ( "cmsghdr should have a 'data' element here" );
878
868
return ;
879
869
}
880
870
data_len = entry -> calc_space (data_elem , ctx );
@@ -919,7 +909,8 @@ static void from_zval_write_control_array(const zval *arr, char *msghdr_c, ser_c
919
909
struct msghdr * msg = (struct msghdr * )msghdr_c ;
920
910
921
911
if (Z_TYPE_P (arr ) != IS_ARRAY ) {
922
- do_from_zval_err (ctx , "%s" , "expected an array here" );
912
+ /* TODO Improve error message */
913
+ zend_type_error ("Expected array" );
923
914
return ;
924
915
}
925
916
@@ -961,11 +952,11 @@ static void to_zval_read_cmsg_data(const char *cmsghdr_c, zval *zv, res_context
961
952
962
953
entry = get_ancillary_reg_entry (cmsg -> cmsg_level , cmsg -> cmsg_type );
963
954
if (entry == NULL ) {
964
- do_to_zval_err (ctx , "cmsghdr with level %d and type %d not supported" ,
965
- cmsg -> cmsg_level , cmsg -> cmsg_type );
955
+ zend_value_error ("cmsghdr with level %d and type %d not supported" , cmsg -> cmsg_level , cmsg -> cmsg_type );
966
956
return ;
967
957
}
968
958
if (CMSG_LEN (entry -> size ) > cmsg -> cmsg_len ) {
959
+ /* TODO Convert? */
969
960
do_to_zval_err (ctx , "the cmsghdr structure is unexpectedly small; "
970
961
"expected a length of at least " ZEND_LONG_FMT ", but got " ZEND_LONG_FMT ,
971
962
(zend_long )CMSG_LEN (entry -> size ), (zend_long )cmsg -> cmsg_len );
@@ -1057,8 +1048,8 @@ static void from_zval_write_msghdr_buffer_size(const zval *elem, char *msghdr_c,
1057
1048
}
1058
1049
1059
1050
if (lval < 0 || (zend_ulong )lval > MAX_USER_BUFF_SIZE ) {
1060
- do_from_zval_err ( ctx , "the buffer size must be between 1 and " ZEND_LONG_FMT "; "
1061
- "given " ZEND_LONG_FMT , (zend_long )MAX_USER_BUFF_SIZE , lval );
1051
+ zend_value_error ( "The buffer size must be between 1 and " ZEND_LONG_FMT "; given " ZEND_LONG_FMT ,
1052
+ (zend_long ) MAX_USER_BUFF_SIZE , lval );
1062
1053
return ;
1063
1054
}
1064
1055
@@ -1086,7 +1077,8 @@ static void from_zval_write_iov_array(const zval *arr, char *msghdr_c, ser_conte
1086
1077
struct msghdr * msg = (struct msghdr * )msghdr_c ;
1087
1078
1088
1079
if (Z_TYPE_P (arr ) != IS_ARRAY ) {
1089
- do_from_zval_err (ctx , "%s" , "expected an array here" );
1080
+ /* TODO Improve error */
1081
+ zend_type_error ("Expected array" );
1090
1082
return ;
1091
1083
}
1092
1084
@@ -1110,7 +1102,7 @@ static void from_zval_write_controllen(const zval *elem, char *msghdr_c, ser_con
1110
1102
*/
1111
1103
from_zval_write_uint32 (elem , (char * )& len , ctx );
1112
1104
if (!ctx -> err .has_error && len == 0 ) {
1113
- do_from_zval_err ( ctx , "controllen cannot be 0" );
1105
+ zend_value_error ( "controllen cannot be 0" );
1114
1106
return ;
1115
1107
}
1116
1108
msghdr -> msg_control = accounted_emalloc (len , ctx );
@@ -1154,6 +1146,7 @@ void from_zval_write_msghdr_recv(const zval *container, char *msghdr_c, ser_cont
1154
1146
* falsevp = & falsev ;
1155
1147
1156
1148
if (zend_hash_str_add_ptr (& ctx -> params , KEY_FILL_SOCKADDR , sizeof (KEY_FILL_SOCKADDR ) - 1 , (void * )falsevp ) == NULL ) {
1149
+ /* Should throw? */
1157
1150
do_from_zval_err (ctx , "could not add fill_sockaddr; this is a bug" );
1158
1151
return ;
1159
1152
}
@@ -1182,12 +1175,12 @@ static void to_zval_read_iov(const char *msghdr_c, zval *zv, res_context *ctx)
1182
1175
uint32_t i ;
1183
1176
1184
1177
if (iovlen > UINT_MAX ) {
1185
- do_to_zval_err (ctx , "unexpectedly large value for iov_len: %lu" ,
1186
- (unsigned long )iovlen );
1178
+ zend_value_error ("Unexpectedly large value for iov_len: %lu" , (unsigned long ) iovlen );
1187
1179
}
1188
1180
array_init_size (zv , (uint32_t )iovlen );
1189
1181
1190
1182
if ((recvmsg_ret = zend_hash_str_find_ptr (& ctx -> params , KEY_RECVMSG_RET , sizeof (KEY_RECVMSG_RET ) - 1 )) == NULL ) {
1183
+ /* Should throw? */
1191
1184
do_to_zval_err (ctx , "recvmsg_ret not found in params. This is a bug" );
1192
1185
return ;
1193
1186
}
@@ -1228,8 +1221,8 @@ static void from_zval_write_ifindex(const zval *zv, char *uinteger, ser_context
1228
1221
1229
1222
if (Z_TYPE_P (zv ) == IS_LONG ) {
1230
1223
if (Z_LVAL_P (zv ) < 0 || (zend_ulong )Z_LVAL_P (zv ) > UINT_MAX ) { /* allow 0 (unspecified interface) */
1231
- do_from_zval_err ( ctx , "the interface index cannot be negative or "
1232
- "larger than %u; given " ZEND_LONG_FMT , UINT_MAX , Z_LVAL_P (zv ));
1224
+ zend_value_error ( "The interface index cannot be negative or larger than %u; given " ZEND_LONG_FMT ,
1225
+ UINT_MAX , Z_LVAL_P (zv ));
1233
1226
} else {
1234
1227
ret = (unsigned )Z_LVAL_P (zv );
1235
1228
}
@@ -1323,13 +1316,14 @@ size_t calculate_scm_rights_space(const zval *arr, ser_context *ctx)
1323
1316
int num_elems ;
1324
1317
1325
1318
if (Z_TYPE_P (arr ) != IS_ARRAY ) {
1326
- do_from_zval_err (ctx , "%s" , "expected an array here" );
1319
+ /* TODO Improve error */
1320
+ zend_type_error ("Expected array" );
1327
1321
return (size_t )-1 ;
1328
1322
}
1329
1323
1330
1324
num_elems = zend_hash_num_elements (Z_ARRVAL_P (arr ));
1331
1325
if (num_elems == 0 ) {
1332
- do_from_zval_err ( ctx , "%s" , "expected at least one element in this array" );
1326
+ zend_value_error ( "Expected at least one element in this array" );
1333
1327
return (size_t )-1 ;
1334
1328
}
1335
1329
@@ -1351,23 +1345,25 @@ static void from_zval_write_fd_array_aux(zval *elem, unsigned i, void **args, se
1351
1345
1352
1346
stream = (php_stream * )zend_fetch_resource2_ex (elem , NULL , php_file_le_stream (), php_file_le_pstream ());
1353
1347
if (stream == NULL ) {
1354
- do_from_zval_err ( ctx , "resource is not a stream or a socket " );
1348
+ zend_type_error ( "Resource is not a stream nor a scoket " );
1355
1349
return ;
1356
1350
}
1357
1351
1358
1352
if (php_stream_cast (stream , PHP_STREAM_AS_FD , (void * * )& iarr [i - 1 ],
1359
1353
REPORT_ERRORS ) == FAILURE ) {
1354
+ /* Throw? */
1360
1355
do_from_zval_err (ctx , "cast stream to file descriptor failed" );
1361
1356
return ;
1362
1357
}
1363
1358
} else {
1364
- do_from_zval_err ( ctx , "expected a resource variable " );
1359
+ zend_type_error ( "Expected a resource" );
1365
1360
}
1366
1361
}
1367
1362
void from_zval_write_fd_array (const zval * arr , char * int_arr , ser_context * ctx )
1368
1363
{
1369
1364
if (Z_TYPE_P (arr ) != IS_ARRAY ) {
1370
- do_from_zval_err (ctx , "%s" , "expected an array here" );
1365
+ /* TODO Improve error */
1366
+ zend_type_error ("Expected array" );
1371
1367
return ;
1372
1368
}
1373
1369
@@ -1390,8 +1386,8 @@ void to_zval_read_fd_array(const char *data, zval *zv, res_context *ctx)
1390
1386
}
1391
1387
1392
1388
if (* cmsg_len < data_offset ) {
1393
- do_to_zval_err ( ctx , "length of cmsg is smaller than its data member "
1394
- "offset (" ZEND_LONG_FMT " vs " ZEND_LONG_FMT ")" , (zend_long )* cmsg_len , (zend_long )data_offset );
1389
+ zend_value_error ( "Length of cmsg is smaller than its data member offset (" ZEND_LONG_FMT
1390
+ " vs " ZEND_LONG_FMT ")" , (zend_long )* cmsg_len , (zend_long )data_offset );
1395
1391
return ;
1396
1392
}
1397
1393
num_elems = (* cmsg_len - data_offset ) / sizeof (int );
0 commit comments