[libdvdnav-devel] [PATCH] add __DEPRECATED__ modifier which can be used to deprecate API calls where compiler supports it
Timothy Gu
timothygu99 at gmail.com
Mon Jan 19 03:02:30 CET 2015
Sorry for being late.
On Thu Jan 15 2015 at 6:23:03 PM Lawrence D'Oliveiro <
ldo at geek-central.gen.nz> wrote:
>
> OK.
>
> ---
> configure.ac | 7 +++++++
> src/dvdread/ifo_read.h | 6 ++++++
> 2 files changed, 13 insertions(+)
>
The following nitpicking on ac macros is for next time only. The idea
itself DLGTM.
>
> diff --git a/configure.ac b/configure.ac
> index 9142673..697b234 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -47,6 +47,13 @@ AC_SUBST([DVDREAD_LTVERSION],
> [$DVDREAD_LT_CURRENT:$DVDREAD_LT_REVISION:$DVDREAD
>
> AC_PROG_CC
>
> +AS_ECHO_N(["checking whether C compiler supports
> __attribute__((deprecated))... "])
>
AC_MSG_CHECKING
> +AC_COMPILE_IFELSE(
> + [AC_LANG_PROGRAM([__attribute__((deprecated)) extern void f(void);],
> [])],
>
> + [AS_ECHO([yes]); AC_DEFINE([HAVE_ATTRIBUTE_DEPRECATED], [1], [define
> to 1 if C compiler allows __attribute__((deprecated))])],
> + [AS_ECHO([no])]
>
AC_MSG_RESULT
> +)
> +
> AC_CHECK_HEADERS_ONCE([sys/param.h limits.h dlfcn.h])
>
> AC_SYS_LARGEFILE
> diff --git a/src/dvdread/ifo_read.h b/src/dvdread/ifo_read.h
> index 97f4179..8b58b61 100644
> --- a/src/dvdread/ifo_read.h
> +++ b/src/dvdread/ifo_read.h
> @@ -25,6 +25,12 @@
> #include "ifo_types.h"
> #include "dvdread/dvd_reader.h"
>
> +#if defined(HAVE_ATTRIBUTE_DEPRECATED)
> + #define __DEPRECATED__ __attribute__((deprecated))
> +#else
> + #define __DEPRECATED__
> +#endif
> +
> #ifdef __cplusplus
> extern "C" {
> #endif
>
This simply won't work, which is the reason I did not suggest this in the
first place in the other thread.
1. ifo_read.h does not include config.h, and thus will not ever get the
definition of HAVE_ATTRIBUTE_DEPRECATED which is defined in config.h.
2. You can't include config.h in an installed header and it is unwise to
install config.h with crazy things like HAVE_LIMITS_H.
3. You *CAN* use another config.h that is to be installed that includes
HAVE_ATTRIBUTE_DEPRECATED. But what if I am compiling my program with a
version of GCC that is different from the one I used to compile the
library, and that does not support deprecated attribute?
Directly checking gcc version isn't pretty, I know, but it is not without
precedents. For example, the PACKED macro is defined this way:
https://github.com/mirror/libdvdread/blob/master/src/dvdread/ifo_types.h#L34-L37.
Plus FFmpeg/Libav have been doing this since 2006.
Hope this helps.
Timothy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/libdvdnav-devel/attachments/20150119/99baf1e0/attachment.html>
More information about the libdvdnav-devel
mailing list