Commit 81678272 authored by Milo Yip's avatar Milo Yip

Fix #349 emscripten alignment issue

parent ce0184e7
#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;
}
\ No newline at end of file
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment