@@ -575,10 +575,16 @@ static ssize_t php_userstreamop_write(php_stream *stream, const char *buf, size_
575
575
576
576
ZVAL_STRINGL (& args [0 ], (char * )buf , count );
577
577
578
+ uint32_t orig_no_fclose = stream -> flags & PHP_STREAM_FLAG_NO_FCLOSE ;
579
+ stream -> flags |= PHP_STREAM_FLAG_NO_FCLOSE ;
580
+
578
581
call_result = call_method_if_exists (& us -> object , & func_name , & retval , 1 , args );
579
582
zval_ptr_dtor (& args [0 ]);
580
583
zval_ptr_dtor (& func_name );
581
584
585
+ stream -> flags &= ~PHP_STREAM_FLAG_NO_FCLOSE ;
586
+ stream -> flags |= orig_no_fclose ;
587
+
582
588
if (EG (exception )) {
583
589
return -1 ;
584
590
}
@@ -620,6 +626,9 @@ static ssize_t php_userstreamop_read(php_stream *stream, char *buf, size_t count
620
626
621
627
assert (us != NULL );
622
628
629
+ uint32_t orig_no_fclose = stream -> flags & PHP_STREAM_FLAG_NO_FCLOSE ;
630
+ stream -> flags |= PHP_STREAM_FLAG_NO_FCLOSE ;
631
+
623
632
ZVAL_STRINGL (& func_name , USERSTREAM_READ , sizeof (USERSTREAM_READ )- 1 );
624
633
625
634
ZVAL_LONG (& args [0 ], count );
@@ -630,22 +639,22 @@ static ssize_t php_userstreamop_read(php_stream *stream, char *buf, size_t count
630
639
zval_ptr_dtor (& func_name );
631
640
632
641
if (EG (exception )) {
633
- return -1 ;
642
+ goto err ;
634
643
}
635
644
636
645
if (call_result == FAILURE ) {
637
646
php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_READ " is not implemented!" ,
638
647
ZSTR_VAL (us -> wrapper -> ce -> name ));
639
- return -1 ;
648
+ goto err ;
640
649
}
641
650
642
651
if (Z_TYPE (retval ) == IS_FALSE ) {
643
- return -1 ;
652
+ goto err ;
644
653
}
645
654
646
655
if (!try_convert_to_string (& retval )) {
647
656
zval_ptr_dtor (& retval );
648
- return -1 ;
657
+ goto err ;
649
658
}
650
659
651
660
didread = Z_STRLEN (retval );
@@ -669,7 +678,7 @@ static ssize_t php_userstreamop_read(php_stream *stream, char *buf, size_t count
669
678
670
679
if (EG (exception )) {
671
680
stream -> eof = 1 ;
672
- return -1 ;
681
+ goto err ;
673
682
}
674
683
675
684
if (call_result == SUCCESS && Z_TYPE (retval ) != IS_UNDEF && zval_is_true (& retval )) {
@@ -684,7 +693,15 @@ static ssize_t php_userstreamop_read(php_stream *stream, char *buf, size_t count
684
693
685
694
zval_ptr_dtor (& retval );
686
695
696
+ stream -> flags &= ~PHP_STREAM_FLAG_NO_FCLOSE ;
697
+ stream -> flags |= orig_no_fclose ;
698
+
687
699
return didread ;
700
+
701
+ err :
702
+ stream -> flags &= ~PHP_STREAM_FLAG_NO_FCLOSE ;
703
+ stream -> flags |= orig_no_fclose ;
704
+ return -1 ;
688
705
}
689
706
690
707
static int php_userstreamop_close (php_stream * stream , int close_handle )
@@ -749,6 +766,9 @@ static int php_userstreamop_seek(php_stream *stream, zend_off_t offset, int when
749
766
ZVAL_LONG (& args [0 ], offset );
750
767
ZVAL_LONG (& args [1 ], whence );
751
768
769
+ uint32_t orig_no_fclose = stream -> flags & PHP_STREAM_FLAG_NO_FCLOSE ;
770
+ stream -> flags |= PHP_STREAM_FLAG_NO_FCLOSE ;
771
+
752
772
call_result = call_method_if_exists (& us -> object , & func_name , & retval , 2 , args );
753
773
754
774
zval_ptr_dtor (& args [0 ]);
@@ -773,7 +793,7 @@ static int php_userstreamop_seek(php_stream *stream, zend_off_t offset, int when
773
793
ZVAL_UNDEF (& retval );
774
794
775
795
if (ret ) {
776
- return ret ;
796
+ goto out ;
777
797
}
778
798
779
799
/* now determine where we are */
@@ -793,6 +813,11 @@ static int php_userstreamop_seek(php_stream *stream, zend_off_t offset, int when
793
813
794
814
zval_ptr_dtor (& retval );
795
815
zval_ptr_dtor (& func_name );
816
+
817
+ out :
818
+ stream -> flags &= ~PHP_STREAM_FLAG_NO_FCLOSE ;
819
+ stream -> flags |= orig_no_fclose ;
820
+
796
821
return ret ;
797
822
}
798
823
@@ -1403,6 +1428,9 @@ static int php_userstreamop_cast(php_stream *stream, int castas, void **retptr)
1403
1428
break ;
1404
1429
}
1405
1430
1431
+ uint32_t orig_no_fclose = stream -> flags & PHP_STREAM_FLAG_NO_FCLOSE ;
1432
+ stream -> flags |= PHP_STREAM_FLAG_NO_FCLOSE ;
1433
+
1406
1434
call_result = call_method_if_exists (& us -> object , & func_name , & retval , 1 , args );
1407
1435
1408
1436
do {
@@ -1439,6 +1467,9 @@ static int php_userstreamop_cast(php_stream *stream, int castas, void **retptr)
1439
1467
zval_ptr_dtor (& func_name );
1440
1468
zval_ptr_dtor (& args [0 ]);
1441
1469
1470
+ stream -> flags &= ~PHP_STREAM_FLAG_NO_FCLOSE ;
1471
+ stream -> flags |= orig_no_fclose ;
1472
+
1442
1473
return ret ;
1443
1474
}
1444
1475
0 commit comments