am b6d6ec53: am 370a7094: am c50e0197: Merge "Switch to upstream NetBSD tdelete/tfind/tsearch."

* commit 'b6d6ec5326a016e60d2bd82edf857aaec6d5ce95':
  Switch to upstream NetBSD tdelete/tfind/tsearch.
This commit is contained in:
Elliott Hughes 2012-08-14 12:17:26 -07:00 committed by Android Git Automerger
commit bfcd552500
6 changed files with 117 additions and 137 deletions

View File

@ -293,12 +293,9 @@ libc_common_src_files := \
bionic/sha1.c \ bionic/sha1.c \
bionic/stubs.cpp \ bionic/stubs.cpp \
bionic/system_properties.c \ bionic/system_properties.c \
bionic/tdelete.c \
bionic/tdestroy.c \ bionic/tdestroy.c \
bionic/time64.c \ bionic/time64.c \
bionic/tfind.c \
bionic/thread_atexit.c \ bionic/thread_atexit.c \
bionic/tsearch.c \
bionic/utime.c \ bionic/utime.c \
bionic/utmp.c \ bionic/utmp.c \
netbsd/gethnamaddr.c \ netbsd/gethnamaddr.c \
@ -338,6 +335,9 @@ libc_common_src_files := \
libc_upstream_netbsd_src_files := \ libc_upstream_netbsd_src_files := \
upstream-netbsd/libc/gen/nice.c \ upstream-netbsd/libc/gen/nice.c \
upstream-netbsd/libc/stdlib/tdelete.c \
upstream-netbsd/libc/stdlib/tfind.c \
upstream-netbsd/libc/stdlib/tsearch.c \
upstream-netbsd/libc/string/strxfrm.c \ upstream-netbsd/libc/string/strxfrm.c \
# The following files are common, but must be compiled # The following files are common, but must be compiled

View File

@ -483,8 +483,7 @@ SUCH DAMAGE.
------------------------------------------------------------------- -------------------------------------------------------------------
Copyright (c) 1988, 1993 Copyright (c) 1997 Niklas Hallqvist. All rights reserved.
The Regents of the University of California. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -494,21 +493,17 @@ are met:
2. Redistributions in binary form must reproduce the above copyright 2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
3. Neither the name of the University nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
SUCH DAMAGE.
------------------------------------------------------------------- -------------------------------------------------------------------
@ -1850,19 +1845,40 @@ POSSIBILITY OF SUCH DAMAGE.
------------------------------------------------------------------- -------------------------------------------------------------------
Copyright (C) 2012 The Android Open Source Project Copyright (c) 1991, 1993
The Regents of the University of California. All rights reserved.
(c) UNIX System Laboratories, Inc.
All or some portions of this file are derived from material licensed
to the University of California by American Telephone and Telegraph
Co. or Unix System Laboratories, Inc. and are reproduced herein with
the permission of UNIX System Laboratories, Inc.
Licensed under the Apache License, Version 2.0 (the "License"); This code is derived from software contributed to Berkeley by
you may not use this file except in compliance with the License. Hugh Smith at The University of Guelph.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the University nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
Unless required by applicable law or agreed to in writing, software THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
distributed under the License is distributed on an "AS IS" BASIS, ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
See the License for the specific language governing permissions and ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
limitations under the License. FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
------------------------------------------------------------------- -------------------------------------------------------------------
@ -2953,40 +2969,19 @@ SUCH DAMAGE.
------------------------------------------------------------------- -------------------------------------------------------------------
Copyright (c) 1991, 1993 Copyright (C) 2012 The Android Open Source Project
The Regents of the University of California. All rights reserved.
(c) UNIX System Laboratories, Inc.
All or some portions of this file are derived from material licensed
to the University of California by American Telephone and Telegraph
Co. or Unix System Laboratories, Inc. and are reproduced herein with
the permission of UNIX System Laboratories, Inc.
This code is derived from software contributed to Berkeley by Licensed under the Apache License, Version 2.0 (the "License");
Hugh Smith at The University of Guelph. you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Redistribution and use in source and binary forms, with or without http://www.apache.org/licenses/LICENSE-2.0
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the University nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND Unless required by applicable law or agreed to in writing, software
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE distributed under the License is distributed on an "AS IS" BASIS,
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE See the License for the specific language governing permissions and
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL limitations under the License.
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
------------------------------------------------------------------- -------------------------------------------------------------------
@ -3487,7 +3482,8 @@ SUCH DAMAGE.
------------------------------------------------------------------- -------------------------------------------------------------------
Copyright (c) 1997 Niklas Hallqvist. All rights reserved. Copyright (c) 1988, 1993
The Regents of the University of California. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -3497,17 +3493,21 @@ are met:
2. Redistributions in binary form must reproduce the above copyright 2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
3. Neither the name of the University nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
------------------------------------------------------------------- -------------------------------------------------------------------
@ -3559,22 +3559,6 @@ SOFTWARE.
------------------------------------------------------------------- -------------------------------------------------------------------
Copyright 2012, The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-------------------------------------------------------------------
Copyright (c) 1993 Copyright (c) 1993
The Regents of the University of California. All rights reserved. The Regents of the University of California. All rights reserved.

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012, The Android Open Source Project * Copyright (C) 2012 The Android Open Source Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -18,16 +18,19 @@
#include <search.h> #include <search.h>
#include <stdlib.h> #include <stdlib.h>
/* destroy a tree and free all allocated resources */ // Destroy a tree and free all allocated resources.
void // This is a GNU extension, not available from NetBSD.
tdestroy(void *root, void (*destroy_func)(void *)) void tdestroy(void* root, void (*destroy_func)(void*)) {
{ node_t* root_node = (node_t*) root;
node_t *root_node = (node_t *) root; if (root_node == NULL) {
if (root_node == NULL) return; return;
if (root_node->llink) }
tdestroy(root_node->llink, destroy_func); if (root_node->llink) {
if (root_node->rlink) tdestroy(root_node->llink, destroy_func);
tdestroy(root_node->rlink, destroy_func); }
(*destroy_func)(root_node->key); if (root_node->rlink) {
free(root); tdestroy(root_node->rlink, destroy_func);
}
(*destroy_func)(root_node->key);
free(root);
} }

