From e5c71b7f176393cdb3f6b9d17a5969e9bd89c88b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Thu, 20 Feb 2014 14:29:57 +0100 Subject: Deprecate asn1 functions Those asn1 functions are no longer needed because they all have better alternatives. --- bootstrap/lib/stdlib/ebin/otp_internal.beam | Bin 10140 -> 10436 bytes lib/asn1/src/asn1ct.erl | 4 ++++ lib/asn1/src/asn1ct_value.erl | 1 + lib/asn1/src/asn1rt.erl | 3 +-- lib/eldap/src/eldap.erl | 4 ++-- lib/megaco/src/binary/megaco_binary_encoder_lib.erl | 8 ++++---- lib/stdlib/src/otp_internal.erl | 18 ++++++++++++++++++ 7 files changed, 30 insertions(+), 8 deletions(-) diff --git a/bootstrap/lib/stdlib/ebin/otp_internal.beam b/bootstrap/lib/stdlib/ebin/otp_internal.beam index de1c007a77..1146ef9ab8 100644 Binary files a/bootstrap/lib/stdlib/ebin/otp_internal.beam and b/bootstrap/lib/stdlib/ebin/otp_internal.beam differ diff --git a/lib/asn1/src/asn1ct.erl b/lib/asn1/src/asn1ct.erl index 30f493a2df..9ec43197bf 100644 --- a/lib/asn1/src/asn1ct.erl +++ b/lib/asn1/src/asn1ct.erl @@ -19,6 +19,10 @@ %% %% -module(asn1ct). +-deprecated([decode/3,encode/3]). +-compile([{nowarn_deprecated_function,{asn1rt,decode,3}}, + {nowarn_deprecated_function,{asn1rt,encode,2}}, + {nowarn_deprecated_function,{asn1rt,encode,3}}]). %% Compile Time functions for ASN.1 (e.g ASN.1 compiler). diff --git a/lib/asn1/src/asn1ct_value.erl b/lib/asn1/src/asn1ct_value.erl index be8b967cf0..221cd991a7 100644 --- a/lib/asn1/src/asn1ct_value.erl +++ b/lib/asn1/src/asn1ct_value.erl @@ -18,6 +18,7 @@ %% %% -module(asn1ct_value). +-compile([{nowarn_deprecated_function,{asn1rt,utf8_list_to_binary,1}}]). %% Generate Erlang values for ASN.1 types. %% The value is randomized within it's constraints diff --git a/lib/asn1/src/asn1rt.erl b/lib/asn1/src/asn1rt.erl index d18f81346a..ad8b879c38 100644 --- a/lib/asn1/src/asn1rt.erl +++ b/lib/asn1/src/asn1rt.erl @@ -18,14 +18,13 @@ %% %% -module(asn1rt). +-deprecated(module). %% Runtime functions for ASN.1 (i.e encode, decode) -export([encode/2,encode/3,decode/3,load_driver/0,unload_driver/0,info/1]). -export([utf8_binary_to_list/1,utf8_list_to_binary/1]). - --deprecated([load_driver/0,unload_driver/0]). encode(Module,{Type,Term}) -> encode(Module,Type,Term). diff --git a/lib/eldap/src/eldap.erl b/lib/eldap/src/eldap.erl index af5bf94c97..a86fd39adb 100644 --- a/lib/eldap/src/eldap.erl +++ b/lib/eldap/src/eldap.erl @@ -743,7 +743,7 @@ request(S, Data, ID, Request) -> send_request(S, Data, ID, Request) -> Message = #'LDAPMessage'{messageID = ID, protocolOp = Request}, - {ok,Bytes} = asn1rt:encode('ELDAPv3', 'LDAPMessage', Message), + {ok,Bytes} = 'ELDAPv3':encode('LDAPMessage', Message), case do_send(S, Data, Bytes) of {error,Reason} -> throw({gen_tcp_error,Reason}); Else -> Else @@ -762,7 +762,7 @@ do_recv(S, #eldap{using_tls=true, timeout=Timeout}, Len) -> recv_response(S, Data) -> case do_recv(S, Data, 0) of {ok, Packet} -> - case asn1rt:decode('ELDAPv3', 'LDAPMessage', Packet) of + case 'ELDAPv3':decode('LDAPMessage', Packet) of {ok,Resp} -> {ok,Resp}; Error -> throw(Error) end; diff --git a/lib/megaco/src/binary/megaco_binary_encoder_lib.erl b/lib/megaco/src/binary/megaco_binary_encoder_lib.erl index 8a4f4e7509..7d82262a59 100644 --- a/lib/megaco/src/binary/megaco_binary_encoder_lib.erl +++ b/lib/megaco/src/binary/megaco_binary_encoder_lib.erl @@ -66,7 +66,7 @@ version_of(_EC, Binary, 3, [AsnModV1, AsnModV2, AsnModV3]) version_of([], _Binary, Err) -> {error, {decode_failed, lists:reverse(Err)}}; version_of([AsnMod|AsnMods], Binary, Errs) when is_atom(AsnMod) -> - case (catch asn1rt:decode(AsnMod, 'MegacoMessage', Binary)) of + case (catch AsnMod:decode('MegacoMessage', Binary)) of {ok, M} -> V = (M#'MegacoMessage'.mess)#'Message'.version, {ok, V}; @@ -82,14 +82,14 @@ version_of([AsnMod|AsnMods], Binary, Errs) when is_atom(AsnMod) -> encode_message([native], MegaMsg, AsnMod, _TransMod, binary) when is_record(MegaMsg, 'MegacoMessage') -> - asn1rt:encode(AsnMod, 'MegacoMessage', MegaMsg); + AsnMod:encode('MegacoMessage', MegaMsg); encode_message(EC, MegaMsg, AsnMod, TransMod, binary) when is_list(EC) andalso is_record(MegaMsg, 'MegacoMessage') -> case (catch TransMod:tr_message(MegaMsg, encode, EC)) of {'EXIT', Reason} -> {error, Reason}; MegaMsg2 -> - asn1rt:encode(AsnMod, 'MegacoMessage', MegaMsg2) + AsnMod:encode('MegacoMessage', MegaMsg2) end; encode_message(EC, MegaMsg, AsnMod, TransMod, io_list) -> case encode_message(EC, MegaMsg, AsnMod, TransMod, binary) of @@ -276,7 +276,7 @@ decode_message_dynamic(_EC, _BadBin, _Mods, _Type) -> decode_message(EC, Bin, AsnMod, TransMod, _) -> - case asn1rt:decode(AsnMod, 'MegacoMessage', Bin) of + case AsnMod:decode('MegacoMessage', Bin) of {ok, MegaMsg} -> case EC of [native] -> diff --git a/lib/stdlib/src/otp_internal.erl b/lib/stdlib/src/otp_internal.erl index cebc9c91bd..380bc3eccc 100644 --- a/lib/stdlib/src/otp_internal.erl +++ b/lib/stdlib/src/otp_internal.erl @@ -577,6 +577,24 @@ obsolete_1(wxCursor, new, 3) -> obsolete_1(wxCursor, new, 4) -> {deprecated,"deprecated function not available in wxWidgets-2.9 and later"}; +%% Added in OTP 17. +obsolete_1(asn1ct, decode,3) -> + {deprecated,"deprecated; use Mod:decode/2 instead"}; +obsolete_1(asn1ct, encode, 3) -> + {deprecated,"deprecated; use Mod:encode/2 instead"}; +obsolete_1(asn1rt, decode,3) -> + {deprecated,"deprecated; use Mod:decode/2 instead"}; +obsolete_1(asn1rt, encode, 2) -> + {deprecated,"deprecated; use Mod:encode/2 instead"}; +obsolete_1(asn1rt, encode, 3) -> + {deprecated,"deprecated; use Mod:encode/2 instead"}; +obsolete_1(asn1rt, info, 1) -> + {deprecated,"deprecated; use Mod:info/0 instead"}; +obsolete_1(asn1rt, utf8_binary_to_list, 1) -> + {deprecated,{unicode,characters_to_list,1}}; +obsolete_1(asn1rt, utf8_list_to_binary, 1) -> + {deprecated,{unicode,characters_to_binary,1}}; + obsolete_1(_, _, _) -> no. -- cgit v1.2.3 From 1bdb47b00faff39994a041c6d9a291a2c68143d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Thu, 20 Feb 2014 16:09:35 +0100 Subject: Remove or de-emphasize references to the deprecated asn1rt module --- lib/asn1/doc/src/asn1_ug.xml | 50 ++++++++++++-------------------------------- lib/asn1/doc/src/asn1ct.xml | 6 +++++- lib/asn1/doc/src/asn1rt.xml | 30 ++++++++++++++------------ 3 files changed, 35 insertions(+), 51 deletions(-) diff --git a/lib/asn1/doc/src/asn1_ug.xml b/lib/asn1/doc/src/asn1_ug.xml index eb9f000e75..ee54fdffd7 100644 --- a/lib/asn1/doc/src/asn1_ug.xml +++ b/lib/asn1/doc/src/asn1_ug.xml @@ -205,16 +205,13 @@ ok is saved in the People.asn1db file, the generated Erlang code is compiled using the Erlang compiler and loaded into the Erlang runtime system. Now there is a user interface - of encode/2 and decode/2 in the module People, which is invoked by: + for encode/2 and decode/2 in the module People, + which is invoked by:

,),]]>

or

-,),]]>

- - Alternatively one can use the ,,)]]> and ,,)]]> calls. - However, they are not as efficient as the previous methods since they - result in an additional apply/3 call.

+,),]]>

Assume there is a network application which receives instances of the ASN.1 defined type Person, modifies and sends them back again:

@@ -241,16 +238,14 @@ receive encoding-rules.

The encoder and the decoder can also be run from - the shell. The following dialogue with the shell illustrates - how the functions - asn1rt:encode/3 and asn1rt:decode/3 are used.

+ the shell.

 2> Rockstar = {'Person',"Some Name",roving,50}.
 {'Person',"Some Name",roving,50}
-3> {ok,Bin} = asn1rt:encode('People','Person',Rockstar).
+3> {ok,Bin} = 'People':encode('Person',Rockstar).
 {ok,<<243,17,19,9,83,111,109,101,32,78,97,109,101,2,1,2,
       2,1,50>>}
-4> {ok,Person} = asn1rt:decode('People','Person',Bin).
+4> {ok,Person} = 'People':decode('Person',Bin).
 {ok,{'Person',"Some Name",roving,50}}
 5>      
@@ -279,11 +274,8 @@ The encoder and the decoder can also be run from (including the compiler).

-

The module asn1rt which provides the run-time functions. - However, it is preferable to use the generated encode/2 and - decode/2 functions in each module, ie. - Module:encode(Type,Value), in favor of the asn1rt - interface.

