@@ -59,6 +59,13 @@ PHPAPI zend_class_entry *spl_ce_GlobIterator;
59
59
PHPAPI zend_class_entry * spl_ce_SplFileObject ;
60
60
PHPAPI zend_class_entry * spl_ce_SplTempFileObject ;
61
61
62
+ // TODO Use standard Error
63
+ #define CHECK_SPL_FILE_OBJECT_IS_INITIALIZED () \
64
+ if (!intern->u.file.stream) { \
65
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized"); \
66
+ RETURN_THROWS(); \
67
+ }
68
+
62
69
static void spl_filesystem_file_free_line (spl_filesystem_object * intern ) /* {{{ */
63
70
{
64
71
if (intern -> u .file .current_line ) {
@@ -2019,7 +2026,7 @@ static int spl_filesystem_file_read_line(zval * this_ptr, spl_filesystem_object
2019
2026
2020
2027
static void spl_filesystem_file_rewind (zval * this_ptr , spl_filesystem_object * intern ) /* {{{ */
2021
2028
{
2022
- if (!intern -> u .file .stream ) {
2029
+ if (!intern -> u .file .stream ) {
2023
2030
zend_throw_exception_ex (spl_ce_RuntimeException , 0 , "Object not initialized" );
2024
2031
return ;
2025
2032
}
@@ -2147,10 +2154,7 @@ PHP_METHOD(SplFileObject, eof)
2147
2154
RETURN_THROWS ();
2148
2155
}
2149
2156
2150
- if (!intern -> u .file .stream ) {
2151
- zend_throw_exception_ex (spl_ce_RuntimeException , 0 , "Object not initialized" );
2152
- RETURN_THROWS ();
2153
- }
2157
+ CHECK_SPL_FILE_OBJECT_IS_INITIALIZED ();
2154
2158
2155
2159
RETURN_BOOL (php_stream_eof (intern -> u .file .stream ));
2156
2160
} /* }}} */
@@ -2183,10 +2187,7 @@ PHP_METHOD(SplFileObject, fgets)
2183
2187
RETURN_THROWS ();
2184
2188
}
2185
2189
2186
- if (!intern -> u .file .stream ) {
2187
- zend_throw_exception_ex (spl_ce_RuntimeException , 0 , "Object not initialized" );
2188
- RETURN_THROWS ();
2189
- }
2190
+ CHECK_SPL_FILE_OBJECT_IS_INITIALIZED ();
2190
2191
2191
2192
if (spl_filesystem_file_read (intern , 0 ) == FAILURE ) {
2192
2193
RETURN_FALSE ;
@@ -2203,10 +2204,7 @@ PHP_METHOD(SplFileObject, current)
2203
2204
RETURN_THROWS ();
2204
2205
}
2205
2206
2206
- if (!intern -> u .file .stream ) {
2207
- zend_throw_exception_ex (spl_ce_RuntimeException , 0 , "Object not initialized" );
2208
- RETURN_THROWS ();
2209
- }
2207
+ CHECK_SPL_FILE_OBJECT_IS_INITIALIZED ();
2210
2208
2211
2209
if (!intern -> u .file .current_line && Z_ISUNDEF (intern -> u .file .current_zval )) {
2212
2210
spl_filesystem_file_read_line (ZEND_THIS , intern , 1 );
@@ -2337,10 +2335,7 @@ PHP_METHOD(SplFileObject, fgetcsv)
2337
2335
2338
2336
if (zend_parse_parameters (ZEND_NUM_ARGS (), "|sss" , & delim , & d_len , & enclo , & e_len , & esc , & esc_len ) == SUCCESS ) {
2339
2337
2340
- if (!intern -> u .file .stream ) {
2341
- zend_throw_exception_ex (spl_ce_RuntimeException , 0 , "Object not initialized" );
2342
- RETURN_THROWS ();
2343
- }
2338
+ CHECK_SPL_FILE_OBJECT_IS_INITIALIZED ();
2344
2339
2345
2340
switch (ZEND_NUM_ARGS ())
2346
2341
{
@@ -2527,10 +2522,7 @@ PHP_METHOD(SplFileObject, flock)
2527
2522
RETURN_THROWS ();
2528
2523
}
2529
2524
2530
- if (!intern -> u .file .stream ) {
2531
- zend_throw_exception_ex (spl_ce_RuntimeException , 0 , "Object not initialized" );
2532
- RETURN_THROWS ();
2533
- }
2525
+ CHECK_SPL_FILE_OBJECT_IS_INITIALIZED ();
2534
2526
2535
2527
act = operation & PHP_LOCK_UN ;
2536
2528
// TODO doesn't this fail if operation is a bitmask with LOCK_NB?
@@ -2561,10 +2553,7 @@ PHP_METHOD(SplFileObject, fflush)
2561
2553
{
2562
2554
spl_filesystem_object * intern = Z_SPLFILESYSTEM_P (ZEND_THIS );
2563
2555
2564
- if (!intern -> u .file .stream ) {
2565
- zend_throw_exception_ex (spl_ce_RuntimeException , 0 , "Object not initialized" );
2566
- RETURN_THROWS ();
2567
- }
2556
+ CHECK_SPL_FILE_OBJECT_IS_INITIALIZED ();
2568
2557
2569
2558
RETURN_BOOL (!php_stream_flush (intern -> u .file .stream ));
2570
2559
} /* }}} */
@@ -2575,10 +2564,7 @@ PHP_METHOD(SplFileObject, ftell)
2575
2564
spl_filesystem_object * intern = Z_SPLFILESYSTEM_P (ZEND_THIS );
2576
2565
zend_long ret ;
2577
2566
2578
- if (!intern -> u .file .stream ) {
2579
- zend_throw_exception_ex (spl_ce_RuntimeException , 0 , "Object not initialized" );
2580
- RETURN_THROWS ();
2581
- }
2567
+ CHECK_SPL_FILE_OBJECT_IS_INITIALIZED ();
2582
2568
2583
2569
ret = php_stream_tell (intern -> u .file .stream );
2584
2570
@@ -2599,10 +2585,7 @@ PHP_METHOD(SplFileObject, fseek)
2599
2585
RETURN_THROWS ();
2600
2586
}
2601
2587
2602
- if (!intern -> u .file .stream ) {
2603
- zend_throw_exception_ex (spl_ce_RuntimeException , 0 , "Object not initialized" );
2604
- RETURN_THROWS ();
2605
- }
2588
+ CHECK_SPL_FILE_OBJECT_IS_INITIALIZED ();
2606
2589
2607
2590
spl_filesystem_file_free_line (intern );
2608
2591
RETURN_LONG (php_stream_seek (intern -> u .file .stream , pos , (int )whence ));
@@ -2615,10 +2598,7 @@ PHP_METHOD(SplFileObject, fgetc)
2615
2598
char buf [2 ];
2616
2599
int result ;
2617
2600
2618
- if (!intern -> u .file .stream ) {
2619
- zend_throw_exception_ex (spl_ce_RuntimeException , 0 , "Object not initialized" );
2620
- RETURN_THROWS ();
2621
- }
2601
+ CHECK_SPL_FILE_OBJECT_IS_INITIALIZED ();
2622
2602
2623
2603
spl_filesystem_file_free_line (intern );
2624
2604
@@ -2642,10 +2622,7 @@ PHP_METHOD(SplFileObject, fpassthru)
2642
2622
{
2643
2623
spl_filesystem_object * intern = Z_SPLFILESYSTEM_P (ZEND_THIS );
2644
2624
2645
- if (!intern -> u .file .stream ) {
2646
- zend_throw_exception_ex (spl_ce_RuntimeException , 0 , "Object not initialized" );
2647
- RETURN_THROWS ();
2648
- }
2625
+ CHECK_SPL_FILE_OBJECT_IS_INITIALIZED ();
2649
2626
2650
2627
RETURN_LONG (php_stream_passthru (intern -> u .file .stream ));
2651
2628
} /* }}} */
@@ -2662,10 +2639,7 @@ PHP_METHOD(SplFileObject, fscanf)
2662
2639
RETURN_THROWS ();
2663
2640
}
2664
2641
2665
- if (!intern -> u .file .stream ) {
2666
- zend_throw_exception_ex (spl_ce_RuntimeException , 0 , "Object not initialized" );
2667
- RETURN_THROWS ();
2668
- }
2642
+ CHECK_SPL_FILE_OBJECT_IS_INITIALIZED ();
2669
2643
2670
2644
/* Get next line */
2671
2645
if (spl_filesystem_file_read (intern , 0 ) == FAILURE ) {
@@ -2693,10 +2667,7 @@ PHP_METHOD(SplFileObject, fwrite)
2693
2667
RETURN_THROWS ();
2694
2668
}
2695
2669
2696
- if (!intern -> u .file .stream ) {
2697
- zend_throw_exception_ex (spl_ce_RuntimeException , 0 , "Object not initialized" );
2698
- RETURN_THROWS ();
2699
- }
2670
+ CHECK_SPL_FILE_OBJECT_IS_INITIALIZED ();
2700
2671
2701
2672
if (ZEND_NUM_ARGS () > 1 ) {
2702
2673
if (length >= 0 ) {
@@ -2727,10 +2698,7 @@ PHP_METHOD(SplFileObject, fread)
2727
2698
RETURN_THROWS ();
2728
2699
}
2729
2700
2730
- if (!intern -> u .file .stream ) {
2731
- zend_throw_exception_ex (spl_ce_RuntimeException , 0 , "Object not initialized" );
2732
- RETURN_THROWS ();
2733
- }
2701
+ CHECK_SPL_FILE_OBJECT_IS_INITIALIZED ();
2734
2702
2735
2703
if (length <= 0 ) {
2736
2704
php_error_docref (NULL , E_WARNING , "Length parameter must be greater than 0" );
@@ -2779,10 +2747,7 @@ PHP_METHOD(SplFileObject, ftruncate)
2779
2747
RETURN_THROWS ();
2780
2748
}
2781
2749
2782
- if (!intern -> u .file .stream ) {
2783
- zend_throw_exception_ex (spl_ce_RuntimeException , 0 , "Object not initialized" );
2784
- RETURN_THROWS ();
2785
- }
2750
+ CHECK_SPL_FILE_OBJECT_IS_INITIALIZED ();
2786
2751
2787
2752
if (!php_stream_truncate_supported (intern -> u .file .stream )) {
2788
2753
zend_throw_exception_ex (spl_ce_LogicException , 0 , "Can't truncate file %s" , intern -> file_name );
@@ -2801,10 +2766,8 @@ PHP_METHOD(SplFileObject, seek)
2801
2766
if (zend_parse_parameters (ZEND_NUM_ARGS (), "l" , & line_pos ) == FAILURE ) {
2802
2767
RETURN_THROWS ();
2803
2768
}
2804
- if (!intern -> u .file .stream ) {
2805
- zend_throw_exception_ex (spl_ce_RuntimeException , 0 , "Object not initialized" );
2806
- RETURN_THROWS ();
2807
- }
2769
+
2770
+ CHECK_SPL_FILE_OBJECT_IS_INITIALIZED ();
2808
2771
2809
2772
if (line_pos < 0 ) {
2810
2773
zend_throw_exception_ex (spl_ce_LogicException , 0 , "Can't seek file %s to negative line " ZEND_LONG_FMT , intern -> file_name , line_pos );
0 commit comments