diff options
author | Lukas Larsson <[email protected]> | 2011-07-22 16:55:33 +0200 |
---|---|---|
committer | Lukas Larsson <[email protected]> | 2011-08-01 17:29:45 +0200 |
commit | 8649b9257876d1b016746126c95c9e803a680e5d (patch) | |
tree | 1ff781715c0a74ab205f0f70f071a8db2ae6dd70 /lib | |
parent | 97f867992aaf98eac44c8fcd17df3a15e4aa3eab (diff) | |
download | otp-8649b9257876d1b016746126c95c9e803a680e5d.tar.gz otp-8649b9257876d1b016746126c95c9e803a680e5d.tar.bz2 otp-8649b9257876d1b016746126c95c9e803a680e5d.zip |
Extract generic is_nif_loadable function from decode
Diffstat (limited to 'lib')
-rw-r--r-- | lib/asn1/src/asn1rt_ber_bin_v2.erl | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/lib/asn1/src/asn1rt_ber_bin_v2.erl b/lib/asn1/src/asn1rt_ber_bin_v2.erl index 2df289e2b8..4c75b5918f 100644 --- a/lib/asn1/src/asn1rt_ber_bin_v2.erl +++ b/lib/asn1/src/asn1rt_ber_bin_v2.erl @@ -54,6 +54,8 @@ -export([decode_primitive_incomplete/2,decode_selective/2]). +-compile(export_all). + -include("asn1_records.hrl"). % the encoding of class of tag bits 8 and 7 @@ -164,28 +166,36 @@ decode(B) -> %% asn1-1.7 decode(B, nif) -> - case application:get_env(asn1, nif_loadable) of - {ok, true} -> + case is_nif_loadable() of + true -> case asn1rt_nif:decode_ber_tlv(B) of {error, Reason} -> handle_error(Reason, B); Else -> Else end; - {ok, false} -> - decode(B); - undefined -> - case catch code:load_file(asn1rt_nif) of - {module, asn1rt_nif} -> - application:set_env(asn1, nif_loadable, true); - _Else -> - application:set_env(asn1, nif_loadable, false) - end, - decode(B, nif) + false -> + decode(B) end; decode(B,erlang) when is_binary(B) -> decode_primitive(B); decode(Tlv,erlang) -> {Tlv,<<>>}. +%% Have to check this since asn1 is not guaranteed to be available +is_nif_loadable() -> + case application:get_env(asn1, nif_loadable) of + {ok,R} -> + R; + undefined -> + case catch code:load_file(asn1rt_nif) of + {module, asn1rt_nif} -> + application:set_env(asn1, nif_loadable, true), + true; + _Else -> + application:set_env(asn1, nif_loadable, false), + false + end + end. + handle_error([],_)-> exit({error,{asn1,{"memory allocation problem"}}}); handle_error({$1,_},L) -> % error in nif |