+

The module asn1rt_nif which provides the run-time functions + for the ASN.1 decoder for the BER back-end.

The reason for the division of the interface into compile-time @@ -384,25 +376,9 @@ asn1ct:decode('H323-MESSAGES','SomeChoiceType',Bytes).

Run-time Functions -

A brief description of the major functions is given here. For a - complete description of each function see - the Asn1 Reference Manual, the asn1rt module.

-

The generic run-time encode and decode functions can be invoked as below:

-
-asn1rt:encode('H323-MESSAGES','SomeChoiceType',{call,"octetstring"}).
-asn1rt:decode('H323-MESSAGES','SomeChoiceType',Bytes).      
-

Or, preferable like:

-
-'H323-MESSAGES':encode('SomeChoiceType',{call,"octetstring"}).
-'H323-MESSAGES':decode('SomeChoiceType',Bytes).      
-

The asn1 nif is enabled in two occasions: encoding of - asn1 values when the asn1 spec is compiled with per and - or decode of encoded asn1 values when the asn1 spec is - compiled with ber. In - those cases the nif will be loaded automatically at the first call - to encode/decode. If one doesn't want the performance - overhead of the nif being loaded at the first call it is possible - to load the nif separately by loading the asn1rt_nif module.

+

When an ASN.1 specification is compiled with the ber + option, the module asn1rt_nif module and the NIF library in + asn1/priv_dir will be needed at run-time.

