mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-16 18:03:36 +00:00
library/io.call_system.m:
Move the code in the "system access predicates" section of io.m
to this new module.
library/io.environment.m:
Move the predicates dealing with environment variables in io.m
to this new module.
library/io.m:
Delete the code moved to the new modules.
Leave behind in io.m "forwarding predicates", predicates that do nothing
except call the moved predicates in the new modules, to provide backward
compatibility. But do mark the forwarding predicates as obsolete,
to tell people to update their (at their leisure, since the obsoleteness
warning can be turned off).
Also leave behind in io.m the definitions of the types used
by some parameters of some of the moved predicates.
library/MODULES_DOC:
List the new modules among the documented modules.
library/library.m:
List the new modules, including io.file.m (added in a previous change)
among the documented standard library modules.
NEWS:
Announce the changes.
browser/browse.m:
browser/interactive_query.m:
compiler/fact_table.m:
compiler/handle_options.m:
compiler/make.module_target.m:
compiler/mercury_compile_main.m:
compiler/module_cmds.m:
compiler/optimize.m:
compiler/options_file.m:
deep_profiler/conf.m:
deep_profiler/mdprof_cgi.m:
deep_profiler/mdprof_test.m:
library/io.file.m:
mdbcomp/trace_counts.m:
ssdb/ssdb.m:
tests/general/environment.m:
tests/hard_coded/closeable_channel_test.m:
tests/hard_coded/setenv.m:
tests/hard_coded/system_sort.m:
Call the moved predicates directly in their new modules,
not indirectly through io.m.
49 lines
1.3 KiB
Mathematica
49 lines
1.3 KiB
Mathematica
%---------------------------------------------------------------------------%
|
|
% vim: ts=4 sw=4 et ft=mercury
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- module setenv.
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
|
|
:- pred main(io::di, io::uo) is det.
|
|
|
|
:- implementation.
|
|
|
|
:- import_module gc.
|
|
:- import_module int.
|
|
:- import_module io.environment.
|
|
:- import_module list.
|
|
:- import_module maybe.
|
|
:- import_module string.
|
|
|
|
main(!IO) :-
|
|
io.environment.set_environment_var("foo", "bar", !IO),
|
|
|
|
% Earlier versions of the Mercury library relied on putenv, which
|
|
% on many platforms requires that we don't garbage collect the string
|
|
% we pass it. This code tests whether we can handle that.
|
|
use_mem(1_000_000, !IO),
|
|
gc.garbage_collect(!IO),
|
|
use_mem(1_000_000, !IO),
|
|
|
|
io.environment.get_environment_var("foo", Res, !IO),
|
|
(
|
|
Res = yes(Value),
|
|
io.write_string("Got value: " ++ Value ++ "\n", !IO)
|
|
;
|
|
Res = no,
|
|
io.write_string("Failure!\n", !IO)
|
|
).
|
|
|
|
:- pred use_mem(int::in, io::di, io::uo) is det.
|
|
|
|
use_mem(N, !IO) :-
|
|
io.write_string("Use mem: ", !IO),
|
|
( if list.length(1 `..` N) = N then
|
|
io.write_string("ok\n", !IO)
|
|
else
|
|
io.write_string("hmm\n", !IO)
|
|
).
|