Env::C's explanation is that the glue code doesn't translate one to the other, but I'm not going to try to pick apart SWIG internals to find out why not.
Instead, my solution was to do this:
- create a function on the C++ side that returned everything in the 'environ' list (defined by unistd.h) as a single string
- add this function to the perl side:
sub sync_env_settings_from_c {
my $env_string = CCode::getEnvSettings();
# in addition to grabbing changed settings, we also need
# to remove deleted settings, so we reset the %ENV
# hash. Note: do it *after* the call to getEnvSettings
# or else $env_string will be empty.
undef %ENV;
foreach my $block (split($SEPARATOR, $env_string)) {
next if (!$block); # first one's empty because I'm lazy
# each one looks like "key=value":
my ($key, $value) = split(m{=}, $block, 2);
$ENV{$key} = $value;
}
return;
}
- call that function after I know %ENV has been messed with.
I'm sure the efficiency is questionable, but at least it seems to be correct.