46
46
#include <sys/stat.h>
47
47
#endif
48
48
49
+ #ifndef HAVE_RB_IO_DESCRIPTOR
50
+ int io_descriptor_fallback (VALUE io ) {
51
+ rb_io_t * fptr ;
52
+ GetOpenFile (io , fptr );
53
+ return fptr -> fd ;
54
+ }
55
+ #define rb_io_descriptor io_descriptor_fallback
56
+ #endif
57
+
49
58
static VALUE mReadline ;
50
59
51
60
#define EDIT_LINE_LIBRARY_VERSION "EditLine wrapper"
@@ -373,30 +382,36 @@ clear_rl_outstream(void)
373
382
readline_outstream = Qfalse ;
374
383
}
375
384
385
+ VALUE io_descriptor (VALUE io ) {
386
+ return RB_INT2NUM (rb_io_descriptor (io ));
387
+ }
388
+
376
389
static void
377
390
prepare_readline (void )
378
391
{
379
392
static int initialized = 0 ;
393
+ int state ;
394
+
380
395
if (!initialized ) {
381
396
rl_initialize ();
382
397
initialized = 1 ;
383
398
}
384
399
385
400
if (readline_instream ) {
386
- rb_io_t * ifp ;
387
- rb_io_check_initialized ( ifp = RFILE ( rb_io_taint_check ( readline_instream )) -> fptr );
388
- if (ifp -> fd < 0 ) {
401
+ rb_protect ( io_descriptor , readline_instream , & state ) ;
402
+
403
+ if (state ) {
389
404
clear_rl_instream ();
390
- rb_raise ( rb_eIOError , "closed readline input" );
405
+ rb_jump_tag ( state );
391
406
}
392
407
}
393
408
394
409
if (readline_outstream ) {
395
- rb_io_t * ofp ;
396
- rb_io_check_initialized ( ofp = RFILE ( rb_io_taint_check ( readline_outstream )) -> fptr );
397
- if (ofp -> fd < 0 ) {
410
+ rb_protect ( io_descriptor , readline_outstream , & state ) ;
411
+
412
+ if (state ) {
398
413
clear_rl_outstream ();
399
- rb_raise ( rb_eIOError , "closed readline output" );
414
+ rb_jump_tag ( state );
400
415
}
401
416
}
402
417
}
@@ -553,7 +568,6 @@ readline_readline(int argc, VALUE *argv, VALUE self)
553
568
static VALUE
554
569
readline_s_set_input (VALUE self , VALUE input )
555
570
{
556
- rb_io_t * ifp ;
557
571
int fd ;
558
572
FILE * f ;
559
573
@@ -562,9 +576,9 @@ readline_s_set_input(VALUE self, VALUE input)
562
576
}
563
577
else {
564
578
Check_Type (input , T_FILE );
565
- GetOpenFile (input , ifp );
579
+ fd = rb_io_descriptor (input ); g
566
580
clear_rl_instream ();
567
- fd = rb_cloexec_dup (ifp -> fd );
581
+ fd = rb_cloexec_dup ();
568
582
if (fd == -1 )
569
583
rb_sys_fail ("dup" );
570
584
f = fdopen (fd , "r" );
@@ -589,7 +603,6 @@ readline_s_set_input(VALUE self, VALUE input)
589
603
static VALUE
590
604
readline_s_set_output (VALUE self , VALUE output )
591
605
{
592
- rb_io_t * ofp ;
593
606
int fd ;
594
607
FILE * f ;
595
608
@@ -598,9 +611,9 @@ readline_s_set_output(VALUE self, VALUE output)
598
611
}
599
612
else {
600
613
Check_Type (output , T_FILE );
601
- GetOpenFile (output , ofp );
614
+ fd = rb_io_descriptor (output );
602
615
clear_rl_outstream ();
603
- fd = rb_cloexec_dup (ofp -> fd );
616
+ fd = rb_cloexec_dup (fd );
604
617
if (fd == -1 )
605
618
rb_sys_fail ("dup" );
606
619
f = fdopen (fd , "w" );
0 commit comments