On Apr 8, 2011, at 9:13 AM, Stephen Fisher wrote:
> This revision broke builds on FreeBSD 8.2-RELEASE (64-bit):
>
> file_access.c:924: warning: dereferencing 'void *' pointer
> file_access.c:924: error: request for member '_file' in something not a
> structure or union
> file_access.c: In function 'wtap_dump_file_write':
> file_access.c:1084: warning: dereferencing 'void *' pointer
> file_access.c:1084: error: request for member '_flags' in something not
> a structure or union
> gmake[2]: *** [libwiretap_la-file_access.lo] Error 1
>
> It is referring to these two lines:
>
> 924: fd = fileno(wdh->fh);
> 1084: if (ferror(wdh->fh))
>
> "wdh" is a wtap_dumper struct, which contains (wtap-int.h):
>
> struct wtap_dumper {
> WFILE_T fh;
>
> "WFILE_T" is defined in my case to be a gzFile:
>
> #ifdef HAVE_LIBZ
> #include <zlib.h>
> #define WFILE_T gzFile
> #else /* No zLib */
> #define WFILE_T FILE *
> #endif /* HAVE_LIBZ */
>
> And "gzFile" is (from /usr/include/zlib.h):
>
> typedef voidp gzFile;
...and *this* is why C supports incomplete structure declarations such as
struct gz_file;
so you can do things such as
typedev gz_file *gzFile;
(or whatever you want for the structure name), so that you can have a pointer
that points to a specific type, so type checking can be done on it, but keep
the contents of the structure opaque, so you can change them from release to
release without having to worry about breaking source or binary compatibility.
If the zlib guys had done that, the compiler would have complained about
passing a WFILE_T to something expecting a FILE *, rather than saying "void *,
OK, I'll assume whoever wrote this knows what they're doing, whatever". They
may, however, have had to deal with pre-ANSI compilers that don't support that
(I don't think it was *introduced* in ANSI C, but, prior to ANSI C, you didn't
*have* to support it).
It compiles if fileno() is a function - which it is on OS X; fileno_unlocked()
is a macro that directly reaches inside a FILE *, but fileno() is a function.
I guess FreeBSD, or, at least, recent versions of FreeBSD, do it differently.
For now, I've made WFILE_T just be a "void *", and casted it to the appropriate
type in all cases.
___________________________________________________________________________
Sent via: Wireshark-dev mailing list <[email protected]>
Archives: http://www.wireshark.org/lists/wireshark-dev
Unsubscribe: https://wireshark.org/mailman/options/wireshark-dev
mailto:[email protected]?subject=unsubscribe