From 811dbf8d7416a5446d2175ea2325e165c7019766 Mon Sep 17 00:00:00 2001 From: Andrei Medar Date: Thu, 24 Sep 2020 18:17:27 +0000 Subject: [PATCH] applied requested changes. Modified sapi::StatusOr to absl::StatusOr --- oss-internship-2020/sapi_lodepng/.gitignore | 1 + oss-internship-2020/sapi_lodepng/CMakeLists.txt | 3 ++- oss-internship-2020/sapi_lodepng/README.md | 2 +- oss-internship-2020/sapi_lodepng/examples/CMakeLists.txt | 1 + oss-internship-2020/sapi_lodepng/examples/helpers.cc | 4 +++- .../sapi_lodepng/examples/main_sandboxed.cc | 4 ++-- .../sapi_lodepng/examples/main_unsandboxed.cc | 7 +++++-- 7 files changed, 15 insertions(+), 7 deletions(-) diff --git a/oss-internship-2020/sapi_lodepng/.gitignore b/oss-internship-2020/sapi_lodepng/.gitignore index 0e9807b..436efe7 100644 --- a/oss-internship-2020/sapi_lodepng/.gitignore +++ b/oss-internship-2020/sapi_lodepng/.gitignore @@ -1,2 +1,3 @@ build/ .clang-format +.cache diff --git a/oss-internship-2020/sapi_lodepng/CMakeLists.txt b/oss-internship-2020/sapi_lodepng/CMakeLists.txt index 36ae846..2371039 100644 --- a/oss-internship-2020/sapi_lodepng/CMakeLists.txt +++ b/oss-internship-2020/sapi_lodepng/CMakeLists.txt @@ -37,7 +37,8 @@ add_library(lodepng STATIC target_include_directories(lodepng PUBLIC "${PROJECT_BINARY_DIR}/lodepng") # Build SAPI library -set(SAPI_ROOT "${PROJECT_SOURCE_DIR}/../.." CACHE PATH "Path to the Sandboxed API source tree") +#set(SAPI_ROOT "${PROJECT_SOURCE_DIR}/../.." CACHE PATH "Path to the Sandboxed API source tree") +set(SAPI_ROOT "/usr/local/google/home/amedar/internship/sandboxed-api" CACHE PATH "Path to the Sandboxed API source tree") add_subdirectory("${SAPI_ROOT}" "${CMAKE_BINARY_DIR}/sandboxed-api-build" diff --git a/oss-internship-2020/sapi_lodepng/README.md b/oss-internship-2020/sapi_lodepng/README.md index 0984f4b..e418f6e 100644 --- a/oss-internship-2020/sapi_lodepng/README.md +++ b/oss-internship-2020/sapi_lodepng/README.md @@ -4,7 +4,7 @@ Sandboxed version of the [LodePNG](https://github.com/lvandeve/lodepng) library, ## Details -With Sandboxed API, many of the library's functions can be sandboxed. However, they need the `extern "C"` keyword defined so that name mangling does not happen, which is why a fork of the **LodePNG** library is used. The only differences are found in the header file. An alternative to this is to define another library that wraps every needed function, specifying the required keyword. +With Sandboxed API, many of the library's functions can be sandboxed. However, they need the `extern "C"` keyword defined so that name mangling does not happen, which is why a patch that adds it is used. The only differences are found in the header file. An alternative to this is to define another library that wraps every needed function, specifying the required keyword. Even if many of the functions from the library can be sandboxed, there are some that are not supported (those which have `std::vector` parameters, overloaded functions etc.). If you really need these functions, a solution is to implement a custom library that wraps around these functions in order to make them compatible. diff --git a/oss-internship-2020/sapi_lodepng/examples/CMakeLists.txt b/oss-internship-2020/sapi_lodepng/examples/CMakeLists.txt index 1d6b38d..4b35f9b 100644 --- a/oss-internship-2020/sapi_lodepng/examples/CMakeLists.txt +++ b/oss-internship-2020/sapi_lodepng/examples/CMakeLists.txt @@ -22,6 +22,7 @@ target_link_libraries(lodepng_unsandboxed PRIVATE lodepng sapi::sapi sandbox2::temp_file + sandbox2::file_base sandbox2::fileops glog::glog ) diff --git a/oss-internship-2020/sapi_lodepng/examples/helpers.cc b/oss-internship-2020/sapi_lodepng/examples/helpers.cc index 4bd4f98..5c4d0eb 100644 --- a/oss-internship-2020/sapi_lodepng/examples/helpers.cc +++ b/oss-internship-2020/sapi_lodepng/examples/helpers.cc @@ -14,6 +14,8 @@ #include "helpers.h" +#include "sandboxed_api/sandbox2/util/temp_file.h" + std::vector GenerateValues() { std::vector image; image.reserve(kImgLen); @@ -35,7 +37,7 @@ std::string CreateTempDirAtCWD() { CHECK(!cwd.empty()) << "Could not get current working directory"; cwd.append("/"); - sapi::StatusOr result = sandbox2::CreateTempDir(cwd); + absl::StatusOr result = sandbox2::CreateTempDir(cwd); CHECK(result.ok()) << "Could not create temporary directory"; return result.value(); } diff --git a/oss-internship-2020/sapi_lodepng/examples/main_sandboxed.cc b/oss-internship-2020/sapi_lodepng/examples/main_sandboxed.cc index fd612fa..a15ac66 100644 --- a/oss-internship-2020/sapi_lodepng/examples/main_sandboxed.cc +++ b/oss-internship-2020/sapi_lodepng/examples/main_sandboxed.cc @@ -30,7 +30,7 @@ void EncodeDecodeOneStep(SapiLodepngSandbox& sandbox, LodepngApi& api) { sapi::v::ConstCStr sapi_filename("/output/out_generated1.png"); - sapi::StatusOr result = api.lodepng_encode32_file( + absl::StatusOr result = api.lodepng_encode32_file( sapi_filename.PtrBefore(), sapi_image.PtrBefore(), kWidth, kHeight); CHECK(result.ok()) << "encode32_file call failed"; @@ -90,7 +90,7 @@ void EncodeDecodeTwoSteps(SapiLodepngSandbox& sandbox, LodepngApi& api) { sapi::v::IntBase sapi_png_ptr(0); // Encode it into memory. - sapi::StatusOr result = + absl::StatusOr result = api.lodepng_encode32(sapi_png_ptr.PtrBoth(), sapi_pngsize.PtrBoth(), sapi_image.PtrBefore(), kWidth, kHeight); diff --git a/oss-internship-2020/sapi_lodepng/examples/main_unsandboxed.cc b/oss-internship-2020/sapi_lodepng/examples/main_unsandboxed.cc index 82fe168..1074dde 100644 --- a/oss-internship-2020/sapi_lodepng/examples/main_unsandboxed.cc +++ b/oss-internship-2020/sapi_lodepng/examples/main_unsandboxed.cc @@ -19,13 +19,15 @@ #include "helpers.h" #include "lodepng.h" #include "sandboxed_api/sandbox2/util/fileops.h" +#include "sandboxed_api/sandbox2/util/path.h" void EncodeDecodeOneStep(const std::string& images_path) { // Generate the values. std::vector image = GenerateValues(); // Encode the image. - const std::string filename = images_path + "/out_generated1.png"; + const std::string filename = + sandbox2::file::JoinPath(images_path, "/out_generated1.png"); unsigned int result = lodepng_encode32_file(filename.c_str(), image.data(), kWidth, kHeight); @@ -55,7 +57,8 @@ void EncodeDecodeTwoSteps(const std::string& images_path) { std::vector image = GenerateValues(); // Encode the image into memory first. - const std::string filename = images_path + "/out_generated2.png"; + const std::string filename = + sandbox2::file::JoinPath(images_path, "/out_generated2.png"); uint8_t* png; size_t pngsize;