[UUID] version v12

Hello Andy, I just did a small test with the latest uuid library from the vault. IMHO, I found a small error in file uuid.hpp (line 303): function hash_value must be inlined as it is not a template function. Additional is seems that the documentation is out of sync with the implementation. The section 'design notes' is still refering to a former implementation with the create(...) functions. Otherwise, I could compile and link the code on msvc .net 2008 with my setup. thanks for your library, best Johannes

Hi Johannes, On Wed, 8 Oct 2008 15:03:54 +0200, "Johannes Brunen" <JBrunen@DataSolid.de> said:
Hello Andy,
I just did a small test with the latest uuid library from the vault.
IMHO, I found a small error in file uuid.hpp (line 303): function hash_value must be inlined as it is not a template function.
Absolutely correct. Thanks. I will fix this.
Additional is seems that the documentation is out of sync with the implementation. The section 'design notes' is still refering to a former implementation with the create(...) functions.
Again, absolutely correct. Thanks. I will fix this too.
Otherwise, I could compile and link the code on msvc .net 2008 with my setup.
thanks for your library,
best
Johannes
Thank you, Andy Tompkins

Hi Andy, I saw the source code in seed_rng.hpp, I found you use an uninitialized buffer[] if fopen fails. It often rely on the stack contents when previous calling function runs, and that is not always random. I think UUID does not need to be random, it just need to be uniquely. So the seed should contains process id, time, MAC address and so on. 2008/10/9 Andy Tompkins <atompkins@fastmail.fm>:
Hi Johannes,
On Wed, 8 Oct 2008 15:03:54 +0200, "Johannes Brunen" <JBrunen@DataSolid.de> said:
Hello Andy,
I just did a small test with the latest uuid library from the vault.
IMHO, I found a small error in file uuid.hpp (line 303): function hash_value must be inlined as it is not a template function.
Absolutely correct. Thanks. I will fix this.
Additional is seems that the documentation is out of sync with the implementation. The section 'design notes' is still refering to a former implementation with the create(...) functions.
Again, absolutely correct. Thanks. I will fix this too.
Otherwise, I could compile and link the code on msvc .net 2008 with my setup.
thanks for your library,
best
Johannes
Thank you, Andy Tompkins _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Atry wrote:
Hi Andy, I saw the source code in seed_rng.hpp, I found you use an uninitialized buffer[] if fopen fails.
As a side note, would it be possible to use hooks or something so that reading that uninitialized memory doesn't generate errors with memory checking tools such as valgrind?

Hi Mathias, On Thu, 09 Oct 2008 12:54:52 +0200, "Mathias Gaunard" <mathias.gaunard@ens-lyon.org> said:
Atry wrote:
Hi Andy, I saw the source code in seed_rng.hpp, I found you use an uninitialized buffer[] if fopen fails.
As a side note, would it be possible to use hooks or something so that reading that uninitialized memory doesn't generate errors with memory checking tools such as valgrind?
I assume it would be possible, and I'm quite open to the idea. Do you have any suggestions on how to do this? Regards, Andy Tompkins

Andy Tompkins wrote:
Hi Mathias,
On Thu, 09 Oct 2008 12:54:52 +0200, "Mathias Gaunard" <mathias.gaunard@ens-lyon.org> said:
Atry wrote:
Hi Andy, I saw the source code in seed_rng.hpp, I found you use an uninitialized buffer[] if fopen fails. As a side note, would it be possible to use hooks or something so that reading that uninitialized memory doesn't generate errors with memory checking tools such as valgrind?
I assume it would be possible, and I'm quite open to the idea. Do you have any suggestions on how to do this?
Valgrind provides macros to do this sort of thing. I think you'd want VALGRIND_MAKE_MEM_DEFINED from valgrind's memcheck.h. I assume you don't want to make the UUID library depend on valgrind headers, though... John Bytheway

