mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-10-22 16:02:30 +02:00
Compare commits
16 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
52d5591ded | ||
![]() |
6ec09053b1 | ||
![]() |
5401660b07 | ||
![]() |
f3caa8e160 | ||
![]() |
8921f9dcfc | ||
![]() |
7bee573a72 | ||
![]() |
5568abb6ab | ||
![]() |
67486480ac | ||
![]() |
0e3bb789b8 | ||
![]() |
e1eabbfebf | ||
![]() |
e416b534b8 | ||
![]() |
212ef8eb2b | ||
![]() |
7bf06a5885 | ||
![]() |
1822523289 | ||
![]() |
156a4403ab | ||
![]() |
ad5da7f131 |
32
CHANGELOG.md
32
CHANGELOG.md
@@ -1,3 +1,35 @@
|
||||
2015-3-22 version 1.0.1:
|
||||
* Fix compilation error on Mac 10.9 (#244)
|
||||
* Fix typos in documents (#240)
|
||||
* Update CHANGELOG.md for version 1.0.0 (#242)
|
||||
* Fix erb templates for the next code generation (#239)
|
||||
|
||||
2015-03-10 version 1.0.0:
|
||||
* Support msgpack v5 format (str, bin, and ext) https://github.com/msgpack/msgpack/blob/master/spec.md (#142)
|
||||
* Support std::tuple, std::forward_list, std::array, std::unordered_set, std::unordered_map on C++11. tr1 unordered containers are still supported (#53, #130, #137, #154, #169)
|
||||
* Update msgpack-c as a header-only library on C++ (#142)
|
||||
* Move include directory (#142)
|
||||
* Update the name of float format family on msgpack::object from 'dec' to 'f64' (#194)
|
||||
* Remove existing elements on associative containers when unpacking (#127)
|
||||
* Add an API versioning functionality https://github.com/msgpack/msgpack-c/wiki/cpp_versioning (#139)
|
||||
* Add C++11 enum class support (#205)
|
||||
* Map std::vector<char> and std::array<char> to BIN (#100)
|
||||
* Map '\0' teminated char* and char const* to STR (#206)
|
||||
* Add the new parameter on unpacking functions and classes to limit msgpack's bytestream size (https://github.com/msgpack/msgpack-c/wiki/cpp_unpacker#limit-size-of-elements) (#175)
|
||||
* Add the copy or reference choosing function on unpack() and unpacker (https://github.com/msgpack/msgpack-c/wiki/cpp_unpacker#memory-management)
|
||||
* Add the new unpack() overloads for C++11 https://github.com/msgpack/msgpack-c/wiki/cpp_unpacker (#128)
|
||||
* Add a msgpack::object::with_zone (deep) copying function (#133, #163)
|
||||
* Remove the compile-time defined limit of msgpack nest level on C++ (#218)
|
||||
* Add the new unpack() overloads that use an existing zone (#201)
|
||||
* Add the range-based for loop support on msgpack object array and map (#203)
|
||||
* Add msgpack revision getter function for 'revision' (#237)
|
||||
* Support EXT for C (#118, #129)
|
||||
* Fix unpacking buffer allocation problem when malformed data is given (#160, #185)
|
||||
* Add dll exporting function on MSVC (#162)
|
||||
* Fix msgpack::zone::allocate_no_align(). Now it allocates the memory that is not aligned as expected (#171)
|
||||
* Improve documents (https://github.com/msgpack/msgpack-c/wiki)
|
||||
* Other bug fixes and refactoring: #62, #91, #95, #97, #107, #109, #113, #117, #119, #121, #122, #123, #126, #131, #136, #138, #140, #143, #145, #146, #150, #151, #152, #156, #157, #158, #161, #165, #170, #172, #179, #180, #181, #182, #183, #192, #195, #199, #200, #207, #211, #212, #219, #222, #224, #230, #231, #232, #233, #234, #235
|
||||
|
||||
2014-07-02 version 0.5.9:
|
||||
|
||||
* Support std::tr1 unordered containers by default (#51, #63, #68, #69)
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
The serialization library is production-ready.
|
||||
|
||||
Currently, no RPC implementation is not available.
|
||||
Currently, RPC implementation is not available.
|
||||
|
||||
# Install
|
||||
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
The serialization library is production-ready.
|
||||
|
||||
Currently, RPC implementation is testing phase. Requires newer kernel, not running on RHEL5/CentOS5.
|
||||
Currently, RPC implementation is in testing phase. Requires newer kernel, not running on RHEL5/CentOS5.
|
||||
|
||||
# Install
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
`msgpack` for C/C++
|
||||
===================
|
||||
|
||||
Version 1.0.0 [](https://travis-ci.org/msgpack/msgpack-c)
|
||||
Version 1.0.1 [](https://travis-ci.org/msgpack/msgpack-c)
|
||||
|
||||
It's like JSON but small and fast.
|
||||
|
||||
@@ -201,7 +201,7 @@ the binaries:' text box.
|
||||
### Documentation
|
||||
|
||||
You can get addtional information on the
|
||||
[wiki](https://github.com/msgpack/msgpack-c/wiki/cpp_overview).
|
||||
[wiki](https://github.com/msgpack/msgpack-c/wiki/).
|
||||
|
||||
Contributing
|
||||
------------
|
||||
|
@@ -90,7 +90,7 @@ struct define<> {
|
||||
}
|
||||
void msgpack_unpack(msgpack::object const& o)
|
||||
{
|
||||
if(o.type != msgpack::type::ARRAY) { throw type_error(); }
|
||||
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
}
|
||||
void msgpack_object(msgpack::object* o, msgpack::zone&) const
|
||||
{
|
||||
@@ -115,7 +115,7 @@ struct define<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> {
|
||||
}
|
||||
void msgpack_unpack(msgpack::object const& o)
|
||||
{
|
||||
if(o.type != msgpack::type::ARRAY) { throw type_error(); }
|
||||
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
const size_t size = o.via.array.size;
|
||||
if(size > 0) {
|
||||
msgpack::object *ptr = o.via.array.ptr;
|
||||
|
@@ -139,7 +139,7 @@ inline tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> make_tuple(typename tuple_type<
|
||||
inline msgpack::object const& operator>> (
|
||||
msgpack::object const& o,
|
||||
type::tuple<>&) {
|
||||
if(o.type != msgpack::type::ARRAY) { throw type_error(); }
|
||||
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
return o;
|
||||
}
|
||||
<%0.upto(GENERATION_LIMIT) {|i|%>
|
||||
@@ -147,8 +147,8 @@ template <typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
|
||||
inline msgpack::object const& operator>> (
|
||||
msgpack::object const& o,
|
||||
type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>& v) {
|
||||
if(o.type != msgpack::type::ARRAY) { throw type_error(); }
|
||||
if(o.via.array.size < <%=i+1%>) { throw type_error(); }
|
||||
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
if(o.via.array.size < <%=i+1%>) { throw msgpack::type_error(); }
|
||||
<%0.upto(i) {|j|%>
|
||||
o.via.array.ptr[<%=j%>].convert<typename type::tuple_type<A<%=j%>>::type>(v.template get<<%=j%>>());<%}%>
|
||||
return o;
|
||||
|
@@ -52,6 +52,7 @@ void unpack(receiver* r) {
|
||||
msgpack_unpack_return ret;
|
||||
char* buf;
|
||||
size_t recv_len;
|
||||
int recv_count = 0;
|
||||
|
||||
msgpack_unpacked_init(&result);
|
||||
if (msgpack_unpacker_buffer_capacity(unp) < EACH_RECV_SIZE) {
|
||||
@@ -64,7 +65,6 @@ void unpack(receiver* r) {
|
||||
msgpack_unpacker_buffer_consumed(unp, recv_len);
|
||||
|
||||
|
||||
int recv_count = 0;
|
||||
while (recv_len > 0) {
|
||||
int i = 0;
|
||||
printf("receive count: %d %zd bytes received.:\n", recv_count++, recv_len);
|
||||
|
@@ -3,12 +3,15 @@
|
||||
|
||||
int main(void)
|
||||
{
|
||||
/* msgpack::sbuffer is a simple buffer implementation. */
|
||||
msgpack_sbuffer sbuf;
|
||||
msgpack_packer pk;
|
||||
msgpack_zone mempool;
|
||||
msgpack_object deserialized;
|
||||
|
||||
/* msgpack::sbuffer is a simple buffer implementation. */
|
||||
msgpack_sbuffer_init(&sbuf);
|
||||
|
||||
/* serialize values into the buffer using msgpack_sbuffer_write callback function. */
|
||||
msgpack_packer pk;
|
||||
msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write);
|
||||
|
||||
msgpack_pack_array(&pk, 3);
|
||||
@@ -19,10 +22,8 @@ int main(void)
|
||||
|
||||
/* deserialize the buffer into msgpack_object instance. */
|
||||
/* deserialized object is valid during the msgpack_zone instance alive. */
|
||||
msgpack_zone mempool;
|
||||
msgpack_zone_init(&mempool, 2048);
|
||||
|
||||
msgpack_object deserialized;
|
||||
msgpack_unpack(sbuf.data, sbuf.size, NULL, &mempool, &deserialized);
|
||||
|
||||
/* print the deserialized object. */
|
||||
|
@@ -1,13 +1,16 @@
|
||||
#include <msgpack.h>
|
||||
#include <assert.h>
|
||||
|
||||
void test()
|
||||
{
|
||||
size_t size = 10000000;
|
||||
msgpack_sbuffer buf;
|
||||
msgpack_packer * pk;
|
||||
size_t upk_pos = 0;
|
||||
msgpack_unpacked msg;
|
||||
|
||||
msgpack_sbuffer_init(&buf);
|
||||
|
||||
msgpack_packer * pk = msgpack_packer_new(&buf, msgpack_sbuffer_write);
|
||||
pk = msgpack_packer_new(&buf, msgpack_sbuffer_write);
|
||||
|
||||
msgpack_pack_array(pk, size);
|
||||
{
|
||||
@@ -17,9 +20,6 @@ void test()
|
||||
}
|
||||
msgpack_packer_free(pk);
|
||||
|
||||
|
||||
size_t upk_pos = 0;
|
||||
msgpack_unpacked msg;
|
||||
msgpack_unpacked_init(&msg);
|
||||
|
||||
while (msgpack_unpack_next(&msg, buf.data, buf.size, &upk_pos)) {
|
||||
|
@@ -1,14 +1,17 @@
|
||||
#include <msgpack.h>
|
||||
#include <assert.h>
|
||||
|
||||
void test()
|
||||
{
|
||||
uint64_t test_u64 = 0xFFF0000000000001LL;
|
||||
size_t size = 10000000;
|
||||
msgpack_sbuffer buf;
|
||||
msgpack_packer * pk;
|
||||
size_t upk_pos = 0;
|
||||
msgpack_unpacked msg;
|
||||
|
||||
msgpack_sbuffer_init(&buf);
|
||||
|
||||
msgpack_packer * pk = msgpack_packer_new(&buf, msgpack_sbuffer_write);
|
||||
pk = msgpack_packer_new(&buf, msgpack_sbuffer_write);
|
||||
|
||||
msgpack_pack_array(pk, size);
|
||||
{
|
||||
@@ -18,9 +21,6 @@ void test()
|
||||
}
|
||||
msgpack_packer_free(pk);
|
||||
|
||||
|
||||
size_t upk_pos = 0;
|
||||
msgpack_unpacked msg;
|
||||
msgpack_unpacked_init(&msg);
|
||||
|
||||
while (msgpack_unpack_next(&msg, buf.data, buf.size, &upk_pos)) {
|
||||
|
@@ -44,7 +44,7 @@ namespace type {
|
||||
public:
|
||||
using base = std::tuple<Types...>;
|
||||
|
||||
using base::tuple;
|
||||
using base::base;
|
||||
|
||||
tuple() = default;
|
||||
tuple(tuple const&) = default;
|
||||
|
@@ -97,7 +97,7 @@ msgpack_unpack_func(msgpack_unpack_object, _data)(msgpack_unpack_struct(_context
|
||||
msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const char* data, size_t len, size_t* off)
|
||||
{
|
||||
assert(len >= *off);
|
||||
|
||||
{
|
||||
const unsigned char* p = (unsigned char*)data + *off;
|
||||
const unsigned char* const pe = (unsigned char*)data + len;
|
||||
const void* n = NULL;
|
||||
@@ -457,7 +457,7 @@ _end:
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#undef msgpack_unpack_func
|
||||
#undef msgpack_unpack_callback
|
||||
|
@@ -1,3 +1,3 @@
|
||||
#define MSGPACK_VERSION_MAJOR 1
|
||||
#define MSGPACK_VERSION_MINOR 0
|
||||
#define MSGPACK_VERSION_REVISION 0
|
||||
#define MSGPACK_VERSION_REVISION 1
|
||||
|
@@ -20,7 +20,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#if !defined(_MSC_VER) || _MSC_VER >= 1700
|
||||
#if !defined(_MSC_VER) || _MSC_VER >= 1800
|
||||
#include <inttypes.h>
|
||||
#endif
|
||||
|
||||
@@ -71,8 +71,10 @@ int msgpack_pack_object(msgpack_packer* pk, msgpack_object d)
|
||||
case MSGPACK_OBJECT_ARRAY:
|
||||
{
|
||||
int ret = msgpack_pack_array(pk, d.via.array.size);
|
||||
if(ret < 0) { return ret; }
|
||||
|
||||
if(ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
else {
|
||||
msgpack_object* o = d.via.array.ptr;
|
||||
msgpack_object* const oend = d.via.array.ptr + d.via.array.size;
|
||||
for(; o != oend; ++o) {
|
||||
@@ -82,12 +84,15 @@ int msgpack_pack_object(msgpack_packer* pk, msgpack_object d)
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
case MSGPACK_OBJECT_MAP:
|
||||
{
|
||||
int ret = msgpack_pack_map(pk, d.via.map.size);
|
||||
if(ret < 0) { return ret; }
|
||||
|
||||
if(ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
else {
|
||||
msgpack_object_kv* kv = d.via.map.ptr;
|
||||
msgpack_object_kv* const kvend = d.via.map.ptr + d.via.map.size;
|
||||
for(; kv != kvend; ++kv) {
|
||||
@@ -99,6 +104,7 @@ int msgpack_pack_object(msgpack_packer* pk, msgpack_object d)
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
default:
|
||||
return -1;
|
||||
@@ -172,9 +178,9 @@ void msgpack_object_print(FILE* out, msgpack_object o)
|
||||
fprintf(out, "[");
|
||||
if(o.via.array.size != 0) {
|
||||
msgpack_object* p = o.via.array.ptr;
|
||||
msgpack_object* const pend = o.via.array.ptr + o.via.array.size;
|
||||
msgpack_object_print(out, *p);
|
||||
++p;
|
||||
msgpack_object* const pend = o.via.array.ptr + o.via.array.size;
|
||||
for(; p < pend; ++p) {
|
||||
fprintf(out, ", ");
|
||||
msgpack_object_print(out, *p);
|
||||
@@ -187,11 +193,11 @@ void msgpack_object_print(FILE* out, msgpack_object o)
|
||||
fprintf(out, "{");
|
||||
if(o.via.map.size != 0) {
|
||||
msgpack_object_kv* p = o.via.map.ptr;
|
||||
msgpack_object_kv* const pend = o.via.map.ptr + o.via.map.size;
|
||||
msgpack_object_print(out, p->key);
|
||||
fprintf(out, "=>");
|
||||
msgpack_object_print(out, p->val);
|
||||
++p;
|
||||
msgpack_object_kv* const pend = o.via.map.ptr + o.via.map.size;
|
||||
for(; p < pend; ++p) {
|
||||
fprintf(out, ", ");
|
||||
msgpack_object_print(out, p->key);
|
||||
|
46
src/unpack.c
46
src/unpack.c
@@ -58,8 +58,8 @@ static int template_execute(
|
||||
|
||||
static inline msgpack_object template_callback_root(unpack_user* u)
|
||||
{
|
||||
MSGPACK_UNUSED(u);
|
||||
msgpack_object o;
|
||||
MSGPACK_UNUSED(u);
|
||||
o.type = MSGPACK_OBJECT_NIL;
|
||||
return o;
|
||||
}
|
||||
@@ -306,26 +306,28 @@ static inline _msgpack_atomic_counter_t get_count(void* buffer)
|
||||
return *(volatile _msgpack_atomic_counter_t*)buffer;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool msgpack_unpacker_init(msgpack_unpacker* mpac, size_t initial_buffer_size)
|
||||
{
|
||||
char* buffer;
|
||||
void* ctx;
|
||||
msgpack_zone* z;
|
||||
|
||||
if(initial_buffer_size < COUNTER_SIZE) {
|
||||
initial_buffer_size = COUNTER_SIZE;
|
||||
}
|
||||
|
||||
char* buffer = (char*)malloc(initial_buffer_size);
|
||||
buffer = (char*)malloc(initial_buffer_size);
|
||||
if(buffer == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void* ctx = malloc(sizeof(template_context));
|
||||
ctx = malloc(sizeof(template_context));
|
||||
if(ctx == NULL) {
|
||||
free(buffer);
|
||||
return false;
|
||||
}
|
||||
|
||||
msgpack_zone* z = msgpack_zone_new(MSGPACK_ZONE_CHUNK_SIZE);
|
||||
z = msgpack_zone_new(MSGPACK_ZONE_CHUNK_SIZE);
|
||||
if(z == NULL) {
|
||||
free(ctx);
|
||||
free(buffer);
|
||||
@@ -357,7 +359,6 @@ void msgpack_unpacker_destroy(msgpack_unpacker* mpac)
|
||||
decr_count(mpac->buffer);
|
||||
}
|
||||
|
||||
|
||||
msgpack_unpacker* msgpack_unpacker_new(size_t initial_buffer_size)
|
||||
{
|
||||
msgpack_unpacker* mpac = (msgpack_unpacker*)malloc(sizeof(msgpack_unpacker));
|
||||
@@ -394,6 +395,7 @@ bool msgpack_unpacker_expand_buffer(msgpack_unpacker* mpac, size_t size)
|
||||
}
|
||||
|
||||
if(mpac->off == COUNTER_SIZE) {
|
||||
char* tmp;
|
||||
size_t next_size = (mpac->used + mpac->free) * 2; // include COUNTER_SIZE
|
||||
while(next_size < size + mpac->used) {
|
||||
size_t tmp_next_size = next_size * 2;
|
||||
@@ -404,7 +406,7 @@ bool msgpack_unpacker_expand_buffer(msgpack_unpacker* mpac, size_t size)
|
||||
next_size = tmp_next_size;
|
||||
}
|
||||
|
||||
char* tmp = (char*)realloc(mpac->buffer, next_size);
|
||||
tmp = (char*)realloc(mpac->buffer, next_size);
|
||||
if(tmp == NULL) {
|
||||
return false;
|
||||
}
|
||||
@@ -413,6 +415,7 @@ bool msgpack_unpacker_expand_buffer(msgpack_unpacker* mpac, size_t size)
|
||||
mpac->free = next_size - mpac->used;
|
||||
|
||||
} else {
|
||||
char* tmp;
|
||||
size_t next_size = mpac->initial_buffer_size; // include COUNTER_SIZE
|
||||
size_t not_parsed = mpac->used - mpac->off;
|
||||
while(next_size < size + not_parsed + COUNTER_SIZE) {
|
||||
@@ -424,7 +427,7 @@ bool msgpack_unpacker_expand_buffer(msgpack_unpacker* mpac, size_t size)
|
||||
next_size = tmp_next_size;
|
||||
}
|
||||
|
||||
char* tmp = (char*)malloc(next_size);
|
||||
tmp = (char*)malloc(next_size);
|
||||
if(tmp == NULL) {
|
||||
return false;
|
||||
}
|
||||
@@ -470,16 +473,19 @@ msgpack_object msgpack_unpacker_data(msgpack_unpacker* mpac)
|
||||
|
||||
msgpack_zone* msgpack_unpacker_release_zone(msgpack_unpacker* mpac)
|
||||
{
|
||||
msgpack_zone* r;
|
||||
msgpack_zone* old;
|
||||
|
||||
if(!msgpack_unpacker_flush_zone(mpac)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
msgpack_zone* r = msgpack_zone_new(MSGPACK_ZONE_CHUNK_SIZE);
|
||||
r = msgpack_zone_new(MSGPACK_ZONE_CHUNK_SIZE);
|
||||
if(r == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
msgpack_zone* old = mpac->z;
|
||||
old = mpac->z;
|
||||
mpac->z = r;
|
||||
CTX_CAST(mpac->ctx)->user.z = mpac->z;
|
||||
|
||||
@@ -514,9 +520,11 @@ void msgpack_unpacker_reset(msgpack_unpacker* mpac)
|
||||
|
||||
msgpack_unpack_return msgpack_unpacker_next(msgpack_unpacker* mpac, msgpack_unpacked* result)
|
||||
{
|
||||
int ret;
|
||||
|
||||
msgpack_unpacked_destroy(result);
|
||||
|
||||
int ret = msgpack_unpacker_execute(mpac);
|
||||
ret = msgpack_unpacker_execute(mpac);
|
||||
|
||||
if(ret < 0) {
|
||||
result->zone = NULL;
|
||||
@@ -546,14 +554,15 @@ msgpack_unpack(const char* data, size_t len, size_t* off,
|
||||
// FIXME
|
||||
return MSGPACK_UNPACK_CONTINUE;
|
||||
}
|
||||
|
||||
else {
|
||||
int e;
|
||||
template_context ctx;
|
||||
template_init(&ctx);
|
||||
|
||||
ctx.user.z = result_zone;
|
||||
ctx.user.referenced = false;
|
||||
|
||||
int e = template_execute(&ctx, data, len, &noff);
|
||||
e = template_execute(&ctx, data, len, &noff);
|
||||
if(e < 0) {
|
||||
return MSGPACK_UNPACK_PARSE_ERROR;
|
||||
}
|
||||
@@ -572,14 +581,15 @@ msgpack_unpack(const char* data, size_t len, size_t* off,
|
||||
|
||||
return MSGPACK_UNPACK_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
msgpack_unpack_return
|
||||
msgpack_unpack_next(msgpack_unpacked* result,
|
||||
const char* data, size_t len, size_t* off)
|
||||
{
|
||||
size_t noff = 0;
|
||||
msgpack_unpacked_destroy(result);
|
||||
|
||||
size_t noff = 0;
|
||||
if(off != NULL) { noff = *off; }
|
||||
|
||||
if(len <= noff) {
|
||||
@@ -593,14 +603,15 @@ msgpack_unpack_next(msgpack_unpacked* result,
|
||||
if (!result->zone) {
|
||||
return MSGPACK_UNPACK_NOMEM_ERROR;
|
||||
}
|
||||
|
||||
else {
|
||||
int e;
|
||||
template_context ctx;
|
||||
template_init(&ctx);
|
||||
|
||||
ctx.user.z = result->zone;
|
||||
ctx.user.referenced = false;
|
||||
|
||||
int e = template_execute(&ctx, data, len, &noff);
|
||||
e = template_execute(&ctx, data, len, &noff);
|
||||
if(e < 0) {
|
||||
msgpack_zone_free(result->zone);
|
||||
result->zone = NULL;
|
||||
@@ -617,6 +628,7 @@ msgpack_unpack_next(msgpack_unpacked* result,
|
||||
|
||||
return MSGPACK_UNPACK_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(MSGPACK_OLD_COMPILER_BUS_ERROR_WORKAROUND)
|
||||
// FIXME: Dirty hack to avoid a bus error caused by OS X's old gcc.
|
||||
|
@@ -29,15 +29,19 @@ struct msgpack_vrefbuffer_chunk {
|
||||
bool msgpack_vrefbuffer_init(msgpack_vrefbuffer* vbuf,
|
||||
size_t ref_size, size_t chunk_size)
|
||||
{
|
||||
size_t nfirst;
|
||||
struct iovec* array;
|
||||
msgpack_vrefbuffer_chunk* chunk;
|
||||
|
||||
vbuf->chunk_size = chunk_size;
|
||||
vbuf->ref_size =
|
||||
ref_size > MSGPACK_PACKER_MAX_BUFFER_SIZE + 1 ?
|
||||
ref_size : MSGPACK_PACKER_MAX_BUFFER_SIZE + 1 ;
|
||||
|
||||
size_t nfirst = (sizeof(struct iovec) < 72/2) ?
|
||||
nfirst = (sizeof(struct iovec) < 72/2) ?
|
||||
72 / sizeof(struct iovec) : 8;
|
||||
|
||||
struct iovec* array = (struct iovec*)malloc(
|
||||
array = (struct iovec*)malloc(
|
||||
sizeof(struct iovec) * nfirst);
|
||||
if(array == NULL) {
|
||||
return false;
|
||||
@@ -47,13 +51,13 @@ bool msgpack_vrefbuffer_init(msgpack_vrefbuffer* vbuf,
|
||||
vbuf->end = array + nfirst;
|
||||
vbuf->array = array;
|
||||
|
||||
msgpack_vrefbuffer_chunk* chunk = (msgpack_vrefbuffer_chunk*)malloc(
|
||||
chunk = (msgpack_vrefbuffer_chunk*)malloc(
|
||||
sizeof(msgpack_vrefbuffer_chunk) + chunk_size);
|
||||
if(chunk == NULL) {
|
||||
free(array);
|
||||
return false;
|
||||
}
|
||||
|
||||
else {
|
||||
msgpack_vrefbuffer_inner_buffer* const ib = &vbuf->inner_buffer;
|
||||
|
||||
ib->free = chunk_size;
|
||||
@@ -63,6 +67,7 @@ bool msgpack_vrefbuffer_init(msgpack_vrefbuffer* vbuf,
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void msgpack_vrefbuffer_destroy(msgpack_vrefbuffer* vbuf)
|
||||
{
|
||||
@@ -89,6 +94,7 @@ void msgpack_vrefbuffer_clear(msgpack_vrefbuffer* vbuf)
|
||||
c = n;
|
||||
}
|
||||
|
||||
{
|
||||
msgpack_vrefbuffer_inner_buffer* const ib = &vbuf->inner_buffer;
|
||||
msgpack_vrefbuffer_chunk* chunk = ib->head;
|
||||
chunk->next = NULL;
|
||||
@@ -97,6 +103,7 @@ void msgpack_vrefbuffer_clear(msgpack_vrefbuffer* vbuf)
|
||||
|
||||
vbuf->tail = vbuf->array;
|
||||
}
|
||||
}
|
||||
|
||||
int msgpack_vrefbuffer_append_ref(msgpack_vrefbuffer* vbuf,
|
||||
const char* buf, size_t len)
|
||||
@@ -127,14 +134,16 @@ int msgpack_vrefbuffer_append_copy(msgpack_vrefbuffer* vbuf,
|
||||
const char* buf, size_t len)
|
||||
{
|
||||
msgpack_vrefbuffer_inner_buffer* const ib = &vbuf->inner_buffer;
|
||||
char* m;
|
||||
|
||||
if(ib->free < len) {
|
||||
msgpack_vrefbuffer_chunk* chunk;
|
||||
size_t sz = vbuf->chunk_size;
|
||||
if(sz < len) {
|
||||
sz = len;
|
||||
}
|
||||
|
||||
msgpack_vrefbuffer_chunk* chunk = (msgpack_vrefbuffer_chunk*)malloc(
|
||||
chunk = (msgpack_vrefbuffer_chunk*)malloc(
|
||||
sizeof(msgpack_vrefbuffer_chunk) + sz);
|
||||
if(chunk == NULL) {
|
||||
return -1;
|
||||
@@ -146,7 +155,7 @@ int msgpack_vrefbuffer_append_copy(msgpack_vrefbuffer* vbuf,
|
||||
ib->ptr = ((char*)chunk) + sizeof(msgpack_vrefbuffer_chunk);
|
||||
}
|
||||
|
||||
char* m = ib->ptr;
|
||||
m = ib->ptr;
|
||||
memcpy(m, buf, len);
|
||||
ib->free -= len;
|
||||
ib->ptr += len;
|
||||
@@ -172,9 +181,10 @@ int msgpack_vrefbuffer_migrate(msgpack_vrefbuffer* vbuf, msgpack_vrefbuffer* to)
|
||||
|
||||
empty->next = NULL;
|
||||
|
||||
|
||||
{
|
||||
const size_t nused = (size_t)(vbuf->tail - vbuf->array);
|
||||
if(to->tail + nused < vbuf->end) {
|
||||
struct iovec* nvec;
|
||||
const size_t tosize = (size_t)(to->tail - to->array);
|
||||
const size_t reqsize = nused + tosize;
|
||||
size_t nnext = (size_t)(to->end - to->array) * 2;
|
||||
@@ -187,7 +197,7 @@ int msgpack_vrefbuffer_migrate(msgpack_vrefbuffer* vbuf, msgpack_vrefbuffer* to)
|
||||
nnext = tmp_nnext;
|
||||
}
|
||||
|
||||
struct iovec* nvec = (struct iovec*)realloc(
|
||||
nvec = (struct iovec*)realloc(
|
||||
to->array, sizeof(struct iovec)*nnext);
|
||||
if(nvec == NULL) {
|
||||
free(empty);
|
||||
@@ -204,7 +214,7 @@ int msgpack_vrefbuffer_migrate(msgpack_vrefbuffer* vbuf, msgpack_vrefbuffer* to)
|
||||
to->tail += nused;
|
||||
vbuf->tail = vbuf->array;
|
||||
|
||||
|
||||
{
|
||||
msgpack_vrefbuffer_inner_buffer* const ib = &vbuf->inner_buffer;
|
||||
msgpack_vrefbuffer_inner_buffer* const toib = &to->inner_buffer;
|
||||
|
||||
@@ -223,6 +233,8 @@ int msgpack_vrefbuffer_migrate(msgpack_vrefbuffer* vbuf, msgpack_vrefbuffer* to)
|
||||
ib->head = empty;
|
||||
ib->free = sz;
|
||||
ib->ptr = ((char*)empty) + sizeof(msgpack_vrefbuffer_chunk);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
13
src/zone.c
13
src/zone.c
@@ -75,6 +75,7 @@ static inline void clear_chunk_list(msgpack_zone_chunk_list* cl, size_t chunk_si
|
||||
void* msgpack_zone_malloc_expand(msgpack_zone* zone, size_t size)
|
||||
{
|
||||
msgpack_zone_chunk_list* const cl = &zone->chunk_list;
|
||||
msgpack_zone_chunk* chunk;
|
||||
|
||||
size_t sz = zone->chunk_size;
|
||||
|
||||
@@ -87,9 +88,12 @@ void* msgpack_zone_malloc_expand(msgpack_zone* zone, size_t size)
|
||||
sz = tmp_sz;
|
||||
}
|
||||
|
||||
msgpack_zone_chunk* chunk = (msgpack_zone_chunk*)malloc(
|
||||
chunk = (msgpack_zone_chunk*)malloc(
|
||||
sizeof(msgpack_zone_chunk) + sz);
|
||||
if (chunk == NULL) return NULL;
|
||||
if (chunk == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
else {
|
||||
char* ptr = ((char*)chunk) + sizeof(msgpack_zone_chunk);
|
||||
chunk->next = cl->head;
|
||||
cl->head = chunk;
|
||||
@@ -98,6 +102,7 @@ void* msgpack_zone_malloc_expand(msgpack_zone* zone, size_t size)
|
||||
|
||||
return ptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static inline void init_finalizer_array(msgpack_zone_finalizer_array* fa)
|
||||
@@ -131,6 +136,7 @@ bool msgpack_zone_push_finalizer_expand(msgpack_zone* zone,
|
||||
void (*func)(void* data), void* data)
|
||||
{
|
||||
msgpack_zone_finalizer_array* const fa = &zone->finalizer_array;
|
||||
msgpack_zone_finalizer* tmp;
|
||||
|
||||
const size_t nused = (size_t)(fa->end - fa->array);
|
||||
|
||||
@@ -143,8 +149,7 @@ bool msgpack_zone_push_finalizer_expand(msgpack_zone* zone,
|
||||
nnext = nused * 2;
|
||||
}
|
||||
|
||||
msgpack_zone_finalizer* tmp =
|
||||
(msgpack_zone_finalizer*)realloc(fa->array,
|
||||
tmp = (msgpack_zone_finalizer*)realloc(fa->array,
|
||||
sizeof(msgpack_zone_finalizer) * nnext);
|
||||
if(tmp == NULL) {
|
||||
return false;
|
||||
|
Reference in New Issue
Block a user