gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r23833 - gnunet/src/arm gnunet/src/chat gnunet/src/core gnu


From: gnunet
Subject: [GNUnet-SVN] r23833 - gnunet/src/arm gnunet/src/chat gnunet/src/core gnunet/src/dht gnunet/src/fs gnunet/src/include gnunet/src/mesh gnunet/src/namestore gnunet/src/statistics gnunet/src/testing_old gnunet/src/transport gnunet/src/util gnunet-gtk/src/setup
Date: Sun, 16 Sep 2012 13:27:08 +0200

Author: grothoff
Date: 2012-09-16 13:27:08 +0200 (Sun, 16 Sep 2012)
New Revision: 23833

Modified:
   gnunet-gtk/src/setup/gnunet-setup-gns.c
   gnunet/src/arm/gnunet-arm.c
   gnunet/src/chat/gnunet-chat.c
   gnunet/src/core/gnunet-core.c
   gnunet/src/dht/gnunet-dht-monitor.c
   gnunet/src/fs/gnunet-download.c
   gnunet/src/fs/gnunet-publish.c
   gnunet/src/fs/gnunet-unindex.c
   gnunet/src/fs/test_fs_directory.c
   gnunet/src/include/gnunet_strings_lib.h
   gnunet/src/mesh/mesh_api.c
   gnunet/src/namestore/gnunet-namestore.c
   gnunet/src/statistics/gnunet-statistics.c
   gnunet/src/testing_old/testing.c
   gnunet/src/transport/gnunet-transport.c
   gnunet/src/util/common_logging.c
   gnunet/src/util/container_meta_data.c
   gnunet/src/util/strings.c
   gnunet/src/util/test_strings.c
   gnunet/src/util/time.c
Log:
-fixing #2546

Modified: gnunet/src/arm/gnunet-arm.c
===================================================================
--- gnunet/src/arm/gnunet-arm.c 2012-09-16 03:42:46 UTC (rev 23832)
+++ gnunet/src/arm/gnunet-arm.c 2012-09-16 11:27:08 UTC (rev 23833)
@@ -412,8 +412,6 @@
 int
 main (int argc, char *const *argv)
 {
-  static unsigned long long temp_timeout_ms;
-
   static const struct GNUNET_GETOPT_CommandLineOption options[] = {
     {'e', "end", NULL, gettext_noop ("stop all GNUnet services"),
      GNUNET_NO, &GNUNET_GETOPT_set_one, &end},
@@ -433,7 +431,7 @@
      GNUNET_NO, &GNUNET_GETOPT_set_one, &quiet},
     {'T', "timeout", NULL,
      gettext_noop ("timeout for completing current operation"),
-     GNUNET_YES, &GNUNET_GETOPT_set_ulong, &temp_timeout_ms},
+     GNUNET_YES, &GNUNET_GETOPT_set_relative_time, &timeout},
     {'I', "info", NULL, gettext_noop ("List currently running services"),
      GNUNET_NO, &GNUNET_GETOPT_set_one, &list},
     {'O', "no-stdout", NULL, gettext_noop ("Don't let gnunet-service-arm 
inherit standard output"),
@@ -443,9 +441,6 @@
     GNUNET_GETOPT_OPTION_END
   };
 
-  if (temp_timeout_ms > 0)
-    timeout.rel_value = temp_timeout_ms;
-
   if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
     return 2;
 

Modified: gnunet/src/chat/gnunet-chat.c
===================================================================
--- gnunet/src/chat/gnunet-chat.c       2012-09-16 03:42:46 UTC (rev 23832)
+++ gnunet/src/chat/gnunet-chat.c       2012-09-16 11:27:08 UTC (rev 23833)
@@ -118,7 +118,7 @@
   char *non_unique_nick;
   char *nick;
   int nick_is_a_dup;
-  char *time;
+  const char *timestr;
   const char *fmt;
 
   if (NULL == sender)
@@ -176,10 +176,9 @@
     fmt = _("(%s) <%s> said using an unknown message type: %s\n");
     break;
   }
-  time = GNUNET_STRINGS_absolute_time_to_string (timestamp);
-  FPRINTF (stdout, fmt, time, nick, message);
+  timestr = GNUNET_STRINGS_absolute_time_to_string (timestamp);
+  FPRINTF (stdout, fmt, timestr, nick, message);
   GNUNET_free (nick);
-  GNUNET_free (time);
   return GNUNET_OK;
 }
 

Modified: gnunet/src/core/gnunet-core.c
===================================================================
--- gnunet/src/core/gnunet-core.c       2012-09-16 03:42:46 UTC (rev 23832)
+++ gnunet/src/core/gnunet-core.c       2012-09-16 11:27:08 UTC (rev 23833)
@@ -110,7 +110,8 @@
                 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
 {
   struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get();
-  char *now_str;
+  const char *now_str;
+
   if (0 != memcmp (&my_id, peer, sizeof (my_id)))
   {
     monitor_connections_counter ++;
@@ -120,8 +121,6 @@
              _("Connected to"),
              GNUNET_i2s (peer),
              monitor_connections_counter);
-
-    GNUNET_free (now_str);
   }
 }
 
