add disable_sigint to make ctrl-C not crash Julia

This commit is contained in:
Spencer Russell 2020-02-22 21:42:45 -05:00
parent b9c604533d
commit 461cdc1557

View file

@ -233,9 +233,16 @@ end
function Pa_ReadStream(stream::PaStream, buf::Array, frames::Integer=length(buf), function Pa_ReadStream(stream::PaStream, buf::Array, frames::Integer=length(buf),
show_warnings::Bool=true) show_warnings::Bool=true)
frames <= length(buf) || error("Need a buffer at least $frames long") frames <= length(buf) || error("Need a buffer at least $frames long")
err = @tcall @locked ccall((:Pa_ReadStream, libportaudio), PaError, # without this I get a segfault with the error:
(PaStream, Ptr{Cvoid}, Culong), # "error thrown and no exception handler available."
stream, buf, frames) # if the user tries to ctrl-C. Note I've still had some crash problems with
# ctrl-C within `pasuspend`, so for now I think either don't use `pasuspend` or
# don't use ctrl-C.
err = disable_sigint() do
@tcall @locked ccall((:Pa_ReadStream, libportaudio), PaError,
(PaStream, Ptr{Cvoid}, Culong),
stream, buf, frames)
end
handle_status(err, show_warnings) handle_status(err, show_warnings)
buf buf
end end
@ -243,9 +250,11 @@ end
function Pa_WriteStream(stream::PaStream, buf::Array, frames::Integer=length(buf), function Pa_WriteStream(stream::PaStream, buf::Array, frames::Integer=length(buf),
show_warnings::Bool=true) show_warnings::Bool=true)
frames <= length(buf) || error("Need a buffer at least $frames long") frames <= length(buf) || error("Need a buffer at least $frames long")
err = @tcall @locked ccall((:Pa_WriteStream, libportaudio), PaError, err = disable_sigint() do
(PaStream, Ptr{Cvoid}, Culong), @tcall @locked ccall((:Pa_WriteStream, libportaudio), PaError,
stream, buf, frames) (PaStream, Ptr{Cvoid}, Culong),
stream, buf, frames)
end
handle_status(err, show_warnings) handle_status(err, show_warnings)
nothing nothing
end end