From 1ddab9c7b66237ea6dd429fb75e4c81247d88920 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Mon, 25 Jan 2016 13:12:50 +0100 Subject: Eliminate run-time system crash in code:load_abs/1 The run-time system would terminate if code:load_abs/1 was called with a filename containing any non-latin1 characters. The reason is that code_server would attempt to construct a module name from the filename using list_to_atom/1 and that atoms currently are limited to the latin1 character set. But how should the error be reported? I have decided to that the simplest and least confusing way is to move the call to list_to_atom/1 to 'code' module and let it crash the calling process. The resulting stack back trace will make it clear what the reason for the crash was. --- lib/kernel/test/code_SUITE.erl | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/kernel/test/code_SUITE.erl') diff --git a/lib/kernel/test/code_SUITE.erl b/lib/kernel/test/code_SUITE.erl index ef5303defd..8f97b6c6f8 100644 --- a/lib/kernel/test/code_SUITE.erl +++ b/lib/kernel/test/code_SUITE.erl @@ -323,6 +323,7 @@ load_abs(Config) when is_list(Config) -> {error, nofile} = code:load_abs(TestDir ++ "/duuuumy_mod"), {error, badfile} = code:load_abs(TestDir ++ "/code_a_test"), {'EXIT', _} = (catch code:load_abs({})), + {'EXIT', _} = (catch code:load_abs("Non-latin-имя-файла")), {module, code_b_test} = code:load_abs(TestDir ++ "/code_b_test"), code:stick_dir(TestDir), {error, sticky_directory} = code:load_abs(TestDir ++ "/code_b_test"), -- cgit v1.2.3 From 28f7a47ab4d533cc72090484eb3a7e5713fa58bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Mon, 25 Jan 2016 15:56:59 +0100 Subject: code: Correct the types for error returns The specifications for functions that load code in the 'code' module (e.g. code:load_file/1) have some problems: * The specs claim that the functions can return {error,on_load}, but they never do. However, they can return {error,on_load_failure} if the -on_load function in a module fails. * The specs claim that the functions can return {error,native_code}, but they never do. While we are it, also extend the on_load_errors/1 test case to test that the load functions return {error,on_load_failure} when an -on_load function fails. --- lib/kernel/test/code_SUITE.erl | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'lib/kernel/test/code_SUITE.erl') diff --git a/lib/kernel/test/code_SUITE.erl b/lib/kernel/test/code_SUITE.erl index 8f97b6c6f8..2b77ec8972 100644 --- a/lib/kernel/test/code_SUITE.erl +++ b/lib/kernel/test/code_SUITE.erl @@ -1600,6 +1600,17 @@ on_load_errors(Config) when is_list(Config) -> ok end, + %% Make sure that the code loading functions return the correct + %% error code. + Simple = simple_on_load_error, + SimpleList = atom_to_list(Simple), + {error,on_load_failure} = code:load_file(Simple), + {error,on_load_failure} = code:ensure_loaded(Simple), + {ok,SimpleCode} = file:read_file("simple_on_load_error.beam"), + {error,on_load_failure} = code:load_binary(Simple, "", SimpleCode), + {error,on_load_failure} = code:load_abs(SimpleList), + {error,on_load_failure} = code:load_abs(SimpleList, Simple), + ok. do_on_load_error(ReturnValue) -> -- cgit v1.2.3