<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On 7 July 2018 at 02:03, Ken Thomases <span dir="ltr"><<a href="mailto:ken@codeweavers.com" target="_blank">ken@codeweavers.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="overflow-wrap: break-word;"><span class="gmail-">On Jul 6, 2018, at 5:25 PM, <a href="mailto:janisozaur@gmail.com" target="_blank">janisozaur@gmail.com</a> wrote:<br></span><div><span class="gmail-"><blockquote type="cite"><br class="gmail-m_2229263625104897395Apple-interchange-newline"><div><div>From: Michał Janiszewski <<a href="mailto:janisozaur@gmail.com" target="_blank">janisozaur@gmail.com</a>><br><br>Inspired by kernel check and recent unification of ARRAY_SIZE, provide<br>a way of enforcing the macro can only be applied to actual arrays and<br>not to pointers.<br><br>Signed-off-by: Michał Janiszewski <<a href="mailto:janisozaur@gmail.com" target="_blank">janisozaur@gmail.com</a>><br>---<br> include/winnt.h | 21 ++++++++++++++++++++-<br> 1 file changed, 20 insertions(+), 1 deletion(-)<br><br>diff --git a/include/winnt.h b/include/winnt.h<br>index 7f822c4aec..ad945464f1 100644<br>--- a/include/winnt.h<br>+++ b/include/winnt.h<br>@@ -760,7 +760,26 @@ typedef struct _MEMORY_BASIC_INFORMATION<br>   ((type *)((PCHAR)(address) - offsetof(type, field)))<br><br> #ifdef __WINESRC__<br>-# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))<br>+// Validate types used in the expression.<br>+// Based on <a href="https://elixir.bootlin.com/linux/v4.17.4/source/include/linux/kernel.h#L71" target="_blank">https://elixir.bootlin.com/<wbr>linux/v4.17.4/source/include/<wbr>linux/kernel.h#L71</a><br></div></div></blockquote><div><br></div></span><div>Does that pose a licensing issue, since that code is GPL?</div></div></div></blockquote><div><br></div><div>I would hope not, but honestly I don't know how to answer this question.</div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="overflow-wrap: break-word;"><div><span class="gmail-"><div><br></div><blockquote type="cite"><div><div>+<br>+#ifdef __GNUC__<br>+/**<br>+ * Force a compilation error if condition is true, but also produce a<br>+ * result (of value 0 and type size_t), so the expression can be used<br>+ * e.g. in a structure initializer (or where-ever else comma expressions<br>+ * aren't permitted).<br>+ */<br>+#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))<br>+<br>+/* &a[0] degrades to a pointer: a different type from an array */<br>+#define __must_be_array(a) \<br>+    BUILD_BUG_ON_ZERO(__<wbr>builtin_types_compatible_p(<wbr>typeof(a), typeof(&a[0])))<br></div></div></blockquote><div><br></div></span><div>In what version of GCC was __builtin_types_<wbr>compatible_p() introduced?</div></div></div></blockquote><div><br></div><div>It is already listed in manual for GCC 3.2:</div><div><a href="https://gcc.gnu.org/onlinedocs/gcc-3.2/gcc/Other-Builtins.html#Other-Builtins">https://gcc.gnu.org/onlinedocs/gcc-3.2/gcc/Other-Builtins.html#Other-Builtins</a><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="overflow-wrap: break-word;"><div><span class="gmail-"><br><blockquote type="cite"><div><div>+#else<br>+#define __must_be_array(a) 0<br>+#endif<br>+<br>+# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) + __must_be_array(x)<br></div></div></blockquote><div><br></div></span><div>The " + __must_be_array(x)" should be inside the parentheses.</div></div></div></blockquote><div><br></div><div>Indeed. How do I send "v2" patch?<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="overflow-wrap: break-word;"><div><br><blockquote type="cite"><div><div> #endif</div></div></blockquote><span class="gmail-HOEnZb"><font color="#888888"><br></font></span></div><span class="gmail-HOEnZb"><font color="#888888">-Ken<div><br></div></font></span></div></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature">Michal Janiszewski</div>
</div></div>