@@ -137,21 +136,19 @@
 monitor_notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
 {
   struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get();
-  char *now_str;
+  const char *now_str;
 
   if (0 != memcmp (&my_id, peer, sizeof (my_id)))
   {
     now_str = GNUNET_STRINGS_absolute_time_to_string (now);
 
     GNUNET_assert (monitor_connections_counter > 0);
-    monitor_connections_counter --;
-
+    monitor_connections_counter--;
     FPRINTF (stdout, _("%24s: %-17s %4s   (%u connections in total)\n"),
              now_str,
              _("Disconnected from"),
              GNUNET_i2s (peer),
              monitor_connections_counter);
-    GNUNET_free (now_str);
   }
 }
 

Modified: gnunet/src/dht/gnunet-dht-monitor.c
===================================================================
--- gnunet/src/dht/gnunet-dht-monitor.c 2012-09-16 03:42:46 UTC (rev 23832)
+++ gnunet/src/dht/gnunet-dht-monitor.c 2012-09-16 11:27:08 UTC (rev 23833)
@@ -242,7 +242,7 @@
   if (verbose)
     FPRINTF (stderr, 
             "Monitoring for %s\n", 
-            GNUNET_TIME_relative_to_string (timeout_request));
+            GNUNET_STRINGS_relative_time_to_string (timeout_request, 
GNUNET_NO));
   GNUNET_SCHEDULER_add_delayed (timeout_request, &cleanup_task, NULL);
   monitor_handle = GNUNET_DHT_monitor_start (dht_handle,
                                              block_type,

Modified: gnunet/src/fs/gnunet-download.c
===================================================================
--- gnunet/src/fs/gnunet-download.c     2012-09-16 03:42:46 UTC (rev 23832)
+++ gnunet/src/fs/gnunet-download.c     2012-09-16 11:27:08 UTC (rev 23833)
@@ -127,7 +127,7 @@
 progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
 {
   char *s;
-  char *s2;
+  const char *s2;
   char *t;
 
   switch (info->status)
@@ -140,13 +140,15 @@
   case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS:
     if (verbose)
     {
-      s = GNUNET_STRINGS_relative_time_to_string (info->value.download.eta);
+      s = GNUNET_strdup (GNUNET_STRINGS_relative_time_to_string 
(info->value.download.eta,
+                                                                GNUNET_YES));
       if 
(info->value.download.specifics.progress.block_download_duration.rel_value 
           == GNUNET_TIME_UNIT_FOREVER_REL.rel_value)
-        s2 = GNUNET_strdup (_("<unknown time>"));
+        s2 = _("<unknown time>");
       else
         s2 = GNUNET_STRINGS_relative_time_to_string (
-              info->value.download.specifics.progress.block_download_duration);
+                                                    
info->value.download.specifics.progress.block_download_duration,
+                                                    GNUNET_YES);
       t = GNUNET_STRINGS_byte_size_fancy (info->value.download.completed *
                                           1000LL /
                                           (info->value.download.
@@ -157,7 +159,6 @@
                (unsigned long long) info->value.download.completed,
                (unsigned long long) info->value.download.size, s, t, s2);
       GNUNET_free (s);
-      GNUNET_free (s2);
       GNUNET_free (t);
     }
     else

Modified: gnunet/src/fs/gnunet-publish.c
===================================================================
--- gnunet/src/fs/gnunet-publish.c      2012-09-16 03:42:46 UTC (rev 23832)
+++ gnunet/src/fs/gnunet-publish.c      2012-09-16 11:27:08 UTC (rev 23833)
@@ -134,7 +134,7 @@
 static void *
 progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
 {
-  char *s;
+  const char *s;
 
   switch (info->status)
   {
@@ -143,12 +143,12 @@
   case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
     if (verbose)
     {
-      s = GNUNET_STRINGS_relative_time_to_string (info->value.publish.eta);
+      s = GNUNET_STRINGS_relative_time_to_string (info->value.publish.eta,
+                                                 GNUNET_YES);
       FPRINTF (stdout, _("Publishing `%s' at %llu/%llu (%s remaining)\n"),
                info->value.publish.filename,
                (unsigned long long) info->value.publish.completed,
                (unsigned long long) info->value.publish.size, s);
-      GNUNET_free (s);
     }
     break;
   case GNUNET_FS_STATUS_PUBLISH_ERROR:

Modified: gnunet/src/fs/gnunet-unindex.c
===================================================================
--- gnunet/src/fs/gnunet-unindex.c      2012-09-16 03:42:46 UTC (rev 23832)
+++ gnunet/src/fs/gnunet-unindex.c      2012-09-16 11:27:08 UTC (rev 23833)
@@ -76,7 +76,7 @@
 static void *
 progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
 {
-  char *s;
+  const char *s;
 
   switch (info->status)
   {
@@ -85,11 +85,10 @@
   case GNUNET_FS_STATUS_UNINDEX_PROGRESS:
     if (verbose)
     {
-      s = GNUNET_STRINGS_relative_time_to_string (info->value.unindex.eta);
+      s = GNUNET_STRINGS_relative_time_to_string (info->value.unindex.eta, 
GNUNET_YES);
       FPRINTF (stdout, _("Unindexing at %llu/%llu (%s remaining)\n"),
                (unsigned long long) info->value.unindex.completed,
                (unsigned long long) info->value.unindex.size, s);
-      GNUNET_free (s);
     }
     break;
   case GNUNET_FS_STATUS_UNINDEX_ERROR:

Modified: gnunet/src/fs/test_fs_directory.c
===================================================================
--- gnunet/src/fs/test_fs_directory.c   2012-09-16 03:42:46 UTC (rev 23832)
+++ gnunet/src/fs/test_fs_directory.c   2012-09-16 11:27:08 UTC (rev 23833)
@@ -79,7 +79,7 @@
   char txt[128];
   int ret = 0;
   struct GNUNET_TIME_Absolute start;
-  char *s;
+  const char *s;
 
   cls.max = i;
   uris = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri *) * i);
@@ -130,11 +130,11 @@
     GNUNET_FS_directory_builder_add (db, uris[p], mds[p], NULL);
   GNUNET_FS_directory_builder_finish (db, &dlen, (void **) &data);
   s = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration
-                                              (start));
+                                              (start),
+                                             GNUNET_YES);
   FPRINTF (stdout,
            "Creating directory with %u entires and total size %llu took %s\n",
            i, (unsigned long long) dlen, s);
-  GNUNET_free (s);
   if (i < 100)
   {
     cls.pos = 0;

Modified: gnunet/src/include/gnunet_strings_lib.h
===================================================================
--- gnunet/src/include/gnunet_strings_lib.h     2012-09-16 03:42:46 UTC (rev 
23832)
+++ gnunet/src/include/gnunet_strings_lib.h     2012-09-16 11:27:08 UTC (rev 
23833)
@@ -224,22 +224,28 @@
 
 /**
  * "asctime", except for GNUnet time.
+ * This is one of the very few calls in the entire API that is
+ * NOT reentrant!
  *
  * @param t the absolute time to convert
  * @return timestamp in human-readable form
  */
-char *
+const char *
 GNUNET_STRINGS_absolute_time_to_string (struct GNUNET_TIME_Absolute t);
 
 
 /**
  * Give relative time in human-readable fancy format.
+ * This is one of the very few calls in the entire API that is
+ * NOT reentrant! 
  *
  * @param delta time in milli seconds
+ * @param do_round are we allowed to round a bit?
  * @return string in human-readable form
  */
-char *
-GNUNET_STRINGS_relative_time_to_string (struct GNUNET_TIME_Relative delta);
+const char *
+GNUNET_STRINGS_relative_time_to_string (struct GNUNET_TIME_Relative delta,
+                                       int do_round);
 
 
 /**

Modified: gnunet/src/mesh/mesh_api.c
===================================================================
--- gnunet/src/mesh/mesh_api.c  2012-09-16 03:42:46 UTC (rev 23832)
+++ gnunet/src/mesh/mesh_api.c  2012-09-16 11:27:08 UTC (rev 23833)
@@ -828,8 +828,10 @@
         GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_SECONDS,
                                   GNUNET_TIME_relative_multiply
                                   (h->reconnect_time, 2));
-    LOG (GNUNET_ERROR_TYPE_DEBUG, "  Next retry in %sms\n",
-         GNUNET_TIME_relative_to_string (h->reconnect_time));
+    LOG (GNUNET_ERROR_TYPE_DEBUG, 
+        "Next retry in %s\n",
+         GNUNET_STRINGS_relative_time_to_string (h->reconnect_time,
+                                                GNUNET_NO));
     GNUNET_break (0);
     return GNUNET_NO;
   }

Modified: gnunet/src/namestore/gnunet-namestore.c
===================================================================
--- gnunet/src/namestore/gnunet-namestore.c     2012-09-16 03:42:46 UTC (rev 
23832)
+++ gnunet/src/namestore/gnunet-namestore.c     2012-09-16 11:27:08 UTC (rev 
23833)
@@ -277,7 +277,7 @@
   const char *typestring;
   char *s;
   unsigned int i;
-  char *etime;
+  const char *etime;
   struct GNUNET_TIME_Absolute aex;
   struct GNUNET_TIME_Relative rex;
 
@@ -308,7 +308,7 @@
     if (0 != (rd[i].flags & GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION))
     {
       rex.rel_value = rd[i].expiration_time;
-      etime = GNUNET_STRINGS_relative_time_to_string (rex);
+      etime = GNUNET_STRINGS_relative_time_to_string (rex, GNUNET_YES);
     }
     else
     {
@@ -320,7 +320,6 @@
             ? _(/* what follows is relative expiration */ "for at least")
             : _(/* what follows is absolute expiration */ "until"),
             etime);
-    GNUNET_free (etime);
     GNUNET_free (s);    
   }
   FPRINTF (stdout, "%s", "\n");

