Skip to content

Commit

Permalink
0.6.7: Workaround for nested arrays with function pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-st committed Jan 3, 2023
1 parent e60c7e9 commit 7a89574
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 10 deletions.
7 changes: 7 additions & 0 deletions src/ZstdSharp/Unsafe/ZSTD_blockCompressor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using System.Runtime.InteropServices;

namespace ZstdSharp.Unsafe
{
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public unsafe delegate nuint ZSTD_blockCompressor(ZSTD_matchState_t* bs, seqStore_t* seqStore, uint* rep, void* src, nuint srcSize);
}
7 changes: 7 additions & 0 deletions src/ZstdSharp/Unsafe/ZSTD_getAllMatchesFn.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using System.Runtime.InteropServices;

namespace ZstdSharp.Unsafe
{
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public unsafe delegate uint ZSTD_getAllMatchesFn(ZSTD_match_t* param0, ZSTD_matchState_t* param1, uint* param2, byte* param3, byte* param4, uint* rep, uint ll0, uint lengthToBeat);
}
10 changes: 5 additions & 5 deletions src/ZstdSharp/Unsafe/ZstdCompress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2722,14 +2722,14 @@ private static nuint ZSTD_entropyCompressSeqStore(seqStore_t* seqStorePtr, ZSTD_
return cSize;
}

