Skip to content

Commit e6c290c

Browse files
jimmodpgeorge
authored andcommitted
lib/uzlib: Add a source_read_data var to pass to source_read_cb.
For better abstraction for users of this API. Signed-off-by: Jim Mussared <[email protected]>
1 parent 7f16bfc commit e6c290c

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

lib/uzlib/tinflate.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ unsigned char uzlib_get_byte(uzlib_uncomp_t *d)
185185
read next byte using it. (Note: the callback can also update ->source
186186
and ->source_limit). */
187187
if (d->source_read_cb && !d->eof) {
188-
int val = d->source_read_cb(d);
188+
int val = d->source_read_cb(d->source_read_data);
189189
if (val >= 0) {
190190
return (unsigned char)val;
191191
}

lib/uzlib/uzlib.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ typedef struct _uzlib_uncomp_t {
8484
also return -1 in case of EOF (or irrecoverable error). Note that
8585
besides returning the next byte, it may also update source and
8686
source_limit fields, thus allowing for buffered operation. */
87-
int (*source_read_cb)(struct _uzlib_uncomp_t *uncomp);
87+
void *source_read_data;
88+
int (*source_read_cb)(void *);
8889

8990
unsigned int tag;
9091
unsigned int bitcount;

ports/stm32/mboot/gzstream.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ typedef struct _gz_stream_t {
4545

4646
static gz_stream_t gz_stream SECTION_NOZERO_BSS;
4747

48-
static int gz_stream_read_src(uzlib_uncomp_t *decomp) {
48+
static int gz_stream_read_src(void *data) {
49+
uzlib_uncomp_t *decomp = data;
4950
int n = gz_stream.stream_read(gz_stream.stream_data, gz_stream.buf, sizeof(gz_stream.buf));
5051
if (n < 0) {
5152
// Stream error
@@ -76,6 +77,7 @@ int gz_stream_init_from_stream(void *stream_data, stream_read_t stream_read) {
7677
gz_stream.stream_read = stream_read;
7778

7879
memset(&gz_stream.decomp, 0, sizeof(gz_stream.decomp));
80+
gz_stream.decomp.source_read_data = &gz_stream.decomp;
7981
gz_stream.decomp.source_read_cb = gz_stream_read_src;
8082

8183
int header_wbits;

0 commit comments

Comments
 (0)