You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Joe Orton <jo...@redhat.com> on 2007/07/06 12:41:27 UTC
Re: svn commit: r553679 - /apr/apr/trunk/strings/apr_snprintf.c
On Fri, Jul 06, 2007 at 12:46:53AM -0000, Davi Arnaut wrote:
> Author: davi
> Date: Thu Jul 5 17:46:53 2007
> New Revision: 553679
>
> URL: http://svn.apache.org/viewvc?view=rev&rev=553679
> Log:
> Convert wide* types to the portable apr types. Conversion table:
>
> wide_int apr_int32_t
> u_wide_int apr_uint32_t
> widest_int apr_int64_t
> u_widest_int apr_uint64_t
> bool_int int
Are these wide_int -> int32_t changes correct? wide_int was long before
and is now always 32-bit. Also the *INT32_MAX types are from C99
stdint.h which might not be present.
...
> if (var_type == IS_LONG)
> - ui_num = (u_wide_int) va_arg(ap, u_wide_int);
> + ui_num = va_arg(ap, apr_uint32_t);
Re: svn commit: r553679 - /apr/apr/trunk/strings/apr_snprintf.c
Posted by Davi Arnaut <da...@haxent.com.br>.
Joe Orton wrote:
> On Fri, Jul 06, 2007 at 12:46:53AM -0000, Davi Arnaut wrote:
>> Author: davi
>> Date: Thu Jul 5 17:46:53 2007
>> New Revision: 553679
>>
>> URL: http://svn.apache.org/viewvc?view=rev&rev=553679
>> Log:
>> Convert wide* types to the portable apr types. Conversion table:
>>
>> wide_int apr_int32_t
>> u_wide_int apr_uint32_t
>> widest_int apr_int64_t
>> u_widest_int apr_uint64_t
>> bool_int int
>
> Are these wide_int -> int32_t changes correct? wide_int was long before
> and is now always 32-bit. Also the *INT32_MAX types are from C99
> stdint.h which might not be present.
>
Also, as I forgot to mention, there was a change of behavior with the patch:
- if ((magnitude <= ULONG_MAX && is_unsigned)
- || (num <= LONG_MAX && num >= LONG_MIN && !is_unsigned))
- return(conv_10( (wide_int)num, is_unsigned, is_negative,
- buf_end, len));
+ if ((magnitude <= UINT32_MAX && is_unsigned)
+ || (num <= INT32_MAX && num >= INT32_MIN && !is_unsigned))
+ return(conv_10(num, is_unsigned, is_negative, buf_end, ...
On a 64 bits build the conv_10 optimization could be inadvertently used
because ULONG_MAX would be 64-bit large, but since wide_int was `long`
it worked. Now with the behavior fix, conv_10 is only called on values
that really fits on 32 bits.
--
Davi Arnaut
Re: svn commit: r553679 - /apr/apr/trunk/strings/apr_snprintf.c
Posted by Joe Orton <jo...@redhat.com>.
On Fri, Jul 06, 2007 at 08:51:38AM -0300, Davi Arnaut wrote:
> Joe Orton wrote:
> > Are these wide_int -> int32_t changes correct? wide_int was long before
> > and is now always 32-bit.
>
> When I made the patch, it seemed to be correct because the format checks
> using IS_LONG were based upon APR_INT64_T_FMT.
Ah, OK. It looks a bit counter-intuitive but it seems to work OK, so no
problem.
> > Also the *INT32_MAX types are from C99 stdint.h which might not be present.
>
> Good catch, I guess we could use *INT_MAX. This begs the question: why
> don't we have APR_*INT32_MIN/MAX? Should be pretty straight forward:
It's not the first time the question has been asked... no objection to
adding such anyway. Note the private definition in apr_private_common.h
would need to be removed.
> defaults:
>
> #define APR_UINT32_MAX 0xffffffffU
> #define APR_UINT64_MAX 0xffffffffffffffffULL
>
> autoconf logic:
Having autoconf tests to calculate values which are mathematical
constants seems like... overkill :) I would just add the #defines as
above; at most doing:
#ifdef APR_HAVE_STDINT_H
#define APR_UINT32_MAX UINT32_MAX
etc
#else
#define APR_UINT32_MAX 0xetc
etc
note using APR_*INT64_C() for the 64-bit constants is a good idea.
joe
Re: svn commit: r553679 - /apr/apr/trunk/strings/apr_snprintf.c
Posted by Davi Arnaut <da...@haxent.com.br>.
Martin Kraemer wrote:
> On Mon, Jul 09, 2007 at 10:22:54AM -0300, Davi Arnaut wrote:
>> Could you try the attached patch? Thanks.
>
> Okay -- the patch fixes it for FreeBSD-4.11
>
> Thanks for your patch,
>
Ok, thanks. I'm commit the patch in a few minutes.
--
Davi Arnaut
Re: svn commit: r553679 - /apr/apr/trunk/strings/apr_snprintf.c
Posted by Davi Arnaut <da...@haxent.com.br>.
Martin Kraemer wrote:
> On Fri, Jul 06, 2007 at 08:51:38AM -0300, Davi Arnaut wrote:
>>> Also the *INT32_MAX types are from C99 stdint.h which might not be present.
>> Good catch, I guess we could use *INT_MAX. This begs the question: why
>> don't we have APR_*INT32_MIN/MAX?
>
> Good point. Especially for the apr-defined int types, there should
> also be a <type>_MAX define.
>
> I'm +1 for adding them -- as at the moment, on FreeBSD-4.x I cannot compile apr:
>
> /usr/local/bin/bash /home/martin/apachen/X/httpd-2.3/srclib/apr/libtool --silent --mode=compile gcc -g -O2 -Wall -DHAVE_CONFIG_H -D_THREAD_SAFE -D_REENTRANT -I./include -I/home/martin/apachen/X/httpd-2.3/srclib/apr/include/arch/unix -I./include/arch/unix -I/home/martin/apachen/X/httpd-2.3/srclib/apr/include -o strings/apr_snprintf.lo -c strings/apr_snprintf.c && touch strings/apr_snprintf.lo
> strings/apr_snprintf.c: In function `conv_10_quad':
> strings/apr_snprintf.c:384: `UINT32_MAX' undeclared (first use in this function)
> strings/apr_snprintf.c:384: (Each undeclared identifier is reported only once
> strings/apr_snprintf.c:384: for each function it appears in.)
> strings/apr_snprintf.c:385: `INT32_MAX' undeclared (first use in this function)
> strings/apr_snprintf.c:385: `INT32_MIN' undeclared (first use in this function)
> strings/apr_snprintf.c: In function `conv_p2_quad':
> strings/apr_snprintf.c:643: `UINT32_MAX' undeclared (first use in this function)
> Make[1]: *** [strings/apr_snprintf.lo] Error 1
> Make[1]: Leaving directory `/home/martin/apachen/X/httpd-2.3/srclib/apr'
>
> and there's no <stdint.h>, and neither <inttypes.h> nor <limits.h>
> provide something like *INT32_MAX.
>
Could you try the attached patch? Thanks.
--
Davi Arnaut
Re: svn commit: r553679 - /apr/apr/trunk/strings/apr_snprintf.c
Posted by Martin Kraemer <Ma...@Fujitsu-Siemens.com>.
On Fri, Jul 06, 2007 at 08:51:38AM -0300, Davi Arnaut wrote:
>
> > Also the *INT32_MAX types are from C99 stdint.h which might not be present.
>
> Good catch, I guess we could use *INT_MAX. This begs the question: why
> don't we have APR_*INT32_MIN/MAX?
Good point. Especially for the apr-defined int types, there should
also be a <type>_MAX define.
I'm +1 for adding them -- as at the moment, on FreeBSD-4.x I cannot compile apr:
/usr/local/bin/bash /home/martin/apachen/X/httpd-2.3/srclib/apr/libtool --silent --mode=compile gcc -g -O2 -Wall -DHAVE_CONFIG_H -D_THREAD_SAFE -D_REENTRANT -I./include -I/home/martin/apachen/X/httpd-2.3/srclib/apr/include/arch/unix -I./include/arch/unix -I/home/martin/apachen/X/httpd-2.3/srclib/apr/include -o strings/apr_snprintf.lo -c strings/apr_snprintf.c && touch strings/apr_snprintf.lo
strings/apr_snprintf.c: In function `conv_10_quad':
strings/apr_snprintf.c:384: `UINT32_MAX' undeclared (first use in this function)
strings/apr_snprintf.c:384: (Each undeclared identifier is reported only once
strings/apr_snprintf.c:384: for each function it appears in.)
strings/apr_snprintf.c:385: `INT32_MAX' undeclared (first use in this function)
strings/apr_snprintf.c:385: `INT32_MIN' undeclared (first use in this function)
strings/apr_snprintf.c: In function `conv_p2_quad':
strings/apr_snprintf.c:643: `UINT32_MAX' undeclared (first use in this function)
Make[1]: *** [strings/apr_snprintf.lo] Error 1
Make[1]: Leaving directory `/home/martin/apachen/X/httpd-2.3/srclib/apr'
and there's no <stdint.h>, and neither <inttypes.h> nor <limits.h>
provide something like *INT32_MAX.
Martin
--
<Ma...@Fujitsu-Siemens.com> | Fujitsu Siemens
http://www.fujitsu-siemens.com/imprint.html | 81730 Munich, Germany
Re: svn commit: r553679 - /apr/apr/trunk/strings/apr_snprintf.c
Posted by Davi Arnaut <da...@haxent.com.br>.
Joe Orton wrote:
> On Fri, Jul 06, 2007 at 12:46:53AM -0000, Davi Arnaut wrote:
>> Author: davi
>> Date: Thu Jul 5 17:46:53 2007
>> New Revision: 553679
>>
>> URL: http://svn.apache.org/viewvc?view=rev&rev=553679
>> Log:
>> Convert wide* types to the portable apr types. Conversion table:
>>
>> wide_int apr_int32_t
>> u_wide_int apr_uint32_t
>> widest_int apr_int64_t
>> u_widest_int apr_uint64_t
>> bool_int int
>
> Are these wide_int -> int32_t changes correct? wide_int was long before
> and is now always 32-bit.
When I made the patch, it seemed to be correct because the format checks
using IS_LONG were based upon APR_INT64_T_FMT.
> Also the *INT32_MAX types are from C99 stdint.h which might not be present.
Good catch, I guess we could use *INT_MAX. This begs the question: why
don't we have APR_*INT32_MIN/MAX? Should be pretty straight forward:
defaults:
#define APR_UINT32_MAX 0xffffffffU
#define APR_UINT64_MAX 0xffffffffffffffffULL
autoconf logic:
try to figure out from limits.h [1]
try to figure out from stdint.h
if none worked, use defaults.
1:
#include <limits.h>
#define stringify(x) #x
#define to_string(x) stringify(x)
int main()
{
/* also check if different from default */
printf("%s\n", to_string(ULONG_MAX));
return 0;
}
Ok, that's pretty creative.. but should work.
--
Davi Arnaut