ia64/xen-unstable

changeset 16738:2d9a8a4d7e73

libxen: Avoid declarations-after-statement (C++ coding style).
Signed-off-by: Andre Przywara <andre.przywara@amd.com>

libxen: Use build-system CFLAGS and LDFLAGS.
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Jan 17 15:11:22 2008 +0000 (2008-01-17)
parents 8984cc0a1d80
children 33dcf04d7715
files tools/libxen/Makefile tools/libxen/src/xen_common.c tools/libxen/src/xen_int_string_set_map.c tools/libxen/src/xen_string_set.c tools/libxen/src/xen_string_string_map.c
line diff
     1.1 --- a/tools/libxen/Makefile	Thu Jan 17 15:06:30 2008 +0000
     1.2 +++ b/tools/libxen/Makefile	Thu Jan 17 15:11:22 2008 +0000
     1.3 @@ -21,13 +21,13 @@ include $(XEN_ROOT)/tools/Rules.mk
     1.4  MAJOR = 1.0
     1.5  MINOR = 0
     1.6  
     1.7 -CFLAGS = -Iinclude                     \
     1.8 -         $(shell xml2-config --cflags) \
     1.9 -         $(shell curl-config --cflags) \
    1.10 -         -W -Wall -Wmissing-prototypes -Werror -std=c99 -O2 -fPIC
    1.11 +CFLAGS += -Iinclude                     \
    1.12 +          $(shell xml2-config --cflags) \
    1.13 +          $(shell curl-config --cflags) \
    1.14 +          -fPIC
    1.15  
    1.16 -LDFLAGS = $(shell xml2-config --libs) \
    1.17 -          $(shell curl-config --libs)
    1.18 +LDFLAGS += $(shell xml2-config --libs) \
    1.19 +           $(shell curl-config --libs)
    1.20  
    1.21  LIBXENAPI_HDRS = $(wildcard include/xen/api/*.h) include/xen/api/xen_all.h
    1.22  LIBXENAPI_OBJS = $(patsubst %.c, %.o, $(wildcard src/*.c))
     2.1 --- a/tools/libxen/src/xen_common.c	Thu Jan 17 15:06:30 2008 +0000
     2.2 +++ b/tools/libxen/src/xen_common.c	Thu Jan 17 15:11:22 2008 +0000
     2.3 @@ -416,13 +416,13 @@ xen_call_(xen_session *s, const char *me
     2.4            abstract_value params[], int param_count,
     2.5            const abstract_type *result_type, void *value)
     2.6  {
     2.7 +    abstract_value *full_params;
     2.8      if (!s->ok)
     2.9      {
    2.10          return;
    2.11      }
    2.12  
    2.13 -    abstract_value *full_params =
    2.14 -        malloc(sizeof(abstract_value) * (param_count + 1));
    2.15 +    full_params = malloc(sizeof(abstract_value) * (param_count + 1));
    2.16  
    2.17      full_params[0].type = &abstract_type_string;
    2.18      full_params[0].u.string_val = s->session_id;
    2.19 @@ -475,13 +475,14 @@ call_raw(xen_session *s, const char *met
    2.20  
    2.21  static void server_error(xen_session *session, const char *error_string)
    2.22  {
    2.23 +    char **strings;
    2.24      if (!session->ok)
    2.25      {
    2.26          /* Don't wipe out the earlier error message with this one. */
    2.27          return;
    2.28      }
    2.29  
    2.30 -    char **strings = malloc(2 * sizeof(char *));
    2.31 +    strings = malloc(2 * sizeof(char *));
    2.32  
    2.33      strings[0] = xen_strdup_("SERVER_FAULT");
    2.34      strings[1] = xen_strdup_(error_string);
    2.35 @@ -495,13 +496,14 @@ static void server_error(xen_session *se
    2.36  static void server_error_2(xen_session *session, const char *error_string,
    2.37                             const char *param)
    2.38  {
    2.39 +    char **strings;
    2.40      if (!session->ok)
    2.41      {
    2.42          /* Don't wipe out the earlier error message with this one. */
    2.43          return;
    2.44      }
    2.45  
    2.46 -    char **strings = malloc(3 * sizeof(char *));
    2.47 +    strings = malloc(3 * sizeof(char *));
    2.48  
    2.49      strings[0] = xen_strdup_("SERVER_FAULT_2");
    2.50      strings[1] = xen_strdup_(error_string);
    2.51 @@ -791,17 +793,17 @@ static void parse_into(xen_session *s, x
    2.52          }
    2.53          else
    2.54          {
    2.55 -            xmlNode *data_node = value_node->children->children;
    2.56 -            int n = count_children(data_node, "value");
    2.57 +            arbitrary_set *set;
    2.58 +            xmlNode *cur, *data_node = value_node->children->children;
    2.59 +            int i, n = count_children(data_node, "value");
    2.60  
    2.61              const abstract_type *member_type = result_type->child;
    2.62              size_t member_size = size_of_member(member_type);
    2.63  
    2.64 -            arbitrary_set *set =
    2.65 -                calloc(1, sizeof(arbitrary_set) + member_size * n);
    2.66 +            set = calloc(1, sizeof(arbitrary_set) + member_size * n);
    2.67              set->size = n;
    2.68 -            int i = 0;
    2.69 -            xmlNode *cur = data_node->children;
    2.70 +            i = 0;
    2.71 +            cur = data_node->children;
    2.72  
    2.73              while (cur != NULL)
    2.74              {
    2.75 @@ -829,24 +831,25 @@ static void parse_into(xen_session *s, x
    2.76          }
    2.77          else
    2.78          {
    2.79 -            xmlNode *struct_node = value_node->children;
    2.80 -            int n = count_children(struct_node, "member");
    2.81 +            arbitrary_map *map;
    2.82 +            xmlNode *cur, *struct_node = value_node->children;
    2.83 +            int i, n = count_children(struct_node, "member");
    2.84  
    2.85              size_t struct_size = result_type->struct_size;
    2.86  
    2.87              const struct struct_member *key_member = result_type->members;
    2.88              const struct struct_member *val_member = result_type->members + 1;
    2.89  
    2.90 -            arbitrary_map *map =
    2.91 -                calloc(1, sizeof(arbitrary_map) + struct_size * n);
    2.92 +            map = calloc(1, sizeof(arbitrary_map) + struct_size * n);
    2.93              map->size = n;
    2.94 -            int i = 0;
    2.95 -            xmlNode *cur = struct_node->children;
    2.96 +            i = 0;
    2.97 +            cur = struct_node->children;
    2.98  
    2.99              while (cur != NULL)
   2.100              {
   2.101                  if (0 == strcmp((char *)cur->name, "member"))
   2.102                  {
   2.103 +                    xmlChar *name;
   2.104                      if (cur->children == NULL || cur->last == cur->children)
   2.105                      {
   2.106                          server_error(s, "Malformed Map");
   2.107 @@ -854,7 +857,7 @@ static void parse_into(xen_session *s, x
   2.108                          return;
   2.109                      }
   2.110  
   2.111 -                    xmlChar *name = string_from_name(cur);
   2.112 +                    name = string_from_name(cur);
   2.113                      if (name == NULL)
   2.114                      {
   2.115                          server_error(s, "Malformed Map");
   2.116 @@ -919,6 +922,7 @@ static void parse_into(xen_session *s, x
   2.117              {
   2.118                  if (0 == strcmp((char *)cur->name, "member"))
   2.119                  {
   2.120 +                    xmlChar *name;
   2.121                      if (cur->children == NULL || cur->last == cur->children)
   2.122                      {
   2.123                          server_error(s, "Malformed Struct");
   2.124 @@ -927,7 +931,7 @@ static void parse_into(xen_session *s, x
   2.125                          return;
   2.126                      }
   2.127  
   2.128 -                    xmlChar *name = string_from_name(cur);
   2.129 +                    name = string_from_name(cur);
   2.130                      if (name == NULL)
   2.131                      {
   2.132                          server_error(s, "Malformed Struct");
   2.133 @@ -1075,6 +1079,10 @@ static void parse_structmap_value(xen_se
   2.134  
   2.135  static void parse_fault(xen_session *session, xmlXPathContextPtr xpathCtx)
   2.136  {
   2.137 +    xmlNode *fault_node0, *fault_node1;
   2.138 +    xmlChar *fault_code_str, *fault_string_str;
   2.139 +    char **strings;
   2.140 +
   2.141      xmlXPathObjectPtr xpathObj = xmlXPathCompiledEval(faultPath, xpathCtx);
   2.142      if (xpathObj == NULL)
   2.143      {
   2.144 @@ -1090,10 +1098,10 @@ static void parse_fault(xen_session *ses
   2.145          return;
   2.146      }
   2.147  
   2.148 -    xmlNode *fault_node0 = xpathObj->nodesetval->nodeTab[0];
   2.149 -    xmlNode *fault_node1 = xpathObj->nodesetval->nodeTab[1];
   2.150 +    fault_node0 = xpathObj->nodesetval->nodeTab[0];
   2.151 +    fault_node1 = xpathObj->nodesetval->nodeTab[1];
   2.152  
   2.153 -    xmlChar *fault_code_str = string_from_value(fault_node0, "int");
   2.154 +    fault_code_str = string_from_value(fault_node0, "int");
   2.155      if (fault_code_str == NULL)
   2.156      {
   2.157          fault_code_str = string_from_value(fault_node0, "i4");
   2.158 @@ -1105,7 +1113,7 @@ static void parse_fault(xen_session *ses
   2.159          return;
   2.160      }
   2.161  
   2.162 -    xmlChar *fault_string_str = string_from_value(fault_node1, "string");
   2.163 +    fault_string_str = string_from_value(fault_node1, "string");
   2.164      if (fault_string_str == NULL)
   2.165      {
   2.166          xmlFree(fault_code_str);
   2.167 @@ -1114,7 +1122,7 @@ static void parse_fault(xen_session *ses
   2.168          return;
   2.169      }
   2.170  
   2.171 -    char **strings = malloc(3 * sizeof(char *));
   2.172 +    strings = malloc(3 * sizeof(char *));
   2.173  
   2.174      strings[0] = xen_strdup_("FAULT");
   2.175      strings[1] = xen_strdup_((char *)fault_code_str);
   2.176 @@ -1142,12 +1150,15 @@ static void parse_failure(xen_session *s
   2.177  
   2.178      if (session->ok)
   2.179      {
   2.180 +        char **c, **strings;
   2.181 +        int n;
   2.182 +
   2.183          session->ok = false;
   2.184  
   2.185 -        char **c = (char **)error_descriptions->contents;
   2.186 -        int n = error_descriptions->size;
   2.187 +        c = (char **)error_descriptions->contents;
   2.188 +        n = error_descriptions->size;
   2.189  
   2.190 -        char **strings = malloc(n * sizeof(char *));
   2.191 +        strings = malloc(n * sizeof(char *));
   2.192          for (int i = 0; i < n; i++)
   2.193          {
   2.194              strings[i] = c[i];
   2.195 @@ -1169,6 +1180,10 @@ static void parse_result(xen_session *se
   2.196  {
   2.197      xmlDocPtr doc =
   2.198          xmlReadMemory(result, strlen(result), "", NULL, XML_PARSE_NONET);
   2.199 +    xmlXPathContextPtr xpathCtx;
   2.200 +    xmlXPathObjectPtr xpathObj;
   2.201 +    xmlNode *node0, *node1;
   2.202 +    xmlChar *status_code;
   2.203  
   2.204      if (doc == NULL)
   2.205      {
   2.206 @@ -1176,7 +1191,7 @@ static void parse_result(xen_session *se
   2.207          return;
   2.208      }
   2.209  
   2.210 -    xmlXPathContextPtr xpathCtx = xmlXPathNewContext(doc);
   2.211 +    xpathCtx = xmlXPathNewContext(doc);
   2.212      if (xpathCtx == NULL)
   2.213      {
   2.214          xmlFreeDoc(doc);
   2.215 @@ -1184,8 +1199,7 @@ static void parse_result(xen_session *se
   2.216          return;
   2.217      }
   2.218  
   2.219 -    xmlXPathObjectPtr xpathObj =
   2.220 -        xmlXPathCompiledEval(responsePath, xpathCtx);
   2.221 +    xpathObj = xmlXPathCompiledEval(responsePath, xpathCtx);
   2.222      if (xpathObj == NULL)
   2.223      {
   2.224          parse_fault(session, xpathCtx);
   2.225 @@ -1206,10 +1220,10 @@ static void parse_result(xen_session *se
   2.226          return;
   2.227      }
   2.228  
   2.229 -    xmlNode *node0 = xpathObj->nodesetval->nodeTab[0];
   2.230 -    xmlNode *node1 = xpathObj->nodesetval->nodeTab[1];
   2.231 +    node0 = xpathObj->nodesetval->nodeTab[0];
   2.232 +    node1 = xpathObj->nodesetval->nodeTab[1];
   2.233  
   2.234 -    xmlChar *status_code = string_from_value(node0, "string");
   2.235 +    status_code = string_from_value(node0, "string");
   2.236      if (status_code == NULL)
   2.237      {
   2.238          xmlXPathFreeObject(xpathObj);
   2.239 @@ -1364,14 +1378,17 @@ static char *
   2.240  make_body(const char *method_name, abstract_value params[], int param_count)
   2.241  {
   2.242      xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0");
   2.243 -    xmlNode *methodCall = xmlNewNode(NULL, BAD_CAST "methodCall");
   2.244 +    xmlNode *params_node, *methodCall = xmlNewNode(NULL, BAD_CAST "methodCall");
   2.245 +    xmlBufferPtr buffer;
   2.246 +    xmlSaveCtxtPtr save_ctxt;
   2.247 +    xmlChar *content;
   2.248 +
   2.249      xmlDocSetRootElement(doc, methodCall);
   2.250  
   2.251      xmlNewChild(methodCall, NULL, BAD_CAST "methodName",
   2.252                  BAD_CAST method_name);
   2.253  
   2.254 -    xmlNode *params_node =
   2.255 -        xmlNewChild(methodCall, NULL, BAD_CAST "params", NULL);
   2.256 +    params_node = xmlNewChild(methodCall, NULL, BAD_CAST "params", NULL);
   2.257  
   2.258      for (int p = 0; p < param_count; p++)
   2.259      {
   2.260 @@ -1379,9 +1396,8 @@ make_body(const char *method_name, abstr
   2.261          make_body_add_type(v->type->typename, v, params_node);
   2.262      }
   2.263  
   2.264 -    xmlBufferPtr buffer = xmlBufferCreate();
   2.265 -    xmlSaveCtxtPtr save_ctxt =
   2.266 -        xmlSaveToBuffer(buffer, NULL, XML_SAVE_NO_XHTML);
   2.267 +    buffer = xmlBufferCreate();
   2.268 +    save_ctxt = xmlSaveToBuffer(buffer, NULL, XML_SAVE_NO_XHTML);
   2.269  
   2.270      if (xmlSaveDoc(save_ctxt, doc) == -1)
   2.271      {
   2.272 @@ -1390,7 +1406,7 @@ make_body(const char *method_name, abstr
   2.273  
   2.274      xmlFreeDoc(doc);
   2.275      xmlSaveClose(save_ctxt);
   2.276 -    xmlChar *content = xmlStrdup(xmlBufferContent(buffer));
   2.277 +    content = xmlStrdup(xmlBufferContent(buffer));
   2.278      xmlBufferFree(buffer);
   2.279      return (char *)content;
   2.280  }
   2.281 @@ -1611,11 +1627,12 @@ static xmlNode *
   2.282  add_struct_array(xmlNode *struct_node, const char *name)
   2.283  {
   2.284      xmlNode *member_node = add_container(struct_node, "member");
   2.285 +    xmlNode *value_node, *array_node;
   2.286  
   2.287      xmlNewChild(member_node, NULL, BAD_CAST "name", BAD_CAST name);
   2.288  
   2.289 -    xmlNode *value_node = add_container(member_node, "value");
   2.290 -    xmlNode *array_node = add_container(value_node,  "array");
   2.291 +    value_node = add_container(member_node, "value");
   2.292 +    array_node = add_container(value_node,  "array");
   2.293  
   2.294      return add_container(array_node,  "data");
   2.295  }
   2.296 @@ -1625,10 +1642,11 @@ static xmlNode *
   2.297  add_nested_struct(xmlNode *struct_node, const char *name)
   2.298  {
   2.299      xmlNode *member_node = add_container(struct_node, "member");
   2.300 +    xmlNode *value_node;
   2.301  
   2.302      xmlNewChild(member_node, NULL, BAD_CAST "name", BAD_CAST name);
   2.303  
   2.304 -    xmlNode *value_node = add_container(member_node, "value");
   2.305 +    value_node = add_container(member_node, "value");
   2.306  
   2.307      return add_container(value_node, "struct");
   2.308  }
     3.1 --- a/tools/libxen/src/xen_int_string_set_map.c	Thu Jan 17 15:06:30 2008 +0000
     3.2 +++ b/tools/libxen/src/xen_int_string_set_map.c	Thu Jan 17 15:11:22 2008 +0000
     3.3 @@ -36,12 +36,14 @@ xen_int_string_set_map_alloc(size_t size
     3.4  void
     3.5  xen_int_string_set_map_free(xen_int_string_set_map *map)
     3.6  {
     3.7 +	size_t n;
     3.8 +
     3.9      if (map == NULL)
    3.10      {
    3.11          return;
    3.12      }
    3.13  
    3.14 -    size_t n = map->size;
    3.15 +    n = map->size;
    3.16      for (size_t i = 0; i < n; i++)
    3.17      {
    3.18          
     4.1 --- a/tools/libxen/src/xen_string_set.c	Thu Jan 17 15:06:30 2008 +0000
     4.2 +++ b/tools/libxen/src/xen_string_set.c	Thu Jan 17 15:11:22 2008 +0000
     4.3 @@ -33,11 +33,12 @@ xen_string_set_alloc(size_t size)
     4.4  void
     4.5  xen_string_set_free(xen_string_set *set)
     4.6  {
     4.7 +    size_t n;
     4.8      if (set == NULL)
     4.9      {
    4.10          return;
    4.11      }
    4.12 -    size_t n = set->size;
    4.13 +    n = set->size;
    4.14      for (size_t i = 0; i < n; i++)
    4.15      {
    4.16         free(set->contents[i]);
     5.1 --- a/tools/libxen/src/xen_string_string_map.c	Thu Jan 17 15:06:30 2008 +0000
     5.2 +++ b/tools/libxen/src/xen_string_string_map.c	Thu Jan 17 15:11:22 2008 +0000
     5.3 @@ -35,12 +35,13 @@ xen_string_string_map_alloc(size_t size)
     5.4  void
     5.5  xen_string_string_map_free(xen_string_string_map *map)
     5.6  {
     5.7 +    size_t n;
     5.8      if (map == NULL)
     5.9      {
    5.10          return;
    5.11      }
    5.12  
    5.13 -    size_t n = map->size;
    5.14 +    n = map->size;
    5.15      for (size_t i = 0; i < n; i++)
    5.16      {
    5.17          free(map->contents[i].key);