Fix #349 emscripten alignment issue
This commit is contained in:
parent
ce0184e73b
commit
81678272a2
24
emscripten/a.cpp
Normal file
24
emscripten/a.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <streambuf>
|
||||
#include <iostream>
|
||||
|
||||
#define private public
|
||||
#include "rapidjson/document.h"
|
||||
|
||||
int main() {
|
||||
// std::ifstream in_file("config.json", std::ios::in);
|
||||
rapidjson::Document json_config_;
|
||||
// std::string json_string(
|
||||
// (std::istreambuf_iterator<char>(in_file)),
|
||||
// std::istreambuf_iterator<char>());
|
||||
std::string json_string("{\"float_test\": 75.0}");
|
||||
// if (!json_string.empty()) {
|
||||
json_config_.Parse(json_string.c_str());
|
||||
// }
|
||||
|
||||
printf("%p\n", &json_config_);
|
||||
printf("%p\n", &json_config_.data_.o.members[0].value.data_.n.d);
|
||||
|
||||
std::cout << json_config_["float_test"].GetDouble() << std::endl;
|
||||
}
|
@ -181,7 +181,7 @@ public:
|
||||
if (chunkHead_ == 0 || chunkHead_->size + size > chunkHead_->capacity)
|
||||
AddChunk(chunk_capacity_ > size ? chunk_capacity_ : size);
|
||||
|
||||
void *buffer = reinterpret_cast<char *>(chunkHead_ + 1) + chunkHead_->size;
|
||||
void *buffer = reinterpret_cast<char *>(chunkHead_) + RAPIDJSON_ALIGN(sizeof(ChunkHeader)) + chunkHead_->size;
|
||||
chunkHead_->size += size;
|
||||
return buffer;
|
||||
}
|
||||
@ -199,7 +199,7 @@ public:
|
||||
return originalPtr;
|
||||
|
||||
// Simply expand it if it is the last allocation and there is sufficient space
|
||||
if (originalPtr == (char *)(chunkHead_ + 1) + chunkHead_->size - originalSize) {
|
||||
if (originalPtr == (char *)(chunkHead_) + RAPIDJSON_ALIGN(sizeof(ChunkHeader)) + chunkHead_->size - originalSize) {
|
||||
size_t increment = static_cast<size_t>(newSize - originalSize);
|
||||
increment = RAPIDJSON_ALIGN(increment);
|
||||
if (chunkHead_->size + increment <= chunkHead_->capacity) {
|
||||
@ -231,7 +231,7 @@ private:
|
||||
void AddChunk(size_t capacity) {
|
||||
if (!baseAllocator_)
|
||||
ownBaseAllocator_ = baseAllocator_ = RAPIDJSON_NEW(BaseAllocator());
|
||||
ChunkHeader* chunk = reinterpret_cast<ChunkHeader*>(baseAllocator_->Malloc(sizeof(ChunkHeader) + capacity));
|
||||
ChunkHeader* chunk = reinterpret_cast<ChunkHeader*>(baseAllocator_->Malloc(RAPIDJSON_ALIGN(sizeof(ChunkHeader)) + capacity));
|
||||
chunk->capacity = capacity;
|
||||
chunk->size = 0;
|
||||
chunk->next = chunkHead_;
|
||||
|
@ -223,7 +223,7 @@
|
||||
|
||||
//! Whether using 64-bit architecture
|
||||
#ifndef RAPIDJSON_64BIT
|
||||
#if defined(__LP64__) || defined(_WIN64)
|
||||
#if defined(__LP64__) || defined(_WIN64) || defined(__EMSCRIPTEN__)
|
||||
#define RAPIDJSON_64BIT 1
|
||||
#else
|
||||
#define RAPIDJSON_64BIT 0
|
||||
|
Loading…
x
Reference in New Issue
Block a user