[m-rev.] diff: implement io__set_environment_variable in C#
Peter Ross
pro at missioncriticalit.com
Fri Nov 14 21:56:42 AEDT 2003
Hi,
===================================================================
Estimated hours taken: 1.5
Branches: main
Implement io__set_environment_variable in C#.
library/io.m:
Call mercury.runtime.PInovke._putenv to set the environment
variable.
runtime/mercury_dotnet.cs.in:
Use pinvoke to call the Posix function _putenv.
This is defined in the runtime, rather than io.m because at a
later date we will need to use configure to select the correct
putenv for different platforms.
Index: library/io.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/io.m,v
retrieving revision 1.310
diff -u -r1.310 io.m
--- library/io.m 14 Nov 2003 09:55:15 -0000 1.310
+++ library/io.m 14 Nov 2003 10:52:52 -0000
@@ -6415,9 +6415,6 @@
:- pragma foreign_decl("C", "
#include <stdlib.h> /* for getenv() and putenv() */
").
-:- pragma foreign_decl("MC++", "
-#include <stdlib.h> /* for putenv() */
-").
:- pragma promise_semipure(io__getenv/2).
@@ -6457,7 +6454,7 @@
SUCCESS_INDICATOR = (putenv(VarAndValue) == 0);
").
-:- pragma foreign_proc("MC++",
+:- pragma foreign_proc("C#",
io__putenv(VarAndValue::in),
[will_not_call_mercury, tabled_for_io],
"
@@ -6467,16 +6464,7 @@
** platform-specific methods. Currently we use the Posix function
** putenv(), which is also supported on Windows.
*/
-
- /*
- ** Convert VarAndValue from a .NET managed string (System.String)
- ** to an unmanaged C string (`char *') on the unmanaged C heap,
- ** and then just invoke putenv().
- */
- char __nogc *c_string = static_cast<char*>(
- System::Runtime::InteropServices::Marshal::
- StringToHGlobalAnsi(VarAndValue).ToPointer());
- SUCCESS_INDICATOR = (putenv(c_string) == 0);
+ SUCCESS_INDICATOR = (mercury.runtime.PInvoke._putenv(VarAndValue) == 0);
").
/*---------------------------------------------------------------------------*/
Index: runtime/mercury_dotnet.cs.in
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_dotnet.cs.in,v
retrieving revision 1.1
diff -u -r1.1 mercury_dotnet.cs.in
--- runtime/mercury_dotnet.cs.in 13 Nov 2003 15:15:39 -0000 1.1
+++ runtime/mercury_dotnet.cs.in 14 Nov 2003 10:52:52 -0000
@@ -152,5 +152,10 @@
}
}
+class PInvoke {
+ [System.Runtime.InteropServices.DllImport("msvcrt.dll")]
+ public static extern int _putenv(string env);
+}
+
}
}
--
Peter Ross
Software Engineer (Work) +32 2 757 10 15
Mission Critical (Mobile) +32 485 482 559
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list