Skip to content

Commit

Permalink
PY: Fix crash when running nxrunner with python filters.
Browse files Browse the repository at this point in the history
Incorrect use of the getenv() function.

Signed-off-by: Michael Jackson <mike.jackson@bluequartz.net>
  • Loading branch information
imikejackson committed Dec 27, 2023
1 parent cded997 commit e723eaf
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/nxrunner/src/nxrunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,34 @@ int main(int argc, char* argv[])
LoadApp();

#if SIMPLNX_EMBED_PYTHON
{
constexpr const char k_PYTHONHOME[] = "PYTHONHOME";
constexpr const char k_CONDA_PREFIX[] = "CONDA_PREFIX";

std::string condaPrefix;
char* condaPrefixPtr = getenv(k_CONDA_PREFIX);
if(condaPrefixPtr != nullptr)
{
condaPrefix = condaPrefixPtr;
std::cout << "CONDA_PREFIX=" << condaPrefix << std::endl;
}

std::string pythonHome;
char* pythonHomePtr = getenv(k_PYTHONHOME);
if(pythonHomePtr != nullptr)
{
pythonHome = pythonHomePtr;
std::cout << "PYTHONHOME=" << pythonHome << std::endl;
}

if(pythonHome.empty() && !condaPrefix.empty())
{
std::string envVar = fmt::format("{}={}", k_PYTHONHOME, condaPrefix);
putenv(envVar.data());
std::cout << envVar << std::endl;
}
}

py::scoped_interpreter guard{};

try
Expand Down

0 comments on commit e723eaf

Please sign in to comment.