[vlc-commits] [Git][videolan/vlc][master] 11 commits: access/dtv: use ARRAY_SIZE() instead of local variant

Steve Lhomme (@robUx4) gitlab at videolan.org
Fri Jan 6 15:59:44 UTC 2023



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
f9273339 by Steve Lhomme at 2023-01-06T14:46:46+00:00
access/dtv: use ARRAY_SIZE() instead of local variant

- - - - -
7c43bcba by Steve Lhomme at 2023-01-06T14:46:46+00:00
access/dtv: move the lfind() Windows hack in the module

So that we don't have to include search.h each time vlc_fixups.h is used.

The Win32 prototype of lfind() expects an unsigned* for 'nelp', not a size_t*.

- - - - -
33dc4d13 by Steve Lhomme at 2023-01-06T14:46:46+00:00
vlc_fixups.h: remove unused structure and enums

We only need to define them if they are used in an API but they are not. The
names are very generic and may collide with some defines, so avoid potential
compilation issues.

Only the VISIT enum is needed by twalk().

- - - - -
6a46f115 by Steve Lhomme at 2023-01-06T14:46:46+00:00
compat: define tfind family of functions regardless of the search.h status

The existence of search.h is not relevant for that. search.h may exist but does
not provide tfind, as on Windows.

If tfind.c is included for compilation, then the code needs to be built.

- - - - -
e03c404b by Steve Lhomme at 2023-01-06T14:46:46+00:00
vlc_network: define SHUT_xxx values on Windows if they are missing

They are defined in sys/socket.h on POSIX systems.

- - - - -
14c1c439 by Steve Lhomme at 2023-01-06T14:46:46+00:00
vlc_tick: do explicit float to integer conversion

- - - - -
816af992 by Steve Lhomme at 2023-01-06T14:46:46+00:00
vlc_common: don't use __has_attribute() if it's not defined

That's how it's done in other places.

- - - - -
fe48cc9f by Steve Lhomme at 2023-01-06T14:46:46+00:00
vlc_common: add missing defines when not compiled with gcc/clang

- - - - -
08767361 by Steve Lhomme at 2023-01-06T14:46:46+00:00
picture_pool: avoid allocating more than POOL_MAX pictures

- - - - -
6a7fbc05 by Steve Lhomme at 2023-01-06T14:46:46+00:00
rcu: use the thread_local define for thread local variables

- - - - -
780cfad4 by Steve Lhomme at 2023-01-06T14:46:46+00:00
winvlc: clean function pointer definition

- - - - -


9 changed files:

- bin/winvlc.c
- compat/tfind.c
- include/vlc_common.h
- include/vlc_fixups.h
- include/vlc_network.h
- include/vlc_tick.h
- modules/access/dtv/access.c
- src/misc/picture_pool.c
- src/misc/rcu.c


Changes:

=====================================
bin/winvlc.c
=====================================
@@ -94,7 +94,7 @@ static void PrioritizeSystem32(void)
     } PROCESS_MITIGATION_IMAGE_LOAD_POLICY;
 #endif
 #if _WIN32_WINNT < _WIN32_WINNT_WIN8
-    BOOL WINAPI (*SetProcessMitigationPolicy)(PROCESS_MITIGATION_POLICY, PVOID, SIZE_T);
+    BOOL (WINAPI *SetProcessMitigationPolicy)(PROCESS_MITIGATION_POLICY, PVOID, SIZE_T);
     HINSTANCE h_Kernel32 = GetModuleHandle(TEXT("kernel32.dll"));
     if ( !h_Kernel32 )
         return;


=====================================
compat/tfind.c
=====================================
@@ -6,9 +6,6 @@
 # include <config.h>
 #endif
 
-/** search.h is not present so every t* functions has to be implemented */
-#ifndef HAVE_SEARCH_H
-
 #include <assert.h>
 #include <stdlib.h>
 
@@ -240,5 +237,3 @@ twalk(const void *vroot, cmp_fn_t action) /* Root of the tree to be walked */
 	if (vroot != NULL && action != NULL)
 		trecurse(vroot, action, 0);
 }
-
-#endif // HAVE_SEARCH_H


=====================================
include/vlc_common.h
=====================================
@@ -170,6 +170,10 @@
  */
 #  define VLC_USED
 # endif
+#else // !GCC
+# define VLC_USED
+# define VLC_MALLOC
+# define VLC_DEPRECATED
 #endif
 
 
@@ -599,10 +603,12 @@ static inline size_t vlc_align(size_t v, size_t align)
     return (v + (align - 1)) & ~(align - 1);
 }
 
-#if defined(__clang__) && __has_attribute(diagnose_if)
+#if defined __has_attribute
+# if __has_attribute(diagnose_if)
 static inline size_t vlc_align(size_t v, size_t align)
     __attribute__((diagnose_if(((align & (align - 1)) || (align == 0)),
         "align must be power of 2", "error")));
+# endif
 #endif
 
 /** Greatest common divisor */


=====================================
include/vlc_fixups.h
=====================================
@@ -481,16 +481,7 @@ ssize_t sendmsg(int, const struct msghdr *, int);
 #endif
 
 /* search.h */
