don't hide calldata structure, no reason to, and forced an unnecessary allocation which is bad

This commit is contained in:
jp9000 2013-12-26 02:02:24 -07:00
parent e9ded173f1
commit a136748bd3
2 changed files with 23 additions and 35 deletions

View File

@ -34,17 +34,12 @@
* [size_t param2_data_size]
* [uint8_t[] param2_data]
* [...]
* [size_t 0]
*
* Strings and string sizes always include the null terminator to allow for
* direct referencing.
*/
struct calldata {
size_t size; /* size of the stack, in bytes */
size_t capacity; /* capacity of the stack, in bytes */
uint8_t *stack;
};
static inline void cd_serialize(uint8_t **pos, void *ptr, size_t size)
{
memcpy(ptr, *pos, size);
@ -164,23 +159,6 @@ static inline void cd_ensure_capacity(calldata_t data, uint8_t **pos,
/* ------------------------------------------------------------------------- */
calldata_t calldata_create(void)
{
struct calldata *data = bmalloc(sizeof(struct calldata));
memset(data, 0, sizeof(struct calldata));
return data;
}
void calldata_destroy(calldata_t data)
{
if (data) {
bfree(data->stack);
bfree(data);
}
}
/* ------------------------------------------------------------------------- */
bool calldata_getdata(calldata_t data, const char *name, void *out, size_t size)
{
uint8_t *pos;
@ -246,14 +224,6 @@ void calldata_setdata(calldata_t data, const char *name, const void *in,
}
}
void calldata_clear(calldata_t data)
{
if (data->size) {
data->size = sizeof(size_t);
*(size_t*)data->stack = 0;
}
}
bool calldata_getstring(calldata_t data, const char *name, const char **str)
{
uint8_t *pos;

View File

@ -30,11 +30,23 @@ extern "C" {
* procedures, and callbacks.
*/
struct calldata;
struct calldata {
size_t size; /* size of the stack, in bytes */
size_t capacity; /* capacity of the stack, in bytes */
uint8_t *stack;
};
typedef struct calldata *calldata_t;
EXPORT calldata_t calldata_create(void);
EXPORT void calldata_destroy(calldata_t data);
static inline void calldata_init(struct calldata *data)
{
memset(data, 0, sizeof(struct calldata));
}
static inline void calldata_free(struct calldata *data)
{
bfree(data->stack);
}
/* NOTE: 'get' functions return true only if paramter exists, and is the
* same size. They return false otherwise. */
@ -44,7 +56,13 @@ EXPORT bool calldata_getdata(calldata_t data, const char *name, void *out,
EXPORT void calldata_setdata(calldata_t data, const char *name, const void *in,
size_t new_size);
EXPORT void calldata_clear(calldata_t data);
static inline void calldata_clear(struct calldata *data)
{
if (data->stack) {
data->size = sizeof(size_t);
*(size_t*)data->stack = 0;
}
}
inline bool calldata_getchar (calldata_t data, const char *name, char *val)
{