Skip to content

Commit bf3ed57

Browse files
authored
pty_{master,slave} -> pt{m,s} (#36315)
We decided to get rid of the master/slave terminology in Julia in #30058. However, we decided to keep it for PTYs, where the terminology is imposed upon us by POSIX (and thus changing it would be confusing for people who might need to read up on the POSIX definitions of these concepts). It was recently suggested to revisit this, by renaming to ptm and pts instead, which also fit well (as the devies that the fds refer to are `/dev/ptmx` and `/dev/pts` respectively), are googleable (`pty pts` will yield the correct man page) and will probably need to remain even if POSIX adjusts their terminology, since they're part of the ABI (presumably they'll be backronymed to whatever terminology ends up winning). This patch does this rename.
1 parent 0a2644a commit bf3ed57

File tree

4 files changed

+55
-55
lines changed

4 files changed

+55
-55
lines changed

contrib/generate_precompile.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ function generate_precompile_statements()
8686

8787
mktemp() do precompile_file, precompile_file_h
8888
# Run a repl process and replay our script
89-
pty_slave, pty_master = open_fake_pty()
89+
pts, ptm = open_fake_pty()
9090
blackhole = Sys.isunix() ? "/dev/null" : "nul"
9191
if have_repl
9292
cmdargs = ```--color=yes
@@ -104,25 +104,25 @@ function generate_precompile_statements()
104104
--cpu-target=native --startup-file=no --color=yes
105105
-e 'import REPL; REPL.Terminals.is_precompiling[] = true'
106106
-i $cmdargs```,
107-
pty_slave, pty_slave, pty_slave; wait=false)
107+
pts, pts, pts; wait=false)
108108
end
109-
Base.close_stdio(pty_slave)
110-
# Prepare a background process to copy output from process until `pty_slave` is closed
109+
Base.close_stdio(pts)
110+
# Prepare a background process to copy output from process until `pts` is closed
111111
output_copy = Base.BufferStream()
112112
tee = @async try
113-
while !eof(pty_master)
114-
l = readavailable(pty_master)
113+
while !eof(ptm)
114+
l = readavailable(ptm)
115115
write(debug_output, l)
116116
Sys.iswindows() && (sleep(0.1); yield(); yield()) # workaround hang - probably a libuv issue?
117117
write(output_copy, l)
118118
end
119119
close(output_copy)
120-
close(pty_master)
120+
close(ptm)
121121
catch ex
122122
close(output_copy)
123-
close(pty_master)
123+
close(ptm)
124124
if !(ex isa Base.IOError && ex.code == Base.UV_EIO)
125-
rethrow() # ignore EIO on pty_master after pty_slave dies
125+
rethrow() # ignore EIO on ptm after pts dies
126126
end
127127
end
128128
# wait for the definitive prompt before start writing to the TTY
@@ -141,7 +141,7 @@ function generate_precompile_statements()
141141
bytesavailable(output_copy) > 0 && readavailable(output_copy)
142142
# push our input
143143
write(debug_output, "\n#### inputting statement: ####\n$(repr(l))\n####\n")
144-
write(pty_master, l, "\n")
144+
write(ptm, l, "\n")
145145
readuntil(output_copy, "\n")
146146
# wait for the next prompt-like to appear
147147
# NOTE: this is rather innaccurate because the Pkg REPL mode is a special flower
@@ -150,10 +150,10 @@ function generate_precompile_statements()
150150
end
151151
println()
152152
end
153-
write(pty_master, "exit()\n")
153+
write(ptm, "exit()\n")
154154
wait(tee)
155155
success(p) || Base.pipeline_error(p)
156-
close(pty_master)
156+
close(ptm)
157157
write(debug_output, "\n#### FINISHED ####\n")
158158

159159
# Extract the precompile statements from the precompile file

stdlib/LibGit2/test/libgit2.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ function challenge_prompt(cmd::Cmd, challenges; timeout::Integer=60, debug::Bool
4747
return "Process output found:\n\"\"\"\n$str\n\"\"\""
4848
end
4949
out = IOBuffer()
50-
with_fake_pty() do pty_slave, pty_master
51-
p = run(detach(cmd), pty_slave, pty_slave, pty_slave, wait=false)
52-
Base.close_stdio(pty_slave)
50+
with_fake_pty() do pts, ptm
51+
p = run(detach(cmd), pts, pts, pts, wait=false)
52+
Base.close_stdio(pts)
5353

5454
# Kill the process if it takes too long. Typically occurs when process is waiting
5555
# for input.
@@ -79,25 +79,25 @@ function challenge_prompt(cmd::Cmd, challenges; timeout::Integer=60, debug::Bool
7979
end
8080

8181
for (challenge, response) in challenges
82-
write(out, readuntil(pty_master, challenge, keep=true))
83-
if !isopen(pty_master)
82+
write(out, readuntil(ptm, challenge, keep=true))
83+
if !isopen(ptm)
8484
error("Could not locate challenge: \"$challenge\". ",
8585
format_output(out))
8686
end
87-
write(pty_master, response)
87+
write(ptm, response)
8888
end
8989

90-
# Capture output from process until `pty_slave` is closed
90+
# Capture output from process until `pts` is closed
9191
try
92-
write(out, pty_master)
92+
write(out, ptm)
9393
catch ex
9494
if !(ex isa Base.IOError && ex.code == Base.UV_EIO)
9595
rethrow() # ignore EIO from master after slave dies
9696
end
9797
end
9898

9999
status = fetch(timer)
100-
close(pty_master)
100+
close(ptm)
101101
if status != :success
102102
if status == :timeout
103103
error("Process timed out possibly waiting for a response. ",

stdlib/REPL/test/repl.jl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -768,43 +768,43 @@ Base.exit_on_sigint(true)
768768

769769
let exename = Base.julia_cmd()
770770
# Test REPL in dumb mode
771-
with_fake_pty() do pty_slave, pty_master
771+
with_fake_pty() do pts, ptm
772772
nENV = copy(ENV)
773773
nENV["TERM"] = "dumb"
774-
p = run(detach(setenv(`$exename --startup-file=no -q`, nENV)), pty_slave, pty_slave, pty_slave, wait=false)
775-
Base.close_stdio(pty_slave)
776-
output = readuntil(pty_master, "julia> ", keep=true)
774+
p = run(detach(setenv(`$exename --startup-file=no -q`, nENV)), pts, pts, pts, wait=false)
775+
Base.close_stdio(pts)
776+
output = readuntil(ptm, "julia> ", keep=true)
777777
if ccall(:jl_running_on_valgrind, Cint,()) == 0
778778
# If --trace-children=yes is passed to valgrind, we will get a
779779
# valgrind banner here, not just the prompt.
780780
@test output == "julia> "
781781
end
782-
write(pty_master, "1\nexit()\n")
782+
write(ptm, "1\nexit()\n")
783783

784-
output = readuntil(pty_master, ' ', keep=true)
784+
output = readuntil(ptm, ' ', keep=true)
785785
if Sys.iswindows()
786786
# Our fake pty is actually a pipe, and thus lacks the input echo feature of posix
787787
@test output == "1\n\njulia> "
788788
else
789789
@test output == "1\r\nexit()\r\n1\r\n\r\njulia> "
790790
end
791-
@test bytesavailable(pty_master) == 0
791+
@test bytesavailable(ptm) == 0
792792
@test if Sys.iswindows() || Sys.isbsd()
793-
eof(pty_master)
793+
eof(ptm)
794794
else
795795
# Some platforms (such as linux) report EIO instead of EOF
796796
# possibly consume child-exited notification
797797
# for example, see discussion in https://bugs.python.org/issue5380
798798
try
799-
eof(pty_master) && !Sys.islinux()
799+
eof(ptm) && !Sys.islinux()
800800
catch ex
801801
(ex isa Base.IOError && ex.code == Base.UV_EIO) || rethrow()
802-
@test_throws ex eof(pty_master) # make sure the error is sticky
803-
pty_master.readerror = nothing
804-
eof(pty_master)
802+
@test_throws ex eof(ptm) # make sure the error is sticky
803+
ptm.readerror = nothing
804+
eof(ptm)
805805
end
806806
end
807-
@test read(pty_master, String) == ""
807+
@test read(ptm, String) == ""
808808
wait(p)
809809
end
810810

test/testhelpers/FakePTYs.jl

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,25 @@ function open_fake_pty()
1616
pid = string(getpid(), base=16, pad=16)
1717
pipename = """\\\\?\\pipe\\cygwin-$pid-pty10-abcdefg"""
1818
server = listen(pipename)
19-
pty_slave = connect(pipename)
20-
@assert ccall(:jl_ispty, Cint, (Ptr{Cvoid},), pty_slave.handle) == 1
21-
pty_master = accept(server)
19+
pts = connect(pipename)
20+
@assert ccall(:jl_ispty, Cint, (Ptr{Cvoid},), pts.handle) == 1
21+
ptm = accept(server)
2222
close(server)
2323
# extract just the file descriptor
24-
fds = Libc.dup(Base._fd(pty_slave))
25-
close(pty_slave)
26-
pty_slave = fds
27-
# convert pty_slave handle to a TTY
28-
#fds = pty_slave.handle
29-
#pty_slave.status = Base.StatusClosed
30-
#pty_slave.handle = C_NULL
31-
#pty_slave = Base.TTY(fds, Base.StatusOpen)
24+
fds = Libc.dup(Base._fd(pts))
25+
close(pts)
26+
pts = fds
27+
# convert pts handle to a TTY
28+
#fds = pts.handle
29+
#pts.status = Base.StatusClosed
30+
#pts.handle = C_NULL
31+
#pts = Base.TTY(fds, Base.StatusOpen)
3232
else
3333
O_RDWR = Base.Filesystem.JL_O_RDWR
3434
O_NOCTTY = Base.Filesystem.JL_O_NOCTTY
3535

3636
fdm = ccall(:posix_openpt, Cint, (Cint,), O_RDWR | O_NOCTTY)
37-
fdm == -1 && error("Failed to open pty_master")
37+
fdm == -1 && error("Failed to open ptm")
3838
rc = ccall(:grantpt, Cint, (Cint,), fdm)
3939
rc != 0 && error("grantpt failed")
4040
rc = ccall(:unlockpt, Cint, (Cint,), fdm)
@@ -43,21 +43,21 @@ function open_fake_pty()
4343
fds = ccall(:open, Cint, (Ptr{UInt8}, Cint),
4444
ccall(:ptsname, Ptr{UInt8}, (Cint,), fdm), O_RDWR | O_NOCTTY)
4545

46-
pty_slave = RawFD(fds)
47-
# pty_slave = fdio(fds, true)
48-
# pty_slave = Base.Filesystem.File(RawFD(fds))
49-
# pty_slave = Base.TTY(RawFD(fds); readable = false)
50-
pty_master = Base.TTY(RawFD(fdm))
46+
pts = RawFD(fds)
47+
# pts = fdio(fds, true)
48+
# pts = Base.Filesystem.File(RawFD(fds))
49+
# pts = Base.TTY(RawFD(fds); readable = false)
50+
ptm = Base.TTY(RawFD(fdm))
5151
end
52-
return pty_slave, pty_master
52+
return pts, ptm
5353
end
5454

5555
function with_fake_pty(f)
56-
pty_slave, pty_master = open_fake_pty()
56+
pts, ptm = open_fake_pty()
5757
try
58-
f(pty_slave, pty_master)
58+
f(pts, ptm)
5959
finally
60-
close(pty_master)
60+
close(ptm)
6161
end
6262
nothing
6363
end

0 commit comments

Comments
 (0)