Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feedback on page SDL3/SDL_DestroyProcess #716

Open
icculus opened this issue Jan 26, 2025 · 1 comment
Open

Feedback on page SDL3/SDL_DestroyProcess #716

icculus opened this issue Jan 26, 2025 · 1 comment

Comments

@icculus
Copy link
Contributor

icculus commented Jan 26, 2025

Should note if this destroys the IOStreams associated with the process, or if those need to be closed manually.

@MrOnlineCoder
Copy link
Contributor

@icculus Yes it does:

void SDL_SYS_DestroyProcess(SDL_Process *process)
{
    SDL_IOStream *io;

    io = (SDL_IOStream *)SDL_GetPointerProperty(process->props, SDL_PROP_PROCESS_STDIN_POINTER, NULL);
    if (io) {
        SDL_CloseIO(io);
    }

    io = (SDL_IOStream *)SDL_GetPointerProperty(process->props, SDL_PROP_PROCESS_STDOUT_POINTER, NULL);
    if (io) {
        SDL_CloseIO(io);
    }

    io = (SDL_IOStream *)SDL_GetPointerProperty(process->props, SDL_PROP_PROCESS_STDERR_POINTER, NULL);
    if (io) {
        SDL_CloseIO(io);
    }

    SDL_free(process->internal);
}

POSIX: https://github.com/libsdl-org/SDL/blob/3be67ced646f9d884c32ce6858f39fe9dd8d634b/src/process/posix/SDL_posixprocess.c#L465
Windows: https://github.com/libsdl-org/SDL/blob/3be67ced646f9d884c32ce6858f39fe9dd8d634b/src/process/windows/SDL_windowsprocess.c#L534

But worth noting that as I understand that on creation it performs a handle duplication for user provided streams:
https://github.com/libsdl-org/SDL/blob/3be67ced646f9d884c32ce6858f39fe9dd8d634b/src/process/windows/SDL_windowsprocess.c#L70

And later the actual IOStreams saved to process props are new streams created from duplicated handles using internal SDL_IOFromHandle and SDL_IOFromFD functions:
https://github.com/libsdl-org/SDL/blob/3be67ced646f9d884c32ce6858f39fe9dd8d634b/src/process/windows/SDL_windowsprocess.c#L46

I am writing in sense that how this affects user provided IOStream - will process destruction also close user's streams, or no because the actual used streams were newly created duplicates?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants