httpd-apreq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "R. Mattes" ...@mh-freiburg.de>
Subject Murky decalrations/types in apreq_param.h
Date Sun, 14 Aug 2005 20:20:00 GMT
It's currently impossible to compile apache modules using libabreq2
with c++ compilers due to some inconsistent types in file  apreq_param.h.
Here are the error messages:

 In file included from /usr/include/apreq2/apreq_parser.h:21,
                 from /usr/include/apreq2/apreq_module.h:21,
                 from /usr/include/apache2/apreq2/apreq_module_apache2.h:20,
                 from mod_xapian.h:41,
                 from mod_xapian.cc:34:
/usr/include/apreq2/apreq_param.h: In function `apreq_charset_t 
   apreq_param_charset_set(apreq_param_t*, unsigned char)':
/usr/include/apreq2/apreq_param.h:67: error: cannot convert `unsigned char' to 
   `apreq_charset_t' in return
/usr/include/apreq2/apreq_param.h: In function `apreq_charset_t 
   apreq_param_charset_get(apreq_param_t*)':
/usr/include/apreq2/apreq_param.h:73: error: invalid conversion from `unsigned 
   int' to `apreq_charset_t'


Function apreq_param_charset_set does:

 unsigned char old = APREQ_FLAGS_GET(p->flags, APREQ_CHARSET);

ans later on returns 'old' even so the return value of the function is
declared as 'apreq_charset_t' which is of type enum (in c++
typedef'ed enums create distinct types that can't be casted from
integral types). Since 'old' is actually _never touched_ in this
function there seems to be no reason not to do it as follows:

/** Sets the character encoding for this parameter. */
static APR_INLINE
apreq_charset_t apreq_param_charset_set(apreq_param_t *p, unsigned char c) {
    apreq_charset_t old = (apreq_charset_t) APREQ_FLAGS_GET(p->flags,
    APREQ_CHARSET); APREQ_FLAGS_SET(p->flags, APREQ_CHARSET, c); return
    old;
}


Further on, in function 'apreq_param_charset_get(apreq_param_t*)' it would
be nice to expicitly cast the return value to the correct type:

/** Gets the character encoding for this parameter. */
static APR_INLINE
apreq_charset_t apreq_param_charset_get(apreq_param_t *p) {
    return (enum apreq_charset_t) APREQ_FLAGS_GET(p->flags, APREQ_CHARSET);
}
 

Cheers Ralf Mattes






Mime
View raw message