From 7f056f9a853d91964f10460a92e834be81b8239e Mon Sep 17 00:00:00 2001 From: Benjamin Lorenz Date: Tue, 23 Jan 2024 23:59:43 +0100 Subject: [PATCH 1/3] avoid closure cfunctions --- src/Polymake.jl | 8 ++++---- test/util.jl | 9 +++++++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Polymake.jl b/src/Polymake.jl index ce7fde64..5234dd4f 100644 --- a/src/Polymake.jl +++ b/src/Polymake.jl @@ -164,10 +164,10 @@ include(libpolymake_julia_jll.generate_deps_tree) include(type_translator) _pm_rand_helper() = rand(Int64) +const _default_rand_helper = CxxWrap.@safe_cfunction(_pm_rand_helper, Int64, ()) -function set_rand_source(f::Function) - cf = CxxWrap.@safe_cfunction($f, Int64, ()) - set_rand_source(cf) +function set_rand_source() + set_rand_source(_default_rand_helper) end function __init__() @@ -273,7 +273,7 @@ function __init__() application("common") end - set_rand_source(_pm_rand_helper) + set_rand_source() # We need to set the Julia types as c types for polymake for (name, c_type) in C_TYPES diff --git a/test/util.jl b/test/util.jl index 28b412e8..1dd504e2 100644 --- a/test/util.jl +++ b/test/util.jl @@ -1,3 +1,5 @@ +_test_rand_fun() = return 42 + @testset verbose=true "utilities" begin facets = [ 0 1 0 ; 0 0 1 ; 1 -1 0 ; 1 0 -1 ] @@ -85,9 +87,12 @@ @test Polymake.shell_execute(raw"""$c->apply_rule("_4ti2.integer_points");""") isa NamedTuple @test Polymake.exists(c, "LATTICE_POINTS_GENERATORS") || Polymake.exists(c, "HILBERT_BASIS_GENERATORS") end + + @testset verbose=true "seeding" begin try - Polymake.set_rand_source(() -> return 42) + _test_rand_cfun = Polymake.CxxWrap.@safe_cfunction(_test_rand_fun, Int64, ()) + Polymake.set_rand_source(_test_rand_cfun) v1 = Polymake.polytope.rand_sphere(3,10).VERTICES v2 = Polymake.polytope.rand_sphere(3,10).VERTICES vs1 = Polymake.polytope.rand_sphere(3,10; seed=42).VERTICES @@ -99,7 +104,7 @@ vr = Polymake.polytope.rand_sphere(3,10).VERTICES @test v1 != vr finally - Polymake.set_rand_source(Polymake._pm_rand_helper) + Polymake.set_rand_source() end end end From 0057471a0c4e7e20877a869953946a009c0fe777 Mon Sep 17 00:00:00 2001 From: Benjamin Lorenz Date: Wed, 24 Jan 2024 07:31:57 +0100 Subject: [PATCH 2/3] fix tests: don't create default rand cfunction during precompilation --- src/Polymake.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Polymake.jl b/src/Polymake.jl index 5234dd4f..986ba4a7 100644 --- a/src/Polymake.jl +++ b/src/Polymake.jl @@ -164,9 +164,9 @@ include(libpolymake_julia_jll.generate_deps_tree) include(type_translator) _pm_rand_helper() = rand(Int64) -const _default_rand_helper = CxxWrap.@safe_cfunction(_pm_rand_helper, Int64, ()) function set_rand_source() + _default_rand_helper = CxxWrap.@safe_cfunction(_pm_rand_helper, Int64, ()) set_rand_source(_default_rand_helper) end From 5cc6791fecd983b0e2c11b1d9ccb65f65f7148fe Mon Sep 17 00:00:00 2001 From: Benjamin Lorenz Date: Wed, 24 Jan 2024 10:25:24 +0100 Subject: [PATCH 3/3] bump version --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 9cc6c795..c6f04394 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Polymake" uuid = "d720cf60-89b5-51f5-aff5-213f193123e7" repo = "https://github.com/oscar-system/Polymake.jl.git" -version = "0.11.10" +version = "0.11.11" [deps] BinaryWrappers = "f01c122e-0ea1-4f85-ad8f-907073ad7a9f"