From a2e766f136f7692d79bcbadbd52b3198d1fdd6e8 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Sun, 28 Feb 2016 08:20:28 +0100 Subject: [PATCH 1/6] Print the seed of CGAL::default_random in the testsuite or when CGAL_PRINT_SEED is defined --- Random_numbers/include/CGAL/Random.h | 4 +++- Random_numbers/include/CGAL/Random_impl.h | 19 +++++++++++++++++++ Random_numbers/src/CGAL/Random.cpp | 2 +- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Random_numbers/include/CGAL/Random.h b/Random_numbers/include/CGAL/Random.h index 665dd78cb23..b794ab1be33 100644 --- a/Random_numbers/include/CGAL/Random.h +++ b/Random_numbers/include/CGAL/Random.h @@ -66,6 +66,7 @@ public: // creation CGAL_EXPORT Random( ); CGAL_EXPORT Random( unsigned int seed); + CGAL_EXPORT Random(char*); // seed CGAL_EXPORT unsigned int get_seed ( ) const; @@ -237,7 +238,8 @@ CGAL_EXPORT extern Random default_random; #ifdef CGAL_HEADER_ONLY inline Random& get_default_random() { - static Random default_random; + static Random default_random("default"); + std::cerr << "get_default_random()" << std::endl; return default_random; } #else // CGAL_HEADER_ONLY diff --git a/Random_numbers/include/CGAL/Random_impl.h b/Random_numbers/include/CGAL/Random_impl.h index 16cb9e0cbd3..17cbd503c94 100644 --- a/Random_numbers/include/CGAL/Random_impl.h +++ b/Random_numbers/include/CGAL/Random_impl.h @@ -62,6 +62,25 @@ Random( unsigned int seed) random_value = get_int(0, 1<<15); } + +CGAL_INLINE_FUNCTION +Random:: +Random(char* ) + : val(0) +{ + // get system's time + std::time_t s; + std::time( &s); + seed = (unsigned int)s; + +#if defined( CGAL_TEST_SUITE ) || defined( CGAL_PRINT_SEED ) + std::cerr << "default_random::get_seed() = " << seed << std::endl; +#endif + // initialize random numbers generator + rng.seed(static_cast(seed)); + random_value = get_int(0, 1<<15); +} + // seed CGAL_INLINE_FUNCTION unsigned int diff --git a/Random_numbers/src/CGAL/Random.cpp b/Random_numbers/src/CGAL/Random.cpp index 471accc5128..c88e1b7de65 100644 --- a/Random_numbers/src/CGAL/Random.cpp +++ b/Random_numbers/src/CGAL/Random.cpp @@ -29,7 +29,7 @@ namespace CGAL { -Random default_random; + Random default_random = Random("default"); } //namespace CGAL From 83ffff09f96c18aac22eb130bc650fe67680855a Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Mon, 29 Feb 2016 10:55:51 +0100 Subject: [PATCH 2/6] remove debug output --- Random_numbers/include/CGAL/Random.h | 1 - 1 file changed, 1 deletion(-) diff --git a/Random_numbers/include/CGAL/Random.h b/Random_numbers/include/CGAL/Random.h index b794ab1be33..be938605263 100644 --- a/Random_numbers/include/CGAL/Random.h +++ b/Random_numbers/include/CGAL/Random.h @@ -239,7 +239,6 @@ CGAL_EXPORT extern Random default_random; inline Random& get_default_random() { static Random default_random("default"); - std::cerr << "get_default_random()" << std::endl; return default_random; } #else // CGAL_HEADER_ONLY From 79f54a6c7c3af0a1aa1a6e845990fd06f950f63b Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Wed, 23 Mar 2016 11:22:16 +0100 Subject: [PATCH 3/6] Bump the SOVERSION_MINOR - With the addition of that new function Random::Random(char*), the ABI changes, but in a compatible way -> bump the minor version of SOVERSION. The SONAME remains unchanged. - Add tests for `Random` with and without `CGAL_TEST_SUITE`. That will make a difference only with header-only, because at the time the tests are compiled, libCGAL is already compiled. --- Installation/CMakeLists.txt | 4 +++- .../Random_numbers/test_Random-CGAL_TEST_SUITE.cpp | 14 ++++++++++++++ .../test_Random-no-CGAL_TEST_SUITE.cpp | 14 ++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 Random_numbers/test/Random_numbers/test_Random-CGAL_TEST_SUITE.cpp create mode 100644 Random_numbers/test/Random_numbers/test_Random-no-CGAL_TEST_SUITE.cpp diff --git a/Installation/CMakeLists.txt b/Installation/CMakeLists.txt index 3ed8d83072c..9658bed44f6 100644 --- a/Installation/CMakeLists.txt +++ b/Installation/CMakeLists.txt @@ -340,10 +340,12 @@ endif() # CGAL-4.5 : 10.0.4 (Nothing different in CGAL compiled libraries¹.) # CGAL-4.6 : 11.0.0 (int->size_t in CGAL_ImageIO) # CGAL-4.7 : 11.0.1 (Nothing different in CGAL compiled libraries.) +# CGAL-4.8 : 11.0.2 (Nothing different in CGAL compiled libraries.) +# CGAL-4.9 : 11.1.0 (Add Random::Random(char*) to Random.cpp.) # ¹) According to http://upstream-tracker.org/versions/cgal.html set( CGAL_SONAME_VERSION "11" ) -set( CGAL_SOVERSION "11.0.1" ) +set( CGAL_SOVERSION "11.1.0" ) message( STATUS "CGAL_SONAME_VERSION=${CGAL_SONAME_VERSION}" ) message( STATUS "CGAL_SOVERSION =${CGAL_SOVERSION}" ) diff --git a/Random_numbers/test/Random_numbers/test_Random-CGAL_TEST_SUITE.cpp b/Random_numbers/test/Random_numbers/test_Random-CGAL_TEST_SUITE.cpp new file mode 100644 index 00000000000..e5c134e2fe7 --- /dev/null +++ b/Random_numbers/test/Random_numbers/test_Random-CGAL_TEST_SUITE.cpp @@ -0,0 +1,14 @@ +#ifndef CGAL_TEST_SUITE +# define CGAL_TEST_SUITE 1 +#endif + +#include + +int main() +{ + int u = CGAL::get_default_random().get_int( 0, 1000); + if(u >= 0 || u <= 1000) + return 0; + else + return 1; +} diff --git a/Random_numbers/test/Random_numbers/test_Random-no-CGAL_TEST_SUITE.cpp b/Random_numbers/test/Random_numbers/test_Random-no-CGAL_TEST_SUITE.cpp new file mode 100644 index 00000000000..0ad755b7500 --- /dev/null +++ b/Random_numbers/test/Random_numbers/test_Random-no-CGAL_TEST_SUITE.cpp @@ -0,0 +1,14 @@ +#ifdef CGAL_TEST_SUITE +# undef CGAL_TEST_SUITE +#endif + +#include + +int main() +{ + int u = CGAL::get_default_random().get_int( 0, 1000); + if(u >= 0 || u <= 1000) + return 0; + else + return 1; +} From ef624f92dee2cf905e2192dccb0d394bd04a778a Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Wed, 23 Mar 2016 13:01:21 +0100 Subject: [PATCH 4/6] No need for a constructor just for default_random --- Random_numbers/include/CGAL/Random.h | 1 - Random_numbers/include/CGAL/Random_impl.h | 24 +++++------------------ Random_numbers/src/CGAL/Random.cpp | 2 +- 3 files changed, 6 insertions(+), 21 deletions(-) diff --git a/Random_numbers/include/CGAL/Random.h b/Random_numbers/include/CGAL/Random.h index be938605263..20762d04bc2 100644 --- a/Random_numbers/include/CGAL/Random.h +++ b/Random_numbers/include/CGAL/Random.h @@ -66,7 +66,6 @@ public: // creation CGAL_EXPORT Random( ); CGAL_EXPORT Random( unsigned int seed); - CGAL_EXPORT Random(char*); // seed CGAL_EXPORT unsigned int get_seed ( ) const; diff --git a/Random_numbers/include/CGAL/Random_impl.h b/Random_numbers/include/CGAL/Random_impl.h index 17cbd503c94..fb097cca70e 100644 --- a/Random_numbers/include/CGAL/Random_impl.h +++ b/Random_numbers/include/CGAL/Random_impl.h @@ -46,7 +46,11 @@ Random( ) std::time_t s; std::time( &s); seed = (unsigned int)s; - +#if defined( CGAL_TEST_SUITE ) || defined( CGAL_PRINT_SEED ) + if(this == & get_default_random()){ + std::cerr << "default_random::get_seed() = " << seed << std::endl; + } +#endif // initialize random numbers generator rng.seed(static_cast(seed)); random_value = get_int(0, 1<<15); @@ -63,24 +67,6 @@ Random( unsigned int seed) } -CGAL_INLINE_FUNCTION -Random:: -Random(char* ) - : val(0) -{ - // get system's time - std::time_t s; - std::time( &s); - seed = (unsigned int)s; - -#if defined( CGAL_TEST_SUITE ) || defined( CGAL_PRINT_SEED ) - std::cerr << "default_random::get_seed() = " << seed << std::endl; -#endif - // initialize random numbers generator - rng.seed(static_cast(seed)); - random_value = get_int(0, 1<<15); -} - // seed CGAL_INLINE_FUNCTION unsigned int diff --git a/Random_numbers/src/CGAL/Random.cpp b/Random_numbers/src/CGAL/Random.cpp index c88e1b7de65..40210d38557 100644 --- a/Random_numbers/src/CGAL/Random.cpp +++ b/Random_numbers/src/CGAL/Random.cpp @@ -29,7 +29,7 @@ namespace CGAL { - Random default_random = Random("default"); + Random default_random; } //namespace CGAL From fd4e0a51cc77555dc5116ed4b1c39225ed152f6c Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Tue, 29 Mar 2016 12:10:37 +0200 Subject: [PATCH 5/6] Fix the SOVERSION (Partially reverts commit 79f54a6c7c3af0a1aa1a6e845990fd06f950f63b.) --- Installation/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Installation/CMakeLists.txt b/Installation/CMakeLists.txt index 9658bed44f6..70e09b89989 100644 --- a/Installation/CMakeLists.txt +++ b/Installation/CMakeLists.txt @@ -341,11 +341,11 @@ endif() # CGAL-4.6 : 11.0.0 (int->size_t in CGAL_ImageIO) # CGAL-4.7 : 11.0.1 (Nothing different in CGAL compiled libraries.) # CGAL-4.8 : 11.0.2 (Nothing different in CGAL compiled libraries.) -# CGAL-4.9 : 11.1.0 (Add Random::Random(char*) to Random.cpp.) +# CGAL-4.9 : 11.0.3 (Nothing different in CGAL compiled libraries.) # ¹) According to http://upstream-tracker.org/versions/cgal.html set( CGAL_SONAME_VERSION "11" ) -set( CGAL_SOVERSION "11.1.0" ) +set( CGAL_SOVERSION "11.0.3" ) message( STATUS "CGAL_SONAME_VERSION=${CGAL_SONAME_VERSION}" ) message( STATUS "CGAL_SOVERSION =${CGAL_SOVERSION}" ) From d2b0900ec989ea1cd6403487e7d42f0e859d66ce Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Tue, 29 Mar 2016 12:12:37 +0200 Subject: [PATCH 6/6] Do not call `Random(char*)` in header-only Follow-up to: > ef624f92dee2cf905e2192dccb0d394bd04a778a > Author: Andreas Fabri > Date: Wed Mar 23 13:01:21 2016 +0100 > > No need for a constructor just for default_random --- Random_numbers/include/CGAL/Random.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Random_numbers/include/CGAL/Random.h b/Random_numbers/include/CGAL/Random.h index 20762d04bc2..665dd78cb23 100644 --- a/Random_numbers/include/CGAL/Random.h +++ b/Random_numbers/include/CGAL/Random.h @@ -237,7 +237,7 @@ CGAL_EXPORT extern Random default_random; #ifdef CGAL_HEADER_ONLY inline Random& get_default_random() { - static Random default_random("default"); + static Random default_random; return default_random; } #else // CGAL_HEADER_ONLY