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

Promote std.process.Config.preExecFunction to a delegate #8989

Merged

Commits on Apr 25, 2024

  1. Promote std.process.Config.preExecFunction to a delegate

    std.process.Config.preExecFunction is now a delegate instead of a function
    pointer, and can therefore capture an environment, for example:
    
        import core.sys.linux.sys.prctl : PR_SET_PDEATHSIG, prctl;
        import std.process : Config, execute;
    
        void runProgram(int pdeathsig)
        {
            execute(
                ["program"],
                config: Config(
                    preExecFunction: () @trusted =>
                        prctl(PR_SET_PDEATHSIG, pdeathsig, 0, 0, 0) != -1,
                ),
            );
        }
    
    Despite function pointers implicitly converting to delegates, this is a
    backwards-incompatible change, as user code may rely on the field being a
    function pointer. For example, code like the following will no longer compile:
    
        import std.process : Config;
    
        nothrow pure @nogc @safe
        bool f() { return true; }
    
        void example()
        {
            auto config = Config(preExecFunction: &f);
            bool function() g = config.preExecFunction;
        }
    chloekek committed Apr 25, 2024
    Configuration menu
    Copy the full SHA
    5ce5344 View commit details
    Browse the repository at this point in the history

Commits on Apr 26, 2024

  1. Add std.process.Config.preExecDelegate

    std.process.Config.preExecDelegate is just like
    std.process.Config.preExecFunction, but can capture an environment, for
    example:
    
        import core.sys.linux.sys.prctl : PR_SET_PDEATHSIG, prctl;
        import std.process : Config, execute;
    
        void runProgram(int pdeathsig)
        {
            execute(
                ["program"],
                config: Config(
                    preExecDelegate: () @trusted =>
                        prctl(PR_SET_PDEATHSIG, pdeathsig, 0, 0, 0) != -1,
                ),
            );
        }
    
    preExecFunction is retained for backwards compatibility. If both
    preExecFunction and preExecDelegate are given, both are called.
    chloekek committed Apr 26, 2024
    Configuration menu
    Copy the full SHA
    7a280a9 View commit details
    Browse the repository at this point in the history