On December 3, 2013 at 4:38:18 AM, Maxim Dounin (mdou...@mdounin.ru) wrote: Hello! On Mon, Dec 02, 2013 at 03:44:53PM -0800, 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. These macros are used as a maximum length of a string representation of the relevant types. Note "_LEN", not "_MAX". Relevant maximum value for int32_t is NGX_MAX_INT32_VALUE defined below in the same file. Noted, sounds like this may be a case of not fully reading ngx_config.h on my part. > 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. This code allocates memory for the "NGINX=x;y;z;\0" string, where "x", "y", "z" - are string representations of listening sockets. The "+ 1" is for ";" after each socket. The "+ 2" is for "=" and trailing "\0" (well, it looks like a only "+ 1" is actually needed here, as sizeof(NGINX_VAR) already includes an extra byte). I had a suspicion that it was something like that but I didn’t quite get the pieces together. Thanks for the clarification. -- Maxim Dounin http://nginx.org/en/donation.html _______________________________________________ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
_______________________________________________ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel