diff options
author | Patrik Nyblom <[email protected]> | 2012-03-22 19:08:07 +0100 |
---|---|---|
committer | Patrik Nyblom <[email protected]> | 2012-03-22 19:08:07 +0100 |
commit | 8a886bda04b7656f9f6ced9be14a98d6b6df0a0a (patch) | |
tree | a0a201c8b1ee29169aca97e3befa133da867d5cd /erts/preloaded/src/prim_file.erl | |
parent | aa0d3a28d6f8350965d43cd13014125a63ac25d9 (diff) | |
parent | 5957a8338fe1f4e79a39277174094bbd9e978896 (diff) | |
download | otp-8a886bda04b7656f9f6ced9be14a98d6b6df0a0a.tar.gz otp-8a886bda04b7656f9f6ced9be14a98d6b6df0a0a.tar.bz2 otp-8a886bda04b7656f9f6ced9be14a98d6b6df0a0a.zip |
Merge branch 'maint'
Conflicts:
erts/emulator/beam/beam_emu.c
erts/emulator/beam/bif.tab
erts/preloaded/ebin/prim_file.beam
lib/hipe/cerl/erl_bif_types.erl
Diffstat (limited to 'erts/preloaded/src/prim_file.erl')
-rw-r--r-- | erts/preloaded/src/prim_file.erl | 58 |
1 files changed, 41 insertions, 17 deletions
diff --git a/erts/preloaded/src/prim_file.erl b/erts/preloaded/src/prim_file.erl index fcf94c5fa2..d66f0e09cc 100644 --- a/erts/preloaded/src/prim_file.erl +++ b/erts/preloaded/src/prim_file.erl @@ -294,7 +294,7 @@ advise(#file_descriptor{module = ?MODULE, data = {Port, _}}, %% Returns {error, Reason} | ok. write(#file_descriptor{module = ?MODULE, data = {Port, _}}, Bytes) -> - case drv_command(Port, [?FILE_WRITE,Bytes]) of + case drv_command_nt(Port, [?FILE_WRITE,erlang:dt_prepend_vm_tag_data(Bytes)],undefined) of {ok, _Size} -> ok; Error -> @@ -309,8 +309,8 @@ pwrite(#file_descriptor{module = ?MODULE, data = {Port, _}}, L) pwrite_int(_, [], 0, [], []) -> ok; pwrite_int(Port, [], N, Spec, Data) -> - Header = list_to_binary([<<?FILE_PWRITEV, N:32>> | reverse(Spec)]), - case drv_command_raw(Port, [Header | reverse(Data)]) of + Header = list_to_binary([?FILE_PWRITEV, erlang:dt_prepend_vm_tag_data(<<N:32>>) | reverse(Spec)]), + case drv_command_nt(Port, [Header | reverse(Data)], undefined) of {ok, _Size} -> ok; Error -> @@ -428,7 +428,7 @@ pread(#file_descriptor{module = ?MODULE, data = {Port, _}}, L) pread_int(_, [], 0, []) -> {ok, []}; pread_int(Port, [], N, Spec) -> - drv_command(Port, [<<?FILE_PREADV, 0:32, N:32>> | reverse(Spec)]); + drv_command_nt(Port, [?FILE_PREADV, erlang:dt_prepend_vm_tag_data(<<0:32, N:32>>) | reverse(Spec)],undefined); pread_int(Port, [{Offs, Size} | T], N, Spec) when is_integer(Offs), is_integer(Size), 0 =< Size -> if @@ -449,9 +449,9 @@ pread(#file_descriptor{module = ?MODULE, data = {Port, _}}, Offs, Size) if -(?LARGEFILESIZE) =< Offs, Offs < ?LARGEFILESIZE, Size < ?LARGEFILESIZE -> - case drv_command(Port, - <<?FILE_PREADV, 0:32, 1:32, - Offs:64/signed, Size:64>>) of + case drv_command_nt(Port, + [?FILE_PREADV, erlang:dt_prepend_vm_tag_data(<<0:32, 1:32, + Offs:64/signed, Size:64>>)], undefined) of {ok, [eof]} -> eof; {ok, [Data]} -> @@ -949,12 +949,17 @@ drv_open(Driver, Portopts) -> %% Closes a port in a safe way. Returns ok. drv_close(Port) -> - try erlang:port_close(Port) catch error:_ -> ok end, - receive %% Ugly workaround in case the caller==owner traps exits - {'EXIT', Port, _Reason} -> - ok - after 0 -> - ok + Save = erlang:dt_spread_tag(false), + try + try erlang:port_close(Port) catch error:_ -> ok end, + receive %% Ugly workaround in case the caller==owner traps exits + {'EXIT', Port, _Reason} -> + ok + after 0 -> + ok + end + after + erlang:dt_restore_tag(Save) end. @@ -964,9 +969,6 @@ drv_close(Port) -> %% then closed after the result has been received. %% Returns {ok, Result} or {error, Reason}. -drv_command_raw(Port, Command) -> - drv_command(Port, Command, false, undefined). - drv_command(Port, Command) -> drv_command(Port, Command, undefined). @@ -982,7 +984,8 @@ drv_command(Port, Command, R) -> end. drv_command(Port, Command, Validated, R) when is_port(Port) -> - try erlang:port_command(Port, Command) of + Save = erlang:dt_spread_tag(false), + try erlang:port_command(Port, erlang:dt_append_vm_tag_data(Command)) of true -> drv_get_response(Port, R) catch @@ -1001,6 +1004,8 @@ drv_command(Port, Command, Validated, R) when is_port(Port) -> end; error:Reason -> {error, Reason} + after + erlang:dt_restore_tag(Save) end; drv_command({Driver, Portopts}, Command, Validated, R) -> case drv_open(Driver, Portopts) of @@ -1011,6 +1016,25 @@ drv_command({Driver, Portopts}, Command, Validated, R) -> Error -> Error end. +drv_command_nt(Port, Command, R) when is_port(Port) -> + Save = erlang:dt_spread_tag(false), + try erlang:port_command(Port, Command) of + true -> + drv_get_response(Port, R) + catch + error:badarg -> + try erlang:iolist_size(Command) of + _ -> % Valid + {error, einval} + catch + error:_ -> + {error, badarg} + end; + error:Reason -> + {error, Reason} + after + erlang:dt_restore_tag(Save) + end. |