Skip to content

Commit

Permalink
changed error macros to require a ; at the end.
Browse files Browse the repository at this point in the history
  • Loading branch information
klemens-morgenstern committed Oct 27, 2024
1 parent 22c2ad0 commit adf3d62
Show file tree
Hide file tree
Showing 22 changed files with 187 additions and 148 deletions.
17 changes: 6 additions & 11 deletions include/boost/process/v2/detail/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,6 @@ namespace filesystem = std::filesystem;
using std::quoted;
using std::optional;

#define BOOST_PROCESS_V2_RETURN_EC(ev) \
return ::BOOST_PROCESS_V2_NAMESPACE::error_code(ev, ::BOOST_PROCESS_V2_NAMESPACE::system_category()); \

#define BOOST_PROCESS_V2_ASSIGN_EC(ec, ...) ec.assign(__VA_ARGS__);
#define BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) \
ec.assign(::BOOST_PROCESS_V2_NAMESPACE::detail::get_last_error()); \
Expand All @@ -123,23 +120,21 @@ namespace filesystem = std::filesystem;
namespace filesystem = boost::filesystem;
#endif

#define BOOST_PROCESS_V2_RETURN_EC(ev) \
{ \
static constexpr auto loc##__LINE__((BOOST_CURRENT_LOCATION)); \
return ::BOOST_PROCESS_V2_NAMESPACE::error_code(ev, ::BOOST_PROCESS_V2_NAMESPACE::system_category(), &loc##__LINE__); \
}

#define BOOST_PROCESS_V2_ASSIGN_EC(ec, ...) \
do \
{ \
static constexpr auto loc##__LINE__((BOOST_CURRENT_LOCATION)); \
ec.assign(__VA_ARGS__, &loc##__LINE__); \
}
} \
while (false)

#define BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) \
do \
{ \
static constexpr auto loc##__LINE__((BOOST_CURRENT_LOCATION)); \
ec.assign(::BOOST_PROCESS_V2_NAMESPACE::detail::get_last_error(), &loc##__LINE__); \
}
} \
while (false)


#endif
Expand Down
23 changes: 23 additions & 0 deletions include/boost/process/v2/experimental/basic_stream_input.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// Copyright (c) 2024 Klemens Morgenstern (klemens.morgenstern@gmx.net)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//

#ifndef BOOST_PROCESS_BASIC_STREAM_INPUT_HPP
#define BOOST_PROCESS_BASIC_STREAM_INPUT_HPP

#include <boost/process/v2/detail/config.hpp>

BOOST_PROCESS_V2_BEGIN_NAMESPACE




template<typename Executor>
basic_stream_input<Executor> open_stdin(Executor executor, bool duplicate = true);

BOOST_PROCESS_V2_END_NAMESPACE

#endif //BOOST_PROCESS_BASIC_STREAM_INPUT_HPP
21 changes: 21 additions & 0 deletions include/boost/process/v2/experimental/stream_input.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// Copyright (c) 2024 Klemens Morgenstern (klemens.morgenstern@gmx.net)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//

#ifndef BOOST_PROCESS_V2_EXPERIMENTAL_STREAM_INPUT_HPP
#define BOOST_PROCESS_V2_EXPERIMENTAL_STREAM_INPUT_HPP

#include <boost/process/v2/detail/config.hpp>
#include <boost/process/v2/experimental/basic_stream_input.hpp>


BOOST_PROCESS_V2_BEGIN_NAMESPACE

typedef basic_stream_input<> stream_input;

BOOST_PROCESS_V2_END_NAMESPACE

#endif //BOOST_PROCESS_V2_EXPERIMENTAL_STREAM_INPUT_HPP
12 changes: 6 additions & 6 deletions include/boost/process/v2/posix/default_launcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,12 +365,12 @@ struct default_launcher
pipe_guard pg;
if (::pipe(pg.p))
{
BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category())
BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category());
return basic_process<Executor>{exec};
}
if (::fcntl(pg.p[1], F_SETFD, FD_CLOEXEC))
{
BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category())
BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category());
return basic_process<Executor>{exec};
}
ec = detail::on_setup(*this, executable, argv, inits ...);
Expand All @@ -391,7 +391,7 @@ struct default_launcher
detail::on_fork_error(*this, executable, argv, ec, inits...);
detail::on_error(*this, executable, argv, ec, inits...);

BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category())
BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category());
return basic_process<Executor>{exec};
}
else if (pid == 0)
Expand All @@ -407,7 +407,7 @@ struct default_launcher
::execve(executable.c_str(), const_cast<char * const *>(argv), const_cast<char * const *>(env));

ignore_unused(::write(pg.p[1], &errno, sizeof(int)));
BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category())
BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category());
detail::on_exec_error(*this, executable, argv, ec, inits...);
::exit(EXIT_FAILURE);
return basic_process<Executor>{exec};
Expand All @@ -423,12 +423,12 @@ struct default_launcher
int err = errno;
if ((err != EAGAIN) && (err != EINTR))
{
BOOST_PROCESS_V2_ASSIGN_EC(ec, err, system_category())
BOOST_PROCESS_V2_ASSIGN_EC(ec, err, system_category());
break;
}
}
if (count != 0)
BOOST_PROCESS_V2_ASSIGN_EC(ec, child_error, system_category())
BOOST_PROCESS_V2_ASSIGN_EC(ec, child_error, system_category());

if (ec)
{
Expand Down
4 changes: 2 additions & 2 deletions include/boost/process/v2/posix/fork_and_forget_launcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ struct fork_and_forget_launcher : default_launcher
detail::on_fork_error(*this, executable, argv, ec, inits...);
detail::on_error(*this, executable, argv, ec, inits...);

BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category())
BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category());
return basic_process<Executor>{exec};
}
else if (pid == 0)
Expand All @@ -107,7 +107,7 @@ struct fork_and_forget_launcher : default_launcher
if (!ec)
::execve(executable.c_str(), const_cast<char * const *>(argv), const_cast<char * const *>(env));

BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category())
BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category());
detail::on_exec_error(*this, executable, argv, ec, inits...);
::exit(EXIT_FAILURE);
return basic_process<Executor>{exec};
Expand Down
12 changes: 6 additions & 6 deletions include/boost/process/v2/posix/pdfork_launcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ struct pdfork_launcher : default_launcher
pipe_guard pg;
if (::pipe(pg.p))
{
BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category())
BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category());
return basic_process<Executor>{exec};
}
if (::fcntl(pg.p[1], F_SETFD, FD_CLOEXEC))
{
BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category())
BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category());
return basic_process<Executor>{exec};
}
ec = detail::on_setup(*this, executable, argv, inits ...);
Expand All @@ -111,7 +111,7 @@ struct pdfork_launcher : default_launcher
detail::on_fork_error(*this, executable, argv, ec, inits...);
detail::on_error(*this, executable, argv, ec, inits...);

BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category())
BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category());
return basic_process<Executor>{exec};
}
else if (pid == 0)
Expand All @@ -128,7 +128,7 @@ struct pdfork_launcher : default_launcher
::execve(executable.c_str(), const_cast<char * const *>(argv), const_cast<char * const *>(env));

default_launcher::ignore_unused(::write(pg.p[1], &errno, sizeof(int)));
BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category())
BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category());
detail::on_exec_error(*this, executable, argv, ec, inits...);
::exit(EXIT_FAILURE);
return basic_process<Executor>{exec};
Expand All @@ -143,12 +143,12 @@ struct pdfork_launcher : default_launcher
int err = errno;
if ((err != EAGAIN) && (err != EINTR))
{
BOOST_PROCESS_V2_ASSIGN_EC(ec, err, system_category())
BOOST_PROCESS_V2_ASSIGN_EC(ec, err, system_category());
break;
}
}
if (count != 0)
BOOST_PROCESS_V2_ASSIGN_EC(ec, child_error, system_category())
BOOST_PROCESS_V2_ASSIGN_EC(ec, child_error, system_category());

if (ec)
{
Expand Down
4 changes: 2 additions & 2 deletions include/boost/process/v2/posix/vfork_launcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ struct vfork_launcher : default_launcher
detail::on_fork_error(*this, executable, argv, ec, inits...);
detail::on_error(*this, executable, argv, ec, inits...);

BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category())
BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category());
return basic_process<Executor>{exec};
}
else if (pid == 0)
Expand All @@ -107,7 +107,7 @@ struct vfork_launcher : default_launcher
if (!ec)
::execve(executable.c_str(), const_cast<char * const *>(argv), const_cast<char * const *>(env));

BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category())
BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category());
detail::on_exec_error(*this, executable, argv, ec, inits...);
::_exit(EXIT_FAILURE);
return basic_process<Executor>{exec};
Expand Down
4 changes: 2 additions & 2 deletions include/boost/process/v2/stdio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ struct process_io_binding
fd = p[1];
if (::fcntl(p[0], F_SETFD, FD_CLOEXEC) == -1)
{
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec)
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec);
return ;
}
fd_needs_closing = true;
Expand All @@ -223,7 +223,7 @@ struct process_io_binding
fd = p[0];
if (::fcntl(p[1], F_SETFD, FD_CLOEXEC) == -1)
{
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec)
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec);
return ;
}
fd_needs_closing = true;
Expand Down
2 changes: 1 addition & 1 deletion include/boost/process/v2/windows/as_user_launcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ struct as_user_launcher : default_launcher

if (ok == 0)
{
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec)
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec);
detail::on_error(*this, executable, command_line, ec, inits...);

if (process_information.hProcess != INVALID_HANDLE_VALUE)
Expand Down
2 changes: 1 addition & 1 deletion include/boost/process/v2/windows/default_launcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ struct default_launcher

if (ok == 0)
{
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec)
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec);
detail::on_error(*this, executable, command_line, ec, inits...);

if (process_information.hProcess != INVALID_HANDLE_VALUE)
Expand Down
2 changes: 1 addition & 1 deletion include/boost/process/v2/windows/with_logon_launcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ struct with_logon_launcher : default_launcher

if (ok == 0)
{
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec)
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec);
detail::on_error(*this, executable, command_line, ec, inits...);

if (process_information.hProcess != INVALID_HANDLE_VALUE)
Expand Down
2 changes: 1 addition & 1 deletion include/boost/process/v2/windows/with_token_launcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ struct with_token_launcher : default_launcher

if (ok == 0)
{
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec)
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec);
detail::on_error(*this, executable, command_line, ec, inits...);

if (process_information.hProcess != INVALID_HANDLE_VALUE)
Expand Down
6 changes: 3 additions & 3 deletions src/detail/environment_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ basic_cstring_ref<char_type, value_char_traits<char>> get(
auto res = ::getenv(key.c_str());
if (res == nullptr)
{
BOOST_PROCESS_V2_ASSIGN_EC(ec, ENOENT, system_category())
BOOST_PROCESS_V2_ASSIGN_EC(ec, ENOENT, system_category());
return {};
}
return res;
Expand All @@ -41,13 +41,13 @@ void set(basic_cstring_ref<char_type, key_char_traits<char_type>> key,
error_code & ec)
{
if (::setenv(key.c_str(), value.c_str(), true))
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec)
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec);
}

void unset(basic_cstring_ref<char_type, key_char_traits<char_type>> key, error_code & ec)
{
if (::unsetenv(key.c_str()))
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec)
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec);
}


Expand Down
12 changes: 6 additions & 6 deletions src/detail/environment_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ std::basic_string<char_type, value_char_traits<char_type>> get(
buf.resize(size);

if (buf.size() == 0)
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec)
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec);

return buf;
}
Expand All @@ -55,14 +55,14 @@ void set(basic_cstring_ref<char_type, key_char_traits<char_type>> key,
error_code & ec)
{
if (!::SetEnvironmentVariableW(key.c_str(), value.c_str()))
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec)
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec);
}

void unset(basic_cstring_ref<char_type, key_char_traits<char_type>> key,
error_code & ec)
{
if (!::SetEnvironmentVariableW(key.c_str(), nullptr))
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec)
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec);
}


Expand All @@ -83,7 +83,7 @@ std::basic_string<char, value_char_traits<char>> get(
buf.resize(size);

if (buf.size() == 0)
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec)
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec);

return buf;
}
Expand All @@ -93,14 +93,14 @@ void set(basic_cstring_ref<char, key_char_traits<char>> key,
error_code & ec)
{
if (!::SetEnvironmentVariableA(key.c_str(), value.c_str()))
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec)
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec);
}

void unset(basic_cstring_ref<char, key_char_traits<char>> key,
error_code & ec)
{
if (!::SetEnvironmentVariableA(key.c_str(), nullptr))
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec)
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec);
}


Expand Down
Loading

0 comments on commit adf3d62

Please sign in to comment.