@@ -566,6 +566,9 @@ static ssize_t php_userstreamop_write(php_stream *stream, const char *buf, size_
566
566
567
567
ZVAL_STRINGL (& args [0 ], (char * )buf , count );
568
568
569
+ uint32_t orig_no_fclose = stream -> flags & PHP_STREAM_FLAG_NO_FCLOSE ;
570
+ stream -> flags |= PHP_STREAM_FLAG_NO_FCLOSE ;
571
+
569
572
zend_string * func_name = ZSTR_INIT_LITERAL (USERSTREAM_WRITE , false);
570
573
zend_result call_result = zend_call_method_if_exists (Z_OBJ (us -> object ), func_name , & retval , 1 , args );
571
574
zend_string_release_ex (func_name , false);
@@ -575,6 +578,10 @@ static ssize_t php_userstreamop_write(php_stream *stream, const char *buf, size_
575
578
php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_WRITE " is not implemented!" ,
576
579
ZSTR_VAL (us -> wrapper -> ce -> name ));
577
580
}
581
+
582
+ stream -> flags &= ~PHP_STREAM_FLAG_NO_FCLOSE ;
583
+ stream -> flags |= orig_no_fclose ;
584
+
578
585
/* Exception occurred */
579
586
if (Z_ISUNDEF (retval )) {
580
587
return -1 ;
@@ -609,28 +616,31 @@ static ssize_t php_userstreamop_read(php_stream *stream, char *buf, size_t count
609
616
610
617
assert (us != NULL );
611
618
619
+ uint32_t orig_no_fclose = stream -> flags & PHP_STREAM_FLAG_NO_FCLOSE ;
620
+ stream -> flags |= PHP_STREAM_FLAG_NO_FCLOSE ;
621
+
612
622
ZVAL_LONG (& args [0 ], count );
613
623
zend_string * func_name = ZSTR_INIT_LITERAL (USERSTREAM_READ , false);
614
624
zend_result call_result = zend_call_method_if_exists (Z_OBJ (us -> object ), func_name , & retval , 1 , args );
615
625
zend_string_release_ex (func_name , false);
616
626
617
627
if (UNEXPECTED (Z_ISUNDEF (retval ))) {
618
- return -1 ;
628
+ goto err ;
619
629
}
620
630
621
631
if (UNEXPECTED (call_result == FAILURE )) {
622
632
php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_READ " is not implemented!" ,
623
633
ZSTR_VAL (us -> wrapper -> ce -> name ));
624
- return -1 ;
634
+ goto err ;
625
635
}
626
636
627
637
if (Z_TYPE (retval ) == IS_FALSE ) {
628
- return -1 ;
638
+ goto err ;
629
639
}
630
640
631
641
if (!try_convert_to_string (& retval )) {
632
642
zval_ptr_dtor (& retval );
633
- return -1 ;
643
+ goto err ;
634
644
}
635
645
636
646
didread = Z_STRLEN (retval );
@@ -657,19 +667,27 @@ static ssize_t php_userstreamop_read(php_stream *stream, char *buf, size_t count
657
667
"%s::" USERSTREAM_EOF " is not implemented! Assuming EOF" ,
658
668
ZSTR_VAL (us -> wrapper -> ce -> name ));
659
669
stream -> eof = 1 ;
660
- return -1 ;
670
+ goto err ;
661
671
}
662
672
if (UNEXPECTED (Z_ISUNDEF (retval ))) {
663
673
stream -> eof = 1 ;
664
- return -1 ;
674
+ goto err ;
665
675
}
666
676
667
677
if (zval_is_true (& retval )) {
668
678
stream -> eof = 1 ;
669
679
}
670
680
zval_ptr_dtor (& retval );
671
681
682
+ stream -> flags &= ~PHP_STREAM_FLAG_NO_FCLOSE ;
683
+ stream -> flags |= orig_no_fclose ;
684
+
672
685
return didread ;
686
+
687
+ err :
688
+ stream -> flags &= ~PHP_STREAM_FLAG_NO_FCLOSE ;
689
+ stream -> flags |= orig_no_fclose ;
690
+ return -1 ;
673
691
}
674
692
675
693
static int php_userstreamop_close (php_stream * stream , int close_handle )
@@ -723,6 +741,9 @@ static int php_userstreamop_seek(php_stream *stream, zend_off_t offset, int when
723
741
ZVAL_LONG (& args [0 ], offset );
724
742
ZVAL_LONG (& args [1 ], whence );
725
743
744
+ uint32_t orig_no_fclose = stream -> flags & PHP_STREAM_FLAG_NO_FCLOSE ;
745
+ stream -> flags |= PHP_STREAM_FLAG_NO_FCLOSE ;
746
+
726
747
zend_string * func_name = ZSTR_INIT_LITERAL (USERSTREAM_SEEK , false);
727
748
zend_result call_result = zend_call_method_if_exists (Z_OBJ (us -> object ), func_name , & retval , 2 , args );
728
749
zend_string_release_ex (func_name , false);
@@ -737,7 +758,8 @@ static int php_userstreamop_seek(php_stream *stream, zend_off_t offset, int when
737
758
738
759
zval_ptr_dtor (& retval );
739
760
740
- return -1 ;
761
+ ret = -1 ;
762
+ goto out ;
741
763
} else if (call_result == SUCCESS && Z_TYPE (retval ) != IS_UNDEF && zval_is_true (& retval )) {
742
764
ret = 0 ;
743
765
} else {
@@ -748,7 +770,7 @@ static int php_userstreamop_seek(php_stream *stream, zend_off_t offset, int when
748
770
ZVAL_UNDEF (& retval );
749
771
750
772
if (ret ) {
751
- return ret ;
773
+ goto out ;
752
774
}
753
775
754
776
/* now determine where we are */
@@ -767,6 +789,11 @@ static int php_userstreamop_seek(php_stream *stream, zend_off_t offset, int when
767
789
}
768
790
769
791
zval_ptr_dtor (& retval );
792
+
793
+ out :
794
+ stream -> flags &= ~PHP_STREAM_FLAG_NO_FCLOSE ;
795
+ stream -> flags |= orig_no_fclose ;
796
+
770
797
return ret ;
771
798
}
772
799
@@ -1394,6 +1421,9 @@ static int php_userstreamop_cast(php_stream *stream, int castas, void **retptr)
1394
1421
break ;
1395
1422
}
1396
1423
1424
+ uint32_t orig_no_fclose = stream -> flags & PHP_STREAM_FLAG_NO_FCLOSE ;
1425
+ stream -> flags |= PHP_STREAM_FLAG_NO_FCLOSE ;
1426
+
1397
1427
zend_string * func_name = ZSTR_INIT_LITERAL (USERSTREAM_CAST , false);
1398
1428
zend_result call_result = zend_call_method_if_exists (Z_OBJ (us -> object ), func_name , & retval , 1 , args );
1399
1429
zend_string_release_ex (func_name , false);
@@ -1403,7 +1433,7 @@ static int php_userstreamop_cast(php_stream *stream, int castas, void **retptr)
1403
1433
php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_CAST " is not implemented!" ,
1404
1434
ZSTR_VAL (us -> wrapper -> ce -> name ));
1405
1435
}
1406
- return FAILURE ;
1436
+ goto out ;
1407
1437
}
1408
1438
1409
1439
do {
@@ -1432,6 +1462,10 @@ static int php_userstreamop_cast(php_stream *stream, int castas, void **retptr)
1432
1462
1433
1463
zval_ptr_dtor (& retval );
1434
1464
1465
+ out :
1466
+ stream -> flags &= ~PHP_STREAM_FLAG_NO_FCLOSE ;
1467
+ stream -> flags |= orig_no_fclose ;
1468
+
1435
1469
return ret ;
1436
1470
}
1437
1471
0 commit comments