aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Module.Taskfile.yaml2
-rw-r--r--apps/VNLib.WebServer/src/VNLib.WebServer.csproj2
-rw-r--r--lib/Net.Compression/VNLib.Net.Compression/CompressionExtensions.cs113
-rw-r--r--lib/Net.Compression/VNLib.Net.Compression/NativeCompressionLib.cs66
-rw-r--r--lib/Net.Compression/vnlib_compress/CMakeLists.txt56
-rw-r--r--lib/Net.Compression/vnlib_compress/Taskfile.yaml43
-rw-r--r--lib/Net.Compression/vnlib_compress/src/compression.c58
-rw-r--r--lib/Net.Compression/vnlib_compress/src/compression.h83
-rw-r--r--lib/Net.Compression/vnlib_compress/src/feature_brotli.c25
-rw-r--r--lib/Net.Compression/vnlib_compress/src/feature_brotli.h11
-rw-r--r--lib/Net.Compression/vnlib_compress/src/feature_zlib.c29
-rw-r--r--lib/Net.Compression/vnlib_compress/src/feature_zlib.h14
-rw-r--r--lib/Net.Compression/vnlib_compress/src/platform.h90
-rw-r--r--lib/Net.Compression/vnlib_compress/src/util.h69
-rw-r--r--lib/Net.Compression/vnlib_compress/src/vnlib_compress.vcxitems1
15 files changed, 388 insertions, 274 deletions
diff --git a/Module.Taskfile.yaml b/Module.Taskfile.yaml
index aa5893f..6ec8fc6 100644
--- a/Module.Taskfile.yaml
+++ b/Module.Taskfile.yaml
@@ -63,7 +63,7 @@ tasks:
- cd lib/Utils.Memory/vnlib_mimalloc && task dev-init
- cd lib/Utils.Cryptography/monocypher && task build
- cd lib/Utils.Cryptography/argon2 && task build
- - cd lib/Net.Compression/vnlib_compress && task build
+ - cd lib/Net.Compression/vnlib_compress && task build
- cmd: echo "dev init complete"
silent: true
diff --git a/apps/VNLib.WebServer/src/VNLib.WebServer.csproj b/apps/VNLib.WebServer/src/VNLib.WebServer.csproj
index 37808b5..3dc8318 100644
--- a/apps/VNLib.WebServer/src/VNLib.WebServer.csproj
+++ b/apps/VNLib.WebServer/src/VNLib.WebServer.csproj
@@ -29,7 +29,7 @@
<Copyright>Copyright © 2024 Vaughn Nugent</Copyright>
<Product>VNLib.Webserver</Product>
<PackageProjectUrl>https://www.vaughnnugent.com/resources/software/modules/vnlib.core</PackageProjectUrl>
- <RepositoryUrl>https://github.com/VnUgE/VNLib.Core/tree/master/app/VNLib.Webserver/</RepositoryUrl>
+ <RepositoryUrl>https://github.com/VnUgE/VNLib.Core/tree/master/apps/VNLib.WebServer</RepositoryUrl>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
</PropertyGroup>
diff --git a/lib/Net.Compression/VNLib.Net.Compression/CompressionExtensions.cs b/lib/Net.Compression/VNLib.Net.Compression/CompressionExtensions.cs
index 4509b67..0d1fc73 100644
--- a/lib/Net.Compression/VNLib.Net.Compression/CompressionExtensions.cs
+++ b/lib/Net.Compression/VNLib.Net.Compression/CompressionExtensions.cs
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2023 Vaughn Nugent
+* Copyright (c) 2024 Vaughn Nugent
*
* Library: VNLib
* Package: VNLib.Net.Compression
@@ -36,12 +36,18 @@ namespace VNLib.Net.Compression
/// Compresses a block using the compressor context pointer provided
/// </summary>
/// <param name="nativeLib"></param>
- /// <param name="comp">A pointer to the compressor context</param>
+ /// <param name="compressorInstance">A pointer to the compressor context</param>
/// <param name="output">A buffer to write the result to</param>
/// <param name="input">The input block of memory to compress</param>
/// <param name="finalBlock">A value that indicates if a flush is requested</param>
/// <returns>The results of the compression operation</returns>
- public static unsafe CompressionResult CompressBlock(this LibraryWrapper nativeLib, IntPtr comp, Memory<byte> output, ReadOnlyMemory<byte> input, bool finalBlock)
+ public static unsafe CompressionResult CompressBlock(
+ this LibraryWrapper nativeLib,
+ IntPtr compressorInstance,
+ Memory<byte> output,
+ ReadOnlyMemory<byte> input,
+ bool finalBlock
+ )
{
/*
* Since .NET only supports int32 size memory blocks
@@ -51,46 +57,51 @@ namespace VNLib.Net.Compression
* sizes (read/written)
*/
- //get pointers to the input and output buffers
- using MemoryHandle inPtr = input.Pin();
- using MemoryHandle outPtr = output.Pin();
-
//Create the operation struct
- CompressionOperation operation;
- CompressionOperation* op = &operation;
+ CompressionOperation operation = default;
- op->flush = finalBlock ? 1 : 0;
- op->bytesRead = 0;
- op->bytesWritten = 0;
+ operation.flush = finalBlock ? 1 : 0;
- //Configure the input and output buffers
- op->inputBuffer = inPtr.Pointer;
- op->inputSize = (uint)input.Length;
+ checked
+ {
+ //get pointers to the input and output buffers
+ using MemoryHandle inPtr = input.Pin();
+ using MemoryHandle outPtr = output.Pin();
- op->outputBuffer = outPtr.Pointer;
- op->outputSize = (uint)output.Length;
+ //Configure the input and output buffers
+ operation.inputBuffer = inPtr.Pointer;
+ operation.inputSize = (uint)input.Length;
- //Call the native compress function
- nativeLib!.CompressBlock(comp, &operation);
+ operation.outputBuffer = outPtr.Pointer;
+ operation.outputSize = (uint)output.Length;
- //Return the number of bytes written
- return new()
- {
- BytesRead = (int)op->bytesRead,
- BytesWritten = (int)op->bytesWritten
- };
+ //Call the native compress function
+ nativeLib!.CompressBlock(compressorInstance, &operation);
+
+ return new()
+ {
+ BytesRead = (int)operation.bytesRead,
+ BytesWritten = (int)operation.bytesWritten
+ };
+ }
}
/// <summary>
/// Compresses a block using the compressor context pointer provided
/// </summary>
/// <param name="nativeLib"></param>
- /// <param name="comp">A pointer to the compressor context</param>
+ /// <param name="compressorInstance">A pointer to the compressor context</param>
/// <param name="output">A buffer to write the result to</param>
/// <param name="input">The input block of memory to compress</param>
/// <param name="finalBlock">A value that indicates if a flush is requested</param>
/// <returns>The results of the compression operation</returns>
- public static unsafe CompressionResult CompressBlock(this LibraryWrapper nativeLib, IntPtr comp, Span<byte> output, ReadOnlySpan<byte> input, bool finalBlock)
+ public static unsafe CompressionResult CompressBlock(
+ this LibraryWrapper nativeLib,
+ IntPtr compressorInstance,
+ Span<byte> output,
+ ReadOnlySpan<byte> input,
+ bool finalBlock
+ )
{
/*
* Since .NET only supports int32 size memory blocks
@@ -100,33 +111,31 @@ namespace VNLib.Net.Compression
* sizes (read/written)
*/
- fixed(byte* inputPtr = &MemoryMarshal.GetReference(input),
- outPtr = &MemoryMarshal.GetReference(output))
- {
- //Create the operation struct
- CompressionOperation operation;
- CompressionOperation* op = &operation;
-
- op->flush = finalBlock ? 1 : 0;
- op->bytesRead = 0;
- op->bytesWritten = 0;
-
- //Configure the input and output buffers
- op->inputBuffer = inputPtr;
- op->inputSize = (uint)input.Length;
-
- op->outputBuffer = outPtr;
- op->outputSize = (uint)output.Length;
-
- //Call the native compress function
- nativeLib!.CompressBlock(comp, &operation);
+ //Create the operation struct
+ CompressionOperation operation = default;
+ operation.flush = finalBlock ? 1 : 0;
- //Return the number of bytes written
- return new()
+ checked
+ {
+ fixed (byte* inputPtr = &MemoryMarshal.GetReference(input),
+ outPtr = &MemoryMarshal.GetReference(output))
{
- BytesRead = (int)op->bytesRead,
- BytesWritten = (int)op->bytesWritten
- };
+ //Configure the input and output buffers
+ operation.inputBuffer = inputPtr;
+ operation.inputSize = (uint)input.Length;
+
+ operation.outputBuffer = outPtr;
+ operation.outputSize = (uint)output.Length;
+
+ //Call the native compress function
+ nativeLib!.CompressBlock(compressorInstance, &operation);
+
+ return new()
+ {
+ BytesRead = (int)operation.bytesRead,
+ BytesWritten = (int)operation.bytesWritten
+ };
+ }
}
}
}
diff --git a/lib/Net.Compression/VNLib.Net.Compression/NativeCompressionLib.cs b/lib/Net.Compression/VNLib.Net.Compression/NativeCompressionLib.cs
index 438f777..0df8392 100644
--- a/lib/Net.Compression/VNLib.Net.Compression/NativeCompressionLib.cs
+++ b/lib/Net.Compression/VNLib.Net.Compression/NativeCompressionLib.cs
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2023 Vaughn Nugent
+* Copyright (c) 2024 Vaughn Nugent
*
* Library: VNLib
* Package: VNLib.Net.Compression
@@ -94,16 +94,26 @@ namespace VNLib.Net.Compression
public CompressionResult Compress(ReadOnlyMemory<byte> input, Memory<byte> output)
{
CompressorHandle.ThrowIfClosed();
- IntPtr compressor = CompressorHandle.DangerousGetHandle();
- return LibComp.CompressBlock(compressor, output, input, false);
+
+ return LibComp.CompressBlock(
+ CompressorHandle.DangerousGetHandle(),
+ output,
+ input,
+ finalBlock: false
+ );
}
///<inheritdoc/>
public CompressionResult Compress(ReadOnlySpan<byte> input, Span<byte> output)
{
CompressorHandle.ThrowIfClosed();
- IntPtr compressor = CompressorHandle.DangerousGetHandle();
- return LibComp.CompressBlock(compressor, output, input, false);
+
+ return LibComp.CompressBlock(
+ CompressorHandle.DangerousGetHandle(),
+ output,
+ input,
+ finalBlock: false
+ );
}
///<inheritdoc/>
@@ -113,8 +123,14 @@ namespace VNLib.Net.Compression
public int Flush(Memory<byte> buffer)
{
CompressorHandle.ThrowIfClosed();
- IntPtr compressor = CompressorHandle.DangerousGetHandle();
- CompressionResult result = LibComp.CompressBlock(compressor, buffer, default, true);
+
+ CompressionResult result = LibComp.CompressBlock(
+ CompressorHandle.DangerousGetHandle(),
+ buffer,
+ input: default,
+ finalBlock: true
+ );
+
return result.BytesWritten;
}
@@ -122,8 +138,14 @@ namespace VNLib.Net.Compression
public int Flush(Span<byte> buffer)
{
CompressorHandle.ThrowIfClosed();
- IntPtr compressor = CompressorHandle.DangerousGetHandle();
- CompressionResult result = LibComp.CompressBlock(compressor, buffer, default, true);
+
+ CompressionResult result = LibComp.CompressBlock(
+ CompressorHandle.DangerousGetHandle(),
+ buffer,
+ input: default,
+ finalBlock: true
+ );
+
return result.BytesWritten;
}
@@ -131,32 +153,42 @@ namespace VNLib.Net.Compression
public uint GetBlockSize()
{
CompressorHandle.ThrowIfClosed();
- IntPtr compressor = CompressorHandle.DangerousGetHandle();
- return LibComp.GetBlockSize(compressor);
+
+ return LibComp.GetBlockSize(
+ CompressorHandle.DangerousGetHandle()
+ );
}
///<inheritdoc/>
public uint GetCompressedSize(uint size)
{
CompressorHandle.ThrowIfClosed();
- IntPtr compressor = CompressorHandle.DangerousGetHandle();
- return (uint)LibComp.GetOutputSize(compressor, size, 1);
+
+ return (uint)LibComp.GetOutputSize(
+ CompressorHandle.DangerousGetHandle(),
+ size,
+ flush: 1 //truthy enables flushing
+ );
}
///<inheritdoc/>
public CompressionLevel GetCompressionLevel()
{
CompressorHandle.ThrowIfClosed();
- IntPtr compressor = CompressorHandle.DangerousGetHandle();
- return LibComp.GetCompressorLevel(compressor);
+
+ return LibComp.GetCompressorLevel(
+ CompressorHandle.DangerousGetHandle()
+ );
}
///<inheritdoc/>
public CompressionMethod GetCompressionMethod()
{
CompressorHandle.ThrowIfClosed();
- IntPtr compressor = CompressorHandle.DangerousGetHandle();
- return LibComp.GetCompressorType(compressor);
+
+ return LibComp.GetCompressorType(
+ CompressorHandle.DangerousGetHandle()
+ );
}
}
}
diff --git a/lib/Net.Compression/vnlib_compress/CMakeLists.txt b/lib/Net.Compression/vnlib_compress/CMakeLists.txt
index d0dbbb2..da27882 100644
--- a/lib/Net.Compression/vnlib_compress/CMakeLists.txt
+++ b/lib/Net.Compression/vnlib_compress/CMakeLists.txt
@@ -18,7 +18,10 @@ include(FetchContent)
#the compression source file is required, all other sources will be added
set(VNLIB_COMPRESS_SOURCES
+ src/util.h
+ src/platform.h
src/compression.c
+ src/compression.h
)
###############################
@@ -80,20 +83,6 @@ if(ENABLE_ZLIB)
add_compile_definitions(VNLIB_COMPRESSOR_ZLIB_ENABLED)
endif()
-#Add support for rpmalloc memmory allocator
-if(ENABLE_RPMALLOC)
-
- #enable greedy mode for rpmalloc
- set(ENABLE_GREEDY ON)
-
- add_subdirectory(
- ../../Utils.Memory/vnlib_rpmalloc/
- ${CMAKE_CURRENT_BINARY_DIR}/vnlib_rpmalloc/
- )
-
- add_compile_definitions(VNLIB_CUSTOM_MALLOC_ENABLE)
-endif()
-
###############################
#
# CONFIGURE LIBRARY BUILD
@@ -111,7 +100,7 @@ else()
add_library(${_COMP_PROJ_NAME} STATIC ${VNLIB_COMPRESS_SOURCES})
endif()
-target_compile_features(${_COMP_PROJ_NAME} PRIVATE c_std_90) #force compiler to use c90 standard for library
+target_compile_features(${_COMP_PROJ_NAME} PRIVATE c_std_99) #force compiler to use c90 standard for library
#if on unix lib will be appended, so we can adjust
if(UNIX)
@@ -135,15 +124,6 @@ if(ENABLE_ZLIB)
target_link_libraries(${_COMP_PROJ_NAME} PRIVATE zlib)
endif()
-#link rpmalloc to the main project
-if(ENABLE_RPMALLOC)
- target_link_libraries(${_COMP_PROJ_NAME} PRIVATE vnlib_rpmalloc_static)
- add_dependencies(${_COMP_PROJ_NAME} vnlib_rpmalloc_static)
-
- #Include the nativeheap api header
- target_include_directories(${_COMP_PROJ_NAME} PRIVATE ../../Utils.Memory/vnlib_rpmalloc/)
-endif()
-
#setup flags for windows compilation
if(MSVC)
target_compile_options(
@@ -209,15 +189,31 @@ else()
message(FATAL_ERROR "Unsupported compiler, sorry. Submit an issue for your platform and I'll work on it :)")
endif()
-if(NATIVE_HEAP_LIB_PATH)
-
- message(STATUS "Linking native heap library to the main project found at ${NATIVE_HEAP_LIB_PATH}")
+if(NATIVE_HEAP_NAME)
+
+ find_library(
+ _native_heap_lib
+ NAMES
+ ${NATIVE_HEAP_NAME}_static #attempt to load static library first
+ ${NATIVE_HEAP_NAME}
+
+ HINTS
+ ${NATIVE_HEAP_SRC}
+ ${NATIVE_HEAP_SRC}/build
+ ${NATIVE_HEAP_SRC}/build/${CMAKE_BUILD_TYPE}
+
+ NO_CACHE
+ REQUIRED
+ )
+
+ message(STATUS "Linking native heap library to the main project found at ${_native_heap_lib}")
#Include the nativeheap api header
include_directories(${NATIVE_HEAP_INCLUDES})
-
+
#If manual heap linking is enabled, we need to link the native heap library
- target_link_libraries(${_COMP_PROJ_NAME} PRIVATE ${NATIVE_HEAP_LIB_PATH})
- target_compile_definitions(${_COMP_PROJ_NAME} PRIVATE VNLIB_CUSTOM_MALLOC_ENABLE) #configure src
+ target_link_libraries(${_COMP_PROJ_NAME} PRIVATE ${_native_heap_lib})
+
+ target_compile_definitions(${_COMP_PROJ_NAME} PRIVATE VNLIB_CUSTOM_MALLOC_ENABLE) #enable native heap memory overrides
endif() \ No newline at end of file
diff --git a/lib/Net.Compression/vnlib_compress/Taskfile.yaml b/lib/Net.Compression/vnlib_compress/Taskfile.yaml
index 2133c0b..fec32d5 100644
--- a/lib/Net.Compression/vnlib_compress/Taskfile.yaml
+++ b/lib/Net.Compression/vnlib_compress/Taskfile.yaml
@@ -10,27 +10,44 @@ version: '3'
vars:
PROJECT_NAME: 'vnlib_compress'
+ RPMALLOC_SRC_DIR: '../../Utils.Memory/vnlib_rpmalloc'
+ BUILD_TYPE: '{{ .BUILD_TYPE | default "Release" }}'
tasks:
default:
+ desc: 'Builds the {{ .PROJECT_NAME }} library for the current platform'
cmds:
- cmd: echo "Building {{ .PROJECT_NAME }}"
silent: true
- - cmake -Bbuild/ -DCMAKE_BUILD_TYPE=Release {{ .CLI_ARGS }}
+
+ - cmake -Bbuild/ {{ .CLI_ARGS }}
+ '-DCMAKE_BUILD_TYPE={{ .BUILD_TYPE }}'
+
- cmake --build build/ --config Release
#called by ci pipline to build the winx64 project
build:
- cmds:
+ desc: 'DO NOT USE. This is an internal task'
+ platforms: [ windows ]
+ cmds:
#the CI pipline may have issues reading modules if the third-party dir is not cleaned every time a build runs, only an issue after build
- defer: { task: clean-third-party }
- #invoke cmake for build (notify that we are precompiling for ci pipeline and rpmalloc lib should be local)
- - cmake -B./build -DCI_PRECOMPILE=ON -DENABLE_RPMALLOC=ON
-
- #build for platform
+ #build the local rpmalloc library for linking
+ - task: build_rpmalloc
+ vars: { RPMALLOC_ARGS: '-DCMAKE_BUILD_TYPE={{ .BUILD_TYPE }}' }
+
+ #configure the build with rpmalloc since we know the source must be local during CI
+ - cmake -B./build {{ .CLI_ARGS }}
+ '-DCMAKE_BUILD_TYPE={{ .BUILD_TYPE }}'
+ '-DCI_PRECOMPILE=ON'
+ '-DNATIVE_HEAP_NAME=vnlib_rpmalloc_static'
+ '-DNATIVE_HEAP_SRC={{ .RPMALLOC_SRC_DIR }}'
+ '-DNATIVE_HEAP_INCLUDES={{ .RPMALLOC_SRC_DIR }}'
+
+ #build for platform, since Windows, build in both modes
- cmake --build build/ --config debug
- cmake --build build/ --config release
@@ -40,6 +57,11 @@ tasks:
- cmd: powershell mkdir -Force 'bin/'
- task: pack_parallel
+ build_rpmalloc:
+ internal: true
+ cmds:
+ - cmd: cd {{ .RPMALLOC_SRC_DIR }} && task build -- {{ .RPMALLOC_ARGS }}
+
pack_parallel:
internal: true
vars:
@@ -47,12 +69,14 @@ tasks:
REL_TAR_FILES:
"{{ .PROJECT_NAME }}.dll
{{ .PROJECT_NAME }}.lib
+ platform.h
compression.h
license.txt"
DEBUG_TAR_FILES:
"{{ .PROJECT_NAME }}.dll
{{ .PROJECT_NAME }}.pdb
{{ .PROJECT_NAME }}.lib
+ platform.h
compression.h
license.txt"
@@ -78,7 +102,9 @@ tasks:
internal: true
cmds:
- powershell cp ../LICENSE '{{ .TARGET }}/license.txt'
- - powershell cp src/compression.h '{{ .TARGET }}/compression.h'
+
+ - for: [ platform.h, compression.h ]
+ cmd: powershell cp 'src/{{ .ITEM }}' '{{ .TARGET }}/{{ .ITEM }}'
#packages source code for distribution
pack_source:
@@ -102,13 +128,14 @@ tasks:
#Remove the output dirs on clean
clean:
+ desc: 'Cleans any build artifcats and output directories'
ignore_error: true
cmds:
- for: [ bin/, build/ ]
cmd: powershell rm -Recurse '{{ .ITEM }}' -Force
clean-third-party:
- internal: false
+ internal: true
ignore_error: true
cmds:
- cmd: powershell rm -Recurse -Force 'build/_deps/'
diff --git a/lib/Net.Compression/vnlib_compress/src/compression.c b/lib/Net.Compression/vnlib_compress/src/compression.c
index 0cba998..fc648d5 100644
--- a/lib/Net.Compression/vnlib_compress/src/compression.c
+++ b/lib/Net.Compression/vnlib_compress/src/compression.c
@@ -31,16 +31,16 @@
#define VNLIB_COMPRESS_EXPORTING 1
-#include "compression.h"
#include "util.h"
+#include "compression.h"
#ifdef VNLIB_COMPRESSOR_BROTLI_ENABLED
-#include "feature_brotli.h"
+ #include "feature_brotli.h"
#endif /* VNLIB_COMPRESSOR_BROTLI_ENABLED */
#ifdef VNLIB_COMPRESSOR_ZLIB_ENABLED
-#include "feature_zlib.h"
+ #include "feature_zlib.h"
#endif /* VNLIB_COMPRESSOR_GZIP_ENABLED */
/*
@@ -75,33 +75,32 @@ VNLIB_COMPRESS_EXPORT CompressorType VNLIB_COMPRESS_CC GetSupportedCompressors(v
VNLIB_COMPRESS_EXPORT CompressorType VNLIB_COMPRESS_CC GetCompressorType(_In_ const void* compressor)
{
CHECK_NULL_PTR(compressor)
- return ((CompressorState*)compressor)->type;
+ return ((_cmp_state_t*)compressor)->type;
}
VNLIB_COMPRESS_EXPORT CompressionLevel VNLIB_COMPRESS_CC GetCompressorLevel(_In_ const void* compressor)
{
CHECK_NULL_PTR(compressor)
- return ((CompressorState*)compressor)->level;
+ return ((_cmp_state_t*)compressor)->level;
}
VNLIB_COMPRESS_EXPORT int64_t VNLIB_COMPRESS_CC GetCompressorBlockSize(_In_ const void* compressor)
{
CHECK_NULL_PTR(compressor)
- return (int64_t)((CompressorState*)compressor)->blockSize;
+ return (int64_t)((_cmp_state_t*)compressor)->blockSize;
}
VNLIB_COMPRESS_EXPORT void* VNLIB_COMPRESS_CC AllocateCompressor(CompressorType type, CompressionLevel level)
{
- int result;
- CompressorState* state;
-
/* Validate input arguments */
if (level < 0 || level > 9)
{
return (void*)ERR_COMP_LEVEL_NOT_SUPPORTED;
}
- state = (CompressorState*)vncalloc(1, sizeof(CompressorState));
+ int result = ERR_COMP_TYPE_NOT_SUPPORTED;
+
+ _cmp_state_t* state = (_cmp_state_t*)vncalloc(1, sizeof(_cmp_state_t));
if (!state)
{
@@ -110,9 +109,7 @@ VNLIB_COMPRESS_EXPORT void* VNLIB_COMPRESS_CC AllocateCompressor(CompressorType
/* Configure the comp state */
state->type = type;
- state->level = level;
-
- result = ERR_COMP_TYPE_NOT_SUPPORTED;
+ state->level = level;
/*
* Compressor types are defined at compile time
@@ -184,13 +181,11 @@ VNLIB_COMPRESS_EXPORT void* VNLIB_COMPRESS_CC AllocateCompressor(CompressorType
VNLIB_COMPRESS_EXPORT int VNLIB_COMPRESS_CC FreeCompressor(void* compressor)
{
- CompressorState* comp;
- int errorCode;
-
CHECK_NULL_PTR(compressor)
- comp = (CompressorState*)compressor;
- errorCode = TRUE;
+ int errorCode = VNCMP_SUCCESS;
+ _cmp_state_t* comp = (_cmp_state_t*)compressor;
+
switch (comp->type)
{
@@ -232,21 +227,22 @@ VNLIB_COMPRESS_EXPORT int VNLIB_COMPRESS_CC FreeCompressor(void* compressor)
return errorCode;
}
-VNLIB_COMPRESS_EXPORT int64_t VNLIB_COMPRESS_CC GetCompressedSize(_In_ const void* compressor, uint64_t inputLength, int32_t flush)
+VNLIB_COMPRESS_EXPORT int64_t VNLIB_COMPRESS_CC GetCompressedSize(
+ _In_ const void* compressor,
+ uint64_t inputLength,
+ int32_t flush
+)
{
- CompressorState* comp;
- int64_t result;
-
- CHECK_NULL_PTR(compressor)
+ _cmp_state_t* comp = (_cmp_state_t*)compressor;
+ int64_t result = ERR_COMP_TYPE_NOT_SUPPORTED;
+ CHECK_NULL_PTR(compressor);
+
if (inputLength > INT64_MAX)
{
- return ERR_OVERFLOW;
+ return ERR_OUT_OF_BOUNDS;
}
-
- comp = (CompressorState*)compressor;
- result = ERR_COMP_TYPE_NOT_SUPPORTED;
-
+
switch (comp->type)
{
@@ -286,10 +282,8 @@ VNLIB_COMPRESS_EXPORT int64_t VNLIB_COMPRESS_CC GetCompressedSize(_In_ const voi
*/
VNLIB_COMPRESS_EXPORT int VNLIB_COMPRESS_CC CompressBlock(_In_ const void* compressor, CompressionOperation* operation)
{
- int result;
- CompressorState* comp;
-
- comp = (CompressorState*)compressor;
+ int result = ERR_INVALID_ARGUMENT;
+ _cmp_state_t* comp = (_cmp_state_t*)compressor;
/*
* Validate input arguments
diff --git a/lib/Net.Compression/vnlib_compress/src/compression.h b/lib/Net.Compression/vnlib_compress/src/compression.h
index 3d03145..cc0dcd5 100644
--- a/lib/Net.Compression/vnlib_compress/src/compression.h
+++ b/lib/Net.Compression/vnlib_compress/src/compression.h
@@ -35,18 +35,16 @@
#pragma once
-#ifndef COMPRESSION_H_
-#define COMPRESSION_H_
+#ifndef _VNCMP_COMPRESSION_H_
+#define _VNCMP_COMPRESSION_H_
#include <stdint.h>
+#include "platform.h"
-#if defined(_MSC_VER) || defined(WIN32) || defined(_WIN32)
- #define _IS_WINDOWS
-#endif
/*Set api export calling convention(allow used to override)*/
#ifndef VNLIB_COMPRESS_CC
- #ifdef _IS_WINDOWS
+ #ifdef _VNCMP_IS_WINDOWS
/*STD for importing to other languages such as.NET*/
#define VNLIB_COMPRESS_CC __stdcall
#else
@@ -56,16 +54,16 @@
#ifndef VNLIB_COMPRESS_EXPORT /*Allow users to disable the export/impoty macro if using source code directly*/
#ifdef VNLIB_COMPRESS_EXPORTING
- #ifdef _IS_WINDOWS
+ #ifdef _VNCMP_IS_WINDOWS
#define VNLIB_COMPRESS_EXPORT __declspec(dllexport)
#else
#define VNLIB_COMPRESS_EXPORT __attribute__((visibility("default")))
#endif /* IS_WINDOWS */
#else
- #ifdef _IS_WINDOWS
+ #ifdef _VNCMP_IS_WINDOWS
#define VNLIB_COMPRESS_EXPORT __declspec(dllimport)
#else
- #define VNLIB_COMPRESS_EXPORT
+ #define VNLIB_COMPRESS_EXPORT extern
#endif /* IS_WINDOWS */
#endif /* !VNLIB_EXPORTING */
#endif /* !VNLIB_EXPORT */
@@ -74,18 +72,22 @@
#define _In_
#endif
+#define VNCMP_SUCCESS 1
+
/*
* ERRORS AND CONSTANTS
*/
-#define ERR_INVALID_PTR -1
-#define ERR_OUT_OF_MEMORY -2
-
-#define ERR_COMP_TYPE_NOT_SUPPORTED -9
-#define ERR_COMP_LEVEL_NOT_SUPPORTED -10
-#define ERR_INVALID_INPUT_DATA -11
-#define ERR_INVALID_OUTPUT_DATA -12
-#define ERR_COMPRESSION_FAILED -13
-#define ERR_OVERFLOW -14
+#define ERR_INVALID_PTR -1
+#define ERR_OUT_OF_MEMORY -2
+#define ERR_OUT_OF_BOUNDS -3
+#define ERR_INVALID_ARGUMENT -4
+
+#define ERR_COMP_TYPE_NOT_SUPPORTED -9
+#define ERR_COMP_LEVEL_NOT_SUPPORTED -10
+#define ERR_INVALID_INPUT_DATA -11
+#define ERR_INVALID_OUTPUT_DATA -12
+#define ERR_COMPRESSION_FAILED -13
+#define ERR_OVERFLOW -14
/*
* Enumerated list of supported compression types for user selection
@@ -93,11 +95,11 @@
*/
typedef enum CompressorType
{
- COMP_TYPE_NONE = 0x00,
- COMP_TYPE_GZIP = 0x01,
- COMP_TYPE_DEFLATE = 0x02,
- COMP_TYPE_BROTLI = 0x04,
- COMP_TYPE_LZ4 = 0x08
+ COMP_TYPE_NONE = 0x00,
+ COMP_TYPE_GZIP = 0x01,
+ COMP_TYPE_DEFLATE = 0x02,
+ COMP_TYPE_BROTLI = 0x04,
+ COMP_TYPE_LZ4 = 0x08
} CompressorType;
@@ -111,31 +113,31 @@ typedef enum CompressionLevel
The compression operation should be optimally compressed, even if the operation
takes a longer time to complete.
*/
- COMP_LEVEL_OPTIMAL = 0,
+ COMP_LEVEL_OPTIMAL = 0,
/*
The compression operation should complete as quickly as possible, even if the
resulting file is not optimally compressed.
*/
- COMP_LEVEL_FASTEST = 1,
+ COMP_LEVEL_FASTEST = 1,
/*
No compression should be performed on the file.
*/
- COMP_LEVEL_NO_COMPRESSION = 2,
+ COMP_LEVEL_NO_COMPRESSION = 2,
/*
The compression operation should create output as small as possible, even if
the operation takes a longer time to complete.
*/
- COMP_LEVEL_SMALLEST_SIZE = 3
+ COMP_LEVEL_SMALLEST_SIZE = 3
} CompressionLevel;
typedef enum CompressorStatus {
- COMPRESSOR_STATUS_READY = 0x00,
- COMPRESSOR_STATUS_INITALIZED = 0x01,
- COMPRESSOR_STATUS_NEEDS_FLUSH = 0x02
+ COMPRESSOR_STATUS_READY = 0x00,
+ COMPRESSOR_STATUS_INITALIZED = 0x01,
+ COMPRESSOR_STATUS_NEEDS_FLUSH = 0x02
} CompressorStatus;
-typedef struct CompressorStateStruct{
+typedef struct _vn_cmp_state_struct{
/*
Pointer to the underlying compressor implementation.
@@ -159,7 +161,7 @@ typedef struct CompressorStateStruct{
uint32_t blockSize;
-} CompressorState;
+} _cmp_state_t;
/*
* An extern caller generated structure passed to calls for
@@ -179,10 +181,10 @@ typedef struct CompressionOperationStruct {
/*
* If the operation is a flush operation
*/
- const int32_t flush;
+ int32_t flush;
- const uint32_t bytesInLength;
- const uint32_t bytesOutLength;
+ uint32_t bytesInLength;
+ uint32_t bytesOutLength;
/*
* Results of the streaming operation
@@ -248,7 +250,11 @@ VNLIB_COMPRESS_EXPORT int VNLIB_COMPRESS_CC FreeCompressor(void* compressor);
* @param inputLength The length of the input data in bytes.
* @return The maximum compressed size of the specified input data in bytes.
*/
-VNLIB_COMPRESS_EXPORT int64_t VNLIB_COMPRESS_CC GetCompressedSize(_In_ const void* compressor, uint64_t inputLength, int32_t flush);
+VNLIB_COMPRESS_EXPORT int64_t VNLIB_COMPRESS_CC GetCompressedSize(
+ _In_ const void* compressor,
+ uint64_t inputLength,
+ int32_t flush
+);
/*
@@ -258,6 +264,9 @@ VNLIB_COMPRESS_EXPORT int64_t VNLIB_COMPRESS_CC GetCompressedSize(_In_ const voi
* @param operation A pointer to the compression operation structure
* @return The underlying compressor's native return code
*/
-VNLIB_COMPRESS_EXPORT int VNLIB_COMPRESS_CC CompressBlock(_In_ const void* compressor, CompressionOperation* operation);
+VNLIB_COMPRESS_EXPORT int VNLIB_COMPRESS_CC CompressBlock(
+ _In_ const void* compressor,
+ CompressionOperation* operation
+);
#endif /* !VNLIB_COMPRESS_MAIN_H_ */ \ No newline at end of file
diff --git a/lib/Net.Compression/vnlib_compress/src/feature_brotli.c b/lib/Net.Compression/vnlib_compress/src/feature_brotli.c
index 361c61a..80c0de4 100644
--- a/lib/Net.Compression/vnlib_compress/src/feature_brotli.c
+++ b/lib/Net.Compression/vnlib_compress/src/feature_brotli.c
@@ -21,10 +21,9 @@
#include <brotli/encode.h>
#include "feature_brotli.h"
-#include "util.h"
#define validateCompState(state) \
- if (!state) return ERR_INVALID_PTR; \
+ CHECK_NULL_PTR(state); \
if (!state->compressor) return ERR_BR_INVALID_STATE; \
/*
@@ -32,13 +31,13 @@
*/
static void* _brAllocCallback(void* opaque, size_t size)
{
- (void)opaque;
+ (void)sizeof(opaque);
return vnmalloc(size, 1);
}
static void _brFreeCallback(void* opaque, void* address)
{
- (void)opaque;
+ (void)sizeof(opaque);
/*Brotli may pass a null address to the free callback*/
if (address)
@@ -48,11 +47,11 @@ static void _brFreeCallback(void* opaque, void* address)
}
-int BrAllocCompressor(CompressorState* state)
+int BrAllocCompressor(_cmp_state_t* state)
{
BrotliEncoderState* comp;
- assert(state != NULL);
+ DEBUG_ASSERT2(state != NULL, "Expected non-null compressor state argument");
/*
* Never allow no compression, it is not supported by the br encoder
@@ -119,12 +118,12 @@ int BrAllocCompressor(CompressorState* state)
break;
}
- return TRUE;
+ return VNCMP_SUCCESS;
}
-void BrFreeCompressor(CompressorState* state)
+void BrFreeCompressor(_cmp_state_t* state)
{
- assert(state != NULL);
+ DEBUG_ASSERT2(state != NULL, "Expected non-null state parameter");
/*
* Free the compressor instance if it exists
@@ -136,7 +135,7 @@ void BrFreeCompressor(CompressorState* state)
}
}
-int BrCompressBlock(const CompressorState* state, CompressionOperation* operation)
+int BrCompressBlock(_In_ const _cmp_state_t* state, CompressionOperation* operation)
{
BrotliEncoderOperation brOperation;
BROTLI_BOOL brResult;
@@ -145,6 +144,8 @@ int BrCompressBlock(const CompressorState* state, CompressionOperation* operatio
const uint8_t* nextIn;
uint8_t* nextOut;
+ DEBUG_ASSERT2(operation != NULL, "Expected non-null operation parameter");
+
/* Validate inputs */
validateCompState(state)
@@ -159,7 +160,7 @@ int BrCompressBlock(const CompressorState* state, CompressionOperation* operatio
if (operation->bytesInLength == 0 && operation->flush < 1)
{
- return TRUE;
+ return VNCMP_SUCCESS;
}
/*
@@ -221,7 +222,7 @@ int BrCompressBlock(const CompressorState* state, CompressionOperation* operatio
}
-int64_t BrGetCompressedSize(const CompressorState* state, uint64_t length, int32_t flush)
+int64_t BrGetCompressedSize(_In_ const _cmp_state_t* state, uint64_t length, int32_t flush)
{
size_t size;
diff --git a/lib/Net.Compression/vnlib_compress/src/feature_brotli.h b/lib/Net.Compression/vnlib_compress/src/feature_brotli.h
index 1f2090b..6b4bbca 100644
--- a/lib/Net.Compression/vnlib_compress/src/feature_brotli.h
+++ b/lib/Net.Compression/vnlib_compress/src/feature_brotli.h
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2023 Vaughn Nugent
+* Copyright (c) 2024 Vaughn Nugent
*
* Library: VNLib
* Package: vnlib_compress
@@ -24,6 +24,7 @@
#ifndef BROTLI_STUB_H_
#define BROTLI_STUB_H_
+#include "util.h"
#include "compression.h"
#define ERR_BR_INVALID_STATE -24
@@ -35,12 +36,12 @@
#define BR_DEFAULT_WINDOW 22
-int BrAllocCompressor(CompressorState* state);
+int BrAllocCompressor(_cmp_state_t* state);
-void BrFreeCompressor(CompressorState* state);
+void BrFreeCompressor(_cmp_state_t* state);
-int BrCompressBlock(const CompressorState* state, CompressionOperation* operation);
+int BrCompressBlock(_In_ const _cmp_state_t* state, CompressionOperation* operation);
-int64_t BrGetCompressedSize(const CompressorState* state, uint64_t length, int32_t flush);
+int64_t BrGetCompressedSize(_In_ const _cmp_state_t* state, uint64_t length, int32_t flush);
#endif /* !BROTLI_STUB_H_ */ \ No newline at end of file
diff --git a/lib/Net.Compression/vnlib_compress/src/feature_zlib.c b/lib/Net.Compression/vnlib_compress/src/feature_zlib.c
index a07f106..2358cb1 100644
--- a/lib/Net.Compression/vnlib_compress/src/feature_zlib.c
+++ b/lib/Net.Compression/vnlib_compress/src/feature_zlib.c
@@ -26,7 +26,6 @@
#include <zlib.h>
#include "feature_zlib.h"
-#include "util.h"
#define validateCompState(state) \
if (!state) return ERR_INVALID_PTR; \
@@ -37,28 +36,27 @@
*/
static void* _gzAllocCallback(void* opaque, uint32_t items, uint32_t size)
{
- (void)opaque;
+ (void)sizeof(opaque);
return vnmalloc(items, size);
}
static void _gzFreeCallback(void* opaque, void* address)
{
- (void)opaque;
+ (void)sizeof(opaque);
vnfree(address);
}
-int DeflateAllocCompressor(CompressorState* state)
+int DeflateAllocCompressor(_cmp_state_t* state)
{
int result, compLevel;
- z_stream* stream;
- assert(state);
+ DEBUG_ASSERT2(state, "Expected non-null state parameter");
/*
* Allocate the z-stream state on the heap so we can
* store it in the compressor state
*/
- stream = (z_stream*)vncalloc(1, sizeof(z_stream));
+ z_stream* stream = (z_stream*)vncalloc(1, sizeof(z_stream));
if (!stream)
{
@@ -146,14 +144,14 @@ int DeflateAllocCompressor(CompressorState* state)
* Assign the z-stream state to the compressor state, all done!
*/
state->compressor = stream;
- return TRUE;
+ return VNCMP_SUCCESS;
}
-int DeflateFreeCompressor(CompressorState* state)
+int DeflateFreeCompressor(_cmp_state_t* state)
{
int result;
- assert(state);
+ DEBUG_ASSERT2(state != NULL, "Expected non-null compressor state");
/*
* Free the z-stream state, only if the compressor is initialized
@@ -186,12 +184,11 @@ int DeflateFreeCompressor(CompressorState* state)
return result == Z_OK || result == Z_DATA_ERROR;
}
- return TRUE;
+ return VNCMP_SUCCESS;
}
-int DeflateCompressBlock(const CompressorState* state, CompressionOperation* operation)
+int DeflateCompressBlock(_In_ const _cmp_state_t* state, CompressionOperation* operation)
{
- z_stream* stream;
int result;
validateCompState(state)
@@ -207,10 +204,10 @@ int DeflateCompressBlock(const CompressorState* state, CompressionOperation* ope
if (operation->bytesInLength == 0 && operation->flush < 1)
{
- return TRUE;
+ return VNCMP_SUCCESS;
}
- stream = (z_stream*)state->compressor;
+ z_stream* stream = (z_stream*)state->compressor;
/*
* Overwrite the stream state with the operation parameters from
@@ -264,7 +261,7 @@ int DeflateCompressBlock(const CompressorState* state, CompressionOperation* ope
return result;
}
-int64_t DeflateGetCompressedSize(const CompressorState* state, uint64_t length, int32_t flush)
+int64_t DeflateGetCompressedSize(_In_ const _cmp_state_t* state, uint64_t length, int32_t flush)
{
uint64_t compressedSize;
diff --git a/lib/Net.Compression/vnlib_compress/src/feature_zlib.h b/lib/Net.Compression/vnlib_compress/src/feature_zlib.h
index 2544d25..089c3a0 100644
--- a/lib/Net.Compression/vnlib_compress/src/feature_zlib.h
+++ b/lib/Net.Compression/vnlib_compress/src/feature_zlib.h
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2023 Vaughn Nugent
+* Copyright (c) 2024 Vaughn Nugent
*
* Library: VNLib
* Package: vnlib_compress
@@ -24,6 +24,7 @@
#ifndef ZLIB_STUB_H_
#define ZLIB_STUB_H_
+#include "util.h"
#include "compression.h"
#define ERR_GZ_INVALID_STATE -16
@@ -31,20 +32,19 @@
/* Allow user to define their own memory level value */
#ifndef GZ_DEFAULT_MEM_LEVEL
-#define GZ_DEFAULT_MEM_LEVEL 8
+ #define GZ_DEFAULT_MEM_LEVEL 8
#endif
/* Specifies the window value to enable GZIP */
#define GZ_ENABLE_GZIP_WINDOW 15 + 16
#define GZ_ENABLE_RAW_DEFLATE_WINDOW -15
+int DeflateAllocCompressor(_cmp_state_t* state);
-int DeflateAllocCompressor(CompressorState* state);
+int DeflateFreeCompressor(_cmp_state_t* state);
-int DeflateFreeCompressor(CompressorState* state);
+int DeflateCompressBlock(_In_ const _cmp_state_t* state, CompressionOperation* operation);
-int DeflateCompressBlock(const CompressorState* state, CompressionOperation* operation);
-
-int64_t DeflateGetCompressedSize(const CompressorState* state, uint64_t length, int32_t flush);
+int64_t DeflateGetCompressedSize(_In_ const _cmp_state_t* state, uint64_t length, int32_t flush);
#endif
diff --git a/lib/Net.Compression/vnlib_compress/src/platform.h b/lib/Net.Compression/vnlib_compress/src/platform.h
new file mode 100644
index 0000000..b05c8b8
--- /dev/null
+++ b/lib/Net.Compression/vnlib_compress/src/platform.h
@@ -0,0 +1,90 @@
+/*
+* Copyright(c) 2024 Vaughn Nugent
+*
+* Library: VNLib
+* Package: vnlib_compress
+* File: platform.h
+*
+* vnlib_compress is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published
+* by the Free Software Foundation, either version 2 of the License,
+* or (at your option) any later version.
+*
+* vnlib_compress is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with vnlib_compress. If not, see http://www.gnu.org/licenses/.
+*/
+
+
+/*
+* Contains platform specific defintions
+*/
+
+#pragma once
+
+#ifndef _VNCMP_PLATFORM_H
+#define _VNCMP_PLATFORM_H
+
+#if defined(_MSC_VER) || defined(WIN32) || defined(_WIN32)
+ #define _VNCMP_IS_WINDOWS
+#elif defined(__linux__) || defined(__unix__) || defined(__posix__)
+ #define _VNCMP_IS_LINUX
+#elif defined(__APPLE__) || defined(__MACH__)
+ #define _VNCMP_IS_MAC
+#endif
+
+/*
+* Define supported inline defintions for various compilers
+* and C standards
+*/
+
+#if defined(_VNCMP_IS_WINDOWS) || defined(inline) || defined(__clang__)
+ #define _vncmp_inline inline
+#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 allows usage of inline keyword */
+ #define _vncmp_inline inline
+#elif defined(__GNUC__) || defined(__GNUG__)
+ #define _vncmp_inline __inline__
+#else
+ #define _vncmp_inline
+ #pragma message("Warning: No inline keyword defined for this compiler")
+#endif
+
+/* NULL */
+#ifndef NULL
+ #define NULL ((void*)0)
+#endif /* !NULL */
+
+#ifdef DEBUG
+ /* Must include assert.h for assertions */
+ #include <assert.h>
+ #define DEBUG_ASSERT(x) assert(x);
+ #define DEBUG_ASSERT2(x, message) assert(x && message);
+
+ /*
+ * Compiler enabled static assertion keywords are
+ * only available in C11 and later. Later versions
+ * have macros built-in from assert.h so we can use
+ * the static_assert macro directly.
+ *
+ * Static assertions are only used for testing such as
+ * sanity checks and this library targets the c89 standard
+ * so static_assret very likely will not be available.
+ */
+ #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
+ #define STATIC_ASSERT(x, m) static_assert(x, m);
+ #elif !defined(STATIC_ASSERT)
+ #define STATIC_ASSERT(x, m)
+ #pragma message("Static assertions are not supported by this language version")
+ #endif
+
+#else
+ #define DEBUG_ASSERT(x)
+ #define DEBUG_ASSERT2(x, message)
+ #define STATIC_ASSERT(x, m)
+#endif
+
+#endif // !VNCP_PLATFORM_H
diff --git a/lib/Net.Compression/vnlib_compress/src/util.h b/lib/Net.Compression/vnlib_compress/src/util.h
index 292e3bf..d1a1ddd 100644
--- a/lib/Net.Compression/vnlib_compress/src/util.h
+++ b/lib/Net.Compression/vnlib_compress/src/util.h
@@ -21,8 +21,10 @@
#pragma once
-#ifndef UTIL_H_
-#define UTIL_H_
+#ifndef _VNCMP_UTIL_H_
+#define _VNCMP_UTIL_H_
+
+#include "platform.h"
/*
* If a custom allocator is enabled, use the native heap api
@@ -30,48 +32,13 @@
* will be enabled when heapapi.h is included.
*/
#ifdef VNLIB_CUSTOM_MALLOC_ENABLE
- /* Since static linking ie snabled, heapapi must have extern symbol not dllimport */
+ # /* Since static linking ie snabled, heapapi must have extern symbol not dllimport */
#define VNLIB_HEAP_API extern
#include <NativeHeapApi.h>
#endif
-#if defined(_MSC_VER) || defined(WIN32) || defined(_WIN32)
- #define IS_WINDOWS
-#endif
-
-#if defined(IS_WINDOWS) || defined(inline) || defined(__clang__)
- #define _cp_fn_inline inline
-#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 allows usage of inline keyword */
- #define _cp_fn_inline inline
-#elif defined(__GNUC__) || defined(__GNUG__)
- #define _cp_fn_inline __inline__
-#else
- #define _cp_fn_inline
- #pragma message("Warning: No inline keyword defined for this compiler")
-#endif
-
-#ifndef NULL
- #define NULL ((void*)0)
-#endif /* !NULL */
-
-#ifndef TRUE
- #define TRUE 1
-#endif /* !TRUE */
-
-#ifndef FALSE
- #define FALSE 0
-#endif /* !FALSE */
-
-/*
-* Add debug runtime assertions
-*/
-#ifdef DEBUG
- #include <assert.h>
-#else
- #define assert(x) {}
-#endif
-
#define CHECK_NULL_PTR(ptr) if(!ptr) return ERR_INVALID_PTR;
+#define CHECK_ARG_RANGE(x, min, max) if(x < min || x > max) return ERR_OUT_OF_BOUNDS;
#ifdef NATIVE_HEAP_API /* Defined in the NativeHeapApi */
@@ -85,32 +52,22 @@
* api consistency.
*/
- static _cp_fn_inline void* vnmalloc(size_t num, size_t size)
+ static _vncmp_inline void* vnmalloc(size_t num, size_t size)
{
- return heapAlloc(heapGetSharedHeapHandle(), num, size, FALSE);
+ return heapAlloc(heapGetSharedHeapHandle(), num, size, 0);
}
- static _cp_fn_inline void* vncalloc(size_t num, size_t size)
+ static _vncmp_inline void* vncalloc(size_t num, size_t size)
{
- return heapAlloc(heapGetSharedHeapHandle(), num, size, TRUE);
+ return heapAlloc(heapGetSharedHeapHandle(), num, size, 1);
}
- static _cp_fn_inline void vnfree(void* ptr)
+ static _vncmp_inline void vnfree(void* ptr)
{
- #ifdef DEBUG
-
- ERRNO result;
- result = heapFree(heapGetSharedHeapHandle(), ptr);
+ ERRNO result = heapFree(heapGetSharedHeapHandle(), ptr);
/* track failed free results */
- assert(result > 0);
-
- #else
-
- heapFree(heapGetSharedHeapHandle(), ptr);
-
- #endif
-
+ DEBUG_ASSERT(result > 0);
}
#else
diff --git a/lib/Net.Compression/vnlib_compress/src/vnlib_compress.vcxitems b/lib/Net.Compression/vnlib_compress/src/vnlib_compress.vcxitems
index 7f5eb0e..b871fde 100644
--- a/lib/Net.Compression/vnlib_compress/src/vnlib_compress.vcxitems
+++ b/lib/Net.Compression/vnlib_compress/src/vnlib_compress.vcxitems
@@ -21,6 +21,7 @@
<ItemGroup>
<ClInclude Include="$(MSBuildThisFileDirectory)feature_brotli.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)compression.h" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)platform.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)util.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)feature_zlib.h" />
</ItemGroup>