Modified: gnunet/src/statistics/gnunet-statistics.c
===================================================================
--- gnunet/src/statistics/gnunet-statistics.c   2012-09-16 03:42:46 UTC (rev 
23832)
+++ gnunet/src/statistics/gnunet-statistics.c   2012-09-16 11:27:08 UTC (rev 
23833)
@@ -79,7 +79,8 @@
          int is_persistent)
 {
   struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get();
-  char * now_str;
+  const char * now_str;
+
   if (quiet == GNUNET_NO)
   {
     if (GNUNET_YES == watch)
@@ -89,7 +90,6 @@
                now_str,
                is_persistent ? "!" : " ",
                subsystem, _(name), (unsigned long long) value);
-      GNUNET_free (now_str);
     }
     else
     {

Modified: gnunet/src/testing_old/testing.c
===================================================================
--- gnunet/src/testing_old/testing.c    2012-09-16 03:42:46 UTC (rev 23832)
+++ gnunet/src/testing_old/testing.c    2012-09-16 11:27:08 UTC (rev 23833)
@@ -417,9 +417,9 @@
          GNUNET_OS_start_process (GNUNET_YES, 
GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "gnunet-arm", "gnunet-arm", "-c",
                                    d->cfgfile,
                                    "-s", "-q", "-T",
-                                   GNUNET_TIME_relative_to_string
+                                   GNUNET_STRINGS_relative_time_to_string
                                    (GNUNET_TIME_absolute_get_remaining
-                                    (d->max_timeout)), NULL);
+                                    (d->max_timeout), GNUNET_NO), NULL);
     }
     else
     {
@@ -438,9 +438,9 @@
                                            "-q",
                                            dst, "gnunet-arm",
                                            "-c", d->cfgfile, "-s", "-q", "-T",
-                                           GNUNET_TIME_relative_to_string
+                                           
GNUNET_STRINGS_relative_time_to_string
                                            (GNUNET_TIME_absolute_get_remaining
-                                            (d->max_timeout)), NULL);
+                                            (d->max_timeout), GNUNET_NO), 
NULL);
       }
       else
       {
@@ -451,9 +451,9 @@
                                      "-q",
                                      dst, "gnunet-arm",
                                      "-c", d->cfgfile, "-s", "-q", "-T",
-                                     GNUNET_TIME_relative_to_string
+                                     GNUNET_STRINGS_relative_time_to_string
                                      (GNUNET_TIME_absolute_get_remaining
-                                      (d->max_timeout)), NULL);
+                                      (d->max_timeout), GNUNET_NO), NULL);
       }
       GNUNET_free (dst);
     }
@@ -897,7 +897,7 @@
                                        arg, "gnunet-arm",
                                        "-c", d->cfgfile, "-i", service, "-q",
                                        "-T",
-                                       GNUNET_TIME_relative_to_string 
(timeout),
+                                                    
GNUNET_STRINGS_relative_time_to_string (timeout, GNUNET_NO),
                                        NULL);
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "Starting gnunet-arm with command ssh %s gnunet-arm -c %s -i 
%s -q\n",
@@ -911,7 +911,7 @@
     d->proc_arm_srv_start = GNUNET_OS_start_process (GNUNET_YES, 
GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "gnunet-arm", "gnunet-arm",
                                        "-c", d->cfgfile, "-i", service, "-q",
                                        "-T",
-                                       GNUNET_TIME_relative_to_string 
(timeout),
+                                                    
GNUNET_STRINGS_relative_time_to_string (timeout, GNUNET_NO),
                                        NULL);
   }
 
@@ -965,12 +965,12 @@
                                        arg, "gnunet-arm",
                                        "-c", d->cfgfile, "-i", service, "-q",
                                        "-T",
-                                       GNUNET_TIME_relative_to_string 
(timeout),
+                                                    
GNUNET_STRINGS_relative_time_to_string (timeout, GNUNET_NO),
                                        NULL);
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "Starting gnunet-arm with command ssh %s gnunet-arm -c %s -i 
%s -q -T %s\n",
                 arg, "gnunet-arm", d->cfgfile, service,
-                GNUNET_TIME_relative_to_string (timeout));
+                GNUNET_STRINGS_relative_time_to_string (timeout, GNUNET_NO));
     GNUNET_free (arg);
   }
   else
@@ -980,12 +980,12 @@
     d->proc_arm_srv_start = GNUNET_OS_start_process (GNUNET_YES, 
GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "gnunet-arm", "gnunet-arm",
                                        "-c", d->cfgfile, "-i", service, "-q",
                                        "-T",
-                                       GNUNET_TIME_relative_to_string 
(timeout),
+                                                    
GNUNET_STRINGS_relative_time_to_string (timeout, GNUNET_NO),
                                        NULL);
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "Starting gnunet-arm with command %s -c %s -i %s -q -T %s\n",
                 "gnunet-arm", d->cfgfile, service,
-                GNUNET_TIME_relative_to_string (timeout));
+                GNUNET_STRINGS_relative_time_to_string (timeout, GNUNET_NO));
   }
 
   d->max_timeout = GNUNET_TIME_relative_to_absolute (timeout);
@@ -1382,7 +1382,7 @@
                                        arg, "gnunet-arm",
                                        "-c", d->cfgfile, "-k", service, "-q",
                                        "-T",
-                                       GNUNET_TIME_relative_to_string 
(timeout),
+                                                   
GNUNET_STRINGS_relative_time_to_string (timeout, GNUNET_NO),
                                        NULL);
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "Stopping gnunet-arm with command ssh %s gnunet-arm -c %s -k 
%s -q\n",
@@ -1396,7 +1396,7 @@
     d->proc_arm_srv_stop = GNUNET_OS_start_process (GNUNET_YES, 
GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "gnunet-arm", "gnunet-arm",
                                        "-c", d->cfgfile, "-k", service, "-q",
                                        "-T",
-                                       GNUNET_TIME_relative_to_string 
(timeout),
+                                                   
GNUNET_STRINGS_relative_time_to_string (timeout, GNUNET_NO),
                                        NULL);
   }
 
@@ -1550,7 +1550,7 @@
                                        "-q",
                                        arg, "gnunet-arm",
                                        "-c", d->cfgfile, "-e", "-q", "-T",
-                                       GNUNET_TIME_relative_to_string 
(timeout),
+                                               
GNUNET_STRINGS_relative_time_to_string (timeout, GNUNET_NO),
                                        del_arg, NULL);
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "Stopping gnunet-arm with command ssh %s gnunet-arm -c %s -e 
-q %s\n",
@@ -1564,7 +1564,7 @@
                 "Stopping gnunet-arm with config `%s' locally.\n", d->cfgfile);
     d->proc_arm_stop = GNUNET_OS_start_process (GNUNET_NO, 
GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "gnunet-arm", "gnunet-arm",
                                        "-c", d->cfgfile, "-e", "-q", "-T",
-                                       GNUNET_TIME_relative_to_string 
(timeout),
+                                               
GNUNET_STRINGS_relative_time_to_string (timeout, GNUNET_NO),
                                        del_arg, NULL);
     GNUNET_assert (NULL != d->proc_arm_stop);
   }

Modified: gnunet/src/transport/gnunet-transport.c
===================================================================
--- gnunet/src/transport/gnunet-transport.c     2012-09-16 03:42:46 UTC (rev 
23832)
+++ gnunet/src/transport/gnunet-transport.c     2012-09-16 11:27:08 UTC (rev 
23833)
@@ -447,14 +447,13 @@
 {
   monitor_connections_counter ++;
   struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get();
-  char *now_str = GNUNET_STRINGS_absolute_time_to_string (now);
+  const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now);
+
   FPRINTF (stdout, _("%24s: %-17s %4s   (%u connections in total)\n"),
            now_str,
            _("Connected to"),
            GNUNET_i2s (peer),
            monitor_connections_counter);
-
-  GNUNET_free (now_str);
 }
 
 
@@ -469,7 +468,7 @@
 monitor_notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
 {
   struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get();
-  char *now_str = GNUNET_STRINGS_absolute_time_to_string (now);
+  const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now);
 
   GNUNET_assert (monitor_connections_counter > 0);
   monitor_connections_counter --;
@@ -479,7 +478,6 @@
            _("Disconnected from"),
            GNUNET_i2s (peer),
            monitor_connections_counter);
-  GNUNET_free (now_str);
 }
 
 

Modified: gnunet/src/util/common_logging.c
===================================================================
--- gnunet/src/util/common_logging.c    2012-09-16 03:42:46 UTC (rev 23832)
+++ gnunet/src/util/common_logging.c    2012-09-16 11:27:08 UTC (rev 23833)
@@ -798,7 +798,7 @@
   char msg[DATE_STR_SIZE + BULK_TRACK_SIZE + 256];
   int rev;
   char *last;
-  char *ft;
+  const char *ft;
 
   if ((last_bulk_time.abs_value == 0) || (last_bulk_repeat == 0))
     return;
