mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-26 18:41:17 +00:00
Adjust sexpr-related interfaces to be const-correct.
* src/sexpr.c (sexpr_cons, append, sexpr_append, sexpr2string) (sexpr_lookup_key, sexpr_lookup, sexpr_node, sexpr_fmt_node): Add "const" attribute where appropriate. * src/xend_internal.c (sexpr_int, sexpr_float, sexpr_u64) (sexpr_uuid, sexpr_to_xend_domain_info, sexpr_to_xend_node_info) (sexpr_to_xend_topology_xml, sexpr_to_domain): Likewise. * src/sexpr.h: Adjust prototypes.
This commit is contained in:
parent
a430f22be4
commit
64b3019d69
@ -1,5 +1,14 @@
|
|||||||
Mon Jan 21 15:03:04 CET 2008 Jim Meyering <meyering@redhat.com>
|
Mon Jan 21 15:03:04 CET 2008 Jim Meyering <meyering@redhat.com>
|
||||||
|
|
||||||
|
Adjust sexpr-related interfaces to be const-correct.
|
||||||
|
* src/sexpr.c (sexpr_cons, append, sexpr_append, sexpr2string)
|
||||||
|
(sexpr_lookup_key, sexpr_lookup, sexpr_node, sexpr_fmt_node):
|
||||||
|
Add "const" attribute where appropriate.
|
||||||
|
* src/xend_internal.c (sexpr_int, sexpr_float, sexpr_u64)
|
||||||
|
(sexpr_uuid, sexpr_to_xend_domain_info, sexpr_to_xend_node_info)
|
||||||
|
(sexpr_to_xend_topology_xml, sexpr_to_domain): Likewise.
|
||||||
|
* src/sexpr.h: Adjust prototypes.
|
||||||
|
|
||||||
Don't access line[-1] for a zero-length "line" from fgets.
|
Don't access line[-1] for a zero-length "line" from fgets.
|
||||||
A NUL byte at beginning of input, or just after a newline
|
A NUL byte at beginning of input, or just after a newline
|
||||||
would provoke an invalid buf[-1] access (possible segfault).
|
would provoke an invalid buf[-1] access (possible segfault).
|
||||||
|
26
src/sexpr.c
26
src/sexpr.c
@ -150,15 +150,15 @@ sexpr_string(const char *str, ssize_t len)
|
|||||||
* Returns the resulting S-Expression pointer or NULL in case of error.
|
* Returns the resulting S-Expression pointer or NULL in case of error.
|
||||||
*/
|
*/
|
||||||
struct sexpr *
|
struct sexpr *
|
||||||
sexpr_cons(struct sexpr *car, struct sexpr *cdr)
|
sexpr_cons(const struct sexpr *car, const struct sexpr *cdr)
|
||||||
{
|
{
|
||||||
struct sexpr *ret = sexpr_new();
|
struct sexpr *ret = sexpr_new();
|
||||||
|
|
||||||
if (ret == NULL)
|
if (ret == NULL)
|
||||||
return ret;
|
return ret;
|
||||||
ret->kind = SEXPR_CONS;
|
ret->kind = SEXPR_CONS;
|
||||||
ret->u.s.car = car;
|
ret->u.s.car = (struct sexpr *) car;
|
||||||
ret->u.s.cdr = cdr;
|
ret->u.s.cdr = (struct sexpr *) cdr;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -171,14 +171,14 @@ sexpr_cons(struct sexpr *car, struct sexpr *cdr)
|
|||||||
* Internal operation appending a value at the end of an existing list
|
* Internal operation appending a value at the end of an existing list
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
append(struct sexpr *lst, struct sexpr *value)
|
append(struct sexpr *lst, const struct sexpr *value)
|
||||||
{
|
{
|
||||||
while (lst->kind != SEXPR_NIL) {
|
while (lst->kind != SEXPR_NIL) {
|
||||||
lst = lst->u.s.cdr;
|
lst = lst->u.s.cdr;
|
||||||
}
|
}
|
||||||
|
|
||||||
lst->kind = SEXPR_CONS;
|
lst->kind = SEXPR_CONS;
|
||||||
lst->u.s.car = value;
|
lst->u.s.car = (struct sexpr *) value;
|
||||||
lst->u.s.cdr = sexpr_nil();
|
lst->u.s.cdr = sexpr_nil();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,7 +191,7 @@ append(struct sexpr *lst, struct sexpr *value)
|
|||||||
* Returns lst or NULL in case of error
|
* Returns lst or NULL in case of error
|
||||||
*/
|
*/
|
||||||
struct sexpr *
|
struct sexpr *
|
||||||
sexpr_append(struct sexpr *lst, struct sexpr *value)
|
sexpr_append(struct sexpr *lst, const struct sexpr *value)
|
||||||
{
|
{
|
||||||
if (lst == NULL)
|
if (lst == NULL)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
@ -215,7 +215,7 @@ sexpr_append(struct sexpr *lst, struct sexpr *value)
|
|||||||
* 0 in case of error.
|
* 0 in case of error.
|
||||||
*/
|
*/
|
||||||
size_t
|
size_t
|
||||||
sexpr2string(struct sexpr * sexpr, char *buffer, size_t n_buffer)
|
sexpr2string(const struct sexpr * sexpr, char *buffer, size_t n_buffer)
|
||||||
{
|
{
|
||||||
size_t ret = 0, tmp;
|
size_t ret = 0, tmp;
|
||||||
|
|
||||||
@ -415,7 +415,7 @@ string2sexpr(const char *buffer)
|
|||||||
* Returns the pointer to the sub expression or NULL if not found.
|
* Returns the pointer to the sub expression or NULL if not found.
|
||||||
*/
|
*/
|
||||||
static struct sexpr *
|
static struct sexpr *
|
||||||
sexpr_lookup_key(struct sexpr *sexpr, const char *node)
|
sexpr_lookup_key(const struct sexpr *sexpr, const char *node)
|
||||||
{
|
{
|
||||||
char buffer[4096], *ptr, *token;
|
char buffer[4096], *ptr, *token;
|
||||||
|
|
||||||
@ -436,7 +436,7 @@ sexpr_lookup_key(struct sexpr *sexpr, const char *node)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (token = strsep(&ptr, "/"); token; token = strsep(&ptr, "/")) {
|
for (token = strsep(&ptr, "/"); token; token = strsep(&ptr, "/")) {
|
||||||
struct sexpr *i;
|
const struct sexpr *i;
|
||||||
|
|
||||||
if (token == NULL)
|
if (token == NULL)
|
||||||
continue;
|
continue;
|
||||||
@ -464,7 +464,7 @@ sexpr_lookup_key(struct sexpr *sexpr, const char *node)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return sexpr;
|
return (struct sexpr *) sexpr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -478,7 +478,7 @@ sexpr_lookup_key(struct sexpr *sexpr, const char *node)
|
|||||||
* Returns the pointer to the sub expression or NULL if not found.
|
* Returns the pointer to the sub expression or NULL if not found.
|
||||||
*/
|
*/
|
||||||
struct sexpr *
|
struct sexpr *
|
||||||
sexpr_lookup(struct sexpr *sexpr, const char *node)
|
sexpr_lookup(const struct sexpr *sexpr, const char *node)
|
||||||
{
|
{
|
||||||
struct sexpr *s = sexpr_lookup_key(sexpr, node);
|
struct sexpr *s = sexpr_lookup_key(sexpr, node);
|
||||||
|
|
||||||
@ -528,7 +528,7 @@ sexpr_has(struct sexpr *sexpr, const char *node)
|
|||||||
* Returns the value of the node or NULL if not found.
|
* Returns the value of the node or NULL if not found.
|
||||||
*/
|
*/
|
||||||
const char *
|
const char *
|
||||||
sexpr_node(struct sexpr *sexpr, const char *node)
|
sexpr_node(const struct sexpr *sexpr, const char *node)
|
||||||
{
|
{
|
||||||
struct sexpr *n = sexpr_lookup(sexpr, node);
|
struct sexpr *n = sexpr_lookup(sexpr, node);
|
||||||
|
|
||||||
@ -547,7 +547,7 @@ sexpr_node(struct sexpr *sexpr, const char *node)
|
|||||||
* Returns the value of the node or NULL if not found.
|
* Returns the value of the node or NULL if not found.
|
||||||
*/
|
*/
|
||||||
const char *
|
const char *
|
||||||
sexpr_fmt_node(struct sexpr *sexpr, const char *fmt, ...)
|
sexpr_fmt_node(const struct sexpr *sexpr, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
char node[4096];
|
char node[4096];
|
||||||
|
12
src/sexpr.h
12
src/sexpr.h
@ -35,20 +35,20 @@ struct sexpr {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* conversion to/from strings */
|
/* conversion to/from strings */
|
||||||
size_t sexpr2string(struct sexpr *sexpr, char *buffer, size_t n_buffer);
|
size_t sexpr2string(const struct sexpr *sexpr, char *buffer, size_t n_buffer);
|
||||||
struct sexpr *string2sexpr(const char *buffer);
|
struct sexpr *string2sexpr(const char *buffer);
|
||||||
|
|
||||||
/* constructors and destructors */
|
/* constructors and destructors */
|
||||||
struct sexpr *sexpr_nil(void);
|
struct sexpr *sexpr_nil(void);
|
||||||
struct sexpr *sexpr_string(const char *str, ssize_t len);
|
struct sexpr *sexpr_string(const char *str, ssize_t len);
|
||||||
struct sexpr *sexpr_cons(struct sexpr *car, struct sexpr *cdr);
|
struct sexpr *sexpr_cons(const struct sexpr *car, const struct sexpr *cdr);
|
||||||
struct sexpr *sexpr_append(struct sexpr *lst, struct sexpr *item);
|
struct sexpr *sexpr_append(struct sexpr *lst, const struct sexpr *item);
|
||||||
void sexpr_free(struct sexpr *sexpr);
|
void sexpr_free(struct sexpr *sexpr);
|
||||||
|
|
||||||
/* lookup in S-Expressions */
|
/* lookup in S-Expressions */
|
||||||
const char *sexpr_node(struct sexpr *sexpr, const char *node);
|
const char *sexpr_node(const struct sexpr *sexpr, const char *node);
|
||||||
const char *sexpr_fmt_node(struct sexpr *sexpr, const char *fmt, ...)
|
const char *sexpr_fmt_node(const struct sexpr *sexpr, const char *fmt, ...)
|
||||||
ATTRIBUTE_FORMAT(printf,2,3);
|
ATTRIBUTE_FORMAT(printf,2,3);
|
||||||
struct sexpr *sexpr_lookup(struct sexpr *sexpr, const char *node);
|
struct sexpr *sexpr_lookup(const struct sexpr *sexpr, const char *node);
|
||||||
int sexpr_has(struct sexpr *sexpr, const char *node);
|
int sexpr_has(struct sexpr *sexpr, const char *node);
|
||||||
#endif
|
#endif
|
||||||
|
@ -730,7 +730,7 @@ sexpr_get(virConnectPtr xend, const char *fmt, ...)
|
|||||||
* Returns the value found or 0 if not found (but may not be an error)
|
* Returns the value found or 0 if not found (but may not be an error)
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
sexpr_int(struct sexpr *sexpr, const char *name)
|
sexpr_int(const struct sexpr *sexpr, const char *name)
|
||||||
{
|
{
|
||||||
const char *value = sexpr_node(sexpr, name);
|
const char *value = sexpr_node(sexpr, name);
|
||||||
|
|
||||||
@ -751,7 +751,7 @@ sexpr_int(struct sexpr *sexpr, const char *name)
|
|||||||
* Returns the value found or 0 if not found (but may not be an error)
|
* Returns the value found or 0 if not found (but may not be an error)
|
||||||
*/
|
*/
|
||||||
static double
|
static double
|
||||||
sexpr_float(struct sexpr *sexpr, const char *name)
|
sexpr_float(const struct sexpr *sexpr, const char *name)
|
||||||
{
|
{
|
||||||
const char *value = sexpr_node(sexpr, name);
|
const char *value = sexpr_node(sexpr, name);
|
||||||
|
|
||||||
@ -772,7 +772,7 @@ sexpr_float(struct sexpr *sexpr, const char *name)
|
|||||||
* Returns the value found or 0 if not found (but may not be an error)
|
* Returns the value found or 0 if not found (but may not be an error)
|
||||||
*/
|
*/
|
||||||
static uint64_t
|
static uint64_t
|
||||||
sexpr_u64(struct sexpr *sexpr, const char *name)
|
sexpr_u64(const struct sexpr *sexpr, const char *name)
|
||||||
{
|
{
|
||||||
const char *value = sexpr_node(sexpr, name);
|
const char *value = sexpr_node(sexpr, name);
|
||||||
|
|
||||||
@ -794,7 +794,7 @@ sexpr_u64(struct sexpr *sexpr, const char *name)
|
|||||||
* Returns a -1 on error, 0 on success
|
* Returns a -1 on error, 0 on success
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
sexpr_uuid(unsigned char *ptr, struct sexpr *node, const char *path)
|
sexpr_uuid(unsigned char *ptr, const struct sexpr *node, const char *path)
|
||||||
{
|
{
|
||||||
const char *r = sexpr_node(node, path);
|
const char *r = sexpr_node(node, path);
|
||||||
if (!r)
|
if (!r)
|
||||||
@ -1840,7 +1840,8 @@ xend_parse_domain_sexp(virConnectPtr conn, char *sexpr, int xendConfigVersion) {
|
|||||||
* Returns 0 in case of success, -1 in case of error
|
* Returns 0 in case of success, -1 in case of error
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
sexpr_to_xend_domain_info(virDomainPtr domain, struct sexpr *root, virDomainInfoPtr info)
|
sexpr_to_xend_domain_info(virDomainPtr domain, const struct sexpr *root,
|
||||||
|
virDomainInfoPtr info)
|
||||||
{
|
{
|
||||||
const char *flags;
|
const char *flags;
|
||||||
|
|
||||||
@ -1889,7 +1890,7 @@ sexpr_to_xend_domain_info(virDomainPtr domain, struct sexpr *root, virDomainInfo
|
|||||||
* Returns 0 in case of success, -1 in case of error
|
* Returns 0 in case of success, -1 in case of error
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
sexpr_to_xend_node_info(struct sexpr *root, virNodeInfoPtr info)
|
sexpr_to_xend_node_info(const struct sexpr *root, virNodeInfoPtr info)
|
||||||
{
|
{
|
||||||
const char *machine;
|
const char *machine;
|
||||||
|
|
||||||
@ -1943,7 +1944,8 @@ sexpr_to_xend_node_info(struct sexpr *root, virNodeInfoPtr info)
|
|||||||
* Returns 0 in case of success, -1 in case of error
|
* Returns 0 in case of success, -1 in case of error
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
sexpr_to_xend_topology_xml(virConnectPtr conn, struct sexpr *root, virBufferPtr xml)
|
sexpr_to_xend_topology_xml(virConnectPtr conn, const struct sexpr *root,
|
||||||
|
virBufferPtr xml)
|
||||||
{
|
{
|
||||||
const char *nodeToCpu;
|
const char *nodeToCpu;
|
||||||
int numCells = 0;
|
int numCells = 0;
|
||||||
@ -1996,7 +1998,7 @@ error:
|
|||||||
* Returns the domain pointer or NULL in case of error.
|
* Returns the domain pointer or NULL in case of error.
|
||||||
*/
|
*/
|
||||||
static virDomainPtr
|
static virDomainPtr
|
||||||
sexpr_to_domain(virConnectPtr conn, struct sexpr *root)
|
sexpr_to_domain(virConnectPtr conn, const struct sexpr *root)
|
||||||
{
|
{
|
||||||
virDomainPtr ret = NULL;
|
virDomainPtr ret = NULL;
|
||||||
unsigned char uuid[VIR_UUID_BUFLEN];
|
unsigned char uuid[VIR_UUID_BUFLEN];
|
||||||
|
Loading…
Reference in New Issue
Block a user