-#ifndef HAVE_SEARCH_H
-typedef struct entry {
-    char *key;
-    void *data;
-} ENTRY;
-
-typedef enum {
-    FIND, ENTER
-} ACTION;
-
+#ifndef HAVE_TFIND
 typedef enum {
     preorder,
     postorder,
@@ -502,21 +493,12 @@ void *tsearch( const void *key, void **rootp, int(*cmp)(const void *, const void
 void *tfind( const void *key, void * const *rootp, int(*cmp)(const void *, const void *) );
 void *tdelete( const void *key, void **rootp, int(*cmp)(const void *, const void *) );
 void twalk( const void *root, void(*action)(const void *nodep, VISIT which, int depth) );
-#ifndef _WIN64
-/* the Win32 prototype of lfind() expects an unsigned* for 'nelp' */
+#ifndef _WIN32
+/* the Win32 prototype of lfind() expects an unsigned* for 'nmemb' */
 void *lfind( const void *key, const void *base, size_t *nmemb,
              size_t size, int(*cmp)(const void *, const void *) );
 #endif
-#endif /* HAVE_SEARCH_H */
-
-#ifdef _WIN64
-# ifdef HAVE_SEARCH_H
-#  include <search.h>
-# endif
-/* the Win32 prototype of lfind() expects an unsigned* for 'nelp' */
-# define lfind(a,b,c,d,e) \
-         lfind((a),(b), &(unsigned){ (*(c) > UINT_MAX) ? UINT_MAX : *(c) }, (d),(e))
-#endif /* _WIN64 */
+#endif /* HAVE_TFIND */
 
 #ifndef HAVE_TDESTROY
 void tdestroy( void *root, void (*free_node)(void *nodep) );


=====================================
include/vlc_network.h
=====================================
@@ -48,6 +48,11 @@
 #   ifndef IPV6_V6ONLY
 #       define IPV6_V6ONLY 27
 #   endif
+#   if !defined(SHUT_RDWR)
+#       define SHUT_RDWR (SD_BOTH)
+#       define SHUT_WR   (SD_SEND)
+#       define SHUT_RD   (SD_RECEIVE)
+#   endif
 #else
 #   include <sys/socket.h>
 #   include <netinet/in.h>


=====================================
include/vlc_tick.h
=====================================
@@ -92,7 +92,7 @@ static inline double secf_from_vlc_tick(vlc_tick_t vtk)
 
 static inline vlc_tick_t vlc_tick_rate_duration(float frame_rate)
 {
-    return CLOCK_FREQ / frame_rate;
+    return (vlc_tick_t)(CLOCK_FREQ / frame_rate);
 }
 
 /*


=====================================
modules/access/dtv/access.c
=====================================
@@ -31,6 +31,11 @@
 #ifdef HAVE_SEARCH_H
 #include <search.h>
 #endif
+#if defined(_WIN32)
+/* the Win32 prototype of lfind() expects an unsigned* for 'nelp' */
+# define lfind(a,b,c,d,e) \
+         lfind((a),(b), &(unsigned){ (*(c) > UINT_MAX) ? UINT_MAX : *(c) }, (d),(e))
+#endif
 
 #include "dtv.h"
 
@@ -659,7 +664,7 @@ static const char *var_InheritModulation (vlc_object_t *obj, const char *var)
     if (mod == NULL)
         return "";
 
-    size_t n = sizeof (modulation_vlc) / sizeof (modulation_vlc[0]);
+    size_t n = ARRAY_SIZE(modulation_vlc);
     const char *const *p = lfind (mod, modulation_vlc, &n, sizeof (mod), modcmp);
     if (p != NULL)
     {


=====================================
src/misc/picture_pool.c
=====================================
@@ -128,8 +128,10 @@ picture_pool_t *picture_pool_NewFromFormat(const video_format_t *fmt,
 {
     if (count == 0)
         vlc_assert_unreachable();
+    if (unlikely(count > POOL_MAX))
+        return NULL;
 
-    picture_t *picture[count];
+    picture_t *picture[POOL_MAX];
     unsigned i;
 
     for (i = 0; i < count; i++) {
@@ -154,8 +156,10 @@ picture_pool_t *picture_pool_Reserve(picture_pool_t *master, unsigned count)
 {
     if (count == 0)
         vlc_assert_unreachable();
+    if (unlikely(count > POOL_MAX))
+        return NULL;
 
-    picture_t *picture[count];
+    picture_t *picture[POOL_MAX];
     unsigned i;
 
     for (i = 0; i < count; i++) {


=====================================
src/misc/rcu.c
=====================================
@@ -40,7 +40,7 @@ struct vlc_rcu_thread {
     uintptr_t recursion;
 };
 
-static _Thread_local struct vlc_rcu_thread current;
+static thread_local struct vlc_rcu_thread current;
 
 bool vlc_rcu_read_held(void)
 {
@@ -108,7 +108,7 @@ void vlc_rcu_synchronize(void)
     idx = (idx + 1) % ARRAY_SIZE(gens);
     atomic_store_explicit(&generation, &gens[idx], memory_order_release);
 
-    /* Let old generation readers know that we are waiting for them. */ 
+    /* Let old generation readers know that we are waiting for them. */
     atomic_exchange_explicit(&gen->writer, 1, memory_order_acquire);
 
     while (atomic_load_explicit(&gen->readers, memory_order_relaxed) > 0)



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/545d52eb83e56ba8e54c1373b121b9c81cbfe47b...780cfad471b61c7def8df90f72b0358cf263fb10

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/545d52eb83e56ba8e54c1373b121b9c81cbfe47b...780cfad471b61c7def8df90f72b0358cf263fb10
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list