@@ -805,27 +805,8 @@ def self.parse_mode(mode)
805
805
ret
806
806
end
807
807
808
- def self . pipe ( external = nil , internal = nil , options = nil )
809
- fds = FFI ::MemoryPointer . new ( :int , 2 ) do |ptr |
810
- r = Truffle ::POSIX . pipe ( ptr )
811
- Errno . handle if r == -1
812
- ptr . read_array_of_int ( 2 )
813
- end
814
-
815
- lhs = self . new ( fds [ 0 ] , RDONLY )
816
- rhs = self . new ( fds [ 1 ] , WRONLY )
817
-
818
- lhs . close_on_exec = true
819
- rhs . close_on_exec = true
820
-
821
- lhs . set_encoding external || Encoding . default_external ,
822
- internal || Encoding . default_internal , options
823
-
824
- lhs . sync = true
825
- rhs . sync = true
826
-
827
- lhs . pipe = true
828
- rhs . pipe = true
808
+ def self . pipe ( external = nil , internal = nil , options = nil )
809
+ lhs , rhs = Truffle ::IOOperations . create_pipe ( self , self , external , internal , options )
829
810
830
811
if block_given?
831
812
begin
@@ -881,16 +862,14 @@ def self.popen(*args)
881
862
readable = true
882
863
end
883
864
884
- pa_read , ch_write = pipe if readable
865
+ # We only need the Bidirectional pipe if we're reading and writing.
866
+ # Otherwise, we can just return the IO object for the proper half.
867
+ read_class = ( readable && writable ) ? IO ::BidirectionalPipe : self
868
+
869
+ pa_read , ch_write = Truffle ::IOOperations . create_pipe ( read_class , self ) if readable
885
870
ch_read , pa_write = pipe if writable
886
871
887
- # We only need the Bidirectional pipe if we're reading and writing.
888
- # If we're only doing one, we can just return the IO object for
889
- # the proper half.
890
872
if readable and writable
891
- # Transmogrify pa_read into a BidirectionalPipe object,
892
- # and then tell it about its pid and pa_write
893
- Truffle ::Internal ::Unsafe . set_class pa_read , IO ::BidirectionalPipe
894
873
pipe = pa_read
895
874
pipe . set_pipe_info ( pa_write )
896
875
elsif readable
0 commit comments