Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mobject-store
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
11
Issues
11
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sds
mobject-store
Commits
50b8c379
Commit
50b8c379
authored
Oct 17, 2017
by
Matthieu Dorier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
some write operations now copy their parameters
parent
a3645a19
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
10 deletions
+47
-10
src/write-actions.h
src/write-actions.h
+9
-4
src/write-op.c
src/write-op.c
+38
-6
No files found.
src/write-actions.h
View file @
50b8c379
...
...
@@ -86,17 +86,22 @@ typedef struct wr_action_ZERO {
typedef
struct
wr_action_OMAP_SET
{
struct
wr_action_BASE
base
;
char
const
*
const
*
keys
;
char
const
*
const
*
vals
;
const
size_t
*
lens
;
size_t
num
;
char
data
[
1
];
}
*
wr_action_omap_set_t
;
// data above is meant to hold keys, lengths, and values,
// all put together in the same contiguous buffer.
// The buffer holds a series of [key,len,value] segments
// where key is a null-terminated string, len is a size_t,
// and value is a len-sized segment.
typedef
struct
wr_action_RM_KEYS
{
struct
wr_action_BASE
base
;
char
const
*
const
*
keys
;
size_t
keys_len
;
char
keys
[
1
];
}
*
wr_action_omap_rm_keys_t
;
// keys above is meant to hold keys in a contiguous buffer.
// The keys are null-terminated strings.
#endif
src/write-op.c
View file @
50b8c379
...
...
@@ -5,6 +5,7 @@
*/
#include <stdlib.h>
#include <string.h>
#include "mobject-store-config.h"
#include "utlist.h"
#include "libmobject-store.h"
...
...
@@ -162,13 +163,31 @@ void mobject_store_write_op_omap_set(mobject_store_write_op_t write_op,
{
MOBJECT_ASSERT
(
write_op
!=
MOBJECT_WRITE_OP_NULL
,
"invalid mobject_store_write_op_t obect"
);
wr_action_omap_set_t
action
=
(
wr_action_omap_set_t
)
calloc
(
1
,
sizeof
(
*
action
));
// compute the size required to embed the keys and values
size_t
i
;
size_t
extra_size
=
sizeof
(
lens
[
0
])
*
num
;
for
(
i
=
0
;
i
<
num
;
i
++
)
{
extra_size
+=
strlen
(
keys
[
i
])
+
1
;
extra_size
+=
lens
[
i
];
}
wr_action_omap_set_t
action
=
(
wr_action_omap_set_t
)
calloc
(
1
,
sizeof
(
*
action
)
-
1
+
extra_size
);
action
->
base
.
type
=
WRITE_OPCODE_OMAP_SET
;
action
->
keys
=
keys
;
action
->
vals
=
vals
;
action
->
lens
=
lens
;
action
->
num
=
num
;
char
*
data
=
action
->
data
;
for
(
i
=
0
;
i
<
num
;
i
++
)
{
// serialize key
strcpy
(
data
,
keys
[
i
]);
data
+=
strlen
(
keys
[
i
])
+
1
;
// serialize size of value
memcpy
(
data
,
&
lens
[
i
],
sizeof
(
lens
[
i
]));
data
+=
sizeof
(
lens
[
i
]);
// serialize value
memcpy
(
data
,
vals
[
i
],
lens
[
i
]);
data
+=
lens
[
i
];
}
WRITE_ACTION_UPCAST
(
base
,
action
);
DL_APPEND
(
write_op
->
actions
,
base
);
}
...
...
@@ -179,11 +198,24 @@ void mobject_store_write_op_omap_rm_keys(mobject_store_write_op_t write_op,
{
MOBJECT_ASSERT
(
write_op
!=
MOBJECT_WRITE_OP_NULL
,
"invalid mobject_store_write_op_t obect"
);
wr_action_omap_rm_keys_t
action
=
(
wr_action_omap_rm_keys_t
)
calloc
(
1
,
sizeof
(
*
action
));
// find out the extra memory to allocate
size_t
i
;
size_t
extra_mem
=
0
;
for
(
i
=
0
;
i
<
keys_len
;
i
++
)
{
extra_mem
+=
strlen
(
keys
[
i
])
+
1
;
}
wr_action_omap_rm_keys_t
action
=
(
wr_action_omap_rm_keys_t
)
calloc
(
1
,
sizeof
(
*
action
)
-
1
+
extra_mem
);
action
->
base
.
type
=
WRITE_OPCODE_OMAP_RM_KEYS
;
action
->
keys
=
keys
;
action
->
keys_len
=
keys_len
;
char
*
data
=
action
->
keys
;
// serialize the keys
for
(
i
=
0
;
i
<
keys_len
;
i
++
)
{
strcpy
(
data
,
keys
[
i
]);
data
+=
strlen
(
keys
[
i
])
+
1
;
}
WRITE_ACTION_UPCAST
(
base
,
action
);
DL_APPEND
(
write_op
->
actions
,
base
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment