From 94eda4f777d79b159f0b6fd5ff5519649aa5affb Mon Sep 17 00:00:00 2001 From: Patrik Nyblom Date: Fri, 26 Nov 2010 14:14:22 +0100 Subject: Teach prim_file not to accept atoms and not to throw exceptions --- erts/emulator/beam/erl_unicode.c | 7 +++++++ erts/preloaded/src/prim_file.erl | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/erts/emulator/beam/erl_unicode.c b/erts/emulator/beam/erl_unicode.c index 3434ce3979..72207df621 100644 --- a/erts/emulator/beam/erl_unicode.c +++ b/erts/emulator/beam/erl_unicode.c @@ -2429,6 +2429,13 @@ BIF_RETTYPE prim_file_internal_name2native_1(BIF_ALIST_1) Sint need; Eterm bin_term; byte* bin_p; + /* Prim file explicitly does not allow atoms, although we could + very well cope with it. Instead of letting 'file' handle them, + it would probably be more efficient to handle them here. Subject to + change in R15. */ + if (is_atom(BIF_ARG_1)) { + BIF_ERROR(BIF_P,BADARG); + } if (is_binary(BIF_ARG_1)) { byte *temp_alloc = NULL; byte *bytes; diff --git a/erts/preloaded/src/prim_file.erl b/erts/preloaded/src/prim_file.erl index 75b0faacd3..10be852e92 100644 --- a/erts/preloaded/src/prim_file.erl +++ b/erts/preloaded/src/prim_file.erl @@ -1228,5 +1228,7 @@ reverse(X) -> lists:reverse(X, []). reverse(L, T) -> lists:reverse(L, T). % Will add zero termination too +% The 'EXIT' tuple from a bad argument will eventually generate an error +% in list_to_binary, which is caught and generates the {error,badarg} return pathname(File) -> - prim_file:internal_name2native(File). + (catch prim_file:internal_name2native(File)). -- cgit v1.2.3