Skip to content

Commit cce8b4d

Browse files
committed
Support OTP-28 uncompressed literals
Handle new OTP-28 uncompressed literals when running on OTP 28 and later, continues to support zlib compression for literals with earlier OTP versions. Adds OTP-28 to the workflow test matrix. Closes #30 Signed-off-by: Winford <[email protected]>
1 parent 2daea6d commit cce8b4d

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

.github/workflows/build-and-test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
runs-on: "ubuntu-24.04"
1414
strategy:
1515
matrix:
16-
otp: ["25", "26", "27"]
16+
otp: ["25", "26", "27", "28"]
1717

1818
steps:
1919
# Setup

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [0.7.4] - Unreleased
8-
8+
- Add support for OTP-28
99

1010
## [0.7.3] (2024.06.06)
1111

src/packbeam_api.erl

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ filter_modules(Modules, ParsedFiles) ->
586586
%% @private
587587
parse_file(beam, _ModuleName, Data, IncludeLines) ->
588588
{ok, Module, Chunks} = beam_lib:all_chunks(Data),
589-
{UncompressedChunks, UncompressedLiterals} = uncompress_literals(Chunks),
589+
{UncompressedChunks, UncompressedLiterals} = maybe_uncompress_literals(Chunks),
590590
FilteredChunks = filter_chunks(UncompressedChunks, IncludeLines),
591591
{ok, Binary} = beam_lib:build_module(FilteredChunks),
592592
{ok, {Module, ChunkRefs}} = beam_lib:chunks(Data, [imports, exports, atoms]),
@@ -707,23 +707,29 @@ strip_padding(Data) ->
707707
Data.
708708

709709
%% @private
710-
uncompress_literals(Chunks) ->
710+
maybe_uncompress_literals(Chunks) ->
711711
case proplists:get_value("LitT", Chunks) of
712712
undefined ->
713713
{Chunks, undefined};
714-
<<_Header:4/binary, Data/binary>> ->
715-
UncompressedData = zlib:uncompress(Data),
716-
{
717-
lists:keyreplace(
718-
"LitT",
719-
1,
720-
Chunks,
721-
{"LitU", UncompressedData}
722-
),
723-
UncompressedData
724-
}
714+
<<0:32, Data/binary>> ->
715+
{Chunks, Data};
716+
<<_Size:4/binary, Data/binary>> ->
717+
do_uncompress_literals(Chunks, Data)
725718
end.
726719

720+
%% @private
721+
do_uncompress_literals(Chunks, Data) ->
722+
UncompressedData = zlib:uncompress(Data),
723+
{
724+
lists:keyreplace(
725+
"LitT",
726+
1,
727+
Chunks,
728+
{"LitU", UncompressedData}
729+
),
730+
UncompressedData
731+
}.
732+
727733
%% @private
728734
write_packbeam(OutputFilePath, ParsedFiles) ->
729735
PackedData =

0 commit comments

Comments
 (0)