@@ -33,7 +33,7 @@ static zend_class_entry *php_ce_stream_exception;
3333static void php_stream_error_entry_free (php_stream_error_entry * entry );
3434
3535/* Helper to create a single StreamError object from an entry */
36- static void php_stream_error_create_object (zval * zv , php_stream_error_entry * entry )
36+ static void php_stream_error_create_object (zval * zv , const php_stream_error_entry * entry )
3737{
3838 object_init_ex (zv , php_ce_stream_error );
3939
@@ -69,11 +69,11 @@ static void php_stream_error_create_object(zval *zv, php_stream_error_entry *ent
6969}
7070
7171/* Create array of StreamError objects from error chain */
72- static void php_stream_error_create_array (zval * zv , php_stream_error_entry * first )
72+ static void php_stream_error_create_array (zval * zv , const php_stream_error_entry * first )
7373{
7474 array_init (zv );
7575
76- php_stream_error_entry * entry = first ;
76+ const php_stream_error_entry * entry = first ;
7777 while (entry ) {
7878 zval error_obj ;
7979 php_stream_error_create_object (& error_obj , entry );
@@ -113,7 +113,7 @@ static php_stream_error_store php_stream_auto_decide_error_store_mode(php_stream
113113 }
114114}
115115
116- static php_stream_error_mode php_stream_get_error_mode (php_stream_context * context )
116+ static php_stream_error_mode php_stream_get_error_mode (const php_stream_context * context )
117117{
118118 if (!context ) {
119119 return PHP_STREAM_ERROR_MODE_ERROR ;
@@ -143,7 +143,7 @@ static php_stream_error_mode php_stream_get_error_mode(php_stream_context *conte
143143}
144144
145145static php_stream_error_store php_stream_get_error_store_mode (
146- php_stream_context * context , php_stream_error_mode error_mode )
146+ const php_stream_context * context , php_stream_error_mode error_mode )
147147{
148148 if (!context ) {
149149 return php_stream_auto_decide_error_store_mode (error_mode );
@@ -178,9 +178,9 @@ static php_stream_error_store php_stream_get_error_store_mode(
178178
179179/* Helper functions */
180180
181- static bool php_stream_has_terminating_error (php_stream_error_operation * op )
181+ static bool php_stream_has_terminating_error (const php_stream_error_operation * op )
182182{
183- php_stream_error_entry * entry = op -> first_error ;
183+ const php_stream_error_entry * entry = op -> first_error ;
184184 while (entry ) {
185185 if (entry -> terminating ) {
186186 return true;
@@ -205,7 +205,7 @@ static inline php_stream_error_operation *php_stream_get_operation_at_depth(uint
205205
206206static inline php_stream_error_operation * php_stream_get_parent_operation (void )
207207{
208- php_stream_error_state * state = & FG (stream_error_state );
208+ const php_stream_error_state * state = & FG (stream_error_state );
209209
210210 if (state -> operation_depth <= 1 ) {
211211 return NULL ;
@@ -265,7 +265,7 @@ PHPAPI void php_stream_error_state_cleanup(void)
265265
266266PHPAPI void php_stream_error_get_last (zval * return_value )
267267{
268- php_stream_error_state * state = & FG (stream_error_state );
268+ const php_stream_error_state * state = & FG (stream_error_state );
269269
270270 if (!state -> stored_errors ) {
271271 ZVAL_EMPTY_ARRAY (return_value );
@@ -359,7 +359,7 @@ static void php_stream_error_add(zend_enum_StreamErrorCode code, const char *wra
359359
360360/* Error reporting */
361361
362- static void php_stream_call_error_handler (zval * handler , zval * errors_array )
362+ static void php_stream_call_error_handler (const zval * handler , zval * errors_array )
363363{
364364 zend_fcall_info_cache fcc ;
365365 char * is_callable_error = NULL ;
@@ -375,7 +375,7 @@ static void php_stream_call_error_handler(zval *handler, zval *errors_array)
375375 zend_call_known_fcc (& fcc , NULL , 1 , errors_array , NULL );
376376}
377377
378- static void php_stream_throw_exception_with_errors (php_stream_error_operation * op )
378+ static void php_stream_throw_exception_with_errors (const php_stream_error_operation * op )
379379{
380380 if (!op -> first_error ) {
381381 return ;
@@ -401,7 +401,7 @@ static void php_stream_throw_exception_with_errors(php_stream_error_operation *o
401401 zend_throw_exception_object (& ex );
402402}
403403
404- static void php_stream_report_errors (php_stream_context * context , php_stream_error_operation * op ,
404+ static void php_stream_report_errors (const php_stream_context * context , const php_stream_error_operation * op ,
405405 php_stream_error_mode error_mode , bool is_terminating )
406406{
407407 switch (error_mode ) {
@@ -426,7 +426,7 @@ static void php_stream_report_errors(php_stream_context *context, php_stream_err
426426 }
427427
428428 /* Call user error handler if set */
429- zval * handler
429+ const zval * handler
430430 = context ? php_stream_context_get_option (context , "stream" , "error_handler" ) : NULL ;
431431
432432 if (handler ) {
@@ -441,7 +441,7 @@ static void php_stream_report_errors(php_stream_context *context, php_stream_err
441441
442442/* Error storage */
443443
444- PHPAPI void php_stream_error_operation_end (php_stream_context * context )
444+ PHPAPI void php_stream_error_operation_end (const php_stream_context * context )
445445{
446446 php_stream_error_state * state = & FG (stream_error_state );
447447 php_stream_error_operation * op = state -> current_operation ;
@@ -533,7 +533,7 @@ PHPAPI void php_stream_error_operation_end(php_stream_context *context)
533533 op -> error_count = 0 ;
534534}
535535
536- PHPAPI void php_stream_error_operation_end_for_stream (php_stream * stream )
536+ PHPAPI void php_stream_error_operation_end_for_stream (const php_stream * stream )
537537{
538538 php_stream_error_state * state = & FG (stream_error_state );
539539 php_stream_error_operation * op = state -> current_operation ;
@@ -551,7 +551,7 @@ PHPAPI void php_stream_error_operation_end_for_stream(php_stream *stream)
551551 return ;
552552 }
553553
554- php_stream_context * context = PHP_STREAM_CONTEXT (stream );
554+ const php_stream_context * context = PHP_STREAM_CONTEXT (stream );
555555 php_stream_error_operation_end (context );
556556}
557557
@@ -575,7 +575,7 @@ PHPAPI void php_stream_error_operation_abort(void)
575575
576576/* Wrapper error reporting */
577577
578- static void php_stream_wrapper_error_internal (const char * wrapper_name , php_stream_context * context ,
578+ static void php_stream_wrapper_error_internal (const char * wrapper_name , const php_stream_context * context ,
579579 const char * docref , int severity , bool terminating ,
580580 zend_enum_StreamErrorCode code , zend_string * message )
581581{
@@ -592,7 +592,7 @@ static void php_stream_wrapper_error_internal(const char *wrapper_name, php_stre
592592}
593593
594594PHPAPI void php_stream_wrapper_error_with_name (const char * wrapper_name ,
595- php_stream_context * context , const char * docref , int options , int severity ,
595+ const php_stream_context * context , const char * docref , int options , int severity ,
596596 bool terminating , zend_enum_StreamErrorCode code , const char * fmt , ...)
597597{
598598 if (!(options & REPORT_ERRORS )) {
@@ -608,7 +608,9 @@ PHPAPI void php_stream_wrapper_error_with_name(const char *wrapper_name,
608608 wrapper_name , context , docref , severity , terminating , code , message );
609609}
610610
611- PHPAPI void php_stream_wrapper_error (php_stream_wrapper * wrapper , php_stream_context * context ,
611+ PHPAPI void php_stream_wrapper_error (
612+ const php_stream_wrapper * wrapper ,
613+ const php_stream_context * context ,
612614 const char * docref , int options , int severity , bool terminating ,
613615 zend_enum_StreamErrorCode code , const char * fmt , ...)
614616{
@@ -629,7 +631,7 @@ PHPAPI void php_stream_wrapper_error(php_stream_wrapper *wrapper, php_stream_con
629631
630632/* Stream error reporting */
631633
632- PHPAPI void php_stream_error (php_stream * stream , const char * docref , int severity ,
634+ PHPAPI void php_stream_error (const php_stream * stream , const char * docref , int severity ,
633635 bool terminating , zend_enum_StreamErrorCode code , const char * fmt , ...)
634636{
635637 va_list args ;
@@ -640,7 +642,7 @@ PHPAPI void php_stream_error(php_stream *stream, const char *docref, int severit
640642
641643 const char * wrapper_name = stream -> wrapper ? stream -> wrapper -> wops -> label : "stream" ;
642644
643- php_stream_context * context = PHP_STREAM_CONTEXT (stream );
645+ const php_stream_context * context = PHP_STREAM_CONTEXT (stream );
644646
645647 php_stream_wrapper_error_internal (wrapper_name , context , docref , severity ,
646648 terminating , code , message );
@@ -694,7 +696,7 @@ static void php_stream_wrapper_log_store_error(zend_string *message, zend_enum_S
694696}
695697
696698PHPAPI void php_stream_wrapper_log_error (const php_stream_wrapper * wrapper ,
697- php_stream_context * context , int options , int severity , bool terminating ,
699+ const php_stream_context * context , int options , int severity , bool terminating ,
698700 zend_enum_StreamErrorCode code , const char * fmt , ...)
699701{
700702 va_list args ;
@@ -722,12 +724,12 @@ static zend_llist *php_stream_get_wrapper_errors_list(const char *wrapper_name)
722724}
723725
724726PHPAPI void php_stream_display_wrapper_name_errors (const char * wrapper_name ,
725- php_stream_context * context , zend_enum_StreamErrorCode code ,
727+ const php_stream_context * context , zend_enum_StreamErrorCode code ,
726728 const char * caption )
727729{
728730 char * msg ;
729731 char errstr [256 ];
730- int free_msg = 0 ;
732+ bool free_msg = false ;
731733
732734 if (EG (exception )) {
733735 return ;
@@ -737,9 +739,7 @@ PHPAPI void php_stream_display_wrapper_name_errors(const char *wrapper_name,
737739 zend_llist * err_list = php_stream_get_wrapper_errors_list (wrapper_name );
738740 if (err_list ) {
739741 size_t l = 0 ;
740- int brlen ;
741- int i ;
742- int count = (int ) zend_llist_count (err_list );
742+ size_t brlen ;
743743 const char * br ;
744744 php_stream_error_entry * * err_entry_p ;
745745 zend_llist_position pos ;
@@ -752,7 +752,9 @@ PHPAPI void php_stream_display_wrapper_name_errors(const char *wrapper_name,
752752 br = "\n" ;
753753 }
754754
755- for (err_entry_p = zend_llist_get_first_ex (err_list , & pos ), i = 0 ; err_entry_p ;
755+ size_t i = 0 ;
756+ const size_t count = zend_llist_count (err_list );
757+ for (i = 0 , err_entry_p = zend_llist_get_first_ex (err_list , & pos ); err_entry_p ;
756758 err_entry_p = zend_llist_get_next_ex (err_list , & pos ), i ++ ) {
757759 l += ZSTR_LEN ((* err_entry_p )-> message );
758760 if (i < count - 1 ) {
@@ -769,7 +771,7 @@ PHPAPI void php_stream_display_wrapper_name_errors(const char *wrapper_name,
769771 }
770772 }
771773
772- free_msg = 1 ;
774+ free_msg = true ;
773775 } else {
774776 if (!strcmp (wrapper_name , php_plain_files_wrapper .wops -> label )) {
775777 msg = php_socket_strerror_s (errno , errstr , sizeof (errstr ));
@@ -791,8 +793,8 @@ PHPAPI void php_stream_display_wrapper_name_errors(const char *wrapper_name,
791793 }
792794}
793795
794- PHPAPI void php_stream_display_wrapper_errors (php_stream_wrapper * wrapper ,
795- php_stream_context * context , zend_enum_StreamErrorCode code ,
796+ PHPAPI void php_stream_display_wrapper_errors (const php_stream_wrapper * wrapper ,
797+ const php_stream_context * context , zend_enum_StreamErrorCode code ,
796798 const char * caption )
797799{
798800 if (wrapper ) {
@@ -808,7 +810,7 @@ PHPAPI void php_stream_tidy_wrapper_name_error_log(const char *wrapper_name)
808810 }
809811}
810812
811- PHPAPI void php_stream_tidy_wrapper_error_log (php_stream_wrapper * wrapper )
813+ PHPAPI void php_stream_tidy_wrapper_error_log (const php_stream_wrapper * wrapper )
812814{
813815 if (wrapper ) {
814816 const char * wrapper_name = PHP_STREAM_ERROR_WRAPPER_NAME (wrapper );
@@ -822,7 +824,7 @@ PHP_METHOD(StreamException, getErrors)
822824{
823825 ZEND_PARSE_PARAMETERS_NONE ();
824826
825- zval * errors = zend_read_property (
827+ const zval * errors = zend_read_property (
826828 php_ce_stream_exception , Z_OBJ_P (ZEND_THIS ), ZEND_STRL ("errors" ), 1 , NULL );
827829
828830 RETURN_COPY (errors );
0 commit comments