Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: openkim/kim-api
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: ef8c6f55ddc2818ed4507a5907f4c15609b82b46
Choose a base ref
..
head repository: openkim/kim-api
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 1ddb0ed0530f993be52477b39fd92c223a992166
Choose a head ref
Showing with 33 additions and 0 deletions.
  1. +11 −0 CMakeLists.txt
  2. +22 −0 cpp/src/KIM_SharedLibrary.cpp
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -50,6 +50,9 @@ endif()

message(STATUS "KIM-API Build Type: ${CMAKE_BUILD_TYPE}")

# C++ Language Standard, enforced to be C++11
# set(CMAKE_CXX_STANDARD 11)

set_cache_with_fallback(KIM_API_LOG_MAXIMUM_LEVEL "${_LOG_MAX}" STRING "Maximum log verbosity")
unset(_LOG_MAX)
set_property(CACHE KIM_API_LOG_MAXIMUM_LEVEL PROPERTY STRINGS "" SILENT FATAL ERROR WARNING INFORMATION DEBUG)
@@ -160,6 +163,14 @@ if(NOT WIN32 OR CYGWIN)
endif()


# Keeping the name XXD for now, as otherwise this will result in much larger refactoring
# But everywhere, XXD = base64-encode
set(XXD_EXECUTABLE ${PROJECT_BINARY_DIR}/utils/base64-encode)
add_subdirectory(cpp/src/base64-encode)
add_dependencies(kim-api base64-encode)
install(TARGETS base64-encode
RUNTIME DESTINATION ${CMAKE_INSTALL_RELOC_BINDIR})

# Add install rules for kim-api
#
install(TARGETS kim-api
22 changes: 22 additions & 0 deletions cpp/src/KIM_SharedLibrary.cpp
Original file line number Diff line number Diff line change
@@ -55,6 +55,10 @@
#include "KIM_SharedLibrarySchema.hpp"
#endif

#ifndef BASE64_HPP
#include "base64-encode/base64.hpp" // For base64 decoding
#endif

namespace
{
static void * const referencePointForKIM_Library = NULL;
@@ -647,6 +651,14 @@ int SharedLibrary::WriteParameterFileDirectory()
fl.open(specificationFilePathName.string().c_str(),
std::ifstream::out | std::ifstream::binary);

std::vector<char> binary_line;
binary_line.reserve(base64::decoded_size(len));
std::pair<std::size_t, std::size_t> char_out_and_char_in
= base64::decode(binary_line.data(), specificationData, len);

fl.write(reinterpret_cast<char *>(binary_line.data()),
static_cast<std::streamsize>(char_out_and_char_in.first));

if (!fl)
{
LOG_ERROR("Unable to get write parameter file.");
@@ -679,6 +691,16 @@ int SharedLibrary::WriteParameterFileDirectory()
fl.open(parameterFilePathName.string().c_str(),
std::ifstream::out | std::ifstream::binary);

int usable_chars = static_cast<int>(
length); // unsigned int to signed to avoid underflow

std::vector<char> binary_line;
binary_line.reserve(base64::decoded_size(length));
std::pair<std::size_t, std::size_t> char_out_and_char_in
= base64::decode(binary_line.data(), strPtr, usable_chars);

fl.write(reinterpret_cast<char *>(binary_line.data()),
static_cast<std::streamsize>(char_out_and_char_in.first));
if (!fl)
{
LOG_ERROR("Unable to get write parameter file.");