random.h (random_device): Avoid using the FILE type.

2013-07-24  Paolo Carlini  <paolo.carlini@oracle.com>

	* include/bits/random.h (random_device): Avoid using the FILE type.
	* include/std/random: Do not include <cstdio>.
	* src/c++11/random.cc: ... include it here.
	(random_device::_M_init, random_device::_M_fini,
	random_device::_M_getval): Cast back and forth void* and FILE*.

From-SVN: r201215
This commit is contained in:
Paolo Carlini 2013-07-24 15:42:06 +00:00
parent 37c74e2816
commit 821f6f1b31
4 changed files with 23 additions and 15 deletions

View File

@ -1,3 +1,11 @@
2013-07-24 Paolo Carlini <paolo.carlini@oracle.com>
* include/bits/random.h (random_device): Avoid using the FILE type.
* include/std/random: Do not include <cstdio>.
* src/c++11/random.cc: ... include it here.
(random_device::_M_init, random_device::_M_fini,
random_device::_M_getval): Cast back and forth void* and FILE*.
2013-07-24 Tim Shen <timshen91@gmail.com>
Reimplment matcher using Depth-first search(backtracking).
@ -24,8 +32,8 @@
New.
* testsuite/28_regex/iterators/regex_token_iterator/char/string_01.cc:
New.
* testsuite/28_regex/iterators/regex_token_iterator/wchar_t/string_01.cc:
New.
* testsuite/28_regex/iterators/regex_token_iterator/wchar_t/
string_01.cc: New.
2013-07-23 Paolo Carlini <paolo.carlini@oracle.com>

View File

@ -1638,9 +1638,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
union
{
FILE* _M_file;
mt19937 _M_mt;
};
void* _M_file;
mt19937 _M_mt;
};
};
/* @} */ // group random_generators

View File

@ -36,7 +36,6 @@
#else
#include <cmath>
#include <cstdio> // For FILE
#include <cstdlib>
#include <string>
#include <iosfwd>

View File

@ -30,13 +30,14 @@
# include <cpuid.h>
#endif
#include <cstdio>
#ifdef _GLIBCXX_HAVE_UNISTD_H
# include <unistd.h>
#endif
namespace std _GLIBCXX_VISIBILITY(default)
{
namespace
{
static unsigned long
@ -72,7 +73,6 @@ namespace std _GLIBCXX_VISIBILITY(default)
#endif
}
void
random_device::_M_init(const std::string& token)
{
@ -102,8 +102,8 @@ namespace std _GLIBCXX_VISIBILITY(default)
std::__throw_runtime_error(__N("random_device::"
"random_device(const std::string&)"));
_M_file = std::fopen(fname, "rb");
if (! _M_file)
_M_file = static_cast<void*>(std::fopen(fname, "rb"));
if (!_M_file)
goto fail;
}
@ -117,23 +117,24 @@ namespace std _GLIBCXX_VISIBILITY(default)
random_device::_M_fini()
{
if (_M_file)
std::fclose(_M_file);
std::fclose(static_cast<FILE*>(_M_file));
}
random_device::result_type
random_device::_M_getval()
{
#if (defined __i386__ || defined __x86_64__) && defined _GLIBCXX_X86_RDRAND
if (! _M_file)
if (!_M_file)
return __x86_rdrand();
#endif
result_type __ret;
#ifdef _GLIBCXX_HAVE_UNISTD_H
read(fileno(_M_file), reinterpret_cast<void*>(&__ret), sizeof(result_type));
read(fileno(static_cast<FILE*>(_M_file)),
static_cast<void*>(&__ret), sizeof(result_type));
#else
std::fread(reinterpret_cast<void*>(&__ret), sizeof(result_type),
1, _M_file);
std::fread(static_cast<void*>(&__ret), sizeof(result_type),
1, static_cast<FILE*>(_M_file));
#endif
return __ret;
}