[PATCH libpciaccess] Use correct type for pci_id file accessor functions
Mathias Krause
mathias.krause at secunet.com
Tue Feb 7 07:46:52 PST 2012
On 07.02.2012 16:29, walter harms wrote:
> Am 07.02.2012 09:36, schrieb Mathias Krause:
>> On 31.01.2012 11:46, Mathias Krause wrote:
>>> This fixes the compiler warning of using the wrong type for gzgets() and
>>> gzclose() as they want a gzFile argument, not a pointer to gzFile. The
>>> abstraction layer pci_id_file should just abstract the full type.
>>>
>>> Signed-off-by: Mathias Krause <mathias.krause at secunet.com>
>>> ---
>>> src/common_device_name.c | 4 ++--
>>> 1 files changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/src/common_device_name.c b/src/common_device_name.c
>>> index 8e8a752..bc87708 100644
>>> --- a/src/common_device_name.c
>>> +++ b/src/common_device_name.c
>>> @@ -69,7 +69,7 @@ pci_id_file_open(void)
>>> #define pci_id_file_gets(l, s, f) gzgets(f, l, s)
>>> #define pci_id_file_close(f) gzclose(f)
>>> #else
>>> -typedef FILE pci_id_file;
>>> +typedef FILE * pci_id_file;
>>> #define pci_id_file_open() fopen(PCIIDS_PATH "/pci.ids", "r")
>>> #define pci_id_file_gets(l, s, f) fgets(l, s, f)
>>> #define pci_id_file_close(f) fclose(f)
>>> @@ -189,7 +189,7 @@ insert( uint16_t vendor )
>>> static void
>>> populate_vendor( struct pci_id_leaf * vend, int fill_device_data )
>>> {
>>> - pci_id_file * f;
>>> + pci_id_file f;
>>> char buf[128];
>>> unsigned vendor = PCI_MATCH_ANY;
>>>
>
> I think the idea here was to replace FILE not FILE* what means the use in gzgets()
> looks wrong.
The idea in the original code (and still is) is to abstract the concrete
type -- use FILE * if build without zlib support, otherwise use gzFile.
And this is what is wrong in the old code as "f" in populate_vendor is a
pointer type and not a plain gzFile as required by zlib (see prototypes
of gzopen(), gzgets() and gzclose() in zlib.h).
> but if there is only one use i would drop the whole typedef and use FILE instead.
But then you would loose zlib support, i.e. where only able to handle
pci.ids not pci.ids.gz.
> NTL i am not familar with that interface.
Me neither, just stumbled across the compiler warnings and was surprised
that GCC doesn't warn for the gzopen() case in the current code base.
Thanks,
Mathias
More information about the xorg-devel
mailing list