Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0004499OCamlOCaml windowspublic2008-02-05 18:102013-07-29 16:56
Reporterfrisch 
Assigned To 
PrioritynormalSeverityminorReproducibilityalways
StatusacknowledgedResolutionopen 
PlatformOSWindowsOS Version
Product Version 
Target Version4.01.1+devFixed in Version 
Summary0004499: Changes to the environment are invisible to Sys.getenv
DescriptionWindows has functions like SetEnvironmentVariable/GetEnvironmentVariable to access the process environment. The MS C runtime library also has getenv/putenv functions, but they operate on a snapshot of the environment taken when the process started. putenv also push modifications to the real environment through SetEnvironmentVariable.

So, if we mix in a single process OCaml code and other native code that set environment variables directly (from .Net, we only have SetEnvironmentVariable, not putenv), these changes are not seen from OCaml, which uses getenv.

A fix would be to use the "native" win32 functions for OCaml (not only for implementing Sys.getenv, but also for all the calls to getenv in the runtime system; and some care is needed for execve).

(At LexiFi, we use a temporary solution: we have a function to "refresh" the local copy of the environment in the libc by fetching all the real environment variable and putenv'ing them.)
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0004452)
doligez (administrator)
2008-02-19 14:49

I could easily argue that this is a bug in the getenv of the MS C runtime library.
(0007582)
frisch (developer)
2012-06-20 11:25

> I could easily argue that this is a bug in the getenv of the MS C runtime library.

Probably, but it's easier (for us) to work-around the problem on the OCaml side than to convince Microsoft to fix their C runtime. As long as the effort remains reasonable, I think it's good to provide a coherent semantics between all the supported OCaml ports, even if this requires to work around bugs created by third parties.
(0008078)
doligez (administrator)
2012-09-15 11:57

The right solution is probably to define our own functions sys_getenv and sys_putenv once with system-dependent code, and then use them everywhere.

In fact, from your description it seems we only need to redefine getenv.
(0009989)
xleroy (administrator)
2013-07-29 16:56

Pushing this for later, as I don't see the issue fixed in time for 4.01.


- Issue History
Date Modified Username Field Change
2008-02-05 18:10 frisch New Issue
2008-02-19 14:49 doligez Note Added: 0004452
2008-02-19 14:49 doligez Status new => acknowledged
2012-06-20 11:20 frisch Category OCaml general => OCaml windows
2012-06-20 11:25 frisch Note Added: 0007582
2012-07-11 15:58 doligez Target Version => 4.01.0+dev
2012-07-31 13:37 doligez Target Version 4.01.0+dev => 4.00.1+dev
2012-09-15 11:57 doligez Note Added: 0008078
2012-09-15 11:57 doligez Target Version 4.00.1+dev => 4.00.2+dev
2013-07-09 16:09 doligez Target Version 4.00.2+dev => 4.01.0+dev
2013-07-29 16:56 xleroy Note Added: 0009989
2013-07-29 16:56 xleroy Target Version 4.01.0+dev => 4.01.1+dev


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker