[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 08:36:48 CET 2015


On Sun Jan 18 2015 at 6:25:54 PM Lawrence D'Oliveiro <
ldo at geek-central.gen.nz> wrote:

> On Mon, 19 Jan 2015 02:02:30 +0000, Timothy Gu wrote:
>
> > AC_MSG_CHECKING
> > AC_MSG_RESULT
>
> Thanks for mentioning those, I shall look at them. :)
>
> >> +#if defined(HAVE_ATTRIBUTE_DEPRECATED)
> >> +    #define __DEPRECATED__ __attribute__((deprecated))
> >> +#else
> >> +    #define __DEPRECATED__
> >> +#endif
> >
> > This simply won't work...
> >
> > 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.
>
> It does work--I did check that. For example, adding the following quick
> patch
>
> diff --git a/src/dvdread/ifo_read.h b/src/dvdread/ifo_read.h
> index 8b58b61..1436ec6 100644
> --- a/src/dvdread/ifo_read.h
> +++ b/src/dvdread/ifo_read.h
> @@ -215,7 +215,7 @@ int ifoRead_TXTDT_MGI(ifo_handle_t *);
>   * below are safe:  they will not mind if you attempt to free part of
> an IFO
>   * file which was not read in or which does not exist.
>   */
> -void ifoFree_PTL_MAIT(ifo_handle_t *);
> +__DEPRECATED__ void ifoFree_PTL_MAIT(ifo_handle_t *);
>  void ifoFree_VTS_ATRT(ifo_handle_t *);
>  void ifoFree_TT_SRPT(ifo_handle_t *);
>  void ifoFree_VTS_PTT_SRPT(ifo_handle_t *);
>
> and then building, produces the expected warning:
>
>   CC       src/ifo_read.lo
> src/ifo_read.c: In function ‘ifoClose’:
> src/ifo_read.c:496:3: warning: ‘ifoFree_PTL_MAIT’ is deprecated
> (declared at src/dvdread/ifo_read.h:218) [-Wdeprecated-declarations]
>
> Of course, it could be working “accidentally”... :)
>

Pretty sure that is the case. src/ifo_read.c includes config.h before
dvdread/ifo_read.h so the HAVE_ATTRIBUTE_DEPRECATED got pulled in.

If you *really* want to test it, try installing your (modified) library and
try compiling this:


#include <dvdread/ifo_read.h>

int main()
{
    ifoFree_PTL_MAIT(NULL);
}

Also BTW you can't use __DEPRECATED__ as the macro name as it is reserved by
the C standard for C implementations:

> All identifiers that begin with an underscore and either an uppercase
letter or another underscore are always reserved for any use.

(ISO/IEC 9899:2011 §7.1.3)

Timothy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/libdvdnav-devel/attachments/20150119/48d2de2d/attachment.html>


More information about the libdvdnav-devel mailing list