public static delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint>[][] blockCompressor = new delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint>[4][] { new delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint>[10] { &ZSTD_compressBlock_fast, &ZSTD_compressBlock_fast, &ZSTD_compressBlock_doubleFast, &ZSTD_compressBlock_greedy, &ZSTD_compressBlock_lazy, &ZSTD_compressBlock_lazy2, &ZSTD_compressBlock_btlazy2, &ZSTD_compressBlock_btopt, &ZSTD_compressBlock_btultra, &ZSTD_compressBlock_btultra2 }, new delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint>[10] { &ZSTD_compressBlock_fast_extDict, &ZSTD_compressBlock_fast_extDict, &ZSTD_compressBlock_doubleFast_extDict, &ZSTD_compressBlock_greedy_extDict, &ZSTD_compressBlock_lazy_extDict, &ZSTD_compressBlock_lazy2_extDict, &ZSTD_compressBlock_btlazy2_extDict, &ZSTD_compressBlock_btopt_extDict, &ZSTD_compressBlock_btultra_extDict, &ZSTD_compressBlock_btultra_extDict }, new delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint>[10] { &ZSTD_compressBlock_fast_dictMatchState, &ZSTD_compressBlock_fast_dictMatchState, &ZSTD_compressBlock_doubleFast_dictMatchState, &ZSTD_compressBlock_greedy_dictMatchState, &ZSTD_compressBlock_lazy_dictMatchState, &ZSTD_compressBlock_lazy2_dictMatchState, &ZSTD_compressBlock_btlazy2_dictMatchState, &ZSTD_compressBlock_btopt_dictMatchState, &ZSTD_compressBlock_btultra_dictMatchState, &ZSTD_compressBlock_btultra_dictMatchState }, new delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint>[10] { null, null, null, &ZSTD_compressBlock_greedy_dedicatedDictSearch, &ZSTD_compressBlock_lazy_dedicatedDictSearch, &ZSTD_compressBlock_lazy2_dedicatedDictSearch, null, null, null, null } };
public static delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint>[][] rowBasedBlockCompressors = new delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint>[4][] { new delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint>[3] { &ZSTD_compressBlock_greedy_row, &ZSTD_compressBlock_lazy_row, &ZSTD_compressBlock_lazy2_row }, new delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint>[3] { &ZSTD_compressBlock_greedy_extDict_row, &ZSTD_compressBlock_lazy_extDict_row, &ZSTD_compressBlock_lazy2_extDict_row }, new delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint>[3] { &ZSTD_compressBlock_greedy_dictMatchState_row, &ZSTD_compressBlock_lazy_dictMatchState_row, &ZSTD_compressBlock_lazy2_dictMatchState_row }, new delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint>[3] { &ZSTD_compressBlock_greedy_dedicatedDictSearch_row, &ZSTD_compressBlock_lazy_dedicatedDictSearch_row, &ZSTD_compressBlock_lazy2_dedicatedDictSearch_row } };
public static ZSTD_blockCompressor[][] blockCompressor = new ZSTD_blockCompressor[4][] { new ZSTD_blockCompressor[10] { ZSTD_compressBlock_fast, ZSTD_compressBlock_fast, ZSTD_compressBlock_doubleFast, ZSTD_compressBlock_greedy, ZSTD_compressBlock_lazy, ZSTD_compressBlock_lazy2, ZSTD_compressBlock_btlazy2, ZSTD_compressBlock_btopt, ZSTD_compressBlock_btultra, ZSTD_compressBlock_btultra2 }, new ZSTD_blockCompressor[10] { ZSTD_compressBlock_fast_extDict, ZSTD_compressBlock_fast_extDict, ZSTD_compressBlock_doubleFast_extDict, ZSTD_compressBlock_greedy_extDict, ZSTD_compressBlock_lazy_extDict, ZSTD_compressBlock_lazy2_extDict, ZSTD_compressBlock_btlazy2_extDict, ZSTD_compressBlock_btopt_extDict, ZSTD_compressBlock_btultra_extDict, ZSTD_compressBlock_btultra_extDict }, new ZSTD_blockCompressor[10] { ZSTD_compressBlock_fast_dictMatchState, ZSTD_compressBlock_fast_dictMatchState, ZSTD_compressBlock_doubleFast_dictMatchState, ZSTD_compressBlock_greedy_dictMatchState, ZSTD_compressBlock_lazy_dictMatchState, ZSTD_compressBlock_lazy2_dictMatchState, ZSTD_compressBlock_btlazy2_dictMatchState, ZSTD_compressBlock_btopt_dictMatchState, ZSTD_compressBlock_btultra_dictMatchState, ZSTD_compressBlock_btultra_dictMatchState }, new ZSTD_blockCompressor[10] { null, null, null, ZSTD_compressBlock_greedy_dedicatedDictSearch, ZSTD_compressBlock_lazy_dedicatedDictSearch, ZSTD_compressBlock_lazy2_dedicatedDictSearch, null, null, null, null } };
public static ZSTD_blockCompressor[][] rowBasedBlockCompressors = new ZSTD_blockCompressor[4][] { new ZSTD_blockCompressor[3] { ZSTD_compressBlock_greedy_row, ZSTD_compressBlock_lazy_row, ZSTD_compressBlock_lazy2_row }, new ZSTD_blockCompressor[3] { ZSTD_compressBlock_greedy_extDict_row, ZSTD_compressBlock_lazy_extDict_row, ZSTD_compressBlock_lazy2_extDict_row }, new ZSTD_blockCompressor[3] { ZSTD_compressBlock_greedy_dictMatchState_row, ZSTD_compressBlock_lazy_dictMatchState_row, ZSTD_compressBlock_lazy2_dictMatchState_row }, new ZSTD_blockCompressor[3] { ZSTD_compressBlock_greedy_dedicatedDictSearch_row, ZSTD_compressBlock_lazy_dedicatedDictSearch_row, ZSTD_compressBlock_lazy2_dedicatedDictSearch_row } };
/* ZSTD_selectBlockCompressor() :
* Not static, but internal use only (used by long distance matcher)
* assumption : strat is a valid strategy */
public static delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint> ZSTD_selectBlockCompressor(ZSTD_strategy strat, ZSTD_paramSwitch_e useRowMatchFinder, ZSTD_dictMode_e dictMode)
public static ZSTD_blockCompressor ZSTD_selectBlockCompressor(ZSTD_strategy strat, ZSTD_paramSwitch_e useRowMatchFinder, ZSTD_dictMode_e dictMode)
{
delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint> selectedCompressor;
ZSTD_blockCompressor selectedCompressor;
assert(ZSTD_cParam_withinBounds(ZSTD_cParameter.ZSTD_c_strategy, (int)strat) != 0);
if (ZSTD_rowMatchFinderUsed(strat, useRowMatchFinder) != 0)
{
Expand Down Expand Up @@ -2824,7 +2824,7 @@ private static nuint ZSTD_buildSeqStore(ZSTD_CCtx_s* zc, void* src, nuint srcSiz
}
else
{
delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint> blockCompressor = ZSTD_selectBlockCompressor(zc->appliedParams.cParams.strategy, zc->appliedParams.useRowMatchFinder, dictMode);
ZSTD_blockCompressor blockCompressor = ZSTD_selectBlockCompressor(zc->appliedParams.cParams.strategy, zc->appliedParams.useRowMatchFinder, dictMode);
ms->ldmSeqStore = null;
lastLLSize = blockCompressor(ms, &zc->seqStore, zc->blockState.nextCBlock->rep, src, srcSize);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ZstdSharp/Unsafe/ZstdLdm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ public static nuint ZSTD_ldm_blockCompress(rawSeqStore_t* rawSeqStore, ZSTD_matc
{
ZSTD_compressionParameters* cParams = &ms->cParams;
uint minMatch = cParams->minMatch;
delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint> blockCompressor = ZSTD_selectBlockCompressor(cParams->strategy, useRowMatchFinder, ZSTD_matchState_dictMode(ms));
ZSTD_blockCompressor blockCompressor = ZSTD_selectBlockCompressor(cParams->strategy, useRowMatchFinder, ZSTD_matchState_dictMode(ms));
/* Input bounds */
byte* istart = (byte*)src;
byte* iend = istart + srcSize;
Expand Down
6 changes: 3 additions & 3 deletions src/ZstdSharp/Unsafe/ZstdOpt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -799,8 +799,8 @@ private static uint ZSTD_btGetAllMatches_dictMatchState_6(ZSTD_match_t* matches,
return ZSTD_btGetAllMatches_internal(matches, ms, nextToUpdate3, ip, iHighLimit, rep, ll0, lengthToBeat, ZSTD_dictMode_e.ZSTD_dictMatchState, 6);
}

public static delegate* managed<ZSTD_match_t*, ZSTD_matchState_t*, uint*, byte*, byte*, uint*, uint, uint, uint>[][] getAllMatchesFns = new delegate* managed<ZSTD_match_t*, ZSTD_matchState_t*, uint*, byte*, byte*, uint*, uint, uint, uint>[3][] { new delegate* managed<ZSTD_match_t*, ZSTD_matchState_t*, uint*, byte*, byte*, uint*, uint, uint, uint>[4] { &ZSTD_btGetAllMatches_noDict_3, &ZSTD_btGetAllMatches_noDict_4, &ZSTD_btGetAllMatches_noDict_5, &ZSTD_btGetAllMatches_noDict_6 }, new delegate* managed<ZSTD_match_t*, ZSTD_matchState_t*, uint*, byte*, byte*, uint*, uint, uint, uint>[4] { &ZSTD_btGetAllMatches_extDict_3, &ZSTD_btGetAllMatches_extDict_4, &ZSTD_btGetAllMatches_extDict_5, &ZSTD_btGetAllMatches_extDict_6 }, new delegate* managed<ZSTD_match_t*, ZSTD_matchState_t*, uint*, byte*, byte*, uint*, uint, uint, uint>[4] { &ZSTD_btGetAllMatches_dictMatchState_3, &ZSTD_btGetAllMatches_dictMatchState_4, &ZSTD_btGetAllMatches_dictMatchState_5, &ZSTD_btGetAllMatches_dictMatchState_6 } };
private static delegate* managed<ZSTD_match_t*, ZSTD_matchState_t*, uint*, byte*, byte*, uint*, uint, uint, uint> ZSTD_selectBtGetAllMatches(ZSTD_matchState_t* ms, ZSTD_dictMode_e dictMode)
public static ZSTD_getAllMatchesFn[][] getAllMatchesFns = new ZSTD_getAllMatchesFn[3][] { new ZSTD_getAllMatchesFn[4] { ZSTD_btGetAllMatches_noDict_3, ZSTD_btGetAllMatches_noDict_4, ZSTD_btGetAllMatches_noDict_5, ZSTD_btGetAllMatches_noDict_6 }, new ZSTD_getAllMatchesFn[4] { ZSTD_btGetAllMatches_extDict_3, ZSTD_btGetAllMatches_extDict_4, ZSTD_btGetAllMatches_extDict_5, ZSTD_btGetAllMatches_extDict_6 }, new ZSTD_getAllMatchesFn[4] { ZSTD_btGetAllMatches_dictMatchState_3, ZSTD_btGetAllMatches_dictMatchState_4, ZSTD_btGetAllMatches_dictMatchState_5, ZSTD_btGetAllMatches_dictMatchState_6 } };
private static ZSTD_getAllMatchesFn ZSTD_selectBtGetAllMatches(ZSTD_matchState_t* ms, ZSTD_dictMode_e dictMode)
{
uint mls = 3 > (ms->cParams.minMatch < 6 ? ms->cParams.minMatch : 6) ? 3 : ms->cParams.minMatch < 6 ? ms->cParams.minMatch : 6;
assert((uint)dictMode < 3);
Expand Down Expand Up @@ -953,7 +953,7 @@ private static nuint ZSTD_compressBlock_opt_generic(ZSTD_matchState_t* ms, seqSt
byte* @base = ms->window.@base;
byte* prefixStart = @base + ms->window.dictLimit;
ZSTD_compressionParameters* cParams = &ms->cParams;
delegate* managed<ZSTD_match_t*, ZSTD_matchState_t*, uint*, byte*, byte*, uint*, uint, uint, uint> getAllMatches = ZSTD_selectBtGetAllMatches(ms, dictMode);
ZSTD_getAllMatchesFn getAllMatches = ZSTD_selectBtGetAllMatches(ms, dictMode);
uint sufficient_len = cParams->targetLength < (1 << 12) - 1 ? cParams->targetLength : (1 << 12) - 1;
uint minMatch = (uint)(cParams->minMatch == 3 ? 3 : 4);
uint nextToUpdate3 = ms->nextToUpdate;
Expand Down
2 changes: 1 addition & 1 deletion src/ZstdSharp/ZstdSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<Version>0.6.6</Version>
<Version>0.6.7</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
Expand Down

0 comments on commit 7a89574

Please sign in to comment.