Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

polymake_oscarnumber: disable gc free callbacks during exit #449

Merged
merged 3 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Polymake"
uuid = "d720cf60-89b5-51f5-aff5-213f193123e7"
repo = "https://github.com/oscar-system/Polymake.jl.git"
version = "0.11.3"
version = "0.11.4"

[deps]
BinaryWrappers = "f01c122e-0ea1-4f85-ad8f-907073ad7a9f"
Expand Down Expand Up @@ -35,4 +35,4 @@ julia = "^1.6"
lib4ti2_jll = "^1.6.10"
libpolymake_julia_jll = "~0.10.3"
polymake_jll = "^400.900.0"
polymake_oscarnumber_jll = "~0.2.2"
polymake_oscarnumber_jll = "~0.2.5"
7 changes: 6 additions & 1 deletion src/Polymake.jl
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,12 @@ function __init__()
if isdefined(Main, :IJulia) && Main.IJulia.inited
prepare_jupyter_kernel_for_visualization()
end

# this will disable callbacks for oscarnumber gc free calls
# to avoid some crashes during exit
# the data will be cleaned anyway once the iddict is cleared
Base.atexit() do
Polymake.oscarnumber_prepare_cleanup()
end
end

include("setup_apps.jl")
Expand Down
6 changes: 6 additions & 0 deletions src/perlobj.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ function bigobject(fname::String, name::String; kwargsdata...)
return obj
end

function bigobject_eltype(obj::BigObject)
res = call_function(:User, :get_bigobject_elemtype, obj)
res isa CxxWrap.StdString && !isempty(res) || error("could not determine element type of BigObject")
return String(res)
end

# polymake can either just give a reference or do a full copy.
# but even that full copy will contain references to the same data
# objects in memory, but this is fine since most of them are immutable anyway.
Expand Down
10 changes: 10 additions & 0 deletions src/polymake/julia.rules
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,13 @@ function set_shell_scalar($,$) {
no strict 'refs';
${"Polymake::User::$varname"} = $obj;
}

sub get_bigobject_elemtype($) {
my $params = $_[0]->type->params;
return "" unless defined($params) && @$params > 0;
if ($params->[0]->name =~ /^Min|Max$/) {
return $params->[1]->name;
} else {
return $params->[0]->name;
}
}
7 changes: 6 additions & 1 deletion test/perlobj.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@

@test (@pm tropical.Polytope{Max}(POINTS=points_int)) isa Polymake.BigObject

@test (@pm tropical.Polytope{Max}(POINTS=points_int)) isa Polymake.BigObject
tp = @pm tropical.Polytope{Max}(POINTS=points_int)
@test Polymake.bigobject_eltype(tp) == "Rational"

@test (@pm tropical.Polytope{Max, Rational}(POINTS=points_int)) isa Polymake.BigObject
@test (@pm tropical.Polytope{Max, QuadraticExtension}(POINTS=points_int)) isa Polymake.BigObject

Expand All @@ -108,10 +110,12 @@
@test P.VERTICES isa Polymake.Matrix{Float64}
P = @pm polytope.Polytope{Float}(POINTS=[1 0.5 0; 1 0 1])
@test P.VERTICES isa Polymake.Matrix{Float64}
@test Polymake.bigobject_eltype(P) == "Float"
P = @pm polytope.Polytope(POINTS=[1 0.5 0; 1 0 1])
@test P.VERTICES isa Polymake.Matrix{Polymake.Rational}
P = @pm polytope.Polytope{Rational}(POINTS=[1 0.5 0; 1 0 1])
@test P.VERTICES isa Polymake.Matrix{Polymake.Rational}
@test Polymake.bigobject_eltype(P) == "Rational"
end

@testset verbose=true "PolymakeException" begin
Expand Down Expand Up @@ -141,6 +145,7 @@
i = Polymake.polytope.icosahedron()
@test i.VERTICES[1, :] == [1, 0, Polymake.QuadraticExtension{Polymake.Rational}(1//4, 1//4, 5), 1//2]
@test i.VOLUME == Polymake.QuadraticExtension{Polymake.Rational}(5//4, 5//12, 5)
@test Polymake.bigobject_eltype(i) == "QuadraticExtension"
end

@testset verbose=true "attachments" begin
Expand Down
Loading