@@ -814,11 +814,10 @@
     last[0] = '\0';
   }
   ft = GNUNET_STRINGS_relative_time_to_string 
(GNUNET_TIME_absolute_get_duration
-                                               (last_bulk_time));
+                                               (last_bulk_time), GNUNET_YES);
   snprintf (msg, sizeof (msg),
             _("Message `%.*s' repeated %u times in the last %s\n"),
             BULK_TRACK_SIZE, last_bulk, last_bulk_repeat, ft);
-  GNUNET_free (ft);
   if (rev == 1)
     last[0] = '\n';
   output_message (last_bulk_kind, last_bulk_comp, datestr, msg);

Modified: gnunet/src/util/container_meta_data.c
===================================================================
--- gnunet/src/util/container_meta_data.c       2012-09-16 03:42:46 UTC (rev 
23832)
+++ gnunet/src/util/container_meta_data.c       2012-09-16 11:27:08 UTC (rev 
23833)
@@ -427,7 +427,7 @@
 GNUNET_CONTAINER_meta_data_add_publication_date (struct
                                                  GNUNET_CONTAINER_MetaData *md)
 {
-  char *dat;
+  const char *dat;
   struct GNUNET_TIME_Absolute t;
 
   t = GNUNET_TIME_absolute_get ();
@@ -438,7 +438,6 @@
                                      EXTRACTOR_METATYPE_PUBLICATION_DATE,
                                      EXTRACTOR_METAFORMAT_UTF8, "text/plain",
                                      dat, strlen (dat) + 1);
-  GNUNET_free (dat);
 }
 
 

Modified: gnunet/src/util/strings.c
===================================================================
--- gnunet/src/util/strings.c   2012-09-16 03:42:46 UTC (rev 23832)
+++ gnunet/src/util/strings.c   2012-09-16 11:27:08 UTC (rev 23833)
@@ -616,33 +616,46 @@
 
 /**
  * Give relative time in human-readable fancy format.
+ * This is one of the very few calls in the entire API that is
+ * NOT reentrant!
  *
  * @param delta time in milli seconds
+ * @param do_round are we allowed to round a bit?
  * @return time as human-readable string
  */
-char *
-GNUNET_STRINGS_relative_time_to_string (struct GNUNET_TIME_Relative delta)
+const char *
+GNUNET_STRINGS_relative_time_to_string (struct GNUNET_TIME_Relative delta,
+                                       int do_round)
 {
+  static char buf[128];
   const char *unit = _( /* time unit */ "ms");
   char *ret;
   uint64_t dval = delta.rel_value;
 
   if (delta.rel_value == GNUNET_TIME_UNIT_FOREVER_REL.rel_value)
-    return GNUNET_strdup (_("forever"));
-  if ( (dval > 5 * 1000) || (0 == (dval % 1000) ))
+    return _("forever");
+  if ( ( (GNUNET_YES == do_round) && 
+        (dval > 5 * 1000) ) || 
+       (0 == (dval % 1000) ))
   {
     dval = dval / 1000;
     unit = _( /* time unit */ "s");
-    if ( (dval > 5 * 60) || (0 == (dval % 60) ) )
+    if ( ( (GNUNET_YES == do_round) &&
+          (dval > 5 * 60) ) ||
+        (0 == (dval % 60) ) )
     {
       dval = dval / 60;
       unit = _( /* time unit */ "m");
-      if ( (dval > 5 * 60) || (0 == (dval % 60) ))
+      if ( ( (GNUNET_YES == do_round) &&
+            (dval > 5 * 60) ) || 
+          (0 == (dval % 60) ))
       {
         dval = dval / 60;
         unit = _( /* time unit */ "h");
-        if ( (dval > 5 * 24) || (0 == (dval % 24)) )
-        {
+        if ( ( (GNUNET_YES == do_round) &&
+              (dval > 5 * 24) ) ||
+            (0 == (dval % 24)) )
+       {
           dval = dval / 24;
          if (1 == dval)
            unit = _( /* time unit */ "day");
@@ -652,23 +665,26 @@
       }
     }
   }
-  GNUNET_asprintf (&ret, "%llu %s", dval, unit);
-  return ret;
+  GNUNET_snprintf (buf, sizeof (buf),
+                  "%llu %s", dval, unit);
+  return buf;
 }
 
 
 /**
  * "asctime", except for GNUnet time.
+ * This is one of the very few calls in the entire API that is
+ * NOT reentrant!
  *
  * @param t time to convert
  * @return absolute time in human-readable format
  */
-char *
+const char *
 GNUNET_STRINGS_absolute_time_to_string (struct GNUNET_TIME_Absolute t)
 {
+  static char buf[255];
   time_t tt;
   struct tm *tp;
-  char buf[255];
 
   if (t.abs_value == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value)
     return GNUNET_strdup (_("end of time"));

Modified: gnunet/src/util/test_strings.c
===================================================================
--- gnunet/src/util/test_strings.c      2012-09-16 03:42:46 UTC (rev 23832)
+++ gnunet/src/util/test_strings.c      2012-09-16 11:27:08 UTC (rev 23833)
@@ -27,6 +27,7 @@
 
 
 #define WANT(a,b) if (0 != strcmp(a,b)) { fprintf(stderr, "Got `%s', wanted 
`%s'\n", b, a); GNUNET_free(b); GNUNET_break(0); return 1;} else { GNUNET_free 
(b); }
+#define WANTNF(a,b) do { if (0 != strcmp(a,b)) { fprintf(stderr, "Got `%s', 
wanted `%s'\n", b, a); GNUNET_break(0); return 1;} } while (0)
 #define WANTB(a,b,l) if (0 != memcmp(a,b,l)) { GNUNET_break(0); return 1;} 
else { }
 
 int
@@ -35,6 +36,7 @@
   char buf[128];
   char *r;
   char *b;
+  const char *bc;
   struct GNUNET_TIME_Absolute at;
   struct GNUNET_TIME_Absolute atx;
   const char *hdir;
@@ -50,20 +52,20 @@
   b = GNUNET_STRINGS_byte_size_fancy (10240LL * 1024LL * 1024LL * 1024LL);
   WANT (buf, b);
   sprintf (buf, "4 %s", _( /* time unit */ "ms"));
-  b = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_relative_multiply
-                                              (GNUNET_TIME_UNIT_MILLISECONDS,
-                                               4));
-  WANT (buf, b);
+  bc = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_relative_multiply
+                                              (GNUNET_TIME_UNIT_MILLISECONDS,
+                                               4), GNUNET_YES);
+  WANTNF (buf, bc);
   sprintf (buf, "7 %s", _( /* time unit */ "s"));
-  b = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_relative_multiply
-                                              (GNUNET_TIME_UNIT_MILLISECONDS,
-                                               7 * 1000));
-  WANT (buf, b);
+  bc = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_relative_multiply
+                                              (GNUNET_TIME_UNIT_MILLISECONDS,
+                                               7 * 1000), GNUNET_YES);
+  WANTNF (buf, bc);
   sprintf (buf, "7 %s", _( /* time unit */ "h"));
-  b = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_relative_multiply
+  bc = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_relative_multiply
                                               (GNUNET_TIME_UNIT_MILLISECONDS,
-                                               7 * 60 * 60 * 1000));
-  WANT (buf, b);
+                                               7 * 60 * 60 * 1000), 
GNUNET_YES);
+  WANTNF (buf, bc);
 #ifndef MINGW
   hdir = getenv ("HOME");
 #else
@@ -84,27 +86,24 @@
   if (0 != GNUNET_STRINGS_buffer_tokenize (buf, 2, 2, &r, &b))
     return 1;
   at.abs_value = 5000;
-  r = GNUNET_STRINGS_absolute_time_to_string (at);
-  /* r should be something like "Wed Dec 31 17:00:05 1969"
+  bc = GNUNET_STRINGS_absolute_time_to_string (at);
+  /* bc should be something like "Wed Dec 31 17:00:05 1969"
    * where the details of the day and hour depend on the timezone;
    * however, the "0:05 19" should always be there; hence: */
-  if (NULL == strstr (r, "0:05 19"))
+  if (NULL == strstr (bc, "0:05 19"))
   {
-    FPRINTF (stderr, "Got %s\n", r);
+    FPRINTF (stderr, "Got %s\n", bc);
     GNUNET_break (0);
-    GNUNET_free (r);
     return 1;
   }
-  GNUNET_free (r);
   b = GNUNET_STRINGS_to_utf8 ("TEST", 4, "ASCII");
   WANT ("TEST", b);
   
   at = GNUNET_TIME_UNIT_FOREVER_ABS;
-  b = GNUNET_STRINGS_absolute_time_to_string (at);
+  bc = GNUNET_STRINGS_absolute_time_to_string (at);
   GNUNET_assert (GNUNET_OK ==
-                GNUNET_STRINGS_fancy_time_to_absolute (b, &atx));
+                GNUNET_STRINGS_fancy_time_to_absolute (bc, &atx));
   GNUNET_assert (atx.abs_value == at.abs_value);
-  GNUNET_free (b);
 
 #if ENABLE_NLS && HAVE_ICONV
   GNUNET_log_skip (2, GNUNET_NO);

Modified: gnunet/src/util/time.c
===================================================================
--- gnunet/src/util/time.c      2012-09-16 03:42:46 UTC (rev 23832)
+++ gnunet/src/util/time.c      2012-09-16 11:27:08 UTC (rev 23833)
@@ -484,6 +484,7 @@
   return ret;
 }
 
+
 /**
  * Convert relative time from network byte order.
  *
@@ -500,6 +501,7 @@
 
 }
 
+
 /**
  * Convert absolute time to network byte order.
  *
@@ -515,6 +517,7 @@
   return ret;
 }
 
+
 /**
  * Convert absolute time from network byte order.
  *
@@ -531,26 +534,5 @@
 
 }
 
-/**
- * Convert a relative time to a string.
- * This is one of the very few calls in the entire API that is
- * NOT reentrant!
- *
- * @param time the time to print
- *
- * @return string form of the time (as milliseconds)
- */
-const char *
-GNUNET_TIME_relative_to_string (struct GNUNET_TIME_Relative time)
-{
-  static char time_string[21];
 
-  memset (time_string, 0, sizeof (time_string));
-
-  sprintf (time_string, "%llu", (unsigned long long) time.rel_value);
-  return (const char *) time_string;
-}
-
-
-
 /* end of time.c */

Modified: gnunet-gtk/src/setup/gnunet-setup-gns.c
===================================================================
--- gnunet-gtk/src/setup/gnunet-setup-gns.c     2012-09-16 03:42:46 UTC (rev 
23832)
+++ gnunet-gtk/src/setup/gnunet-setup-gns.c     2012-09-16 11:27:08 UTC (rev 
23833)
@@ -1004,7 +1004,7 @@
  *
  * @param renderer updated renderer
  * @param path the path identifying the edited cell
- * @param new_text the new name
+ * @param new_text the new name (not modified)
  * @param user_data unused
  */
 void
@@ -1055,14 +1055,16 @@
   else
   {
     /* update name */
-    gtk_tree_store_set (ts, &it, GNS_TREESTORE_COL_NAME, new_text, -1);
+    gtk_tree_store_set (ts, &it, 
+                       GNS_TREESTORE_COL_NAME, new_text,
+                       -1);
 
     if (gtk_tree_model_iter_children (tm, &child, &it))
     {
       do
       {
         gtk_tree_store_set (ts, &child,
-                           GNS_TREESTORE_COL_NAME, &new_text,
+                           GNS_TREESTORE_COL_NAME, new_text,
                            -1);
         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New text for `%s' is `%s'\n", 
path, new_text);
       }
@@ -1193,7 +1195,7 @@
   GtkTreeSelection * ts;
   gboolean has_parent;
   char *path;
-  char *tstr;
+  const char *tstr;
   int not_dummy;
 
   ts = gtk_tree_view_get_selection(tv);
@@ -1210,12 +1212,11 @@
   /* this is a single record */
   renderer = GTK_CELL_RENDERER_TEXT((GNUNET_SETUP_get_object 
("GNUNET_setup_gns_name_cellrenderertext")));
   path = gtk_tree_model_get_string_from_iter (tm, &it);
-  tstr = GNUNET_STRINGS_relative_time_to_string (reltime);
+  tstr = GNUNET_STRINGS_relative_time_to_string (reltime, GNUNET_NO);
   GNUNET_setup_gns_expiration_cellrenderertext_edited_cb (renderer,
                                                          path,
-                                                         tstr,
+                                                         (gchar *) tstr,
                                                          NULL);
-  GNUNET_free (tstr);
 }
 
 
@@ -1288,7 +1289,7 @@
   char *path;
   int not_dummy;
   char fancydate[128];
-  char *gndate;
+  const char *gndate;
   struct GNUNET_TIME_Absolute atime;
 
   if (GTK_RESPONSE_OK != response_id)
@@ -1327,12 +1328,11 @@
        path = gtk_tree_model_get_string_from_iter (tm, &it);
        GNUNET_setup_gns_expiration_cellrenderertext_edited_cb (renderer,
                                                                path,
-                                                               gndate,
+                                                               (gchar *) 
gndate,
                                                                NULL);
       }
     }
   }
-  GNUNET_free (gndate);
   gtk_widget_destroy (GTK_WIDGET (dialog));    
   g_object_unref (G_OBJECT (builder));
 }
@@ -1552,7 +1552,7 @@
   GtkEntry *pseu_entry;
   int c;
   struct GNUNET_CRYPTO_ShortHashAsciiEncoded shenc;
-  char *exp;
+  const char *exp;
   char *val;
   char * type_str;
   gboolean time_is_relative;
@@ -1621,7 +1621,7 @@
 
       rel_time.rel_value = rd[c].expiration_time;
       exp_t = rel_time.rel_value;
-      exp = GNUNET_STRINGS_relative_time_to_string (rel_time);
+      exp = GNUNET_STRINGS_relative_time_to_string (rel_time, GNUNET_NO);
     }
     else
     {
@@ -1665,7 +1665,6 @@
                                          -1);
     }
     GNUNET_free (type_str);
-    GNUNET_free (exp);
     GNUNET_free (val);
   }
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]