hash_bytes.cc: Move...

2010-09-22  Paolo Carlini  <paolo.carlini@oracle.com>

	* src/hash_bytes.cc: Move...
	* libsupc++/hash_bytes.cc: ... here.
	* src/Makefile.am: Adjust.
	* libsupc++/Makefile.am: Likewise.
	* config/abi/pre/gnu.ver: Likewise.
	* libsupc++/typeinfo (type_info::hash_code): Add in C++0x mode.
	* src/Makefile.in: Regenerate.
	* libsupc++/Makefile.am: Likewise.
	* testsuite/18_support/type_info/hash_code.cc: New.

From-SVN: r164510
This commit is contained in:
Paolo Carlini 2010-09-22 08:19:08 +00:00 committed by Paolo Carlini
parent c69fa2d460
commit 33da99cb9c
9 changed files with 117 additions and 38 deletions

View File

@ -1,3 +1,15 @@
2010-09-22 Paolo Carlini <paolo.carlini@oracle.com>
* src/hash_bytes.cc: Move...
* libsupc++/hash_bytes.cc: ... here.
* src/Makefile.am: Adjust.
* libsupc++/Makefile.am: Likewise.
* config/abi/pre/gnu.ver: Likewise.
* libsupc++/typeinfo (type_info::hash_code): Add in C++0x mode.
* src/Makefile.in: Regenerate.
* libsupc++/Makefile.am: Likewise.
* testsuite/18_support/type_info/hash_code.cc: New.
2010-09-20 Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
PR libstdc++/45711

View File

@ -1178,12 +1178,6 @@ GLIBCXX_3.4.15 {
_ZNSbIwSt11char_traitsIwESaIwEE4backEv;
_ZNKSbIwSt11char_traitsIwESaIwEE4backEv;
# Default function.
_ZSt11_Hash_bytesPKv*;
# FNV hash.
_ZSt15_Fnv_hash_bytesPKv*;
} GLIBCXX_3.4.14;
# Symbols in the support library (libsupc++) have their own tag.
@ -1356,4 +1350,10 @@ CXXABI_1.3.5 {
_ZTIPDn;
_ZTIPKDn;
# Default function.
_ZSt11_Hash_bytesPKv*;
# FNV hash.
_ZSt15_Fnv_hash_bytesPKv*;
} CXXABI_1.3.4;

View File

@ -69,6 +69,7 @@ sources = \
function_type_info.cc \
fundamental_type_info.cc \
guard.cc \
hash_bytes.cc \
new_handler.cc \
new_op.cc \
new_opnt.cc \

View File

@ -95,10 +95,10 @@ am__objects_1 = array_type_info.lo atexit_arm.lo bad_cast.lo \
eh_globals.lo eh_personality.lo eh_ptr.lo eh_term_handler.lo \
eh_terminate.lo eh_throw.lo eh_type.lo eh_unex_handler.lo \
enum_type_info.lo function_type_info.lo \
fundamental_type_info.lo guard.lo new_handler.lo new_op.lo \
new_opnt.lo new_opv.lo new_opvnt.lo pbase_type_info.lo \
pmem_type_info.lo pointer_type_info.lo pure.lo \
si_class_type_info.lo tinfo.lo tinfo2.lo vec.lo \
fundamental_type_info.lo guard.lo hash_bytes.lo new_handler.lo \
new_op.lo new_opnt.lo new_opv.lo new_opvnt.lo \
pbase_type_info.lo pmem_type_info.lo pointer_type_info.lo \
pure.lo si_class_type_info.lo tinfo.lo tinfo2.lo vec.lo \
vmi_class_type_info.lo vterminate.lo
@GLIBCXX_HOSTED_TRUE@am__objects_2 = cp-demangle.lo
am_libsupc___la_OBJECTS = $(am__objects_1) $(am__objects_2)
@ -364,6 +364,7 @@ sources = \
function_type_info.cc \
fundamental_type_info.cc \
guard.cc \
hash_bytes.cc \
new_handler.cc \
new_op.cc \
new_opnt.cc \

View File

