Skip to content

Commit

Permalink
Remove Folly dependency from MappedFileBuffer.cpp
Browse files Browse the repository at this point in the history
Summary:
Folly was just used for some error checking, so do it manually to avoid
adding Folly as a dependency.

Reviewed By: kodafb

Differential Revision: D22177031

fbshipit-source-id: 65f4212047d50d61adcb888a7751298e5e24a6de
  • Loading branch information
willholen authored and facebook-github-bot committed Jun 24, 2020
1 parent 45c2d63 commit 967ed80
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions android/test/java/com/facebook/hermes/test/MappedFileBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,25 @@
#include <MappedFileBuffer.h>

#include <fcntl.h>
#include <folly/Exception.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>
#include <memory>
#include <system_error>

namespace facebook {
namespace jsi {
namespace jni {

MappedFileBuffer::MappedFileBuffer(const std::string &fileName) {
folly::checkUnixError(fd_ = open(fileName.c_str(), O_RDONLY));
fd_ = open(fileName.c_str(), O_RDONLY);
if (fd_ < 0) {
throw std::system_error(errno, std::system_category(), "open failed");
}
struct stat statbuf;
folly::checkUnixError(fstat(fd_, &statbuf));
if (fstat(fd_, &statbuf) < 0) {
throw std::system_error(errno, std::system_category(), "fstat failed");
}
size_ = statbuf.st_size;
void *bytecodeFileMap = mmap(
/*address*/ nullptr, size_, PROT_READ, MAP_PRIVATE, fd_, /*offset*/ 0);
Expand All @@ -30,8 +35,12 @@ MappedFileBuffer::MappedFileBuffer(const std::string &fileName) {
}

MappedFileBuffer::~MappedFileBuffer() {
folly::checkUnixError(munmap(data_, size_));
folly::checkUnixError(close(fd_));
if (munmap(data_, size_) < 0) {
assert(false && "Failed to munmap MappedFileBuffer");
}
if (close(fd_) < 0) {
assert(false && "Failed to close MappedFileBuffer");
}
}

} // namespace jni
Expand Down

0 comments on commit 967ed80

Please sign in to comment.