Skip to content

Fix conflicting exported Brotli APIs #2149

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

Open
wants to merge 2 commits into
base: unity-6000.3-mbe
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Runtime.InteropServices;

namespace Microsoft.Win32.SafeHandles
{
internal sealed class SafeBrotliEncoderHandle : SafeHandle
{
public SafeBrotliEncoderHandle() : base(IntPtr.Zero, true) { }

protected override bool ReleaseHandle()
{
Interop.Brotli.BrotliEncoderDestroyInstance(handle);
return true;
}

public override bool IsInvalid => handle == IntPtr.Zero;
}

internal sealed class SafeBrotliDecoderHandle : SafeHandle
{
public SafeBrotliDecoderHandle() : base(IntPtr.Zero, true) { }

protected override bool ReleaseHandle()
{
Interop.Brotli.BrotliDecoderDestroyInstance(handle);
return true;
}

public override bool IsInvalid => handle == IntPtr.Zero;
}
}
14 changes: 7 additions & 7 deletions external/corefx-bugfix/src/Native/AnyOS/brotli/dec/decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ BROTLI_BOOL BrotliDecoderSetParameter(
}
}

DLLEXPORT BrotliDecoderState* BrotliDecoderCreateInstance(
DLLEXPORT BrotliDecoderState* MonoBrotliDecoderCreateInstance(
brotli_alloc_func alloc_func, brotli_free_func free_func, void* opaque) {
BrotliDecoderState* state = 0;
if (!alloc_func && !free_func) {
Expand All @@ -99,7 +99,7 @@ DLLEXPORT BrotliDecoderState* BrotliDecoderCreateInstance(
}

/* Deinitializes and frees BrotliDecoderState instance. */
DLLEXPORT void BrotliDecoderDestroyInstance(BrotliDecoderState* state) {
DLLEXPORT void MonoBrotliDecoderDestroyInstance(BrotliDecoderState* state) {
if (!state) {
return;
} else {
Expand Down Expand Up @@ -2032,7 +2032,7 @@ static BROTLI_NOINLINE BrotliDecoderErrorCode SafeProcessCommands(
return ProcessCommandsInternal(1, s);
}

DLLEXPORT BrotliDecoderResult BrotliDecoderDecompress(
DLLEXPORT BrotliDecoderResult MonoBrotliDecoderDecompress(
size_t encoded_size, const uint8_t* encoded_buffer, size_t* decoded_size,
uint8_t* decoded_buffer) {
BrotliDecoderState s;
Expand All @@ -2045,7 +2045,7 @@ DLLEXPORT BrotliDecoderResult BrotliDecoderDecompress(
if (!BrotliDecoderStateInit(&s, 0, 0, 0)) {
return BROTLI_DECODER_RESULT_ERROR;
}
result = BrotliDecoderDecompressStream(
result = MonoBrotliDecoderDecompressStream(
&s, &available_in, &next_in, &available_out, &next_out, &total_out);
*decoded_size = total_out;
BrotliDecoderStateCleanup(&s);
Expand All @@ -2066,7 +2066,7 @@ DLLEXPORT BrotliDecoderResult BrotliDecoderDecompress(
buffer ahead of time
- when result is "success" decoder MUST return all unused data back to input
buffer; this is possible because the invariant is held on enter */
DLLEXPORT BrotliDecoderResult BrotliDecoderDecompressStream(
DLLEXPORT BrotliDecoderResult MonoBrotliDecoderDecompressStream(
BrotliDecoderState* s, size_t* available_in, const uint8_t** next_in,
size_t* available_out, uint8_t** next_out, size_t* total_out) {
BrotliDecoderErrorCode result = BROTLI_DECODER_SUCCESS;
Expand Down Expand Up @@ -2565,7 +2565,7 @@ const uint8_t* BrotliDecoderTakeOutput(BrotliDecoderState* s, size_t* size) {
*size = requested_out - available_out;
} else {
/* ... or stream is broken. Normally this should be caught by
BrotliDecoderDecompressStream, this is just a safeguard. */
MonoBrotliDecoderDecompressStream, this is just a safeguard. */
if ((int)status < 0) SaveErrorCode(s, status);
*size = 0;
result = 0;
Expand All @@ -2578,7 +2578,7 @@ BROTLI_BOOL BrotliDecoderIsUsed(const BrotliDecoderState* s) {
BrotliGetAvailableBits(&s->br) != 0);
}

DLLEXPORT BROTLI_BOOL BrotliDecoderIsFinished(const BrotliDecoderState* s) {
DLLEXPORT BROTLI_BOOL MonoBrotliDecoderIsFinished(const BrotliDecoderState* s) {
return TO_BROTLI_BOOL(s->state == BROTLI_STATE_DONE) &&
!BrotliDecoderHasMoreOutput(s);
}
Expand Down
30 changes: 15 additions & 15 deletions external/corefx-bugfix/src/Native/AnyOS/brotli/enc/encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ static size_t RemainingInputBlockSize(BrotliEncoderState* s) {
return block_size - (size_t)delta;
}

DLLEXPORT BROTLI_BOOL BrotliEncoderSetParameter(
DLLEXPORT BROTLI_BOOL MonoBrotliEncoderSetParameter(
BrotliEncoderState* state, BrotliEncoderParameter p, uint32_t value) {
/* Changing parameters on the fly is not implemented yet. */
if (state->is_initialized_) return BROTLI_FALSE;
Expand Down Expand Up @@ -794,7 +794,7 @@ static void BrotliEncoderInitState(BrotliEncoderState* s) {
memcpy(s->saved_dist_cache_, s->dist_cache_, sizeof(s->saved_dist_cache_));
}

DLLEXPORT BrotliEncoderState* BrotliEncoderCreateInstance(
DLLEXPORT BrotliEncoderState* MonoBrotliEncoderCreateInstance(
brotli_alloc_func alloc_func, brotli_free_func free_func, void* opaque) {
BrotliEncoderState* state = 0;
if (!alloc_func && !free_func) {
Expand Down Expand Up @@ -828,7 +828,7 @@ static void BrotliEncoderCleanupState(BrotliEncoderState* s) {
}

/* Deinitializes and frees BrotliEncoderState instance. */
DLLEXPORT void BrotliEncoderDestroyInstance(BrotliEncoderState* state) {
DLLEXPORT void MonoBrotliEncoderDestroyInstance(BrotliEncoderState* state) {
if (!state) {
return;
} else {
Expand Down Expand Up @@ -1468,7 +1468,7 @@ static size_t MakeUncompressedStream(
return result;
}

DLLEXPORT BROTLI_BOOL BrotliEncoderCompress(
DLLEXPORT BROTLI_BOOL MonoBrotliEncoderCompress(
int quality, int lgwin, BrotliEncoderMode mode, size_t input_size,
const uint8_t* input_buffer, size_t* encoded_size,
uint8_t* encoded_buffer) {
Expand Down Expand Up @@ -1499,7 +1499,7 @@ DLLEXPORT BROTLI_BOOL BrotliEncoderCompress(
return BROTLI_TRUE;
}

s = BrotliEncoderCreateInstance(0, 0, 0);
s = MonoBrotliEncoderCreateInstance(0, 0, 0);
if (!s) {
return BROTLI_FALSE;
} else {
Expand All @@ -1509,18 +1509,18 @@ DLLEXPORT BROTLI_BOOL BrotliEncoderCompress(
uint8_t* next_out = encoded_buffer;
size_t total_out = 0;
BROTLI_BOOL result = BROTLI_FALSE;
BrotliEncoderSetParameter(s, BROTLI_PARAM_QUALITY, (uint32_t)quality);
BrotliEncoderSetParameter(s, BROTLI_PARAM_LGWIN, (uint32_t)lgwin);
BrotliEncoderSetParameter(s, BROTLI_PARAM_MODE, (uint32_t)mode);
BrotliEncoderSetParameter(s, BROTLI_PARAM_SIZE_HINT, (uint32_t)input_size);
MonoBrotliEncoderSetParameter(s, BROTLI_PARAM_QUALITY, (uint32_t)quality);
MonoBrotliEncoderSetParameter(s, BROTLI_PARAM_LGWIN, (uint32_t)lgwin);
MonoBrotliEncoderSetParameter(s, BROTLI_PARAM_MODE, (uint32_t)mode);
MonoBrotliEncoderSetParameter(s, BROTLI_PARAM_SIZE_HINT, (uint32_t)input_size);
if (lgwin > BROTLI_MAX_WINDOW_BITS) {
BrotliEncoderSetParameter(s, BROTLI_PARAM_LARGE_WINDOW, BROTLI_TRUE);
MonoBrotliEncoderSetParameter(s, BROTLI_PARAM_LARGE_WINDOW, BROTLI_TRUE);
}
result = BrotliEncoderCompressStream(s, BROTLI_OPERATION_FINISH,
result = MonoBrotliEncoderCompressStream(s, BROTLI_OPERATION_FINISH,
&available_in, &next_in, &available_out, &next_out, &total_out);
if (!BrotliEncoderIsFinished(s)) result = 0;
*encoded_size = total_out;
BrotliEncoderDestroyInstance(s);
MonoBrotliEncoderDestroyInstance(s);
if (!result || (max_out_size && *encoded_size > max_out_size)) {
goto fallback;
}
Expand Down Expand Up @@ -1801,7 +1801,7 @@ static void UpdateSizeHint(BrotliEncoderState* s, size_t available_in) {
}
}

DLLEXPORT BROTLI_BOOL BrotliEncoderCompressStream(
DLLEXPORT BROTLI_BOOL MonoBrotliEncoderCompressStream(
BrotliEncoderState* s, BrotliEncoderOperation op, size_t* available_in,
const uint8_t** next_in, size_t* available_out,uint8_t** next_out,
size_t* total_out) {
Expand Down Expand Up @@ -1892,10 +1892,10 @@ DLLEXPORT BROTLI_BOOL BrotliEncoderCompressStream(

BROTLI_BOOL BrotliEncoderIsFinished(BrotliEncoderState* s) {
return TO_BROTLI_BOOL(s->stream_state_ == BROTLI_STREAM_FINISHED &&
!BrotliEncoderHasMoreOutput(s));
!MonoBrotliEncoderHasMoreOutput(s));
}

DLLEXPORT BROTLI_BOOL BrotliEncoderHasMoreOutput(BrotliEncoderState* s) {
DLLEXPORT BROTLI_BOOL MonoBrotliEncoderHasMoreOutput(BrotliEncoderState* s) {
return TO_BROTLI_BOOL(s->available_out_ != 0);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ extern "C" {
/**
* Opaque structure that holds decoder state.
*
* Allocated and initialized with ::BrotliDecoderCreateInstance.
* Cleaned up and deallocated with ::BrotliDecoderDestroyInstance.
* Allocated and initialized with ::MonoBrotliDecoderCreateInstance.
* Cleaned up and deallocated with ::MonoBrotliDecoderDestroyInstance.
*/
typedef struct BrotliDecoderStateStruct BrotliDecoderState;

/**
* Result type for ::BrotliDecoderDecompress and
* ::BrotliDecoderDecompressStream functions.
* Result type for ::MonoBrotliDecoderDecompress and
* ::MonoBrotliDecoderDecompressStream functions.
*/
typedef enum {
/** Decoding error, e.g. corrupted input or memory allocation problem. */
Expand Down Expand Up @@ -158,7 +158,7 @@ BROTLI_DEC_API BROTLI_BOOL BrotliDecoderSetParameter(
* Creates an instance of ::BrotliDecoderState and initializes it.
*
* The instance can be used once for decoding and should then be destroyed with
* ::BrotliDecoderDestroyInstance, it cannot be reused for a new decoding
* ::MonoBrotliDecoderDestroyInstance, it cannot be reused for a new decoding
* session.
*
* @p alloc_func and @p free_func @b MUST be both zero or both non-zero. In the
Expand All @@ -172,15 +172,15 @@ BROTLI_DEC_API BROTLI_BOOL BrotliDecoderSetParameter(
* @returns @c 0 if instance can not be allocated or initialized
* @returns pointer to initialized ::BrotliDecoderState otherwise
*/
BROTLI_DEC_API BrotliDecoderState* BrotliDecoderCreateInstance(
BROTLI_DEC_API BrotliDecoderState* MonoBrotliDecoderCreateInstance(
brotli_alloc_func alloc_func, brotli_free_func free_func, void* opaque);

/**
* Deinitializes and frees ::BrotliDecoderState instance.
*
* @param state decoder instance to be cleaned up and deallocated
*/
BROTLI_DEC_API void BrotliDecoderDestroyInstance(BrotliDecoderState* state);
BROTLI_DEC_API void MonoBrotliDecoderDestroyInstance(BrotliDecoderState* state);

/**
* Performs one-shot memory-to-memory decompression.
Expand All @@ -199,7 +199,7 @@ BROTLI_DEC_API void BrotliDecoderDestroyInstance(BrotliDecoderState* state);
* allocation failed, or @p decoded_buffer is not large enough;
* @returns ::BROTLI_DECODER_RESULT_SUCCESS otherwise
*/
BROTLI_DEC_API BrotliDecoderResult BrotliDecoderDecompress(
BROTLI_DEC_API BrotliDecoderResult MonoBrotliDecoderDecompress(
size_t encoded_size,
const uint8_t encoded_buffer[BROTLI_ARRAY_PARAM(encoded_size)],
size_t* decoded_size,
Expand Down Expand Up @@ -243,7 +243,7 @@ BROTLI_DEC_API BrotliDecoderResult BrotliDecoderDecompress(
* @returns ::BROTLI_DECODER_RESULT_SUCCESS decoding is finished, no more
* input might be consumed and no more output will be produced
*/
BROTLI_DEC_API BrotliDecoderResult BrotliDecoderDecompressStream(
BROTLI_DEC_API BrotliDecoderResult MonoBrotliDecoderDecompressStream(
BrotliDecoderState* state, size_t* available_in, const uint8_t** next_in,
size_t* available_out, uint8_t** next_out, size_t* total_out);

Expand All @@ -261,7 +261,7 @@ BROTLI_DEC_API BROTLI_BOOL BrotliDecoderHasMoreOutput(
* Acquires pointer to internal output buffer.
*
* This method is used to make language bindings easier and more efficient:
* -# push data to ::BrotliDecoderDecompressStream,
* -# push data to ::MonoBrotliDecoderDecompressStream,
* until ::BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT is reported
* -# use ::BrotliDecoderTakeOutput to peek bytes and copy to language-specific
* entity
Expand Down Expand Up @@ -308,13 +308,13 @@ BROTLI_DEC_API BROTLI_BOOL BrotliDecoderIsUsed(const BrotliDecoderState* state);
* the input and produced all of the output
* @returns ::BROTLI_FALSE otherwise
*/
BROTLI_DEC_API BROTLI_BOOL BrotliDecoderIsFinished(
BROTLI_DEC_API BROTLI_BOOL MonoBrotliDecoderIsFinished(
const BrotliDecoderState* state);

/**
* Acquires a detailed error code.
*
* Should be used only after ::BrotliDecoderDecompressStream returns
* Should be used only after ::MonoBrotliDecoderDecompressStream returns
* ::BROTLI_DECODER_RESULT_ERROR.
*
* See also ::BrotliDecoderErrorString
Expand Down
Loading