diff options
Diffstat (limited to 'lib/stdlib')
-rw-r--r-- | lib/stdlib/doc/src/epp.xml | 2 | ||||
-rw-r--r-- | lib/stdlib/src/Makefile | 1 | ||||
-rw-r--r-- | lib/stdlib/src/epp.erl | 44 | ||||
-rw-r--r-- | lib/stdlib/src/erl_lint.erl | 5 | ||||
-rw-r--r-- | lib/stdlib/src/erl_scan.erl | 2 | ||||
-rw-r--r-- | lib/stdlib/test/erl_lint_SUITE.erl | 25 | ||||
-rw-r--r-- | lib/stdlib/test/escript_SUITE.erl | 69 | ||||
-rw-r--r-- | lib/stdlib/test/escript_SUITE_data/archive_script_file_access/archive_script_file_access.erl | 29 | ||||
-rw-r--r-- | lib/stdlib/test/ets_SUITE.erl | 16 | ||||
-rw-r--r-- | lib/stdlib/test/qlc_SUITE.erl | 8 |
10 files changed, 149 insertions, 52 deletions
diff --git a/lib/stdlib/doc/src/epp.xml b/lib/stdlib/doc/src/epp.xml index 488499581f..a57c7084fa 100644 --- a/lib/stdlib/doc/src/epp.xml +++ b/lib/stdlib/doc/src/epp.xml @@ -51,6 +51,7 @@ <func> <name name="open" arity="2"/> <name name="open" arity="3"/> + <name name="open" arity="4"/> <fsummary>Open a file for preprocessing</fsummary> <desc> <p>Opens a file for preprocessing.</p> @@ -75,6 +76,7 @@ </func> <func> <name name="parse_file" arity="3"/> + <name name="parse_file" arity="4"/> <fsummary>Preprocess and parse an Erlang source file</fsummary> <desc> <p>Preprocesses and parses an Erlang source file. diff --git a/lib/stdlib/src/Makefile b/lib/stdlib/src/Makefile index 8bdaae57fd..54186a3ba7 100644 --- a/lib/stdlib/src/Makefile +++ b/lib/stdlib/src/Makefile @@ -167,6 +167,7 @@ docs: # This is a trick so that the preloaded files will get the correct type # specifications. primary_bootstrap_compiler: \ + $(BOOTSTRAP_COMPILER)/ebin/epp.beam \ $(BOOTSTRAP_COMPILER)/ebin/erl_scan.beam \ $(BOOTSTRAP_COMPILER)/ebin/erl_parse.beam \ $(BOOTSTRAP_COMPILER)/ebin/erl_lint.beam \ diff --git a/lib/stdlib/src/epp.erl b/lib/stdlib/src/epp.erl index ccc14610d7..d958b0af2a 100644 --- a/lib/stdlib/src/epp.erl +++ b/lib/stdlib/src/epp.erl @@ -20,9 +20,9 @@ %% An Erlang code preprocessor. --export([open/2,open/3,open/5,close/1,format_error/1]). +-export([open/2,open/3,open/4, open/5,close/1,format_error/1]). -export([scan_erl_form/1,parse_erl_form/1,macro_defs/1]). --export([parse_file/1, parse_file/3]). +-export([parse_file/1, parse_file/3, parse_file/4]). -export([interpret_file_attribute/1]). -export([normalize_typed_record_fields/1,restore_typed_record_fields/1]). @@ -54,12 +54,14 @@ %% open(FileName, IncludePath) %% open(FileName, IncludePath, PreDefMacros) +%% open(FileName, StartLocation, IncludePath, PredefMacros) %% open(FileName, IoDevice, StartLocation, IncludePath, PreDefMacros) %% close(Epp) %% scan_erl_form(Epp) %% parse_erl_form(Epp) %% parse_file(Epp) %% parse_file(FileName, IncludePath, PreDefMacros) +%% parse_file(FileName, StartLocation, IncludePath, PreDefMacros) %% macro_defs(Epp) -spec open(FileName, IncludePath) -> @@ -81,8 +83,20 @@ open(Name, Path) -> ErrorDescriptor :: term(). open(Name, Path, Pdm) -> + open(Name, 1, Path, Pdm). + +-spec open(FileName, StartLocation, IncludePath, PredefMacros) -> + {'ok', Epp} | {'error', ErrorDescriptor} when + FileName :: file:name(), + StartLocation :: erl_scan:location(), + IncludePath :: [DirectoryName :: file:name()], + PredefMacros :: macros(), + Epp :: epp_handle(), + ErrorDescriptor :: term(). + +open(Name, StartLocation, Path, Pdm) -> Self = self(), - Epp = spawn(fun() -> server(Self, Name, Path, Pdm) end), + Epp = spawn(fun() -> server(Self, Name, StartLocation, Path, Pdm) end), epp_request(Epp). open(Name, File, StartLocation, Path, Pdm) -> @@ -178,7 +192,21 @@ format_error(E) -> file:format_error(E). OpenError :: file:posix() | badarg | system_limit. parse_file(Ifile, Path, Predefs) -> - case open(Ifile, Path, Predefs) of + parse_file(Ifile, 1, Path, Predefs). + +-spec parse_file(FileName, StartLocation, IncludePath, PredefMacros) -> + {'ok', [Form]} | {error, OpenError} when + FileName :: file:name(), + StartLocation :: erl_scan:location(), + IncludePath :: [DirectoryName :: file:name()], + Form :: erl_parse:abstract_form() | {'error', ErrorInfo} | {'eof',Line}, + PredefMacros :: macros(), + Line :: erl_scan:line(), + ErrorInfo :: erl_scan:error_info() | erl_parse:error_info(), + OpenError :: file:posix() | badarg | system_limit. + +parse_file(Ifile, StartLocation, Path, Predefs) -> + case open(Ifile, StartLocation, Path, Predefs) of {ok,Epp} -> Forms = parse_file(Epp), close(Epp), @@ -245,14 +273,12 @@ restore_typed_record_fields([{attribute,La,type,{{record,Record},Fields,[]}}| restore_typed_record_fields([Form|Forms]) -> [Form|restore_typed_record_fields(Forms)]. -%% server(StarterPid, FileName, Path, PreDefMacros) - -server(Pid, Name, Path, Pdm) -> +%% server(StarterPid, FileName, Location, Path, PreDefMacros) +server(Pid, Name, AtLocation, Path, Pdm) -> process_flag(trap_exit, true), case file:open(Name, [read]) of {ok,File} -> - Location = 1, - init_server(Pid, Name, File, Location, Path, Pdm, false); + init_server(Pid, Name, File, AtLocation, Path, Pdm, false); {error,E} -> epp_reply(Pid, {error,E}) end. diff --git a/lib/stdlib/src/erl_lint.erl b/lib/stdlib/src/erl_lint.erl index abab81d31f..648ff349a4 100644 --- a/lib/stdlib/src/erl_lint.erl +++ b/lib/stdlib/src/erl_lint.erl @@ -248,6 +248,8 @@ format_error({illegal_guard_local_call, {F,A}}) -> io_lib:format("call to local/imported function ~w/~w is illegal in guard", [F,A]); format_error(illegal_guard_expr) -> "illegal guard expression"; +format_error(deprecated_tuple_fun) -> + "tuple funs are deprecated and will be removed in R16"; %% --- exports --- format_error({explicit_export,F,A}) -> io_lib:format("in this release, the call to ~w/~w must be written " @@ -1914,7 +1916,8 @@ gexpr({call,Line,{remote,_Lr,{atom,_Lm,erlang},{atom,_Lf,F}},As}, Vt, St0) -> true -> {Asvt,St1}; false -> {Asvt,add_error(Line, illegal_guard_expr, St1)} end; -gexpr({call,L,{tuple,Lt,[{atom,Lm,erlang},{atom,Lf,F}]},As}, Vt, St) -> +gexpr({call,L,{tuple,Lt,[{atom,Lm,erlang},{atom,Lf,F}]},As}, Vt, St0) -> + St = add_warning(L, deprecated_tuple_fun, St0), gexpr({call,L,{remote,Lt,{atom,Lm,erlang},{atom,Lf,F}},As}, Vt, St); gexpr({op,Line,Op,A}, Vt, St0) -> {Avt,St1} = gexpr(A, Vt, St0), diff --git a/lib/stdlib/src/erl_scan.erl b/lib/stdlib/src/erl_scan.erl index 10b2ed2e49..be64b428b1 100644 --- a/lib/stdlib/src/erl_scan.erl +++ b/lib/stdlib/src/erl_scan.erl @@ -55,7 +55,7 @@ token_info/1,token_info/2, attributes_info/1,attributes_info/2,set_attribute/3]). --export_type([error_info/0, line/0, tokens_result/0]). +-export_type([error_info/0, line/0, location/0, tokens_result/0]). %%% %%% Defines and type definitions diff --git a/lib/stdlib/test/erl_lint_SUITE.erl b/lib/stdlib/test/erl_lint_SUITE.erl index dcd622b984..9f9d97b619 100644 --- a/lib/stdlib/test/erl_lint_SUITE.erl +++ b/lib/stdlib/test/erl_lint_SUITE.erl @@ -1331,17 +1331,20 @@ guard(Config) when is_list(Config) -> foo. ">>, [warn_unused_vars, nowarn_obsolete_guard], - {errors,[{2,erl_lint,illegal_guard_expr}, - {4,erl_lint,illegal_guard_expr}, - {6,erl_lint,illegal_guard_expr}, - {8,erl_lint,illegal_guard_expr}, - {10,erl_lint,illegal_guard_expr}, - {12,erl_lint,illegal_guard_expr}, - {14,erl_lint,illegal_guard_expr}, - {16,erl_lint,illegal_guard_expr}, - {18,erl_lint,illegal_guard_expr}, - {20,erl_lint,illegal_guard_expr}], - []}}, + {error,[{2,erl_lint,illegal_guard_expr}, + {4,erl_lint,illegal_guard_expr}, + {6,erl_lint,illegal_guard_expr}, + {8,erl_lint,illegal_guard_expr}, + {10,erl_lint,illegal_guard_expr}, + {12,erl_lint,illegal_guard_expr}, + {14,erl_lint,illegal_guard_expr}, + {16,erl_lint,illegal_guard_expr}, + {18,erl_lint,illegal_guard_expr}, + {20,erl_lint,illegal_guard_expr}], + [{8,erl_lint,deprecated_tuple_fun}, + {14,erl_lint,deprecated_tuple_fun}, + {20,erl_lint,deprecated_tuple_fun}, + {28,erl_lint,deprecated_tuple_fun}]}}, {guard6, <<"-record(apa,{a=a,b=foo:bar()}). apa() -> diff --git a/lib/stdlib/test/escript_SUITE.erl b/lib/stdlib/test/escript_SUITE.erl index 7b03fdafe3..38c085616d 100644 --- a/lib/stdlib/test/escript_SUITE.erl +++ b/lib/stdlib/test/escript_SUITE.erl @@ -469,22 +469,23 @@ archive_script(Config) when is_list(Config) -> %% Test the correction of OTP-10071 %% The errors identified are %% -%% * If primary archive was named "xxx", then a file in the same -%% directory named "xxxyyy" would be interpreted as a file named yyy -%% inside the archive. +%% a) If primary archive was named "xxx", then a file in the same +%% directory named "xxxyyy" would be interpreted as a file named yyy +%% inside the archive. %% -%% * erl_prim_loader did not correctly create and normalize absolute -%% paths for primary archive and files inside it, so unless given -%% with exact same path files inside the archive would not be -%% found. E.g. if escript was started as ./xxx then "xxx/file" would -%% not be found since erl_prim_loader would try to match -%% /full/path/to/xxx with /full/path/to/./xxx. Same problem with -%% ../ +%% b) erl_prim_loader did not correctly create and normalize absolute +%% paths for primary archive and files inside it, so unless given +%% with exact same path files inside the archive would not be +%% found. E.g. if escript was started as ./xxx then "xxx/file" +%% would not be found since erl_prim_loader would try to match +%% /full/path/to/xxx with /full/path/to/./xxx. Same problem with +%% ../. Also, the use of symlinks in the path to the archive would +%% cause problems. %% -%% * Depending on how the primary archive was built, -%% erl_prim_loader:list_dir/1 would sometimes return an empty string -%% inside the file list. This was a virtual element representing the -%% top directory of the archive. This shall not occur. +%% c) Depending on how the primary archive was built, +%% erl_prim_loader:list_dir/1 would sometimes return an empty string +%% inside the file list. This was a virtual element representing the +%% top directory of the archive. This shall not occur. %% archive_script_file_access(Config) when is_list(Config) -> %% Copy the orig files to priv_dir @@ -542,18 +543,22 @@ archive_script_file_access(Config) when is_list(Config) -> ok = escript:create(Script1,[shebang,{emu_args,Flags},{archive,Bin1}]), ok = file:change_mode(Script1,8#00744), + %% If supported, create a symlink to the script. This is used to + %% test error b) described above this test case. + SymlinkName1 = "symlink_to_"++ScriptName1, + Symlink1 = filename:join([PrivDir, SymlinkName1]), + file:make_symlink(ScriptName1,Symlink1), % will fail if not supported + %% Also add a dummy file in the same directory with the same name %% as the script except is also has an extension. This used to - %% cause erl_prim_loader to believe it was a file inside the - %% script. + %% test error a) described above this test case. ok = file:write_file(Script1 ++ ".extension", <<"same name as script, but with extension">>), %% Change to script's directory and run it as "./<script_name>" ok = file:set_cwd(PrivDir), - do_run(PrivDir, "./" ++ ScriptName1, - [<<"file_access:[]\n", - "ExitCode:0">>]), + run(PrivDir, "./" ++ ScriptName1 ++ " " ++ ScriptName1, + [<<"ExitCode:0">>]), ok = file:set_cwd(TopDir), @@ -574,18 +579,34 @@ archive_script_file_access(Config) when is_list(Config) -> %% Also add a dummy file in the same directory with the same name %% as the script except is also has an extension. This used to - %% cause erl_prim_loader to believe it was a file inside the - %% script. + %% test error a) described above this test case. ok = file:write_file(Script2 ++ ".extension", <<"same name as script, but with extension">>), + %% If supported, create a symlink to the script. This is used to + %% test error b) described above this test case. + SymlinkName2 = "symlink_to_"++ScriptName2, + Symlink2 = filename:join([PrivDir, SymlinkName2]), + file:make_symlink(ScriptName2,Symlink2), % will fail if not supported + %% Change to script's directory and run it as "./<script_name>" ok = file:set_cwd(PrivDir), - do_run(PrivDir, "./" ++ ScriptName2, - [<<"file_access:[]\n", - "ExitCode:0">>]), + run(PrivDir, "./" ++ ScriptName2 ++ " " ++ ScriptName2, + [<<"ExitCode:0">>]), + + %% 3. If symlinks are supported, run one of the scripts via a symlink. + %% + %% This is in order to test error b) described above this test case. + case file:read_link(Symlink2) of + {ok,_} -> + run(PrivDir, "./" ++ SymlinkName2 ++ " " ++ ScriptName2, + [<<"ExitCode:0">>]); + _ -> % not supported + ok + end, ok = file:set_cwd(OldDir). + compile_app(TopDir, AppName) -> AppDir = filename:join([TopDir, AppName]), SrcDir = filename:join([AppDir, "src"]), diff --git a/lib/stdlib/test/escript_SUITE_data/archive_script_file_access/archive_script_file_access.erl b/lib/stdlib/test/escript_SUITE_data/archive_script_file_access/archive_script_file_access.erl index 226a8675db..b03c8ba70d 100644 --- a/lib/stdlib/test/escript_SUITE_data/archive_script_file_access/archive_script_file_access.erl +++ b/lib/stdlib/test/escript_SUITE_data/archive_script_file_access/archive_script_file_access.erl @@ -23,12 +23,9 @@ -include_lib("kernel/include/file.hrl"). -main(MainArgs) -> - io:format("file_access:~p\n", [MainArgs]), - ArchiveFile = escript:script_name(), +main([RelArchiveFile]) -> - AbsArchiveFile = filename:absname(ArchiveFile), - RelArchiveFile = filename:basename(ArchiveFile), + AbsArchiveFile = filename:absname(RelArchiveFile), DotSlashArchiveFile = "./" ++ RelArchiveFile, Beam = atom_to_list(?MODULE) ++ ".beam", @@ -39,6 +36,10 @@ main(MainArgs) -> AbsDir = filename:join(AbsArchiveFile,Dir), RelDir = filename:join(RelArchiveFile,Dir), DotSlashDir = filename:join(DotSlashArchiveFile,Dir), + SubDir = "subdir1", + AbsSubDir = filename:join(AbsDir,SubDir), + RelSubDir = filename:join(RelDir,SubDir), + DotSlashSubDir = filename:join(DotSlashDir,SubDir), {ok,List1} = erl_prim_loader:list_dir(AbsArchiveFile), {ok,List1} = erl_prim_loader:list_dir(RelArchiveFile), @@ -48,8 +49,26 @@ main(MainArgs) -> {ok,List1} = erl_prim_loader:list_dir(filename:join([AbsDir,".."])), {ok,List1} = erl_prim_loader:list_dir(filename:join([RelDir,".."])), {ok,List1} = erl_prim_loader:list_dir(filename:join([DotSlashDir,".."])), + {ok,List1} = erl_prim_loader:list_dir(filename:join([AbsSubDir,"..",".."])), + {ok,List1} = erl_prim_loader:list_dir(filename:join([RelSubDir,"..",".."])), + {ok,List1} = erl_prim_loader:list_dir(filename:join([DotSlashSubDir,"..",".."])), false = lists:member([],List1), + %% If symlinks are supported on this platform... + RelSymlinkArchiveFile = "symlink_to_" ++ RelArchiveFile, + case file:read_link(RelSymlinkArchiveFile) of + {ok,_} -> + DotSlashSymlinkArchiveFile = "./" ++ RelSymlinkArchiveFile, + AbsSymlinkArchiveFile=filename:join(filename:dirname(AbsArchiveFile), + RelSymlinkArchiveFile), + {ok,List1} = erl_prim_loader:list_dir(AbsSymlinkArchiveFile), + {ok,List1} = erl_prim_loader:list_dir(RelSymlinkArchiveFile), + {ok,List1} = erl_prim_loader:list_dir(DotSlashSymlinkArchiveFile); + _ -> % not supported + ok + end, + + {ok,List2} = erl_prim_loader:list_dir(AbsDir), {ok,List2} = erl_prim_loader:list_dir(RelDir), {ok,List2} = erl_prim_loader:list_dir(DotSlashDir), diff --git a/lib/stdlib/test/ets_SUITE.erl b/lib/stdlib/test/ets_SUITE.erl index 297c4ec1c9..97ac433cb9 100644 --- a/lib/stdlib/test/ets_SUITE.erl +++ b/lib/stdlib/test/ets_SUITE.erl @@ -74,6 +74,7 @@ -export([bad_table/1, types/1]). -export([otp_9932/1]). -export([otp_9423/1]). +-export([otp_10182/1]). -export([init_per_testcase/2, end_per_testcase/2]). %% Convenience for manual testing @@ -146,6 +147,7 @@ all() -> exit_many_large_table_owner, exit_many_tables_owner, exit_many_many_tables_owner, write_concurrency, heir, give_away, setopts, bad_table, types, + otp_10182, otp_9932, otp_9423]. @@ -5470,6 +5472,20 @@ otp_9423(Config) when is_list(Config) -> Skipped -> Skipped end. + +%% Corrupted binary in compressed table +otp_10182(Config) when is_list(Config) -> + Bin = <<"aHR0cDovL2hvb3RzdWl0ZS5jb20vYy9wcm8tYWRyb2xsLWFi">>, + Key = {test, Bin}, + Value = base64:decode(Bin), + In = {Key,Value}, + Db = ets:new(undefined, [set, protected, {read_concurrency, true}, compressed]), + ets:insert(Db, In), + [Out] = ets:lookup(Db, Key), + io:format("In : ~p\nOut: ~p\n", [In,Out]), + ets:delete(Db), + In = Out. + diff --git a/lib/stdlib/test/qlc_SUITE.erl b/lib/stdlib/test/qlc_SUITE.erl index 1e74ad7727..192268f90e 100644 --- a/lib/stdlib/test/qlc_SUITE.erl +++ b/lib/stdlib/test/qlc_SUITE.erl @@ -2969,12 +2969,14 @@ lookup1(Config) when is_list(Config) -> [3] = lookup_keys(Q) end, [{1,a},{3,3}])">>, + {cres, <<"A = 3, etsc(fun(E) -> Q = qlc:q([X || X <- ets:table(E), A =:= {erlang,element}(1, X)]), [{3,3}] = qlc:e(Q), [3] = lookup_keys(Q) end, [{1,a},{3,3}])">>, + {warnings,[{3,erl_lint,deprecated_tuple_fun}]}}, <<"etsc(fun(E) -> A = 3, @@ -3439,12 +3441,14 @@ lookup2(Config) when is_list(Config) -> [r] = qlc:e(Q), [r] = lookup_keys(Q) end, [{keypos,1}], [#r{}])">>, + {cres, <<"etsc(fun(E) -> Q = qlc:q([element(1, X) || X <- ets:table(E), {erlang,is_record}(X, r, 2)]), [r] = qlc:e(Q), [r] = lookup_keys(Q) end, [{keypos,1}], [#r{}])">>, + {warnings,[{4,erl_lint,deprecated_tuple_fun}]}}, {cres, <<"etsc(fun(E) -> Q = qlc:q([element(1, X) || X <- ets:table(E), @@ -3465,12 +3469,14 @@ lookup2(Config) when is_list(Config) -> [r] = qlc:e(Q), [r] = lookup_keys(Q) end, [{keypos,1}], [#r{}])">>, + {cres, <<"etsc(fun(E) -> Q = qlc:q([element(1, X) || X <- ets:table(E), {erlang,is_record}(X, r)]), [r] = qlc:e(Q), [r] = lookup_keys(Q) - end, [{keypos,1}], [#r{}])">> + end, [{keypos,1}], [#r{}])">>, + {warnings,[{4,erl_lint,deprecated_tuple_fun}]}} ], ?line run(Config, <<"-record(r, {a}).\n">>, TsR), |