aboutsummaryrefslogtreecommitdiffstats
path: root/lib/asn1/src/asn1rt_nif.erl
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2013-01-10 12:15:43 +0100
committerBjörn Gustavsson <[email protected]>2013-01-22 19:20:11 +0100
commit70caf52f1a7e09569c776bb1f99b0bf4737c63c2 (patch)
tree252d673222be3061d07ecf8148bab3357f792816 /lib/asn1/src/asn1rt_nif.erl
parent844e2126e3b814f9fa058be367be3af745c7a80b (diff)
downloadotp-70caf52f1a7e09569c776bb1f99b0bf4737c63c2.tar.gz
otp-70caf52f1a7e09569c776bb1f99b0bf4737c63c2.tar.bz2
otp-70caf52f1a7e09569c776bb1f99b0bf4737c63c2.zip
Correct error handling for the NIF functions
Also make sure that the error handling is contained within the asn1rt_nif module and does not leak out to generated code.
Diffstat (limited to 'lib/asn1/src/asn1rt_nif.erl')
-rw-r--r--lib/asn1/src/asn1rt_nif.erl25
1 files changed, 23 insertions, 2 deletions
diff --git a/lib/asn1/src/asn1rt_nif.erl b/lib/asn1/src/asn1rt_nif.erl
index de1fb94816..0b2e5a62a5 100644
--- a/lib/asn1/src/asn1rt_nif.erl
+++ b/lib/asn1/src/asn1rt_nif.erl
@@ -77,10 +77,31 @@ load_nif() ->
Status
end.
-encode_per_complete(_TagValueList) ->
+decode_ber_tlv(Binary) ->
+ case decode_ber_tlv_raw(Binary) of
+ {error,Reason} ->
+ exit({error,{asn1,Reason}});
+ Other ->
+ Other
+ end.
+
+encode_per_complete(TagValueList) ->
+ case encode_per_complete_raw(TagValueList) of
+ {error,Reason} -> handle_error(Reason, TagValueList);
+ Other when is_binary(Other) -> Other
+ end.
+
+handle_error([], _)->
+ exit({error,{asn1,enomem}});
+handle_error($1, L) -> % error in complete in driver
+ exit({error,{asn1,L}});
+handle_error(ErrL, L) ->
+ exit({error,{asn1,ErrL,L}}).
+
+encode_per_complete_raw(_TagValueList) ->
erlang:nif_error({nif_not_loaded,module,?MODULE,line,?LINE}).
-decode_ber_tlv(_Binary) ->
+decode_ber_tlv_raw(_Binary) ->
erlang:nif_error({nif_not_loaded,module,?MODULE,line,?LINE}).
encode_ber_tlv(_TagValueList) ->