Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
tarantool
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
core
tarantool
Commits
2aedcf91
Commit
2aedcf91
authored
12 years ago
by
Konstantin Osipov
Browse files
Options
Downloads
Patches
Plain Diff
Fix a bug in obuf_dup with buffer reuse.
parent
b8d2fda7
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/iobuf.m
+20
-14
20 additions, 14 deletions
src/iobuf.m
with
20 additions
and
14 deletions
src/iobuf.m
+
20
−
14
View file @
2aedcf91
...
...
@@ -150,7 +150,7 @@ obuf_dup(struct obuf *buf, void *data, size_t size)
* @pre buf->pos points at an array of allocated buffers.
* The array ends with a zero-initialized buffer.
*/
if
(iov->iov_len + size > capacity) {
while
(iov->iov_len + size > capacity) {
/*
* The data doesn't fit into this buffer.
* It could be because the buffer is not
...
...
@@ -158,13 +158,14 @@ obuf_dup(struct obuf *buf, void *data, size_t size)
* Copy as much as possible into already
* allocated buffers.
*/
while
(iov->iov_len
<
capacity
)
{
if
(iov->iov_len
<
capacity
)
{
/
*
*
This
buffer
is
allocated
,
but
can
'
t
*
fit
all
the
data.
Copy
as
much
data
as
*
possible.
*
/
size_t
fill =
capacity
-
iov-
>
iov_len;
assert(fill
<
size
);
memcpy
(
iov-
>
iov_base + iov->iov_len, data, fill);
iov->iov_len += fill;
...
...
@@ -172,22 +173,27 @@ obuf_dup(struct obuf *buf, void *data, size_t size)
data += fill;
size -= fill;
if (size == 0) /* Nothing more to do. */
return;
buf->pos++;
iov =
&buf->iov[buf->pos];
capacity = buf->capacity[buf->pos];
/*
* Check if the remainder can fit
* without allocations.
*/
} else {
assert(capacity == 0);
/**
* Still some data to copy. We have to get
* a new buffer. Before we allocate
* a buffer for this position, ensure
* there is an unallocated buffer in the
* next one, since it works as an end
* marker for the loop above.
*/
obuf_init_pos(buf, buf->pos + 1);
obuf_alloc_pos(buf, buf->pos, size);
break;
}
assert(capacity == 0);
/**
* Still some data to copy. We have to get a new
* buffer. Before we allocate a buffer for this
* position, ensure there is an unallocated buffer
* in the next one, since it works as an end marker
* for the loop above.
*/
obuf_init_pos(buf, buf->pos + 1);
obuf_alloc_pos(buf, buf->pos, size);
}
memcpy(iov->iov_base + iov->iov_len, data, size);
iov->iov_len += size;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment