This is the mail archive of the
elfutils-devel@sourceware.org
mailing list for the elfutils project.
Re: [PATCH] Move nested functions in gzip.c to file scope.
- From: Mark Wielaard <mjw at redhat dot com>
- To: elfutils-devel at lists dot fedorahosted dot org
- Date: Fri, 13 Nov 2015 17:26:02 +0100
- Subject: Re: [PATCH] Move nested functions in gzip.c to file scope.
On Tue, 2015-11-03 at 12:04 -0800, Chih-hung Hsieh wrote:
> Sorry about that.
> Could you take a look of the new attached 0002*gzip.c*patch?
Yes, this works. But I think the state is a bit too big. Like zf, both
fd and start_offset are really only used by open_stream when gzip is
used. So both can be guarded by #if !USE_INFLATE as the diff attached
does. Does that make sense?
Thanks,
Mark
diff --git a/libdwfl/gzip.c b/libdwfl/gzip.c
index 11df349..888ca51 100644
--- a/libdwfl/gzip.c
+++ b/libdwfl/gzip.c
@@ -68,11 +68,11 @@
#define READ_SIZE (1 << 20)
struct unzip_state {
- int fd;
#if !USE_INFLATE
+ int fd;
gzFile zf;
-#endif
off_t start_offset;
+#endif
size_t mapped_size;
void **whole;
void *buffer;
@@ -174,11 +174,11 @@ unzip (int _fd, off_t _start_offset,
{
struct unzip_state state =
{
- .fd = _fd,
#if !USE_INFLATE
+ .fd = _fd,
.zf = NULL,
-#endif
.start_offset = _start_offset,
+#endif
.mapped_size = _mapped_size,
.whole = _whole,
.buffer = NULL,
@@ -195,7 +195,7 @@ unzip (int _fd, off_t _start_offset,
if (unlikely (state.input_buffer == NULL))
return DWFL_E_NOMEM;
- ssize_t n = pread_retry (state.fd, state.input_buffer, READ_SIZE, state.start_offset);
+ ssize_t n = pread_retry (_fd, state.input_buffer, READ_SIZE, _start_offset);
if (unlikely (n < 0))
return zlib_fail (&state, Z (ERRNO));
@@ -241,8 +241,8 @@ unzip (int _fd, off_t _start_offset,
{
if (z.avail_in == 0 && state.input_buffer != NULL)
{
- ssize_t n = pread_retry (state.fd, state.input_buffer, READ_SIZE,
- state.start_offset + state.input_pos);
+ ssize_t n = pread_retry (_fd, state.input_buffer, READ_SIZE,
+ _start_offset + state.input_pos);
if (unlikely (n < 0))
{
inflateEnd (&z);