By invoking the function info/0 in a generated module, one gets information about which compiler options were used.

@@ -414,8 +390,8 @@ asn1rt:decode('H323-MESSAGES','SomeChoiceType',Bytes). a line number indicating where in the source file the error was detected. If no errors are found, an Erlang ASN.1 module will be created as default.

-

The run-time encoders and decoders (in the asn1rt module) do - execute within a catch and returns {ok, Data} or +

The run-time encoders and decoders execute within a catch and + returns {ok, Data} or {error, {asn1, Description}} where Description is an Erlang term describing the error.

diff --git a/lib/asn1/doc/src/asn1ct.xml b/lib/asn1/doc/src/asn1ct.xml index 5871c8ad68..4d5a1a402a 100644 --- a/lib/asn1/doc/src/asn1ct.xml +++ b/lib/asn1/doc/src/asn1ct.xml @@ -61,7 +61,7 @@ and uper_bin options will still work, but will print a warning.

Another change in R16 is that the generated encode/2 - function (and asn1rt:encode/3) always returns a binary. + function always returns a binary. The encode/2 function for the BER back-end used to return an iolist.

@@ -326,6 +326,8 @@ File3.asn not always checked. Returns {ok, Bytes} if successful or {error, Reason} if an error occurred.

+

This function is deprecated. + Use Module:encode(Type, Value) instead.

@@ -339,6 +341,8 @@ File3.asn

Decodes Type from Module from the binary Bytes. Returns {ok, Value} if successful.

+

This function is deprecated. + Use Module:decode(Type, Bytes) instead.

diff --git a/lib/asn1/doc/src/asn1rt.xml b/lib/asn1/doc/src/asn1rt.xml index 6e22e45d93..3cf56b01ca 100644 --- a/lib/asn1/doc/src/asn1rt.xml +++ b/lib/asn1/doc/src/asn1rt.xml @@ -34,9 +34,12 @@ asn1rt ASN.1 runtime support functions -

This module is the interface module for the ASN.1 runtime support functions. - To encode and decode ASN.1 types in runtime the functions in this module - should be used.

+ +

+ All functions in this module are deprecated and will be + removed in a future release. +

+
@@ -52,6 +55,7 @@

Decodes Type from Module from the binary Bytes. Returns {ok,Value} if successful.

+

Use Module:decode(Type, Bytes) instead of this function.

@@ -65,16 +69,13 @@ Reason = term() -

Encodes Value of Type defined in the ASN.1 module - Module. Returns a possibly nested list of bytes and or binaries - if successful. To get as fast execution as possible the - encode function only performs rudimentary tests that the input - Value - is a correct instance of Type. The length of strings is for example - not always checked.

- -

Starting in R16, Bytes is always a binary.

-
+

Encodes Value of Type defined in the ASN.1 + module Module. Returns a binary if successful. To get + as fast execution as possible the encode function only + performs rudimentary tests that the input Value is a + correct instance of Type. The length of strings is, for + example, not always checked.

+

Use Module:encode(Type, Value) instead of this function.

@@ -90,6 +91,7 @@

info/1 returns the version of the asn1 compiler that was used to compile the module. It also returns the compiler options that was used.

+

Use Module:info() instead of this function.

@@ -106,6 +108,7 @@ to a list of integers, where each integer represents one character as its unicode value. The function fails if the binary is not a properly encoded UTF8 string.

+

Use unicode:characters_to_list/1 instead of this function.

@@ -121,6 +124,7 @@

utf8_list_to_binary/1 Transforms a list of integers, where each integer represents one character as its unicode value, to a UTF8 encoded binary.

+

Use unicode:characters_to_binary/1 instead of this function.

-- cgit v1.2.3