Skip to content

Commit

Permalink
Fix C to Julia translation errors in SimpleDoubleBuffer (#44)
Browse files Browse the repository at this point in the history
* remove cache

* fix SimpleDoubleBuffer bug

* update CI
  • Loading branch information
nhz2 authored Feb 1, 2024
1 parent 6b72a77 commit dacd0dd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: CI
on:
push:
branches:
- main
- master
tags: ['*']
pull_request:
branches:
Expand All @@ -21,6 +21,7 @@ jobs:
matrix:
version:
- '1.6'
- '1.9'
- '1'
os:
- ubuntu-latest
Expand All @@ -34,6 +35,7 @@ jobs:
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
show-versioninfo: true
- uses: julia-actions/cache@v1
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
Expand Down
16 changes: 8 additions & 8 deletions src/lz4_compression.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ mutable struct SimpleDoubleBuffer
next::Bool
end

SimpleDoubleBuffer(buf_size::Integer) = SimpleDoubleBuffer(Array{UInt8}(undef, 2, buf_size), false)
SimpleDoubleBuffer(buf_size::Integer) = SimpleDoubleBuffer(Array{UInt8}(undef, buf_size, 2), false)
function get_buffer!(db::SimpleDoubleBuffer)
out_buffer = db.buffer[db.next+1, :]
out_buffer = @view(db.buffer[:, db.next+1])
db.next = !db.next # Update index
return out_buffer
end
Expand Down Expand Up @@ -148,24 +148,24 @@ function TranscodingStreams.process(

input.size == 0 && return (0, 0, :end)
try
in_buffer = pointer(get_buffer!(codec.buffer))
in_buffer = get_buffer!(codec.buffer)

data_size = min(input.size, codec.block_size)
out_buffer = Vector{UInt8}(undef, LZ4_compressBound(data_size))
unsafe_copyto!(in_buffer, input.ptr, data_size)
GC.@preserve in_buffer unsafe_copyto!(pointer(in_buffer), input.ptr, data_size)

compressed_size = LZ4_compress_fast_continue(
codec.streamptr,
in_buffer,
pointer(out_buffer),
out_buffer,
data_size,
length(out_buffer),
codec.acceleration,
)

checkbounds(output, compressed_size + CINT_SIZE)
writeint(output, compressed_size)
unsafe_copyto!(output.ptr + CINT_SIZE, pointer(out_buffer), compressed_size)
GC.@preserve out_buffer unsafe_copyto!(output.ptr + CINT_SIZE, pointer(out_buffer), compressed_size)

return (data_size, compressed_size + CINT_SIZE, :ok)
catch err
Expand Down Expand Up @@ -287,13 +287,13 @@ function TranscodingStreams.process(
decompressed_size = LZ4_decompress_safe_continue(
codec.streamptr,
input.ptr+CINT_SIZE,
pointer(out_buffer),
out_buffer,
data_size,
length(out_buffer)
)

checkbounds(output, decompressed_size)
unsafe_copyto!(output.ptr, pointer(out_buffer), decompressed_size)
GC.@preserve out_buffer unsafe_copyto!(output.ptr, pointer(out_buffer), decompressed_size)

return (data_size + CINT_SIZE, decompressed_size, :ok)
catch err
Expand Down

0 comments on commit dacd0dd

Please sign in to comment.