Skip to content

Commit

Permalink
Mark code that uses improper lists as generated (#556)
Browse files Browse the repository at this point in the history
Addresses [#549](#549) by
marking code that creates improper lists as `generated: true`.
  • Loading branch information
al2o3cr authored Jul 6, 2021
1 parent a849473 commit 3892e45
Show file tree
Hide file tree
Showing 10 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/postgrex/extensions/bit_string.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule Postgrex.Extensions.BitString do
def init(opts), do: Keyword.fetch!(opts, :decode_binary)

def encode(_) do
quote location: :keep do
quote location: :keep, generated: true do
val when is_binary(val) ->
[<<byte_size(val) + 4::int32, bit_size(val)::uint32>> | val]

Expand Down
2 changes: 1 addition & 1 deletion lib/postgrex/extensions/box.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule Postgrex.Extensions.Box do
alias Postgrex.Extensions.Point

def encode(_) do
quote location: :keep do
quote location: :keep, generated: true do
%Postgrex.Box{upper_right: p1, bottom_left: p2} ->
encoded_p1 = Point.encode_point(p1, Postgrex.Box)
encoded_p2 = Point.encode_point(p2, Postgrex.Box)
Expand Down
2 changes: 1 addition & 1 deletion lib/postgrex/extensions/line_segment.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule Postgrex.Extensions.LineSegment do
alias Postgrex.Extensions.Point

def encode(_) do
quote location: :keep do
quote location: :keep, generated: true do
%Postgrex.LineSegment{point1: p1, point2: p2} ->
encoded_p1 = Point.encode_point(p1, Postgrex.LineSegment)
encoded_p2 = Point.encode_point(p2, Postgrex.LineSegment)
Expand Down
2 changes: 1 addition & 1 deletion lib/postgrex/extensions/name.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule Postgrex.Extensions.Name do
def init(opts), do: Keyword.fetch!(opts, :decode_binary)

def encode(_) do
quote location: :keep do
quote location: :keep, generated: true do
name when is_binary(name) and byte_size(name) < 64 ->
[<<byte_size(name)::int32>> | name]

Expand Down
2 changes: 1 addition & 1 deletion lib/postgrex/extensions/numeric.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Postgrex.Extensions.Numeric do
use Postgrex.BinaryExtension, send: "numeric_send"

def encode(_) do
quote location: :keep do
quote location: :keep, generated: true do
%Decimal{} = decimal ->
data = unquote(__MODULE__).encode_numeric(decimal)
[<<IO.iodata_length(data)::int32>> | data]
Expand Down
2 changes: 1 addition & 1 deletion lib/postgrex/extensions/path.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule Postgrex.Extensions.Path do
alias Postgrex.Extensions.Point

def encode(_) do
quote location: :keep do
quote location: :keep, generated: true do
%Postgrex.Path{open: o, points: ps} when is_list(ps) and is_boolean(o) ->
open_byte = Path.open_to_byte(o)
len = length(ps)
Expand Down
2 changes: 1 addition & 1 deletion lib/postgrex/extensions/polygon.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule Postgrex.Extensions.Polygon do
alias Postgrex.Extensions.Point

def encode(_) do
quote location: :keep do
quote location: :keep, generated: true do
%Postgrex.Polygon{vertices: vertices} when is_list(vertices) ->
len = length(vertices)

Expand Down
2 changes: 1 addition & 1 deletion lib/postgrex/extensions/raw.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ defmodule Postgrex.Extensions.Raw do
def init(opts), do: Keyword.fetch!(opts, :decode_binary)

def encode(_) do
quote location: :keep do
quote location: :keep, generated: true do
bin when is_binary(bin) ->
[<<byte_size(bin)::int32>> | bin]

Expand Down
2 changes: 1 addition & 1 deletion lib/postgrex/extensions/uuid.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule Postgrex.Extensions.UUID do
def init(opts), do: Keyword.fetch!(opts, :decode_binary)

def encode(_) do
quote location: :keep do
quote location: :keep, generated: true do
uuid when is_binary(uuid) and byte_size(uuid) == 16 ->
[<<16::int32>> | uuid]

Expand Down
4 changes: 2 additions & 2 deletions lib/postgrex/type_module.ex
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ defmodule Postgrex.TypeModule do
end

defp decode_rows(dispatch, rest, acc, rem, full, rows) do
quote location: :keep do
quote location: :keep, generated: true do
def decode_rows(binary, types, rows) do
decode_rows(binary, byte_size(binary), types, rows)
end
Expand Down Expand Up @@ -464,7 +464,7 @@ defmodule Postgrex.TypeModule do
decode_tuple_dispatch(extension, format, rest, oids, n, acc)
end

quote do
quote generated: true do
def decode_tuple(<<rest::binary>>, count, types) when is_integer(count) do
decode_tuple(rest, count, types, 0, [])
end
Expand Down

0 comments on commit 3892e45

Please sign in to comment.