Welcome! Log In Create A New Profile

Advanced

[PATCH] Core: enclosed parameters of macros in parentheses.

balus
July 18, 2020 08:10AM
Hi,


I have been writing a nginx module recently, in which I use
ngx_buf_t to store data received from network, such as:


static u_char     buffer[4096];
static ngx_buf_t  b;


b.pos = b.last = b.start = buffer;
b.end = b.start + sizeof(buffer);


...


size = ngx_buf_size(&b);


then I find it not work since the parameter in ngx_buf_size is not
closed by parenthese. And I think this is a common situation so I
made this patch:


# HG changeset patch
# User balus <balus@foxmail.com&gt;
# Date 1595073121 -28800
#&nbsp; &nbsp; &nbsp; Sat Jul 18 19:52:01 2020 +0800
# Node ID 92d9878c0c7549345f0a144cd81a6b6d45f21fc6
# Parent&nbsp; 32a343635b50662979975e1204417bb1fc7e1b1f
Core: enclosed parameters of macros in parentheses.


diff -r 32a343635b50 -r 92d9878c0c75 src/core/ngx_buf.h
--- a/src/core/ngx_buf.h Thu Jul 09 16:21:37 2020 +0300
+++ b/src/core/ngx_buf.h Sat Jul 18 19:52:01 2020 +0800
@@ -125,20 +125,22 @@
&nbsp;#define NGX_CHAIN_ERROR&nbsp; &nbsp; &nbsp;(ngx_chain_t *) NGX_ERROR
&nbsp;
&nbsp;
-#define ngx_buf_in_memory(b)&nbsp; &nbsp; &nbsp; &nbsp; (b-&gt;temporary || b-&gt;memory || b-&gt;mmap)
-#define ngx_buf_in_memory_only(b)&nbsp; &nbsp;(ngx_buf_in_memory(b) &amp;&amp; !b-&gt;in_file)
+#define ngx_buf_in_memory(b)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\
+&nbsp; &nbsp; ((b)-&gt;temporary || (b)-&gt;memory || (b)-&gt;mmap)
+#define ngx_buf_in_memory_only(b)&nbsp; &nbsp;(ngx_buf_in_memory(b) &amp;&amp; !(b)-&gt;in_file)
&nbsp;
&nbsp;#define ngx_buf_special(b)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\
-&nbsp; &nbsp; ((b-&gt;flush || b-&gt;last_buf || b-&gt;sync)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \
-&nbsp; &nbsp; &nbsp;&amp;&amp; !ngx_buf_in_memory(b) &amp;&amp; !b-&gt;in_file)
+&nbsp; &nbsp; (((b)-&gt;flush || (b)-&gt;last_buf || (b)-&gt;sync)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \
+&nbsp; &nbsp; &nbsp;&amp;&amp; !ngx_buf_in_memory(b) &amp;&amp; !(b)-&gt;in_file)
&nbsp;
&nbsp;#define ngx_buf_sync_only(b)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\
-&nbsp; &nbsp; (b-&gt;sync&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\
-&nbsp; &nbsp; &nbsp;&amp;&amp; !ngx_buf_in_memory(b) &amp;&amp; !b-&gt;in_file &amp;&amp; !b-&gt;flush &amp;&amp; !b-&gt;last_buf)
+&nbsp; &nbsp; ((b)-&gt;sync&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\
+&nbsp; &nbsp; &nbsp;&amp;&amp; !ngx_buf_in_memory(b)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \
+&nbsp; &nbsp; &nbsp;&amp;&amp; !(b)-&gt;in_file &amp;&amp; !(b)-&gt;flush &amp;&amp; !(b)-&gt;last_buf)
&nbsp;
&nbsp;#define ngx_buf_size(b)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \
-&nbsp; &nbsp; (ngx_buf_in_memory(b) ? (off_t) (b-&gt;last - b-&gt;pos):&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \
-&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (b-&gt;file_last - b-&gt;file_pos))
+&nbsp; &nbsp; (ngx_buf_in_memory(b) ? (off_t) ((b)-&gt;last - (b)-&gt;pos)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\
+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : ((b)-&gt;file_last - (b)-&gt;file_pos))
&nbsp;
&nbsp;ngx_buf_t *ngx_create_temp_buf(ngx_pool_t *pool, size_t size);
&nbsp;ngx_chain_t *ngx_create_chain_of_bufs(ngx_pool_t *pool, ngx_bufs_t *bufs);_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[PATCH] Core: enclosed parameters of macros in parentheses.

balus 129 July 18, 2020 08:10AM

Re: [PATCH] Core: enclosed parameters of macros in parentheses.

ru@nginx.com 12 July 24, 2020 03:58PM

Re: [PATCH] Core: enclosed parameters of macros in parentheses.

balus 21 July 24, 2020 07:52PM



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

Online Users

Guests: 105
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready