[vlc-devel] [PATCH] compat: split twalk from tfind
Steve Lhomme
robux4 at ycbcr.xyz
Fri Sep 7 08:06:08 CEST 2018
Probably OK.
With all the headers we include in vlc_fixups.h even though we hardly
ever use the functions they're related to, it would be nice to use
precompiled headers.
On 06/09/2018 18:56, Jean-Baptiste Kempf wrote:
> [RFC] This happens on Android X, with 16 < X < 21
> ---
> compat/tfind.c | 48 -----------------------------------
> compat/twalk.c | 60 ++++++++++++++++++++++++++++++++++++++++++++
> configure.ac | 2 +-
> include/vlc_fixups.h | 7 +++++-
> 4 files changed, 67 insertions(+), 50 deletions(-)
> create mode 100644 compat/twalk.c
>
> diff --git a/compat/tfind.c b/compat/tfind.c
> index 804ecb8e43..d098a701c5 100644
> --- a/compat/tfind.c
> +++ b/compat/tfind.c
> @@ -204,52 +204,4 @@ tsearch(vkey, vrootp, compar)
> }
> return q;
> }
> -
> -
> -/* $NetBSD: twalk.c,v 1.2 1999/09/16 11:45:37 lukem Exp $ */
> -
> -/*
> - * Tree search generalized from Knuth (6.2.2) Algorithm T just like
> - * the AT&T man page says.
> - *
> - * The node_t structure is for internal use only, lint doesn't grok it.
> - *
> - * Written by reading the System V Interface Definition, not the code.
> - *
> - * Totally public domain.
> - */
> -
> -/* Walk the nodes of a tree */
> -static void
> -twalk_recurse(root, action, level)
> - const node_t *root; /* Root of the tree to be walked */
> - void (*action) (const void *, VISIT, int);
> - int level;
> -{
> - assert(root != NULL);
> - assert(action != NULL);
> -
> - if (root->llink == NULL && root->rlink == NULL)
> - (*action)(root, leaf, level);
> - else {
> - (*action)(root, preorder, level);
> - if (root->llink != NULL)
> - twalk_recurse(root->llink, action, level + 1);
> - (*action)(root, postorder, level);
> - if (root->rlink != NULL)
> - twalk_recurse(root->rlink, action, level + 1);
> - (*action)(root, endorder, level);
> - }
> -}
> -
> -/* Walk the nodes of a tree */
> -void
> -twalk(vroot, action)
> - const void *vroot; /* Root of the tree to be walked */
> - void (*action) (const void *, VISIT, int);
> -{
> - if (vroot != NULL && action != NULL)
> - twalk_recurse(vroot, action, 0);
> -}
> -
> #endif // HAVE_SEARCH_H
> diff --git a/compat/twalk.c b/compat/twalk.c
> new file mode 100644
> index 0000000000..b9c09500ab
> --- /dev/null
> +++ b/compat/twalk.c
> @@ -0,0 +1,60 @@
> +/*****************************************************************************
> + * tfind.c : implement every t* fuctions
> + *****************************************************************************/
> +
> +#ifdef HAVE_CONFIG_H
> +# 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>
> +
> +/* $NetBSD: twalk.c,v 1.2 1999/09/16 11:45:37 lukem Exp $ */
> +
> +/*
> + * Tree search generalized from Knuth (6.2.2) Algorithm T just like
> + * the AT&T man page says.
> + *
> + * The node_t structure is for internal use only, lint doesn't grok it.
> + *
> + * Written by reading the System V Interface Definition, not the code.
> + *
> + * Totally public domain.
> + */
> +
> +/* Walk the nodes of a tree */
> +static void
> +twalk_recurse(root, action, level)
> + const node_t *root; /* Root of the tree to be walked */
> + void (*action) (const void *, VISIT, int);
> + int level;
> +{
> + assert(root != NULL);
> + assert(action != NULL);
> +
> + if (root->llink == NULL && root->rlink == NULL)
> + (*action)(root, leaf, level);
> + else {
> + (*action)(root, preorder, level);
> + if (root->llink != NULL)
> + twalk_recurse(root->llink, action, level + 1);
> + (*action)(root, postorder, level);
> + if (root->rlink != NULL)
> + twalk_recurse(root->rlink, action, level + 1);
> + (*action)(root, endorder, level);
> + }
> +}
> +
> +/* Walk the nodes of a tree */
> +void
> +twalk(vroot, action)
> + const void *vroot; /* Root of the tree to be walked */
> + void (*action) (const void *, VISIT, int);
> +{
> + if (vroot != NULL && action != NULL)
> + twalk_recurse(vroot, action, 0);
> +}
> +#endif
> diff --git a/configure.ac b/configure.ac
> index 54c270df37..dc30c78c90 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -591,7 +591,7 @@ need_libc=false
>
> dnl Check for usual libc functions
> AC_CHECK_FUNCS([accept4 daemon fcntl flock fstatvfs fork getenv getpwuid_r isatty lstat memalign mkostemp mmap newlocale open_memstream openat pipe2 pread posix_fadvise posix_madvise posix_memalign setlocale stricmp strnicmp strptime uselocale])
> -AC_REPLACE_FUNCS([aligned_alloc atof atoll dirfd fdopendir ffsll flockfile fsync getdelim getpid lldiv memrchr nrand48 poll recvmsg rewind sendmsg setenv strcasecmp strcasestr strdup strlcpy strndup strnlen strnstr strsep strtof strtok_r strtoll swab tdestroy tfind timegm timespec_get strverscmp pathconf])
> +AC_REPLACE_FUNCS([aligned_alloc atof atoll dirfd fdopendir ffsll flockfile fsync getdelim getpid lldiv memrchr nrand48 poll recvmsg rewind sendmsg setenv strcasecmp strcasestr strdup strlcpy strndup strnlen strnstr strsep strtof strtok_r strtoll swab tdestroy tfind twalk timegm timespec_get strverscmp pathconf])
> AC_REPLACE_FUNCS([gettimeofday])
> AC_CHECK_FUNC(fdatasync,,
> [AC_DEFINE(fdatasync, fsync, [Alias fdatasync() to fsync() if missing.])
> diff --git a/include/vlc_fixups.h b/include/vlc_fixups.h
> index 3003a154f6..bb65268c3e 100644
> --- a/include/vlc_fixups.h
> +++ b/include/vlc_fixups.h
> @@ -485,8 +485,13 @@ typedef enum {
> void *tsearch( const void *key, void **rootp, int(*cmp)(const void *, const void *) );
> void *tfind( const void *key, const void **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) );
> #endif /* HAVE_SEARCH_H */
> +#ifndef HAVE_TWALK
> +#ifdef HAVE_SEARCH_H
> +# include <search.h>
> +#endif
> +void twalk( const void *root, void(*action)(const void *nodep, VISIT which, int depth) );
> +#endif
> #ifndef HAVE_TDESTROY
> void tdestroy( void *root, void (*free_node)(void *nodep) );
> #endif
> --
> 2.19.0.rc2
>
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel
More information about the vlc-devel
mailing list