View File

@ -1,4 +1,4 @@
/* $NetBSD: tdelete.c,v 1.2 1999/09/16 11:45:37 lukem Exp $ */ /* $NetBSD: tdelete.c,v 1.6 2012/06/25 22:32:45 abs Exp $ */
/* /*
* Tree search generalized from Knuth (6.2.2) Algorithm T just like * Tree search generalized from Knuth (6.2.2) Algorithm T just like
@ -12,32 +12,27 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
#if 0
#if defined(LIBC_SCCS) && !defined(lint) #if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: tdelete.c,v 1.2 1999/09/16 11:45:37 lukem Exp $"); __RCSID("$NetBSD: tdelete.c,v 1.6 2012/06/25 22:32:45 abs Exp $");
#endif /* LIBC_SCCS and not lint */ #endif /* LIBC_SCCS and not lint */
#endif
__FBSDID("$FreeBSD: release/9.0.0/lib/libc/stdlib/tdelete.c 108694 2003-01-05 02:43:18Z tjr $");
#include <assert.h>
#define _SEARCH_PRIVATE #define _SEARCH_PRIVATE
#include <search.h> #include <search.h>
#include <stdlib.h> #include <stdlib.h>
/* /* find a node with key "vkey" in tree "vrootp" */
* delete node with given key
*
* vkey: key to be deleted
* vrootp: address of the root of the tree
* compar: function to carry out node comparisons
*/
void * void *
tdelete(const void * __restrict vkey, void ** __restrict vrootp, tdelete(const void *vkey, void **vrootp,
int (*compar)(const void *, const void *)) int (*compar)(const void *, const void *))
{ {
node_t **rootp = (node_t **)vrootp; node_t **rootp = (node_t **)vrootp;
node_t *p, *q, *r; node_t *p, *q, *r;
int cmp; int cmp;
_DIAGASSERT(vkey != NULL);
_DIAGASSERT(compar != NULL);
if (rootp == NULL || (p = *rootp) == NULL) if (rootp == NULL || (p = *rootp) == NULL)
return NULL; return NULL;
@ -65,7 +60,8 @@ tdelete(const void * __restrict vkey, void ** __restrict vrootp,
q->rlink = (*rootp)->rlink; q->rlink = (*rootp)->rlink;
} }
} }
free(*rootp); /* D4: Free node */ if (p != *rootp)
free(*rootp); /* D4: Free node */
*rootp = q; /* link parent to new node */ *rootp = q; /* link parent to new node */
return p; return p;
} }

