<html><head></head><body>lsearch() can modify the size. lfind() cannot.<br><br>Strictly speaking, the macro is wrong because it does not account for size > UINT_MAX. This can easily be fixed with a static inline rather than a macro.<br><br><div class="gmail_quote">Le 15 juillet 2019 13:03:20 GMT+03:00, Steve Lhomme <robux4@ycbcr.xyz> a écrit :<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<pre class="k9mail">On 2019-07-15 11:53, Steve Lhomme wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #729fcf; padding-left: 1ex;">On 2019-07-15 9:37, Rémi Denis-Courmont wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ad7fa8; padding-left: 1ex;"> Hi,<br><br> A macro is possible, probably:<br><br> #include<search.h><br> #define lfind(a,b,c,d,e) \<br> lfind(a,b&(unsigned){ *(c) },d,e)<br></blockquote>That works for win32 but not for win64 where 'size_t' and 'unsigned' <br>don't have the same size, as verified with this:<br></blockquote><br>Or maybe I misread the patch and it doesn't do a cast, just creates a <br>local variable ? In that case it should work (it's missing a comma after <br>'b').<br><br>Still not sure we're supposed to fill a value in c after the call. But <br>it's not used in the code using lfind and the implementation in compat/ <br>doesn't fill it either.<br><br><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #729fcf; padding-left: 1ex;">static_assert(sizeof(size_t) == sizeof(unsigned), "cannot cast for lfind");<br><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ad7fa8; padding-left: 1ex;">Le 15 juillet 2019 10:07:26 GMT+03:00, Steve Lhomme <robux4@ycbcr.xyz> <br>a écrit :<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #8ae234; padding-left: 1ex;"> Hi<br><br> On 2019-07-12 16:35, Hugo Beauzée-Luyssen wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #fcaf3e; padding-left: 1ex;">On Fri, Jul 12, 2019, at 3:51 PM, Steve Lhomme wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #e9b96e; padding-left: 1ex;"><hr>   include/vlc_search.h | 52<br></blockquote></blockquote>++++++++++++++++++++++++++++++++++++++++++++<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #fcaf3e; padding-left: 1ex;"><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #e9b96e; padding-left: 1ex;">    src/Makefile.am      |  3 ++-<br>    2 files changed, 54 insertions(+), 1 deletion(-)<br>    create mode 100644 include/vlc_search.h<br><br> diff --git a/include/vlc_search.h b/include/vlc_search.h<br> new file mode 100644<br> index 0000000000..6c87fa990d<br> --- /dev/null<br> +++ b/include/vlc_search.h<br> @@ -0,0 +1,52 @@<br><br></blockquote></blockquote> +/***************************************************************************** <br><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #fcaf3e; padding-left: 1ex;"><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #e9b96e; padding-left: 1ex;"> + * vlc_search.h: portability fixups included from config.h<br> +<br><br></blockquote></blockquote> ***************************************************************************** <br><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #fcaf3e; padding-left: 1ex;"><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #e9b96e; padding-left: 1ex;">+ * Copyright © 2019 the VideoLAN project<br>+ *<br>+ * This program is free software; you can redistribute it and/or<br>modify it<br>+ * under the terms of the GNU Lesser General Public License as<br>published by<br>+ * the Free Software Foundation; either version 2.1 of the License,<br></blockquote></blockquote>or<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #fcaf3e; padding-left: 1ex;"><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #e9b96e; padding-left: 1ex;">+ * (at your option) any later version.<br>+ *<br>+ * This program is distributed in the hope that it will be useful,<br>+ * but WITHOUT ANY WARRANTY; without even the implied warranty of<br>+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br>+ * GNU Lesser General Public License for more details.<br>+ *<br>+ * You should have received a copy of the GNU Lesser General Public<br>License<br>+ * along with this program; if not, write to the Free Software<br>Foundation,<br>+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301,<br></blockquote></blockquote>USA.<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #fcaf3e; padding-left: 1ex;"><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #e9b96e; padding-left: 1ex;"> +<br><br></blockquote></blockquote> *****************************************************************************/ <br><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #fcaf3e; padding-left: 1ex;"><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #e9b96e; padding-left: 1ex;">+<br>+/**<br>+ * \file<br>+ * This file is a collection of portability fixes<br>+ */<br>+<br>+#ifndef LIBVLC_SEARCH_H<br>+# define LIBVLC_SEARCH_H 1<br>+<br>+#ifdef __cplusplus<br>+extern "C" {<br>+#endif<br>+<br>+#ifdef _WIN32<br>+/* the Win32 prorotype of lfind() expects an unsigned int for<br></blockquote></blockquote>'nelp' */<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #fcaf3e; padding-left: 1ex;"> Typo (proTotype)<br><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #e9b96e; padding-left: 1ex;">+static inline void *vlc_lfind(const void *key, const void *base,<br>size_t *nelp,<br>+                             size_t size, int(*cmp)(const void *,<br>const void *))<br>+{<br>+    unsigned int n;<br>+    void *res = lfind (key, base, &n, size, cmp);<br>+    *nelp = n;<br>+    return res;<br></blockquote>I must say I don't understand what this wrapper does that wasn't<br></blockquote>already done by calling the function with an uint32_t* instead of a<br>size_t*<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #fcaf3e; padding-left: 1ex;">If what you want is to fix the warning on the callsite, you can<br></blockquote> probably get away with a macro that casts the 3rd pointer no?<br><br> Are "size_t" and "unsigned int" guaranteed to be the same on all<br> Windows<br> compiler ? I think on 64 bits platforms it's not the case.<br><br> So we would need a wrapper with the proper size_t variable. To do that<br> I<br> don't think you can do it as a pure macro because you also need to set<br> the value of the size_t nelp to the value of the unsigned int and then<br> pass that unsigned int as a pointer. (not sure the value on return<br> needs<br> to be set back on the size_t, the lfind documentation is not clear)<br><br> So if it's not a macro, it should be an inline. But to do an inline you<br><br> need to include <search.h> so it knows about lfind(). This cannot be<br> added in vlc_fixups.h<br><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #fcaf3e; padding-left: 1ex;">And in any case case:<br>- Does this need to be in a different file?<br></blockquote> IMO, yes.<br><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #fcaf3e; padding-left: 1ex;">- It could be enable only when _WIN64 is defined<br></blockquote> OK but it doesn't hurt to have the same code between 32 and 64 bits<br> Windows.<br><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #fcaf3e; padding-left: 1ex;"><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #e9b96e; padding-left: 1ex;">+}<br>+#else /* !_WIN32 */<br>+#define vlc_lfind(key, base, nelp, width, compar)  \<br>+            lfind(key, base, nelp, width, compar)<br>+#endif /* !_WIN32 */<br>+<br>+#ifdef __cplusplus<br>+} /* extern "C" */<br>+#endif<br>+<br>+#endif /* !LIBVLC_SEARCH_H */<br>diff --git a/src/Makefile.am b/src/Makefile.am<br>index 006ece5f93..25f9a4fc8b 100644<br>--- a/src/Makefile.am<br>+++ b/src/Makefile.am<br>@@ -88,6 +88,7 @@ pluginsinclude_HEADERS = \<br>       ../include/vlc_fingerprinter.h \<br>       ../include/vlc_interrupt.h \<br>       ../include/vlc_renderer_discovery.h \<br>+    ../include/vlc_search.h \<br>       ../include/vlc_sort.h \<br>       ../include/vlc_sout.h \<br>       ../include/vlc_spu.h \<br>@@ -591,7 +592,7 @@ test_mrl_helpers_SOURCES = test/mrl_helpers.c<br>   test_arrays_SOURCES = test/arrays.c<br>   test_vector_SOURCES = test/vector.c<br>   test_shared_data_ptr_SOURCES = test/shared_data_ptr.cpp<br>-test_extensions_SOURCES = test/extensions.c<br>+test_extensions_SOURCES = test/extensions.c<br></blockquote>Apparently my editor didn't remove the whitespace, sorry about that.<br></blockquote> Although this shouldn't be here :)<br><br> ok<br><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #fcaf3e; padding-left: 1ex;"><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #e9b96e; padding-left: 1ex;">   test_playlist_SOURCES = playlist/test.c \<br>       playlist/content.c \<br>       playlist/control.c \<br></blockquote> Regards,<br><br> -- <br>     Hugo Beauzée-Luyssen<br>     hugo@beauzee.fr<hr> vlc-devel mailing list<br> To unsubscribe or modify your subscription options:<br> <a href="https://mailman.videolan.org/listinfo/vlc-devel">https://mailman.videolan.org/listinfo/vlc-devel</a><br><br></blockquote><hr>vlc-devel mailing list<br>To unsubscribe or modify your subscription options:<br><a href="https://mailman.videolan.org/listinfo/vlc-devel">https://mailman.videolan.org/listinfo/vlc-devel</a><br></blockquote> -- <br> Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez <br> excuser ma brièveté.<hr> vlc-devel mailing list<br> To unsubscribe or modify your subscription options:<br> <a href="https://mailman.videolan.org/listinfo/vlc-devel">https://mailman.videolan.org/listinfo/vlc-devel</a><br><br></blockquote><hr>vlc-devel mailing list<br>To unsubscribe or modify your subscription options:<br><a href="https://mailman.videolan.org/listinfo/vlc-devel">https://mailman.videolan.org/listinfo/vlc-devel</a><br></blockquote><hr>vlc-devel mailing list<br>To unsubscribe or modify your subscription options:<br><a href="https://mailman.videolan.org/listinfo/vlc-devel">https://mailman.videolan.org/listinfo/vlc-devel</a></pre></blockquote></div><br>-- <br>Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma brièveté.</body></html>