Skip to content
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

Fix C/C++ libb64 ABI incompatibility bug #817

Merged
merged 1 commit into from
Jan 16, 2025
Merged
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
6 changes: 3 additions & 3 deletions src/c++/library/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2020-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# Copyright (c) 2020-2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -364,7 +364,7 @@ if(TRITON_ENABLE_CC_HTTP)
# libhttpclient object build
set(
REQUEST_SRCS
http_client.cc common.cc cencode.c
http_client.cc common.cc cencode.cc
)

set(
Expand All @@ -379,7 +379,7 @@ if(TRITON_ENABLE_CC_HTTP)

if (NOT WIN32)
set_property(
SOURCE cencode.c
SOURCE cencode.cc
PROPERTY COMPILE_FLAGS -Wno-implicit-fallthrough
)
endif() # NOT WIN32
Expand Down
4 changes: 4 additions & 0 deletions src/c++/library/cencode.c → src/c++/library/cencode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ For details, see http://sourceforge.net/projects/libb64

#include "cencode.h"

namespace triton::client::libb64 {

const int CHARS_PER_LINE = 72;

void
Expand Down Expand Up @@ -107,3 +109,5 @@ base64_encode_blockend(char* code_out, base64_encodestate* state_in)

return codechar - code_out;
}

} // namespace triton::client::libb64
4 changes: 4 additions & 0 deletions src/c++/library/cencode.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ For details, see http://sourceforge.net/projects/libb64
#ifndef BASE64_CENCODE_H
#define BASE64_CENCODE_H

namespace triton::client::libb64 {

typedef enum { step_A, step_B, step_C } base64_encodestep;

typedef struct {
Expand All @@ -26,4 +28,6 @@ int base64_encode_block(

int base64_encode_blockend(char* code_out, base64_encodestate* state_in);

} // namespace triton::client::libb64

#endif /* BASE64_CENCODE_H */
12 changes: 6 additions & 6 deletions src/c++/library/http_client.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// Copyright 2020-2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -44,9 +44,7 @@
#include <zlib.h>
#endif

extern "C" {
#include "cencode.h"
}

#define TRITONJSON_STATUSTYPE triton::client::Error
#define TRITONJSON_STATUSRETURN(M) return triton::client::Error(M)
Expand Down Expand Up @@ -132,11 +130,13 @@ Base64Encode(
int* encoded_size)
{
// Encode the handle object to base64
base64_encodestate es;
libb64::base64_encodestate es;
base64_init_encodestate(&es);
*encoded_ptr = (char*)malloc(raw_size * 2); /* ~4/3 x raw_size */
*encoded_size = base64_encode_block(raw_ptr, raw_size, *encoded_ptr, &es);
int padding_size = base64_encode_blockend(*encoded_ptr + *encoded_size, &es);
*encoded_size =
libb64::base64_encode_block(raw_ptr, raw_size, *encoded_ptr, &es);
int padding_size =
libb64::base64_encode_blockend(*encoded_ptr + *encoded_size, &es);
*encoded_size += padding_size;
}

Expand Down
Loading