git.droids-corp.org
/
protos
/
libecoli.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fix malloc test
[protos/libecoli.git]
/
src
/
ecoli_node_int.c
diff --git
a/src/ecoli_node_int.c
b/src/ecoli_node_int.c
index
80f2fd5
..
acad9ed
100644
(file)
--- a/
src/ecoli_node_int.c
+++ b/
src/ecoli_node_int.c
@@
-26,7
+26,6
@@
EC_LOG_TYPE_REGISTER(node_int);
/* common to int and uint */
struct ec_node_int_uint {
/* common to int and uint */
struct ec_node_int_uint {
- struct ec_node gen;
bool is_signed;
bool check_min;
bool check_max;
bool is_signed;
bool check_min;
bool check_max;
@@
-41,45
+40,45
@@
struct ec_node_int_uint {
unsigned int base;
};
unsigned int base;
};
-static int parse_llint(struct ec_node_int_uint *
node
, const char *str,
+static int parse_llint(struct ec_node_int_uint *
priv
, const char *str,
int64_t *val)
{
int64_t min, max;
int64_t *val)
{
int64_t min, max;
- if (
node
->check_min)
- min =
node
->min;
+ if (
priv
->check_min)
+ min =
priv
->min;
else
min = LLONG_MIN;
else
min = LLONG_MIN;
- if (
node
->check_max)
- max =
node
->max;
+ if (
priv
->check_max)
+ max =
priv
->max;
else
max = LLONG_MAX;
else
max = LLONG_MAX;
- return ec_str_parse_llint(str,
node
->base, min, max, val);
+ return ec_str_parse_llint(str,
priv
->base, min, max, val);
}
}
-static int parse_ullint(struct ec_node_int_uint *
node
, const char *str,
+static int parse_ullint(struct ec_node_int_uint *
priv
, const char *str,
uint64_t *val)
{
uint64_t min, max;
uint64_t *val)
{
uint64_t min, max;
- if (
node
->check_min)
- min =
node
->min;
+ if (
priv
->check_min)
+ min =
priv
->min;
else
min = 0;
else
min = 0;
- if (
node
->check_max)
- max =
node
->max;
+ if (
priv
->check_max)
+ max =
priv
->max;
else
max = ULLONG_MAX;
else
max = ULLONG_MAX;
- return ec_str_parse_ullint(str,
node
->base, min, max, val);
+ return ec_str_parse_ullint(str,
priv
->base, min, max, val);
}
}
-static int ec_node_int_uint_parse(const struct ec_node *
gen_
node,
- struct ec_p
ars
e *state,
+static int ec_node_int_uint_parse(const struct ec_node *node,
+ struct ec_p
nod
e *state,
const struct ec_strvec *strvec)
{
const struct ec_strvec *strvec)
{
- struct ec_node_int_uint *
node = (struct ec_node_int_uint *)gen_node
;
+ struct ec_node_int_uint *
priv = ec_node_priv(node)
;
const char *str;
uint64_t u64;
int64_t i64;
const char *str;
uint64_t u64;
int64_t i64;
@@
-90,22
+89,22
@@
static int ec_node_int_uint_parse(const struct ec_node *gen_node,
return EC_PARSE_NOMATCH;
str = ec_strvec_val(strvec, 0);
return EC_PARSE_NOMATCH;
str = ec_strvec_val(strvec, 0);
- if (
node
->is_signed) {
- if (parse_llint(
node
, str, &i64) < 0)
+ if (
priv
->is_signed) {
+ if (parse_llint(
priv
, str, &i64) < 0)
return EC_PARSE_NOMATCH;
} else {
return EC_PARSE_NOMATCH;
} else {
- if (parse_ullint(
node
, str, &u64) < 0)
+ if (parse_ullint(
priv
, str, &u64) < 0)
return EC_PARSE_NOMATCH;
}
return 1;
}
static int
return EC_PARSE_NOMATCH;
}
return 1;
}
static int
-ec_node_uint_init_priv(struct ec_node *
gen_
node)
+ec_node_uint_init_priv(struct ec_node *node)
{
{
- struct ec_node_int_uint *
node = (struct ec_node_int_uint *)gen_node
;
+ struct ec_node_int_uint *
priv = ec_node_priv(node)
;
-
node
->is_signed = true;
+
priv
->is_signed = true;
return 0;
}
return 0;
}
@@
-131,10
+130,10
@@
static const struct ec_config_schema ec_node_int_schema[] = {
},
};
},
};
-static int ec_node_int_set_config(struct ec_node *
gen_
node,
+static int ec_node_int_set_config(struct ec_node *node,
const struct ec_config *config)
{
const struct ec_config *config)
{
- struct ec_node_int_uint *
node = (struct ec_node_int_uint *)gen_node
;
+ struct ec_node_int_uint *
priv = ec_node_priv(node)
;
const struct ec_config *min_value = NULL;
const struct ec_config *max_value = NULL;
const struct ec_config *base_value = NULL;
const struct ec_config *min_value = NULL;
const struct ec_config *max_value = NULL;
const struct ec_config *base_value = NULL;
@@
-150,21
+149,21
@@
static int ec_node_int_set_config(struct ec_node *gen_node,
}
if (min_value != NULL) {
}
if (min_value != NULL) {
-
node
->check_min = true;
-
node
->min = min_value->i64;
+
priv
->check_min = true;
+
priv
->min = min_value->i64;
} else {
} else {
-
node
->check_min = false;
+
priv
->check_min = false;
}
if (max_value != NULL) {
}
if (max_value != NULL) {
-
node
->check_max = true;
-
node
->max = max_value->i64;
+
priv
->check_max = true;
+
priv
->max = max_value->i64;
} else {
} else {
-
node
->check_min = false;
+
priv
->check_min = false;
}
if (base_value != NULL)
}
if (base_value != NULL)
-
node
->base = base_value->u64;
+
priv
->base = base_value->u64;
else
else
-
node
->base = 0;
+
priv
->base = 0;
return 0;
return 0;
@@
-178,7
+177,7
@@
static struct ec_node_type ec_node_int_type = {
.schema = ec_node_int_schema,
.set_config = ec_node_int_set_config,
.parse = ec_node_int_uint_parse,
.schema = ec_node_int_schema,
.set_config = ec_node_int_set_config,
.parse = ec_node_int_uint_parse,
- .complete = ec_
node_
complete_unknown,
+ .complete = ec_complete_unknown,
.size = sizeof(struct ec_node_int_uint),
.init_priv = ec_node_uint_init_priv,
};
.size = sizeof(struct ec_node_int_uint),
.init_priv = ec_node_uint_init_priv,
};
@@
-189,11
+188,11
@@
struct ec_node *ec_node_int(const char *id, int64_t min,
int64_t max, unsigned int base)
{
struct ec_config *config = NULL;
int64_t max, unsigned int base)
{
struct ec_config *config = NULL;
- struct ec_node *
gen_
node = NULL;
+ struct ec_node *node = NULL;
int ret;
int ret;
-
gen_
node = ec_node_from_type(&ec_node_int_type, id);
- if (
gen_
node == NULL)
+ node = ec_node_from_type(&ec_node_int_type, id);
+ if (node == NULL)
return NULL;
config = ec_config_dict();
return NULL;
config = ec_config_dict();
@@
-210,16
+209,16
@@
struct ec_node *ec_node_int(const char *id, int64_t min,
if (ret < 0)
goto fail;
if (ret < 0)
goto fail;
- ret = ec_node_set_config(
gen_
node, config);
+ ret = ec_node_set_config(node, config);
config = NULL;
if (ret < 0)
goto fail;
config = NULL;
if (ret < 0)
goto fail;
- return
gen_
node;
+ return node;
fail:
ec_config_free(config);
fail:
ec_config_free(config);
- ec_node_free(
gen_
node);
+ ec_node_free(node);
return NULL;
}
return NULL;
}
@@
-244,10
+243,10
@@
static const struct ec_config_schema ec_node_uint_schema[] = {
},
};
},
};
-static int ec_node_uint_set_config(struct ec_node *
gen_
node,
+static int ec_node_uint_set_config(struct ec_node *node,
const struct ec_config *config)
{
const struct ec_config *config)
{
- struct ec_node_int_uint *
node = (struct ec_node_int_uint *)gen_node
;
+ struct ec_node_int_uint *
priv = ec_node_priv(node)
;
const struct ec_config *min_value = NULL;
const struct ec_config *max_value = NULL;
const struct ec_config *base_value = NULL;
const struct ec_config *min_value = NULL;
const struct ec_config *max_value = NULL;
const struct ec_config *base_value = NULL;
@@
-263,21
+262,21
@@
static int ec_node_uint_set_config(struct ec_node *gen_node,
}
if (min_value != NULL) {
}
if (min_value != NULL) {
-
node
->check_min = true;
-
node
->min = min_value->u64;
+
priv
->check_min = true;
+
priv
->min = min_value->u64;
} else {
} else {
-
node
->check_min = false;
+
priv
->check_min = false;
}
if (max_value != NULL) {
}
if (max_value != NULL) {
-
node
->check_max = true;
-
node
->max = max_value->u64;
+
priv
->check_max = true;
+
priv
->max = max_value->u64;
} else {
} else {
-
node
->check_min = false;
+
priv
->check_min = false;
}
if (base_value != NULL)
}
if (base_value != NULL)
-
node
->base = base_value->u64;
+
priv
->base = base_value->u64;
else
else
-
node
->base = 0;
+
priv
->base = 0;
return 0;
return 0;
@@
-291,7
+290,7
@@
static struct ec_node_type ec_node_uint_type = {
.schema = ec_node_uint_schema,
.set_config = ec_node_uint_set_config,
.parse = ec_node_int_uint_parse,
.schema = ec_node_uint_schema,
.set_config = ec_node_uint_set_config,
.parse = ec_node_int_uint_parse,
- .complete = ec_
node_
complete_unknown,
+ .complete = ec_complete_unknown,
.size = sizeof(struct ec_node_int_uint),
};
.size = sizeof(struct ec_node_int_uint),
};
@@
-301,11
+300,11
@@
struct ec_node *ec_node_uint(const char *id, uint64_t min,
uint64_t max, unsigned int base)
{
struct ec_config *config = NULL;
uint64_t max, unsigned int base)
{
struct ec_config *config = NULL;
- struct ec_node *
gen_
node = NULL;
+ struct ec_node *node = NULL;
int ret;
int ret;
-
gen_
node = ec_node_from_type(&ec_node_uint_type, id);
- if (
gen_
node == NULL)
+ node = ec_node_from_type(&ec_node_uint_type, id);
+ if (node == NULL)
return NULL;
config = ec_config_dict();
return NULL;
config = ec_config_dict();
@@
-322,46
+321,46
@@
struct ec_node *ec_node_uint(const char *id, uint64_t min,
if (ret < 0)
goto fail;
if (ret < 0)
goto fail;
- ret = ec_node_set_config(
gen_
node, config);
+ ret = ec_node_set_config(node, config);
config = NULL;
if (ret < 0)
goto fail;
config = NULL;
if (ret < 0)
goto fail;
- return
gen_
node;
+ return node;
fail:
ec_config_free(config);
fail:
ec_config_free(config);
- ec_node_free(
gen_
node);
+ ec_node_free(node);
return NULL;
}
return NULL;
}
-int ec_node_int_getval(const struct ec_node *
gen_
node, const char *str,
+int ec_node_int_getval(const struct ec_node *node, const char *str,
int64_t *result)
{
int64_t *result)
{
- struct ec_node_int_uint *
node = (struct ec_node_int_uint *)gen_node
;
+ struct ec_node_int_uint *
priv = ec_node_priv(node)
;
int ret;
int ret;
- ret = ec_node_check_type(
gen_
node, &ec_node_int_type);
+ ret = ec_node_check_type(node, &ec_node_int_type);
if (ret < 0)
return ret;
if (ret < 0)
return ret;
- if (parse_llint(
node
, str, result) < 0)
+ if (parse_llint(
priv
, str, result) < 0)
return -1;
return 0;
}
return -1;
return 0;
}
-int ec_node_uint_getval(const struct ec_node *
gen_
node, const char *str,
+int ec_node_uint_getval(const struct ec_node *node, const char *str,
uint64_t *result)
{
uint64_t *result)
{
- struct ec_node_int_uint *
node = (struct ec_node_int_uint *)gen_node
;
+ struct ec_node_int_uint *
priv = ec_node_priv(node)
;
int ret;
int ret;
- ret = ec_node_check_type(
gen_
node, &ec_node_uint_type);
+ ret = ec_node_check_type(node, &ec_node_uint_type);
if (ret < 0)
return ret;
if (ret < 0)
return ret;
- if (parse_ullint(
node
, str, result) < 0)
+ if (parse_ullint(
priv
, str, result) < 0)
return -1;
return 0;
return -1;
return 0;
@@
-370,7
+369,7
@@
int ec_node_uint_getval(const struct ec_node *gen_node, const char *str,
/* LCOV_EXCL_START */
static int ec_node_int_testcase(void)
{
/* LCOV_EXCL_START */
static int ec_node_int_testcase(void)
{
- struct ec_p
ars
e *p;
+ struct ec_p
nod
e *p;
struct ec_node *node;
const char *s;
int testres = 0;
struct ec_node *node;
const char *s;
int testres = 0;
@@
-394,19
+393,19
@@
static int ec_node_int_testcase(void)
testres |= EC_TEST_CHECK_PARSE(node, -1, "0x100000000000000000");
testres |= EC_TEST_CHECK_PARSE(node, -1, "4r");
testres |= EC_TEST_CHECK_PARSE(node, -1, "0x100000000000000000");
testres |= EC_TEST_CHECK_PARSE(node, -1, "4r");
- p = ec_
node_
parse(node, "1");
- s = ec_strvec_val(ec_p
ars
e_strvec(p), 0);
+ p = ec_parse(node, "1");
+ s = ec_strvec_val(ec_p
nod
e_strvec(p), 0);
testres |= EC_TEST_CHECK(s != NULL &&
ec_node_uint_getval(node, s, &u64) == 0 &&
u64 == 1, "bad integer value");
testres |= EC_TEST_CHECK(s != NULL &&
ec_node_uint_getval(node, s, &u64) == 0 &&
u64 == 1, "bad integer value");
- ec_p
ars
e_free(p);
+ ec_p
nod
e_free(p);
- p = ec_
node_
parse(node, "10");
- s = ec_strvec_val(ec_p
ars
e_strvec(p), 0);
+ p = ec_parse(node, "10");
+ s = ec_strvec_val(ec_p
nod
e_strvec(p), 0);
testres |= EC_TEST_CHECK(s != NULL &&
ec_node_uint_getval(node, s, &u64) == 0 &&
u64 == 10, "bad integer value");
testres |= EC_TEST_CHECK(s != NULL &&
ec_node_uint_getval(node, s, &u64) == 0 &&
u64 == 10, "bad integer value");
- ec_p
ars
e_free(p);
+ ec_p
nod
e_free(p);
ec_node_free(node);
node = ec_node_int(EC_NO_ID, -1, LLONG_MAX, 16);
ec_node_free(node);
node = ec_node_int(EC_NO_ID, -1, LLONG_MAX, 16);
@@
-423,12
+422,12
@@
static int ec_node_int_testcase(void)
testres |= EC_TEST_CHECK_PARSE(node, -1, "zzz");
testres |= EC_TEST_CHECK_PARSE(node, -1, "4r");
testres |= EC_TEST_CHECK_PARSE(node, -1, "zzz");
testres |= EC_TEST_CHECK_PARSE(node, -1, "4r");
- p = ec_
node_
parse(node, "10");
- s = ec_strvec_val(ec_p
ars
e_strvec(p), 0);
+ p = ec_parse(node, "10");
+ s = ec_strvec_val(ec_p
nod
e_strvec(p), 0);
testres |= EC_TEST_CHECK(s != NULL &&
ec_node_int_getval(node, s, &i64) == 0 &&
i64 == 16, "bad integer value");
testres |= EC_TEST_CHECK(s != NULL &&
ec_node_int_getval(node, s, &i64) == 0 &&
i64 == 16, "bad integer value");
- ec_p
ars
e_free(p);
+ ec_p
nod
e_free(p);
ec_node_free(node);
node = ec_node_int(EC_NO_ID, LLONG_MIN, 0, 10);
ec_node_free(node);
node = ec_node_int(EC_NO_ID, LLONG_MIN, 0, 10);
@@
-450,14
+449,14
@@
static int ec_node_int_testcase(void)
return -1;
}
testres |= EC_TEST_CHECK_COMPLETE(node,
return -1;
}
testres |= EC_TEST_CHECK_COMPLETE(node,
- "", EC_
NODE_ENDLIST
,
- EC_
NODE_ENDLIST
);
+ "", EC_
VA_END
,
+ EC_
VA_END
);
testres |= EC_TEST_CHECK_COMPLETE(node,
testres |= EC_TEST_CHECK_COMPLETE(node,
- "x", EC_
NODE_ENDLIST
,
- EC_
NODE_ENDLIST
);
+ "x", EC_
VA_END
,
+ EC_
VA_END
);
testres |= EC_TEST_CHECK_COMPLETE(node,
testres |= EC_TEST_CHECK_COMPLETE(node,
- "1", EC_
NODE_ENDLIST
,
- EC_
NODE_ENDLIST
);
+ "1", EC_
VA_END
,
+ EC_
VA_END
);
ec_node_free(node);
return testres;
ec_node_free(node);
return testres;