Skip to content

Commit

Permalink
WIP: rewrite gap_to_julia
Browse files Browse the repository at this point in the history
TODO:
- add more test cases esp. for the various fixes
  e.g. converting the same (identical) objects to multiple
  output types should be working correctly now
- identify issues this patch resolves
- update docs
- update CHANGES,md
- ...
  • Loading branch information
fingolfin committed Apr 4, 2022
1 parent 7d3d9f1 commit 3dd2419
Show file tree
Hide file tree
Showing 7 changed files with 324 additions and 216 deletions.
12 changes: 10 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
# Changes in GAP.jl

<<<<<<< HEAD
## Version 0.8.0-DEV (released YYYY-MM-DD)

- Upgrade to newer GAP snapshot
- Give helpful error if GAP_jll is not available
- Give helpful error if `GAP_jll` is not available
- Remove `Base.big(obj::GapObj)`: nothing was using it and it does not really
fit conceptually into this package.
- Rewrite `gap_to_julia` to improve performance, fix bugs in many corner
cases, and making it easier to extend it correctly in other packages. The
target type of conversions now must be either `Any`, or a supertype of the
given object (in which case the input is returned unmodified), or else a
concrete type. Thus e.g. `GAP.gap_to_julia(AbstractString, x)` no longer
works if `x` is a GAP string object; use `GAP.gap_to_julia(String, x)`
instead.

## Version 0.7.7 (released 2022-02-14)

Expand Down Expand Up @@ -40,7 +48,7 @@

## Version 0.7.2 (released 2021-11-17)

- Use a `GAP_pkg_juliainterface_jll` to installed a compiled version of the
- Use `GAP_pkg_juliainterface_jll` to install a compiled version of the
bundled C code, thus for basic use of GAP.jl no C/C++ compiler is needed
anymore; this also avoids compatibility issues when switching back and forth
between Julia 1.6 and 1.7
Expand Down
8 changes: 4 additions & 4 deletions pkg/JuliaInterface/tst/convert.tst
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ gap> ForAll([0..64], n -> JuliaToGAP( IsInt, -big2^n) = -2^n);
true

#
gap> string := GAPToJulia( Julia.Base.AbstractString, "bla" );
gap> string := GAPToJulia( Julia.Base.String, "bla" );
<Julia: "bla">
gap> JuliaToGAP( IsString, string );
"bla"
Expand Down Expand Up @@ -175,7 +175,7 @@ Error, <obj> must be a Julia range
## empty list vs. empty string
gap> emptylist:= GAPToJulia( JuliaEvalString( "Vector{Any}"), [] );
<Julia: Any[]>
gap> emptystring:= GAPToJulia( Julia.Base.AbstractString, "" );
gap> emptystring:= GAPToJulia( Julia.Base.String, "" );
<Julia: "">
gap> JuliaToGAP( IsList, emptylist );
[ ]
Expand All @@ -201,7 +201,7 @@ gap> JuliaToGAP( IsInt, xx );

## empty record
gap> dict:= GAPToJulia( rec() );
<Julia: Dict{Symbol,Any}()>
<Julia: Dict{Symbol, Any}()>
gap> JuliaToGAP( IsRecord, dict );
rec( )

Expand All @@ -218,7 +218,7 @@ rec( bool := true, list := [ 1, 2, 3 ], string := "abc" )
## something where recursive conversion would run into a Julia error
gap> dict:= GAPToJulia( rec( juliafunc:= Julia.Base.map,
> ) );
<Julia: Dict{Symbol,Any}(:juliafunc=>map)>
<Julia: Dict{Symbol, Any}(:juliafunc => map)>
gap> JuliaToGAP( IsRecord, dict );
rec( juliafunc := <Julia: map> )

Expand Down
7 changes: 3 additions & 4 deletions src/constructors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ function String(obj::GapObj)
Wrappers.IsString(obj) && return CSTR_STRING(Wrappers.CopyToStringRep(obj))
throw(ConversionError(obj, String))
end
(::Type{T})(obj::GapObj) where {T<:AbstractString} = convert(T, String(obj))

"""
Symbol(obj::GapObj)
Expand Down Expand Up @@ -250,7 +249,7 @@ function BitVector(obj::GapObj)
!Wrappers.IsBlist(obj) && throw(ConversionError(obj, BitVector))
# TODO: a much better conversion would be possible, at least if `obj` is
# in IsBlistRep, then we could essentially memcpy data
len = Wrappers.Length(obj)
len = length(obj)
result = BitVector(undef, len)
for i = 1:len
result[i] = obj[i]
Expand Down Expand Up @@ -457,7 +456,7 @@ julia> UnitRange{Int32}(val)

function (::Type{T})(obj::GapObj) where {T<:UnitRange}
!Wrappers.IsRange(obj) && throw(ConversionError(obj, T))
len = Wrappers.Length(obj)
len = length(obj)
if len == 0
# construct an empty UnitRange object
result = 1:0
Expand Down Expand Up @@ -498,7 +497,7 @@ StepRange{Int8, Int8}

function(::Type{T})(obj::GapObj) where {T<:StepRange}
!Wrappers.IsRange(obj) && throw(ConversionError(obj, T))
len = Wrappers.Length(obj)
len = length(obj)
if len == 0
# construct an empty StepRange object
start = 1
Expand Down
Loading

0 comments on commit 3dd2419

Please sign in to comment.