Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion ext/cbor/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,22 @@ void msgpack_buffer_mark(msgpack_buffer_t* b)

bool _msgpack_buffer_shift_chunk(msgpack_buffer_t* b)
{
if(b->rmem_owner == &b->head->mem) {
b->rmem_end = NULL;
b->rmem_last = NULL;
b->rmem_owner = NULL;
}

_msgpack_buffer_chunk_destroy(b->head);

if(b->head == &b->tail) {
/* list becomes empty. don't add head to free_list
* because head should be always available */
b->tail_buffer_end = NULL;
b->read_buffer = NULL;
b->rmem_end = NULL;
b->rmem_last = NULL;
b->rmem_owner = NULL;
return false;
}

Expand Down Expand Up @@ -275,6 +284,13 @@ static inline msgpack_buffer_chunk_t* _msgpack_buffer_alloc_new_chunk(msgpack_bu
return reuse;
}

static inline void _msgpack_buffer_transfer_rmem_owner(msgpack_buffer_t* b, msgpack_buffer_chunk_t* nc)
{
if(b->rmem_owner == &b->tail.mem) {
b->rmem_owner = &nc->mem;
}
}

static inline void _msgpack_buffer_add_new_chunk(msgpack_buffer_t* b)
{
if(b->head == &b->tail) {
Expand All @@ -286,6 +302,7 @@ static inline void _msgpack_buffer_add_new_chunk(msgpack_buffer_t* b)
msgpack_buffer_chunk_t* nc = _msgpack_buffer_alloc_new_chunk(b);

*nc = b->tail;
_msgpack_buffer_transfer_rmem_owner(b, nc);
b->head = nc;
nc->next = &b->tail;

Expand All @@ -310,6 +327,7 @@ static inline void _msgpack_buffer_add_new_chunk(msgpack_buffer_t* b)

/* rebuild tail */
*nc = b->tail;
_msgpack_buffer_transfer_rmem_owner(b, nc);
before_tail->next = nc;
nc->next = &b->tail;
}
Expand Down Expand Up @@ -690,4 +708,3 @@ size_t _msgpack_buffer_skip_from_io(msgpack_buffer_t* b, size_t length)
}
return RSTRING_LEN(b->io_buffer);
}