mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-03-06 22:37:14 +08:00
Various minor changes to allow compliation with msvc (#22182)
Summary: This change is aiming to reduce some of the forking changes we have internally in order to use CxxReact for some additional out of tree platforms. Some of the fixes allow more of the code to compile when using Microsoft Visual Studio Compiler. In particular the change around the default value of RN_EXPORT and some changes around how to enable the packing attribute. Another change moves more of the code for JSBigFileString into the cpp file, so that people can share the header but replace the implementation as appropriate for other platforms. And finally the removal of an unused header include. This is unlikely to be the extent of the changes required for MSVC, but at least gets one of our complication blocks to work against an unforked RN. Pull Request resolved: https://github.com/facebook/react-native/pull/22182 Differential Revision: D12967758 Pulled By: cpojer fbshipit-source-id: a2cc018aedaa9916cd644bfbd9e3a55330cd4c52
This commit is contained in:
committed by
Facebook Github Bot
parent
4d95e85f64
commit
8beb4bb58a
@@ -9,11 +9,65 @@
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <folly/Memory.h>
|
||||
#include <folly/portability/SysMman.h>
|
||||
#include <folly/ScopeGuard.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
JSBigFileString::JSBigFileString(int fd, size_t size, off_t offset /*= 0*/)
|
||||
: m_fd { -1 }
|
||||
, m_data { nullptr } {
|
||||
folly::checkUnixError(m_fd = dup(fd),
|
||||
"Could not duplicate file descriptor");
|
||||
|
||||
// Offsets given to mmap must be page aligend. We abstract away that
|
||||
// restriction by sending a page aligned offset to mmap, and keeping track
|
||||
// of the offset within the page that we must alter the mmap pointer by to
|
||||
// get the final desired offset.
|
||||
if (offset != 0) {
|
||||
const static auto ps = getpagesize();
|
||||
auto d = lldiv(offset, ps);
|
||||
|
||||
m_mapOff = d.quot;
|
||||
m_pageOff = d.rem;
|
||||
m_size = size + m_pageOff;
|
||||
} else {
|
||||
m_mapOff = 0;
|
||||
m_pageOff = 0;
|
||||
m_size = size;
|
||||
}
|
||||
}
|
||||
|
||||
JSBigFileString::~JSBigFileString() {
|
||||
if (m_data) {
|
||||
munmap((void *)m_data, m_size);
|
||||
}
|
||||
close(m_fd);
|
||||
}
|
||||
|
||||
|
||||
const char *JSBigFileString::c_str() const {
|
||||
if (!m_data) {
|
||||
m_data =
|
||||
(const char *) mmap(0, m_size, PROT_READ, MAP_SHARED, m_fd, m_mapOff);
|
||||
CHECK(m_data != MAP_FAILED)
|
||||
<< " fd: " << m_fd
|
||||
<< " size: " << m_size
|
||||
<< " offset: " << m_mapOff
|
||||
<< " error: " << std::strerror(errno);
|
||||
}
|
||||
return m_data + m_pageOff;
|
||||
}
|
||||
|
||||
size_t JSBigFileString::size() const {
|
||||
return m_size - m_pageOff;
|
||||
}
|
||||
|
||||
int JSBigFileString::fd() const {
|
||||
return m_fd;
|
||||
}
|
||||
|
||||
std::unique_ptr<const JSBigFileString> JSBigFileString::fromPath(const std::string& sourceURL) {
|
||||
int fd = ::open(sourceURL.c_str(), O_RDONLY);
|
||||
folly::checkUnixError(fd, "Could not open file", sourceURL);
|
||||
|
||||
Reference in New Issue
Block a user