apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joe Orton <jor...@redhat.com>
Subject Re: apr-util compiler warnings
Date Mon, 23 Feb 2004 14:20:19 GMT
On Sun, Feb 22, 2004 at 06:37:15PM +0100, André Malo wrote:
> compiler is:
> $ gcc --version
> gcc (GCC) 3.3.2 20031218 (Gentoo Linux 3.3.2-r5, propolice-3.3-7)
> 
> I don't know what these messages want to say :-) Any idea?
> 
> dbm/apr_dbm_gdbm.c: In function `vt_gdbm_fetch':
> dbm/apr_dbm_gdbm.c:166: warning: dereferencing type-punned pointer will break
> strict-aliasing rules

It means something like "if you have two pointers which point to the
same object they must be of compatible types otherwise it's really
naughty to dereference one", but don't quote me on that :)

I started fixing this last week then noticed that the sdbm hooks had a
Real Bug(TM) and the gdbm hooks were probably illegal to redistribute
and got distracted... use CFLAGS=-fno-strict-aliasing or something like
the below.  There were more aliasing issues in the test suites though...

--- dbm/apr_dbm_gdbm.c	13 Feb 2004 09:55:25 -0000	1.11
+++ dbm/apr_dbm_gdbm.c	23 Feb 2004 14:15:49 -0000
@@ -36,18 +36,19 @@
 
 typedef GDBM_FILE real_file_t;
 
-typedef datum *cvt_datum_t;
-#define CONVERT_DATUM(cvt, pinput) ((cvt) = (datum *)(pinput))
+typedef datum cvt_datum_t;
+
+#define CONVERT_DATUM(cvt, pinput) ((cvt.dptr) = (pinput)->dptr, (cvt).dsize = (pinput)->dsize)
 
 typedef datum result_datum_t;
-#define RETURN_DATUM(poutput, rd) (*(poutput) = *(apr_datum_t *)&(rd))
+#define RETURN_DATUM(pout, rd) (pout->dptr = rd.dptr, pout->dsize = rd.dsize)
 
 #define APR_DBM_CLOSE(f)        gdbm_close(f)
-#define APR_DBM_FETCH(f, k, v)  ((v) = gdbm_fetch(f, *(k)), APR_SUCCESS)
-#define APR_DBM_STORE(f, k, v)  g2s(gdbm_store(f, *(k), *(v), GDBM_REPLACE))
-#define APR_DBM_DELETE(f, k)    g2s(gdbm_delete(f, *(k)))
+#define APR_DBM_FETCH(f, k, v)  ((v) = gdbm_fetch(f, k), APR_SUCCESS)
+#define APR_DBM_STORE(f, k, v)  g2s(gdbm_store(f, k, v, GDBM_REPLACE))
+#define APR_DBM_DELETE(f, k)    g2s(gdbm_delete(f, k))
 #define APR_DBM_FIRSTKEY(f, k)  ((k) = gdbm_firstkey(f), APR_SUCCESS)
-#define APR_DBM_NEXTKEY(f, k, nk) ((nk) = gdbm_nextkey(f, *(k)), APR_SUCCESS)
+#define APR_DBM_NEXTKEY(f, k, nk) ((nk) = gdbm_nextkey(f, k), APR_SUCCESS)
 #define APR_DBM_FREEDPTR(dptr)  ((dptr) ? free(dptr) : 0)
 
 #undef REGISTER_CLEANUP
@@ -203,9 +204,11 @@
 
 static int vt_gdbm_exists(apr_dbm_t *dbm, apr_datum_t key)
 {
-    datum *ckey = (datum *)&key;
+    cvt_datum_t ckey;
+
+    CONVERT_DATUM(ckey, &key);
 
-    return gdbm_exists(dbm->file, *ckey) != 0;
+    return gdbm_exists(dbm->file, ckey) != 0;
 }
 
 static apr_status_t vt_gdbm_firstkey(apr_dbm_t *dbm, apr_datum_t * pkey)




Mime
View raw message