Hi Atry, On Thu, 9 Oct 2008 13:15:23 +0800, "Atry" <pop.atry@gmail.com> said:
Hi Andy, I saw the source code in seed_rng.hpp, I found you use an uninitialized buffer[] if fopen fails. It often rely on the stack contents when previous calling function runs, and that is not always random.
I think UUID does not need to be random, it just need to be uniquely. So the seed should contains process id, time, MAC address and so on.
There are different types of uuids based on different algorithms. In this case uuid_generator is generating a random-based uuids, and so a random number generator is used and needs to be seeded well to produce the best possible random data. Another type of uuid is a time-based uuid, which does incorporate data like the MAC address. I have not implemented this algorithm. Still I could use data such as process id, and MAC address as random data itself, or to seed a random number generator, but I don't know of portable ways to get this data. < snip > Regards, Andy Tompkins

Hello Andy, I have to report an additional problem with the msvc .net 2008 sp1 (vc 9) platform on windows. Compiling and running the following program in optimized release mode does crash with a runtime exception. However, compiling with compiler flag /Od or in debug mode does work fine. #include <boost/uuid/uuid.hpp> namespace uuid_space = boost::uuids; typedef uuid_space::uuid uuid_type; uuid_type create_uuid() { uuid_space::uuid_generator generator; return generator(); } int main(int argc, char *argv[]) { uuid_type a = create_uuid(); return 0; } My settings: [ /O2 /Ob2 /Oi /GL /I "D:\_4640\Comp\Boost" /I "D:\_4640\Comp\boost-beta" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_SECURE_SCL=0" /D "_SCL_SECURE_NO_WARNINGS" /D "_CRT_SECURE_NO_DEPRECATE" /D "_SCL_SECURE_NO_DEPRECATE" /D "_UNICODE" /D "UNICODE" /FD /EHsc /MD /Gy /Fo"Release\\" /Fd"Release\vc90.pdb" /W3 /nologo /c /TP /errorReport:prompt /OUT:"D:\Learn\boost\uuid\Release\uuid.exe" /INCREMENTAL:NO /NOLOGO /MANIFEST /MANIFESTFILE:"Release\uuid.exe.intermediate.manifest" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"d:\Learn\boost\uuid\Release\uuid.pdb" /SUBSYSTEM:CONSOLE /OPT:REF /OPT:ICF /LTCG /DYNAMICBASE /NXCOMPAT /MACHINE:X86 /ERRORREPORT:PROMPT kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ] I'm not sure whether this reveals a new compiler bug of the microsoft compiler. Could you check if you have the same problem? Any suggestions how to circumvent this problem? Best, Johannes "Andy Tompkins" <atompkins@fastmail.fm> schrieb im Newsbeitrag news:1223508572.7529.1278294277@webmail.messagingengine.com...
Hi Johannes,
On Wed, 8 Oct 2008 15:03:54 +0200, "Johannes Brunen" <JBrunen@DataSolid.de> said:
Hello Andy,
I just did a small test with the latest uuid library from the vault.
IMHO, I found a small error in file uuid.hpp (line 303): function hash_value must be inlined as it is not a template function.
Absolutely correct. Thanks. I will fix this.
Additional is seems that the documentation is out of sync with the implementation. The section 'design notes' is still refering to a former implementation with the create(...) functions.
Again, absolutely correct. Thanks. I will fix this too.
Otherwise, I could compile and link the code on msvc .net 2008 with my setup.
thanks for your library,
best
Johannes
Thank you, Andy Tompkins _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Hello Andy, after some investigations, I think that I have found the origin of the problem: In seed_rng.hpp the following code is used: template <typename UniformRandomNumberGenerator> inline void seed(UniformRandomNumberGenerator& rng) { seed_rng seed_gen; boost::generator_iterator<seed_rng> begin(&seed_gen); boost::generator_iterator<seed_rng> end; rng.seed(begin, end); } Problematic is the construction of the end iterator. Looking into the code (boost/generator_iterator.hpp) shows, that the default constructor of generator_iterator does not initialize its member variables. generator_iterator() {} Howerver, the mersenne_twister seed code does compare the two given iterators as shown below (boost/random/). template<class It> void seed(It& first, It last) { int j; for(j = 0; j < n && first != last; ++j, ++first) x[j] = *first; i = n; if(first == last && j < n) throw std::invalid_argument("mersenne_twister::seed"); } As the end iterator is not initialized the way is open for all throwing the invalid_argument exception. Locally, I did solve the problem by patching the default constructor of class generator_iterator. If this is a valid solution of the problem, it would be fine if anyone applies the correction to the boost code. Greetings, Johannes

Hi Johannes, I have verified what you wrote. You are quite correct. On Mon, 13 Oct 2008 13:12:02 +0200, "Johannes Brunen" <JBrunen@DataSolid.de> said:
Hello Andy,
after some investigations, I think that I have found the origin of the problem:
In seed_rng.hpp the following code is used:
template <typename UniformRandomNumberGenerator> inline void seed(UniformRandomNumberGenerator& rng) { seed_rng seed_gen; boost::generator_iterator<seed_rng> begin(&seed_gen); boost::generator_iterator<seed_rng> end; rng.seed(begin, end); }
I could pass the seed_gen to the end iterator, but then as soon as begin produces the same random number as end, the seed function will stop. May not happen in practice, but could happen. I like your solution (set generator_iterator::m_gen to NULL in the default constructor) much better.
Problematic is the construction of the end iterator. Looking into the code (boost/generator_iterator.hpp) shows, that the default constructor of generator_iterator does not initialize its member variables.
generator_iterator() {}
Howerver, the mersenne_twister seed code does compare the two given iterators as shown below (boost/random/).
template<class It> void seed(It& first, It last) { int j; for(j = 0; j < n && first != last; ++j, ++first) x[j] = *first; i = n; if(first == last && j < n) throw std::invalid_argument("mersenne_twister::seed"); }
As the end iterator is not initialized the way is open for all throwing the invalid_argument exception.
Locally, I did solve the problem by patching the default constructor of class generator_iterator.
If this is a valid solution of the problem, it would be fine if anyone applies the correction to the boost code.
Greetings, Johannes
Thanks, Andy.

Hi Johannes, On Mon, 13 Oct 2008 13:12:02 +0200, "Johannes Brunen" <JBrunen@DataSolid.de> said:
Hello Andy,
after some investigations, I think that I have found the origin of the problem:
In seed_rng.hpp the following code is used:
template <typename UniformRandomNumberGenerator> inline void seed(UniformRandomNumberGenerator& rng) { seed_rng seed_gen; boost::generator_iterator<seed_rng> begin(&seed_gen); boost::generator_iterator<seed_rng> end; rng.seed(begin, end); }
Problematic is the construction of the end iterator. Looking into the code (boost/generator_iterator.hpp) shows, that the default constructor of generator_iterator does not initialize its member variables.
generator_iterator() {}
Howerver, the mersenne_twister seed code does compare the two given iterators as shown below (boost/random/).
template<class It> void seed(It& first, It last) { int j; for(j = 0; j < n && first != last; ++j, ++first) x[j] = *first; i = n; if(first == last && j < n) throw std::invalid_argument("mersenne_twister::seed"); }
As the end iterator is not initialized the way is open for all throwing the invalid_argument exception.
Locally, I did solve the problem by patching the default constructor of class generator_iterator.
If this is a valid solution of the problem, it would be fine if anyone applies the correction to the boost code.
Greetings, Johannes
I have put a new version in the boost vault. http://www.boostpro.com/vault/index.php?action=downloadfile&filename=uuid_v13.zip&directory=& It addresses this problem by making a copy of boost::generator_iterator with your fix. Regards, Andy.
participants (5)
-
Andy Tompkins
-
Atry
-
Johannes Brunen
-
John Bytheway
-
Mathias Gaunard