]> xenbits.xensource.com Git - libvirt.git/commitdiff
Adjust sexpr-related interfaces to be const-correct.
authorJim Meyering <meyering@redhat.com>
Mon, 21 Jan 2008 14:22:15 +0000 (14:22 +0000)
committerJim Meyering <meyering@redhat.com>
Mon, 21 Jan 2008 14:22:15 +0000 (14:22 +0000)
* 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.

ChangeLog
src/sexpr.c
src/sexpr.h
src/xend_internal.c

index 4d7d74bdc8e6cd6e431de971176c2af625d77922..80e4d4ce25e9a469fb01870faf17ce55c8cfe1b1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 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.
        A NUL byte at beginning of input, or just after a newline
        would provoke an invalid buf[-1] access (possible segfault).
index f9e7226274368f0973ce40154ea8e7a94626d1e1..b273117dd64e33dd0cf826c297f84b84714d1a58 100644 (file)
@@ -150,15 +150,15 @@ sexpr_string(const char *str, ssize_t len)
  * Returns the resulting S-Expression pointer or NULL in case of error.
  */
 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();
 
     if (ret == NULL)
         return ret;
     ret->kind = SEXPR_CONS;
-    ret->u.s.car = car;
-    ret->u.s.cdr = cdr;
+    ret->u.s.car = (struct sexpr *) car;
+    ret->u.s.cdr = (struct sexpr *) cdr;
 
     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
  */
 static void
-append(struct sexpr *lst, struct sexpr *value)
+append(struct sexpr *lst, const struct sexpr *value)
 {
     while (lst->kind != SEXPR_NIL) {
         lst = lst->u.s.cdr;
     }
 
     lst->kind = SEXPR_CONS;
-    lst->u.s.car = value;
+    lst->u.s.car = (struct sexpr *) value;
     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
  */
 struct sexpr *
-sexpr_append(struct sexpr *lst, struct sexpr *value)
+sexpr_append(struct sexpr *lst, const struct sexpr *value)
 {
     if (lst == NULL)
         return (NULL);
@@ -215,7 +215,7 @@ sexpr_append(struct sexpr *lst, struct sexpr *value)
  *         0 in case of error.
  */
 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;
 
@@ -415,7 +415,7 @@ string2sexpr(const char *buffer)
  * Returns the pointer to the sub expression or NULL if not found.
  */
 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;
 
@@ -436,7 +436,7 @@ sexpr_lookup_key(struct sexpr *sexpr, const char *node)
     }
 
     for (token = strsep(&ptr, "/"); token; token = strsep(&ptr, "/")) {
-        struct sexpr *i;
+        const struct sexpr *i;
 
         if (token == NULL)
             continue;
@@ -464,7 +464,7 @@ sexpr_lookup_key(struct sexpr *sexpr, const char *node)
         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.
  */
 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);
 
@@ -528,7 +528,7 @@ sexpr_has(struct sexpr *sexpr, const char *node)
  * Returns the value of the node or NULL if not found.
  */
 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);
 
@@ -547,7 +547,7 @@ sexpr_node(struct sexpr *sexpr, const char *node)
  * Returns the value of the node or NULL if not found.
  */
 const char *
-sexpr_fmt_node(struct sexpr *sexpr, const char *fmt, ...)
+sexpr_fmt_node(const struct sexpr *sexpr, const char *fmt, ...)
 {
     va_list ap;
     char node[4096];
index eb82479a70ca0c6985e0d81463a6169440a17742..0dd882d50a3997b54e06f75d02ae97b3095be325 100644 (file)
@@ -35,20 +35,20 @@ struct sexpr {
 };
 
 /* 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);
 
 /* constructors and destructors */
 struct sexpr *sexpr_nil(void);
 struct sexpr *sexpr_string(const char *str, ssize_t len);
-struct sexpr *sexpr_cons(struct sexpr *car, struct sexpr *cdr);
-struct sexpr *sexpr_append(struct sexpr *lst, struct sexpr *item);
+struct sexpr *sexpr_cons(const struct sexpr *car, const struct sexpr *cdr);
+struct sexpr *sexpr_append(struct sexpr *lst, const struct sexpr *item);
 void sexpr_free(struct sexpr *sexpr);
 
 /* lookup in S-Expressions */
-const char *sexpr_node(struct sexpr *sexpr, const char *node);
-const char *sexpr_fmt_node(struct sexpr *sexpr, const char *fmt, ...)
+const char *sexpr_node(const struct sexpr *sexpr, const char *node);
+const char *sexpr_fmt_node(const struct sexpr *sexpr, const char *fmt, ...)
   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);
 #endif
index a192e08d1970ae7c811fae6b187538e69b3e5ce4..6d597f12878ea8634b430b1e73ce9bdf4c38daa9 100644 (file)
@@ -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)
  */
 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);
 
@@ -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)
  */
 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);
 
@@ -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)
  */
 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);
 
@@ -794,7 +794,7 @@ sexpr_u64(struct sexpr *sexpr, const char *name)
  * Returns a -1 on error, 0 on success
  */
 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);
     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
  */
 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;
 
@@ -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
  */
 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;
 
@@ -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
  */
 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;
     int numCells = 0;
@@ -1996,7 +1998,7 @@ error:
  * Returns the domain pointer or NULL in case of error.
  */
 static virDomainPtr
-sexpr_to_domain(virConnectPtr conn, struct sexpr *root)
+sexpr_to_domain(virConnectPtr conn, const struct sexpr *root)
 {
     virDomainPtr ret = NULL;
     unsigned char uuid[VIR_UUID_BUFLEN];