Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Mark some internal symbols as hidden on ELF in xbt
[simgrid.git] / src / xbt / xbt_strbuff.c
index 1db4432..980a3dc 100644 (file)
@@ -1,18 +1,11 @@
-/* $Id: buff.c 3483 2007-05-07 11:18:56Z mquinson $ */
-
 /* strbuff -- string buffers                                                */
 
-/* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team.
+/* Copyright (c) 2007-2015. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
-/* specific to Borland Compiler */
-#ifdef __BORLANDDC__
-#pragma hdrstop
-#endif
-
 #include "xbt/strbuff.h"
 
 #define minimal_increment 512
@@ -31,8 +24,8 @@ XBT_INLINE void xbt_strbuff_empty(xbt_strbuff_t b)
 
 xbt_strbuff_t xbt_strbuff_new(void)
 {
-  xbt_strbuff_t res = malloc(sizeof(s_xbt_strbuff_t));
-  res->data = malloc(512);
+  xbt_strbuff_t res = xbt_malloc(sizeof(s_xbt_strbuff_t));
+  res->data = xbt_malloc(512);
   res->size = 512;
   xbt_strbuff_empty(res);
   return res;
@@ -44,7 +37,7 @@ xbt_strbuff_t xbt_strbuff_new(void)
  */
 XBT_INLINE xbt_strbuff_t xbt_strbuff_new_from(const char *ctn)
 {
-  xbt_strbuff_t res = malloc(sizeof(s_xbt_strbuff_t));
+  xbt_strbuff_t res = xbt_malloc(sizeof(s_xbt_strbuff_t));
   res->data = xbt_strdup(ctn);
   res->used = res->size = strlen(ctn);
   return res;
@@ -78,7 +71,7 @@ void xbt_strbuff_append(xbt_strbuff_t b, const char *toadd)
 
   if (needed_space > b->size) {
     b->size = MAX(minimal_increment + b->used, needed_space);
-    b->data = realloc(b->data, b->size);
+    b->data = xbt_realloc(b->data, b->size);
   }
   strcpy(b->data + b->used, toadd);
   b->used += addlen;
@@ -254,7 +247,7 @@ void xbt_strbuff_varsubst(xbt_strbuff_t b, xbt_dict_t patterns)
 //          XBT_DEBUG("Too short (by %d chars; %d chars left in area)",val_len- (end_subst-beg_subst), b->size - b->used);
           if (newused > b->size) {
             /* We have to realloc the data area before (because b->size is too small). We have to update our pointers, too */
-            char *newdata = realloc(b->data,
+            char *newdata = xbt_realloc(b->data,
                                     b->used + MAX(minimal_increment,
                                                   tooshort));
             int offset = newdata - b->data;
@@ -309,14 +302,14 @@ static void mytest(const char *input, const char *patterns,
   char *str;                    /*foreach */
   xbt_strbuff_t sb;             /* what we test */
 
-  p = xbt_dict_new();
+  p = xbt_dict_new_homogeneous(free);
   dyn_patterns = xbt_str_split(patterns, " ");
   xbt_dynar_foreach(dyn_patterns, cpt, str) {
     xbt_dynar_t keyvals = xbt_str_split(str, "=");
     char *key = xbt_dynar_get_as(keyvals, 0, char *);
     char *val = xbt_dynar_get_as(keyvals, 1, char *);
     xbt_str_subst(key, '_', ' ', 0);    // to put space in names without breaking the enclosing dynar_foreach
-    xbt_dict_set(p, key, xbt_strdup(val), free);
+    xbt_dict_set(p, key, xbt_strdup(val), NULL);
     xbt_dynar_free(&keyvals);
   }
   xbt_dynar_free(&dyn_patterns);