incompatible pointer types with newer zlib

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: incompatible pointer types with newer zlib
Date: 2012-02-23 09:16:11
Message-ID: 1329988571.6474.9.camel@vanquo.pezone.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

According to me update logs, somewhere between zlib versions 1.2.3.4 and
1.2.6, the definition of the gzFile type was changed from void * to
struct gzFile_s *, an opaque struct. Note that gzFile is already the
pointer in either case. Our code has assumed, however, that you use
gzFile like FILE, namely that the APIs take a pointer to the type, but
that is not the case. So code like

gzFile *handle = gzopen(...)

is wrong.

This used to pass silently because you can assign a void* to a void**,
but with the newer definition you get a bunch of warnings like

pg_backup_files.c: In function ‘_StartData’:
pg_backup_files.c:256:11: warning: assignment from incompatible pointer type [enabled by default]
pg_backup_files.c: In function ‘_WriteData’:
pg_backup_files.c:271:2: warning: passing argument 1 of ‘gzwrite’ from incompatible pointer type [enabled by default]
/usr/include/zlib.h:1318:12: note: expected ‘gzFile’ but argument is of type ‘struct gzFile_s **’

Affected are pg_dump and pg_basebackup.

Fixing most of this is not difficult, see attached patch. The only
ugliness is in pg_backup_archiver.h

FILE *FH; /* General purpose file handle */

which is used throughout pg_dump as sometimes a real FILE* and sometimes
a gzFile handle. There are also some fileno() calls on this, so just
replacing this with an #ifdef isn't going to work. This might need some
more restructuring to make the code truly type-safe. My quick patch
replaces the type with void*, thus sort of restoring the original
situation that allowed this to work.

Note that these are only warnings, so we probably don't need to worry
about backpatching this in a hurry.

Attachment Content-Type Size
gzfile.patch text/x-patch 2.3 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Simon Riggs 2012-02-23 09:18:57 Re: foreign key locks, 2nd attempt
Previous Message Gianni Ciolli 2012-02-23 08:50:21 Re: Triggers with DO functionality