Welcome! Log In Create A New Profile

Advanced

Re: NGX_INT32_LEN and NGX_INT64_LEN

December 03, 2013 02:48AM
On Dec 3, 2013, at 3:44 , Dean Pucsek wrote:

> Hello,
>
> While reading through the source code for nginx I came across the following two lines in ngx_config.h
>
> #define NGX_INT32_LEN (sizeof("-2147483648") - 1)
> #define NGX_INT64_LEN (sizeof("-9223372036854775808") - 1)
>
> I was wondering if someone could explain the intention of these lines to me because it is not clear. My understanding is that using sizeof() on a string will return the number of characters in that string. Conversely, I get the feeling these lines are supposed to somehow act as replacements for INT32_MAX and INT64_MAX in stdint.h.
>
> Looking at code where these #define’s are used doesn’t really help clarify things either. For example, in nginx.c there is:
>
> var = ngx_alloc(sizeof(NGINX_VAR)
> + cycle->listening.nelts * (NGX_INT32_LEN + 1) + 2,
> cycle->log);
>
> The code clearly allocates memory, but it’s not clear why the allocation is a multiple of NGX_INT32_LEN (or why we’re adding 1, or 2 for that matter).
>
> Any direction would be much appreciated.

They used to allocate memory for string representation of number.
In this particular case 1 is for ";", 2 is for "=" and trailing zero.


--
Igor Sysoev
http://nginx.com

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

NGX_INT32_LEN and NGX_INT64_LEN

Dean Pucsek 1130 December 02, 2013 06:46PM

Re: NGX_INT32_LEN and NGX_INT64_LEN

Igor Sysoev 694 December 03, 2013 02:48AM

Re: NGX_INT32_LEN and NGX_INT64_LEN

Maxim Dounin 360 December 03, 2013 07:40AM

Re: NGX_INT32_LEN and NGX_INT64_LEN

Dean Pucsek 427 December 03, 2013 07:46PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 246
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready