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

bp::environment::native_handle() cannot be compiled on Linux #332

Open
AJIOB opened this issue Aug 6, 2023 · 1 comment
Open

bp::environment::native_handle() cannot be compiled on Linux #332

AJIOB opened this issue Aug 6, 2023 · 1 comment

Comments

@AJIOB
Copy link
Contributor

AJIOB commented Aug 6, 2023

Code example to reproduce the issue:

#include <boost/process.hpp>

#include <iostream>

namespace bp = boost::process;

int main() {
    auto nativeEnv = boost::this_process::environment();
    auto nativeEnvHandle = nativeEnv.native_handle();
    std::cout << *nativeEnvHandle;

    bp::environment env = nativeEnv;
    // should also work, but don't
    auto envHandle = env.native_handle();
    std::cout << *envHandle;

    return 0;
}

GodBolt link to reproduce the issue: https://godbolt.org/z/cT7ovGv68

Affected library versions: boost 1.77.0, boost 1.82.0 (another versions were not tested).
Affected compilers: gcc 6.3.0, gcc 13.2, clang 16.0.0 (another versions were not tested).

Compiler flags: -std=c++11 -O2

Compiler output (gcc 13.2):

In file included from /opt/compiler-explorer/libs/boost_1_82_0/boost/process/environment.hpp:17,
                 from /opt/compiler-explorer/libs/boost_1_82_0/boost/process/env.hpp:10,
                 from /opt/compiler-explorer/libs/boost_1_82_0/boost/process.hpp:28,
                 from <source>:1:
/opt/compiler-explorer/libs/boost_1_82_0/boost/process/detail/posix/environment.hpp: In instantiation of 'Char** boost::process::detail::posix::basic_environment_impl<Char>::native_handle() const [with Char = char; native_handle_type = char**]':
<source>:14:39:   required from here
/opt/compiler-explorer/libs/boost_1_82_0/boost/process/detail/posix/environment.hpp:213:54: error: cannot convert 'const __gnu_cxx::__alloc_traits<std::allocator<std::__cxx11::basic_string<char> >, std::__cxx11::basic_string<char> >::value_type*' {aka 'const std::__cxx11::basic_string<char>*'} to 'boost::process::detail::posix::basic_environment_impl<char>::native_handle_type' {aka 'char**'} in return
  213 |     native_handle_type native_handle() const {return &_data.front();}
      |                                                      ^~~~~~~~~~~~~~
      |                                                      |
      |                                                      const __gnu_cxx::__alloc_traits<std::allocator<std::__cxx11::basic_string<char> >, std::__cxx11::basic_string<char> >::value_type* {aka const std::__cxx11::basic_string<char>*}
Compiler returned: 1

Proposed solution: store the duplicate vector<char*> _nativeData. Every char* should point on the same element on _data vector. _nativeData should reload elements on every _data rebuilding or element (stored std::string) changing.

klemens-morgenstern added a commit that referenced this issue Aug 8, 2023
@klemens-morgenstern
Copy link
Collaborator

Well that's embarrassing. Pretty amazing that you're the first one to catch it though. I'll have a fix in the next release.

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