@ -32,8 +32,7 @@
// function apears to be better in both speed and hash quality, and
// FNV is provided primarily for backward compatibility.
#include <cstring>
#include <bits/functional_hash.h>
#include <bits/c++config.h>
namespace
{
@ -41,7 +40,7 @@ namespace
unaligned_load(const char* p)
{
std::size_t result;
std::memcpy(&result, p, sizeof(result));
__builtin_memcpy(&result, p, sizeof(result));
return result;
}
@ -50,7 +49,7 @@ namespace
inline std::size_t
load_bytes(const char* p, int n)
{
size_t result = 0;
std::size_t result = 0;
--n;
do
result = (result << 8) + static_cast<unsigned char>(p[n]);

View File

@ -78,6 +78,11 @@ namespace __cxxabiv1
namespace std
{
#ifdef __GXX_EXPERIMENTAL_CXX0X__
size_t
_Hash_bytes(const void* __ptr, size_t __len, size_t __seed);
#endif
/**
* @brief Part of RTTI.
*
@ -135,6 +140,18 @@ namespace std
bool operator!=(const type_info& __arg) const
{ return !operator==(__arg); }
#ifdef __GXX_EXPERIMENTAL_CXX0X__
size_t hash_code() const throw()
{
# if !__GXX_MERGED_TYPEINFO_NAMES
return _Hash_bytes(name(), __builtin_strlen(name()),
static_cast<size_t>(0xc70f6907UL));
# else
return reinterpret_cast<size_t>(__name);
# endif
}
#endif // __GXX_EXPERIMENTAL_CXX0X__
// Return true if this is a pointer type of some kind
virtual bool __is_pointer_p() const;

View File

@ -179,7 +179,6 @@ sources = \
hash_tr1.cc \
hashtable_c++0x.cc \
hashtable_tr1.cc \
hash_bytes.cc \
ios.cc \
ios_failure.cc \
ios_init.cc \
@ -310,11 +309,6 @@ hashtable_c++0x.lo: hashtable_c++0x.cc
hashtable_c++0x.o: hashtable_c++0x.cc
$(CXXCOMPILE) -std=gnu++0x -c $<
hash_bytes.lo: hash_bytes.cc
$(LTCXXCOMPILE) -std=gnu++0x -c $<
hash_bytes.o: hash_bytes.cc
$(CXXCOMPILE) -std=gnu++0x -c $<
limits.lo: limits.cc
$(LTCXXCOMPILE) -std=gnu++0x -c $<
limits.o: limits.cc

View File

@ -100,18 +100,17 @@ am__objects_5 = atomic.lo bitmap_allocator.lo pool_allocator.lo \
compatibility-c++0x.lo compatibility-debug_list.lo \
compatibility-list.lo complex_io.lo ctype.lo debug.lo \
functexcept.lo globals_io.lo hash_c++0x.lo hash_tr1.lo \
hashtable_c++0x.lo hashtable_tr1.lo hash_bytes.lo ios.lo \
ios_failure.lo ios_init.lo ios_locale.lo limits.lo list.lo \
debug_list.lo locale.lo locale_init.lo locale_facets.lo \
localename.lo math_stubs_float.lo math_stubs_long_double.lo \
stdexcept.lo strstream.lo system_error.lo tree.lo \
allocator-inst.lo concept-inst.lo fstream-inst.lo ext-inst.lo \
ios-inst.lo iostream-inst.lo istream-inst.lo istream.lo \
locale-inst.lo misc-inst.lo ostream-inst.lo sstream-inst.lo \
streambuf-inst.lo streambuf.lo string-inst.lo valarray-inst.lo \
wlocale-inst.lo wstring-inst.lo mutex.lo condition_variable.lo \
chrono.lo thread.lo future.lo $(am__objects_1) \
$(am__objects_4)
hashtable_c++0x.lo hashtable_tr1.lo ios.lo ios_failure.lo \
ios_init.lo ios_locale.lo limits.lo list.lo debug_list.lo \
locale.lo locale_init.lo locale_facets.lo localename.lo \
math_stubs_float.lo math_stubs_long_double.lo stdexcept.lo \
strstream.lo system_error.lo tree.lo allocator-inst.lo \
concept-inst.lo fstream-inst.lo ext-inst.lo ios-inst.lo \
iostream-inst.lo istream-inst.lo istream.lo locale-inst.lo \
misc-inst.lo ostream-inst.lo sstream-inst.lo streambuf-inst.lo \
streambuf.lo string-inst.lo valarray-inst.lo wlocale-inst.lo \
wstring-inst.lo mutex.lo condition_variable.lo chrono.lo \
thread.lo future.lo $(am__objects_1) $(am__objects_4)
am_libstdc___la_OBJECTS = $(am__objects_5)
libstdc___la_OBJECTS = $(am_libstdc___la_OBJECTS)
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
@ -384,7 +383,6 @@ sources = \
hash_tr1.cc \
hashtable_c++0x.cc \
hashtable_tr1.cc \
hash_bytes.cc \
ios.cc \
ios_failure.cc \
ios_init.cc \
@ -887,11 +885,6 @@ hashtable_c++0x.lo: hashtable_c++0x.cc
hashtable_c++0x.o: hashtable_c++0x.cc
$(CXXCOMPILE) -std=gnu++0x -c $<
hash_bytes.lo: hash_bytes.cc
$(LTCXXCOMPILE) -std=gnu++0x -c $<
hash_bytes.o: hash_bytes.cc
$(CXXCOMPILE) -std=gnu++0x -c $<
limits.lo: limits.cc
$(LTCXXCOMPILE) -std=gnu++0x -c $<
limits.o: limits.cc

View File

@ -0,0 +1,62 @@
// { dg-options "-std=gnu++0x" }
// 2010-09-21 Paolo Carlini <paolo.carlini@oracle.com>
//
// Copyright (C) 2010 Free Software Foundation
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
#include <typeinfo>
#include <testsuite_hooks.h>
class Abraca { };
Abraca a1, a2_;
const Abraca a2 = a2_;
class Dabra { };
Dabra d1;
void test01()
{
bool test __attribute__((unused)) = true;
VERIFY( typeid(int) != typeid(double) );
VERIFY( typeid(int).hash_code() != typeid(double).hash_code() );
VERIFY( typeid(a1) == typeid(a2) );
VERIFY( typeid(a1).hash_code() == typeid(a2).hash_code() );
VERIFY( typeid(Abraca) == typeid(const Abraca) );
VERIFY( typeid(Abraca).hash_code() == typeid(const Abraca).hash_code() );
VERIFY( typeid(Abraca) == typeid(a2) );
VERIFY( typeid(Abraca).hash_code() == typeid(a2).hash_code() );
VERIFY( typeid(Abraca) == typeid(const Abraca&) );
VERIFY( typeid(Abraca).hash_code() == typeid(const Abraca&).hash_code() );
VERIFY( typeid(Abraca) != typeid(Dabra) );
VERIFY( typeid(Abraca).hash_code() != typeid(Dabra).hash_code() );
VERIFY( typeid(a1) != typeid(d1) );
VERIFY( typeid(a1).hash_code() != typeid(d1).hash_code() );
}
int main()
{
test01();
return 0;
}