Skip to content

Commit

Permalink
likely working argv parsing code
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlange6 committed Mar 1, 2019
1 parent 776c762 commit 78750b8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
22 changes: 17 additions & 5 deletions FWCore/PyDevParameterSet/src/PyBind11ProcessDesc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,24 @@ PyBind11ProcessDesc::PyBind11ProcessDesc(std::string const& config, int argc, ch
pybind11::initialize_interpreter();
edm::python::initializePyBind11Module();
prepareToRead();
{
#if PY_MAJOR_VERSION >= 3
typedef std::unique_ptr<wchar_t[], decltype(&PyMem_RawFree)> WArgUPtr;
std::vector<WArgUPtr> v_argv;
std::vector<wchar_t *> vp_argv;
v_argv.reserve(argc);
vp_argv.reserve(argc);
for (int i = 0; i < argc; i++) {
v_argv.emplace_back(Py_DecodeLocale(argv[i], NULL), &PyMem_RawFree);
vp_argv.emplace_back(v_argv.back().get());
}

wchar_t **argvt = vp_argv.data();
#else
char **argvt = argv;
#endif

if ( argc > 0 ) {
pybind11::list argvList;
for ( int i=0; i<argc; i++)
argvList.append(argv[i]);
pybind11::module::import("sys").attr("argv") = argvList;
PySys_SetArgv(argc, argvt);
}
read(config);
}
Expand Down
6 changes: 2 additions & 4 deletions FWCore/PyDevParameterSet/src/PyBind11Wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <vector>
#include <string>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <iostream>

namespace edm {
Expand All @@ -15,10 +16,7 @@ void

template<typename T>
pybind11::list toPython11List(const std::vector<T> & v) {
pybind11::list result;
for(const auto & i: v) {
result.append(i);
}
pybind11::list result=pybind11::cast(v);
return result;
}

Expand Down

0 comments on commit 78750b8

Please sign in to comment.