Skip to content

Commit ce61c60

Browse files
committed
Deprecates binary_to_term and term_to_binary in Kernel.
1 parent dc0dd43 commit ce61c60

File tree

3 files changed

+9
-56
lines changed

3 files changed

+9
-56
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Bug fixes
66

77
* Deprecations
8+
* [Kernel] `binary_to_term/1`, `binary_to_term/2`, `term_to_binary/1` and `term_to_binary/2` are deprecated in favor of their counterparts in the `:erlang` module
89

910
* Backwards incompatible changes
1011

lib/elixir/lib/kernel.ex

Lines changed: 8 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -212,44 +212,15 @@ defmodule Kernel do
212212
:erlang.binary_to_float(some_binary)
213213
end
214214

215-
@doc """
216-
Returns an Erlang term which is the result of decoding the binary
217-
object `binary`, which must be encoded according to the Erlang external
218-
term format.
219-
220-
## Examples
221-
222-
iex> binary_to_term(term_to_binary("foo"))
223-
"foo"
224-
225-
"""
226-
@spec binary_to_term(binary) :: term
215+
@doc false
227216
def binary_to_term(binary) do
217+
IO.write "binary_to_term/1 is deprecated, please use :erlang.binary_to_term/1 instead\n#{Exception.format_stacktrace}"
228218
:erlang.binary_to_term(binary)
229219
end
230220

231-
@doc """
232-
As `binary_to_term/1`, but accepts a safe option useful when receiving
233-
binaries from an untrusted source.
234-
235-
When enabled, it prevents decoding data that may be used to attack the
236-
Erlang system. In the event of receiving unsafe data, decoding fails
237-
with a badarg error.
238-
239-
Currently, this prevents creation of new atoms directly, creation of
240-
new atoms indirectly (as they are embedded in certain structures like pids,
241-
refs, funs, etc), and creation of new external function references. None
242-
of those resources are currently garbage collected, so unchecked creation
243-
of them can exhaust available memory.
244-
245-
## Examples
246-
247-
iex> binary_to_term(term_to_binary("foo"), [:safe])
248-
"foo"
249-
250-
"""
251-
@spec binary_to_term(binary, [] | [:safe]) :: term
221+
@doc false
252222
def binary_to_term(binary, options) do
223+
IO.write "binary_to_term/2 is deprecated, please use :erlang.binary_to_term/2 instead\n#{Exception.format_stacktrace}"
253224
:erlang.binary_to_term(binary, options)
254225
end
255226

@@ -971,30 +942,15 @@ defmodule Kernel do
971942
:erlang.spawn_link(module, fun, args)
972943
end
973944

974-
@doc """
975-
Returns a binary which is the result of encoding the given `term`
976-
according to the Erlang external term format.
977-
978-
This can be used for a variety of purposes, for example, writing a term
979-
to a file in an efficient way, or sending an Erlang term to some type
980-
of communications channel not supported by distributed.
981-
"""
982-
@spec term_to_binary(term) :: binary
945+
@doc false
983946
def term_to_binary(term) do
947+
IO.write "term_to_binary/1 is deprecated, please use :erlang.term_to_binary/1 instead\n#{Exception.format_stacktrace}"
984948
:erlang.term_to_binary(term)
985949
end
986950

987-
@doc """
988-
The same as `term_to_binary/1` but also supports two options:
989-
990-
* `compressed`: the level of compression to be used from 0 to 9;
991-
* `minor_version`: used to control the details of encoding. Can be 0 or 1,
992-
please read http://www.erlang.org/doc/man/erlang.html#term_to_binary-2
993-
for more details
994-
995-
"""
996-
@spec term_to_binary(term, list({:compressed, 0..9}|{:minor_version, 0}|{:minor_version, 1})) :: binary
951+
@doc false
997952
def term_to_binary(term, opts) do
953+
IO.write "term_to_binary/2 is deprecated, please use :erlang.term_to_binary/2 instead\n#{Exception.format_stacktrace}"
998954
:erlang.term_to_binary(term, opts)
999955
end
1000956

lib/elixir/src/elixir_dispatch.erl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,6 @@ in_erlang_functions() ->
326326
{ binary_to_float, 2 },
327327
{ binary_to_integer, 1 },
328328
{ binary_to_integer, 2 },
329-
{ binary_to_term, 1 },
330-
{ binary_to_term, 2 },
331329
{ bit_size, 1 },
332330
{ bitstring_to_list, 1 },
333331
{ byte_size, 1 },
@@ -382,8 +380,6 @@ in_erlang_functions() ->
382380
{ spawn_link, 1 },
383381
{ spawn_link, 3 },
384382
% { split_binary, 2 },
385-
{ term_to_binary, 1 },
386-
{ term_to_binary, 2 },
387383
{ throw, 1 },
388384
% { time, 0 },
389385
{ tl, 1 },

0 commit comments

Comments
 (0)