View File

@ -1,4 +1,4 @@
/* $NetBSD: tfind.c,v 1.2 1999/09/16 11:45:37 lukem Exp $ */ /* $NetBSD: tfind.c,v 1.7 2012/06/25 22:32:45 abs Exp $ */
/* /*
* Tree search generalized from Knuth (6.2.2) Algorithm T just like * Tree search generalized from Knuth (6.2.2) Algorithm T just like
@ -12,25 +12,24 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
#if 0
#if defined(LIBC_SCCS) && !defined(lint) #if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: tfind.c,v 1.2 1999/09/16 11:45:37 lukem Exp $"); __RCSID("$NetBSD: tfind.c,v 1.7 2012/06/25 22:32:45 abs Exp $");
#endif /* LIBC_SCCS and not lint */ #endif /* LIBC_SCCS and not lint */
#endif
__FBSDID("$FreeBSD: release/9.0.0/lib/libc/stdlib/tfind.c 108694 2003-01-05 02:43:18Z tjr $");
#include <assert.h>
#define _SEARCH_PRIVATE #define _SEARCH_PRIVATE
#include <stdlib.h> #include <stdlib.h>
#include <search.h> #include <search.h>
/* find a node, or return 0 */ /* find a node by key "vkey" in tree "vrootp", or return 0 */
void * void *
tfind(vkey, vrootp, compar) tfind(const void *vkey, void * const *vrootp,
const void *vkey; /* key to be found */ int (*compar)(const void *, const void *))
void * const *vrootp; /* address of the tree root */
int (*compar)(const void *, const void *);
{ {
node_t **rootp = (node_t **)vrootp; node_t * const *rootp = (node_t * const*)vrootp;
_DIAGASSERT(vkey != NULL);
_DIAGASSERT(compar != NULL);
if (rootp == NULL) if (rootp == NULL)
return NULL; return NULL;

View File

@ -1,4 +1,4 @@
/* $NetBSD: tsearch.c,v 1.3 1999/09/16 11:45:37 lukem Exp $ */ /* $NetBSD: tsearch.c,v 1.7 2012/06/25 22:32:45 abs Exp $ */
/* /*
* Tree search generalized from Knuth (6.2.2) Algorithm T just like * Tree search generalized from Knuth (6.2.2) Algorithm T just like
@ -12,27 +12,26 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
#if 0
#if defined(LIBC_SCCS) && !defined(lint) #if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: tsearch.c,v 1.3 1999/09/16 11:45:37 lukem Exp $"); __RCSID("$NetBSD: tsearch.c,v 1.7 2012/06/25 22:32:45 abs Exp $");
#endif /* LIBC_SCCS and not lint */ #endif /* LIBC_SCCS and not lint */
#endif
__FBSDID("$FreeBSD: release/9.0.0/lib/libc/stdlib/tsearch.c 108694 2003-01-05 02:43:18Z tjr $");
#include <assert.h>
#define _SEARCH_PRIVATE #define _SEARCH_PRIVATE
#include <search.h> #include <search.h>
#include <stdlib.h> #include <stdlib.h>
/* find or insert datum into search tree */ /* find or insert datum into search tree */
void * void *
tsearch(vkey, vrootp, compar) tsearch(const void *vkey, void **vrootp,
const void *vkey; /* key to be located */ int (*compar)(const void *, const void *))
void **vrootp; /* address of tree root */
int (*compar)(const void *, const void *);
{ {
node_t *q; node_t *q;
node_t **rootp = (node_t **)vrootp; node_t **rootp = (node_t **)vrootp;
_DIAGASSERT(vkey != NULL);
_DIAGASSERT(compar != NULL);
if (rootp == NULL) if (rootp == NULL)
return NULL; return NULL;
@ -50,8 +49,7 @@ tsearch(vkey, vrootp, compar)
q = malloc(sizeof(node_t)); /* T5: key not found */ q = malloc(sizeof(node_t)); /* T5: key not found */
if (q != 0) { /* make new node */ if (q != 0) { /* make new node */
*rootp = q; /* link new node to old */ *rootp = q; /* link new node to old */
/* LINTED const castaway ok */ q->key = __UNCONST(vkey); /* initialize new node */
q->key = (void *)vkey; /* initialize new node */
q->llink = q->rlink = NULL; q->llink = q->rlink = NULL;
} }
return q; return q;