Skip to content

Commit

Permalink
Add helper to allocate fifo_in if needed
Browse files Browse the repository at this point in the history
This will be helpful to avoid code duplication in a later commit.

Signed-off-by: Matheus Castanho <msc@linux.ibm.com>
  • Loading branch information
mscastanho committed Apr 13, 2022
1 parent 6ddb40a commit 0153517
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/nx_deflate.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ do { if ((s)->cur_in > (s)->len_in/2) { \
(s)->cur_in = 0; } \
} while(0)

#define fifo_in_alloc_check(s) \
do { if (s->fifo_in == NULL) { \
s->len_in = nx_config.deflate_fifo_in_len; \
s->fifo_in = nx_alloc_buffer(s->len_in, s->page_sz, 0); \
if (s->fifo_in == NULL) \
return Z_MEM_ERROR; } \
} while(0)

#define put_byte(s, c) {(s)->fifo_out[(s)->used_out++] = (Bytef)((c) & 0xff);}
#define put_short(s, b) do { \
Expand Down Expand Up @@ -1640,11 +1647,7 @@ int nx_deflate(z_streamp strm, int flush)
(s->level != 0) && /* not a raw copy */
(s->dict_len == 0)) {
/* if dictionary present do not buffer small input */
if (s->fifo_in == NULL) {
s->len_in = nx_config.deflate_fifo_in_len;
if (NULL == (s->fifo_in = nx_alloc_buffer(s->len_in, s->page_sz, 0)))
return Z_MEM_ERROR;
}
fifo_in_alloc_check(s);
/* small input and no request made for flush or finish */
small_copy_nxstrm_in_to_fifo_in(s);
return Z_OK;
Expand Down

0 comments on commit 0153517

Please sign in to comment.