[vlc-commits] [Git][videolan/vlc][master] 5 commits: contrib: upnp: Add a patch to avoid implicit declarations of gettimeofday on mingw

Steve Lhomme (@robUx4) gitlab at videolan.org
Fri Apr 29 12:35:46 UTC 2022



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
83d7194d by Martin Storsjö at 2022-04-29T14:44:03+03:00
contrib: upnp: Add a patch to avoid implicit declarations of gettimeofday on mingw

This patch has been sent upstream at
https://github.com/pupnp/pupnp/pull/387, but hasn't been acted
on by upstream yet.

In mingw headers, both time.h and sys/time.h define
struct timezone and _TIMEZONE_DEFINED - however only one of them,
sys/time.h, define gettimeofday. Thus, if time.h had been included
before, we'd have _TIMEZONE_DEFINED defined, and we'd omit our own
declaration of the gettimeofday function too, leading to calls to
an undeclared function.

(If the actual sys/time.h header is included, its declaration of
the gettimeofday function does conflict with both the declaration
and the definition of upnp's gettimeofday, due to details like missing
the restrict attribute on pointers. But that issue already existed
and is unaffected by this patch.)

Since Clang 15 (which still is under development, so this may
still change before it's released) [1], implicit function
declarations are a hard error by default, when building code
in C99 mode (or newer).

[1] https://github.com/llvm/llvm-project/commit/7d644e1215b376ec5e915df9ea2eeb56e2d94626

- - - - -
9e095923 by Martin Storsjö at 2022-04-29T14:44:03+03:00
contrib: libshout: Apply a patch to avoid implicit declarations of gettimeofday

This patch has been sent upstream at
https://gitlab.xiph.org/xiph/icecast-common/-/merge_requests/2
but hasn't been acted upon there yet.

When building for a mingw target, HAVE_GETTIMEOFDAY is defined
(as the gettimeofday function was found), but the #ifdef _WIN32 #else
block never tried to include <sys/time.h> (which provides the
declaration) and/or <time.h> for such targets. This caused
gettimeofday to be used without a prior declaration.

This has been visible as an easily overlooked warning, but Clang 15
changed this into a fatal error by default, when building in C99
mode (or newer). [1] (While Clang 15 still is under development, this
may still change before it's released, but the warning is valid
in any case.)

Decouple including of those headers from the #ifdef _WIN32 #else
block and just check their corresponding availability defines.

[1] https://github.com/llvm/llvm-project/commit/7d644e1215b376ec5e915df9ea2eeb56e2d94626

- - - - -
a7a4aae3 by Martin Storsjö at 2022-04-29T14:44:45+03:00
contrib: librist: Apply a patch to the bundled mbedtls to avoid implicit declarations of gettimeofday

This patch has been sent upstream at
https://github.com/Mbed-TLS/mbedtls/pull/5770 but hasn't been
acted upon yet. As it hasn't been handled in upstream mbedtls,
I haven't sent it to librist (which bundles mbedtls) yet.

The QueryPerformanceCounter implementation previously was within
defined(_MSC_VER), but it works just as well on other Windows
toolchains, like mingw.

For most common mingw x86 build configurations, one of the earlier
inline assembly implementations would end up used, but for non-x86
(arm, aarch64), it would end up falling back on the gettimeofday
implementation.

This implementation did build successfully (as mingw toolchains do
provide gettimeofday, contrary to MSVC), but the header providing
gettimeofday, <sys/time.h>, wasn't ever included when building
targeting Windows - thus the function was called without a proper
declaration.

Clang 15 changes such implicit function declarations into a hard
error by default, when building in C99 mode (or newer) [1].
(While Clang 15 still is under development, this may still change
before it's released, but it's a valid issue in any case.)

[1] https://github.com/llvm/llvm-project/commit/7d644e1215b376ec5e915df9ea2eeb56e2d94626

- - - - -
68efd7e5 by Martin Storsjö at 2022-04-29T14:44:45+03:00
contrib: zvbi: Add a custom patch to avoid implicit declarations of functions on Windows

Since Clang 15 (which still is under development, so this may
still change before it's released) [1], implicit function
declarations are a hard error by default, when building code
in C99 mode (or newer).

[1] https://github.com/llvm/llvm-project/commit/7d644e1215b376ec5e915df9ea2eeb56e2d94626

The upstream zvbi code doesn't seem to have any support for
building for Windows at all, therefore not trying to upstream it.

On Windows, the <io.h> header is needed for getting declarations
of functions like open/read/write/close. The zvbi project has a
header of its own, named io.h, and it resides on a path added with
-I, so any includes of <io.h> ends up including this header instead
of the system header. Therefore, add an #include_next <io.h> which
should bring in the system header and its declarations too.

Adjust ifdefs to ifdef out larger bits of the code that contained
calls to functions that simply don't exist on Windows, like
ioctl, munmap etc. Previously, the zvbi library has been built with
implicit declarations of those functions, and the static library has
had undefined references to them. As long as those object files
from the static library haven't been included in the link, this issue
has been unnoticed so far.

For the function ffs(), which also was undefined on Windows,
provide a _BitScanForward based reimplementation. This also resides
in a file that doesn't end up included in the end, but for this
case it's just as easy to provide a working implementation as it
would be to ifdef it out.

- - - - -
0e836b4e by Martin Storsjö at 2022-04-29T14:44:45+03:00
contrib: regex: Apply a patch to add missing function declarations

This code seems to be a stale copy of a regex library from glibc,
thus not sending the patch further upstream.

In some configurations, this library seems to choose not to include
standard C headers but declare the functions manually (without a
proper prototype though!). In this case, it already declared malloc
and realloc, but didn't declare abort and free in the same way.

Just add declarations of these functions in the same way - while
the most correct path forward would be to actually make it use
the proper system headers.

- - - - -


10 changed files:

- contrib/src/librist/rules.mak
- + contrib/src/librist/win32-timing.patch
- + contrib/src/regex/decls.patch
- contrib/src/regex/rules.mak
- contrib/src/shout/rules.mak
- + contrib/src/shout/win32-gettimeofday.patch
- contrib/src/upnp/rules.mak
- + contrib/src/upnp/win32-gettimeofday.patch
- contrib/src/zvbi/rules.mak
- + contrib/src/zvbi/zvbi-win32-undefined.patch


Changes:

=====================================
contrib/src/librist/rules.mak
=====================================
@@ -21,6 +21,7 @@ $(TARBALLS)/librist-$(LIBRIST_VERSION).tar.gz:
 librist: librist-$(LIBRIST_VERSION).tar.gz .sum-librist
 	$(UNPACK)
 	$(APPLY) $(SRC)/librist/librist-fix-libcjson-meson.patch
+	$(APPLY) $(SRC)/librist/win32-timing.patch
 	$(MOVE)
 
 .librist: librist crossfile.meson


=====================================
contrib/src/librist/win32-timing.patch
=====================================
@@ -0,0 +1,11 @@
+--- librist/contrib/mbedtls/library/timing.c.orig	2022-04-21 15:15:32.479888797 +0300
++++ librist/contrib/mbedtls/library/timing.c	2022-04-21 15:15:46.615589264 +0300
+@@ -195,7 +195,7 @@
+ #endif /* !HAVE_HARDCLOCK && MBEDTLS_HAVE_ASM &&
+           __GNUC__ && __ia64__ */
+ 
+-#if !defined(HAVE_HARDCLOCK) && defined(_MSC_VER) && \
++#if !defined(HAVE_HARDCLOCK) && defined(_WIN32) && \
+     !defined(EFIX64) && !defined(EFI32)
+ 
+ #define HAVE_HARDCLOCK


=====================================
contrib/src/regex/decls.patch
=====================================
@@ -0,0 +1,11 @@
+--- regex/regex.c.orig	2022-04-21 17:46:06.786845467 +0300
++++ regex/regex.c	2022-04-21 16:46:41.670051683 +0300
+@@ -127,6 +127,8 @@
+ #  else
+ char *malloc ();
+ char *realloc ();
++void abort ();
++void free ();
+ #  endif
+ 
+ /* When used in Emacs's lib-src, we need to get bzero and bcopy somehow..


=====================================
contrib/src/regex/rules.mak
=====================================
@@ -15,6 +15,7 @@ $(TARBALLS)/regex-$(REGEX_VERSION).tar.gz:
 regex: regex-$(REGEX_VERSION).tar.gz .sum-regex
 	$(UNPACK)
 	$(APPLY) $(SRC)/regex/no-docs.patch
+	$(APPLY) $(SRC)/regex/decls.patch
 	$(MOVE)
 
 .regex: regex


=====================================
contrib/src/shout/rules.mak
=====================================
@@ -28,6 +28,7 @@ libshout: libshout-$(SHOUT_VERSION).tar.gz .sum-shout
 	$(APPLY) $(SRC)/shout/no-examples.patch
 	$(APPLY) $(SRC)/shout/no-force-libwsock.patch
 	$(APPLY) $(SRC)/shout/should-win32-ws2tcpip.patch
+	$(APPLY) $(SRC)/shout/win32-gettimeofday.patch
 	$(call pkg_static,"shout.pc.in")
 	$(UPDATE_AUTOCONFIG)
 	$(MOVE)


=====================================
contrib/src/shout/win32-gettimeofday.patch
=====================================
@@ -0,0 +1,22 @@
+--- libshout/src/common/timing/timing.c.orig	2022-04-21 15:00:39.729501137 +0300
++++ libshout/src/common/timing/timing.c	2022-04-21 15:00:43.565527749 +0300
+@@ -37,6 +37,9 @@
+ #include <mmsystem.h>
+ #include <winsock2.h>
+ #else
++#include <unistd.h>
++#endif
++
+ #ifdef TIME_WITH_SYS_TIME
+ #  include <sys/time.h>
+ #  include <time.h>
+@@ -48,9 +51,6 @@
+ #  endif
+ #endif
+ 
+-#include <unistd.h>
+-#endif
+-
+ #ifdef HAVE_SYS_SELECT_H
+ #include <sys/select.h>
+ #endif


=====================================
contrib/src/upnp/rules.mak
=====================================
@@ -42,6 +42,7 @@ ifdef HAVE_WIN32
 	$(APPLY) $(SRC)/upnp/libupnp-win32.patch
 	$(APPLY) $(SRC)/upnp/libupnp-win64.patch
 	$(APPLY) $(SRC)/upnp/windows-version-inet.patch
+	$(APPLY) $(SRC)/upnp/win32-gettimeofday.patch
 endif
 ifdef HAVE_LINUX
 ifndef HAVE_ANDROID


=====================================
contrib/src/upnp/win32-gettimeofday.patch
=====================================
@@ -0,0 +1,12 @@
+--- upnp/upnp/src/threadutil/ThreadPool.h.orig	2022-04-21 15:07:27.194156972 +0300
++++ upnp/upnp/src/threadutil/ThreadPool.h	2022-04-21 15:07:31.026076222 +0300
+@@ -54,8 +54,8 @@
+ 			int  tz_minuteswest; /* minutes W of Greenwich */
+ 			int  tz_dsttime;     /* type of dst correction */
+ 		};
+-		int gettimeofday(struct timeval *tv, struct timezone *tz);
+ 	#endif
++	int gettimeofday(struct timeval *tv, struct timezone *tz);
+ #else /* _WIN32 */
+ 	#include <sys/param.h>
+ 	#include <sys/time.h> /* for gettimeofday() */


=====================================
contrib/src/zvbi/rules.mak
=====================================
@@ -20,6 +20,7 @@ zvbi: zvbi-$(ZVBI_VERSION).tar.bz2 .sum-zvbi
 	$(APPLY) $(SRC)/zvbi/zvbi-fix-static-linking.patch
 ifdef HAVE_WIN32
 	$(APPLY) $(SRC)/zvbi/zvbi-win32.patch
+	$(APPLY) $(SRC)/zvbi/zvbi-win32-undefined.patch
 endif
 	$(APPLY) $(SRC)/zvbi/zvbi-fix-clang-support.patch
 ifdef HAVE_ANDROID


=====================================
contrib/src/zvbi/zvbi-win32-undefined.patch
=====================================
@@ -0,0 +1,88 @@
+--- zvbi/src/io.h.orig	2022-04-27 13:12:22.154124296 +0300
++++ zvbi/src/io.h	2022-04-27 13:12:54.706349113 +0300
+@@ -28,6 +28,12 @@
+ #include "decoder.h"
+ #include "bit_slicer.h"
+ 
++#if defined(_WIN32) && defined(__has_include_next)
++# if __has_include_next(<io.h>)
++#  include_next <io.h>
++# endif
++#endif
++
+ /* Public */
+ 
+ #include <sys/time.h> /* struct timeval */
+--- zvbi/src/io.c.orig	2022-04-21 14:52:30.294105422 +0300
++++ zvbi/src/io.c	2022-04-21 14:39:26.424663785 +0300
+@@ -556,7 +556,6 @@
+ 		return ret;
+ 	}
+ }
+-#endif
+ /* Helper functions to log the communication between the library and drivers.
+    FIXME remove fp arg, call user log function instead (0.3). */
+ 
+@@ -777,7 +776,6 @@
+ 	return err;
+ }
+ 
+-#ifndef _WIN32
+ /**
+  * @internal
+  * Drop-in for mmap(). Logs the request on fp if not NULL.
+@@ -827,7 +825,7 @@
+ 
+ 	return r;
+ }
+-#endif
++
+ /**
+  * @internal
+  * Drop-in for munmap(). Logs the request on fp if not NULL.
+@@ -860,6 +858,7 @@
+ 
+ 	return r;
+ }
++#endif
+ 
+ /*
+ Local variables:
+--- zvbi/src/page_table.c.orig	2022-04-21 14:52:22.018047995 +0300
++++ zvbi/src/page_table.c	2022-04-21 14:48:38.224494983 +0300
+@@ -35,6 +35,17 @@
+ #include "misc.h"
+ #include "page_table.h"
+ 
++#ifdef _WIN32
++#include <intrin.h>
++static inline int ffs(int value) {
++	unsigned long index;
++	if (value == 0)
++		return 0;
++	_BitScanForward(&index, value);
++	return index + 1;
++}
++#endif
++
+ /**
+  * addtogroup PageTable Teletext Page Number Table
+  * ingroup LowDec
+--- zvbi/src/pdc.c.orig	2022-04-21 14:52:12.297980549 +0300
++++ zvbi/src/pdc.c	2022-04-21 14:51:40.529760109 +0300
+@@ -35,6 +35,7 @@
+ #include "pdc.h"
+ #include "conv.h"
+ 
++#ifndef _WIN32
+ /**
+  * @addtogroup ProgramID VPS/PDC Program ID
+  * @ingroup LowDec
+@@ -1460,6 +1461,7 @@
+ 		}
+ 	}
+ }
++#endif
+ 
+ /*
+ Local variables:



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/2cb6eea124b86f6be7ad74cc99e5510594596343...0e836b4eb2b05c8e130b73dcce8c53ac8397466f

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/2cb6eea124b86f6be7ad74cc99e5510594596343...0e836b4eb2b05c8e130b73dcce8c53ac8397466f
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