Boost logo

Boost :

Subject: Re: [boost] Boost.Process: Formal review request
From: Boris Schaeling (boris_at_[hidden])
Date: 2012-12-13 18:26:48


On Thu, 13 Dec 2012 12:23:45 +0100, Roland Bock <rbock_at_[hidden]> wrote:

> [...]The mitigate header is not even included by defaul, and hints
> towards it
> sound like a warning, not an encouragement to use it.

That's correct - exactly what I intended. :)

What I try to get across is that there is a different quality of service.
On the one hand there are functions like execute(), wait_for_exit() or the
various initializers. They are intrinsic to Boost.Process, and I as the
library maintainer guarantee that they work as documented or I'll fix it.
On the other hand there are helpers in the mitigate header which maybe do
what you need - without an exact definition what this should be nor a
guarantee from my side that this will always be the case.

There is for example the typedef boost::process::pipe_end. Depending on
the platform it's a different Boost.Asio class. These Boost.Asio classes
have a couple of member functions which have the same signature on all
platforms. That's what makes it possible to write cross-platform code to
initiate asynchronous operations. But boost::process::pipe_end doesn't
guarantee that you will never need to use #ifdefs. For example, it is
possible that you want to call a member function which exists only on one
platform.

 From Boost.Process' point of view the ideal solution would be if
Boost.Asio provided a cross-platform type for file descriptors/Windows
handles. As this type doesn't exist Boost.Process makes a best effort -
but no more.

> [...]Or Scott Meyers: "Make Interfaces Easy to Use Correctly and Hard to
> Use
> Incorrectly"

I believe that's what I did. These lines of code make it clear for every
C++ developer that it depends on the platform-specific type what you can
do with pipe_end:

#if defined(BOOST_WINDOWS_API)
   typedef boost::asio::windows::stream_handle pipe_end;
#elif defined(BOOST_POSIX_API)
   typedef boost::asio::posix::stream_descriptor pipe_end;
#endif
pipe_end pend(io_service, file_descriptor);

This code however could make you think you have a perfectly fine
cross-platform type as after all it's provided by Boost.Process:

boost::process::pipe_end pend(io_service, file_descriptor);

But your assumption would be wrong, and I would have made it easy for you
to use pipe_end incorrectly. So my hope is that by making you explicitly
include the mitigate header (which defines boost::process::pipe_end) I
help you not to shoot into your foot. And for those who really just want
to use a seemingly cross-platform type including the header is easy enough.

So much about the background information where the mitigate header comes
from. :)

Boris


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk