emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] trunk r117205: Use common string allocation and freeing fu


From: Dmitry Antipov
Subject: [Emacs-diffs] trunk r117205: Use common string allocation and freeing functions where applicable.
Date: Fri, 30 May 2014 13:22:49 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 117205
revision-id: address@hidden
parent: address@hidden
committer: Dmitry Antipov <address@hidden>
branch nick: trunk
timestamp: Fri 2014-05-30 17:22:29 +0400
message:
  Use common string allocation and freeing functions where applicable.
  * lwlib.h (safe_strdup): Remove prototype.
  * lwlib.c (safe_strdup, safe_free_str): Remove.
  (copy_widget_value_tree, allocate_widget_info, free_widget_info):
  (merge_widget_value): Prefer xstrdup, xfree and dupstring.
  * lwlib-Xm.c (make_destroyed_instance, xm_update_one_value): Ditto.
modified:
  lwlib/ChangeLog                changelog-20091113204419-o5vbwnq5f7feedwu-1447
  lwlib/lwlib-Xm.c               lwlibxm.c-20091113204419-o5vbwnq5f7feedwu-666
  lwlib/lwlib-int.h              lwlibint.h-20091113204419-o5vbwnq5f7feedwu-669
  lwlib/lwlib.c                  lwlib.c-20091113204419-o5vbwnq5f7feedwu-672
=== modified file 'lwlib/ChangeLog'
--- a/lwlib/ChangeLog   2014-03-03 04:57:26 +0000
+++ b/lwlib/ChangeLog   2014-05-30 13:22:29 +0000
@@ -1,3 +1,12 @@
+2014-05-30  Dmitry Antipov  <address@hidden>
+
+       Use common string allocation and freeing functions where applicable.
+       * lwlib.h (safe_strdup): Remove prototype.
+       * lwlib.c (safe_strdup, safe_free_str): Remove.
+       (copy_widget_value_tree, allocate_widget_info, free_widget_info):
+       (merge_widget_value): Prefer xstrdup, xfree and dupstring.
+       * lwlib-Xm.c (make_destroyed_instance, xm_update_one_value): Ditto.
+
 2013-12-14  Paul Eggert  <address@hidden>
 
        Use bool for boolean, focusing on headers.

=== modified file 'lwlib/lwlib-Xm.c'
--- a/lwlib/lwlib-Xm.c  2014-01-01 07:43:34 +0000
+++ b/lwlib/lwlib-Xm.c  2014-05-30 13:22:29 +0000
@@ -170,8 +170,8 @@
 {
   destroyed_instance* instance =
     (destroyed_instance*) xmalloc (sizeof (destroyed_instance));
-  instance->name = safe_strdup (name);
-  instance->type = safe_strdup (type);
+  instance->name = xstrdup (name);
+  instance->type = xstrdup (type);
   instance->widget = widget;
   instance->parent = parent;
   instance->pop_up_p = pop_up_p;
@@ -953,10 +953,7 @@
 
              XtVaGetValues (toggle, XmNset, &set, NULL);
              if (set)
-               {
-                 xfree (val->value);
-                 val->value = safe_strdup (XtName (toggle));
-               }
+               dupstring (&val->value, XtName (toggle));
            }
          val->edited = True;
        }
@@ -979,7 +976,7 @@
                  if (pos_list [j] == i)
                    {
                      cur->selected = True;
-                     val->value = safe_strdup (cur->name);
+                     val->value = xstrdup (cur->name);
                    }
              }
          val->edited = 1;

=== modified file 'lwlib/lwlib-int.h'
--- a/lwlib/lwlib-int.h 2014-01-01 07:43:34 +0000
+++ b/lwlib/lwlib-int.h 2014-05-30 13:22:29 +0000
@@ -23,8 +23,6 @@
 
 #include "lwlib.h"
 
-extern char *safe_strdup (const char *);
-
 struct widget_xft_data;
 
 typedef struct _widget_instance

=== modified file 'lwlib/lwlib.c'
--- a/lwlib/lwlib.c     2014-01-01 07:43:34 +0000
+++ b/lwlib/lwlib.c     2014-05-30 13:22:29 +0000
@@ -71,7 +71,6 @@
                                          widget_value *,
                                          int, int *);
 static void instantiate_widget_instance (widget_instance *);
-static void safe_free_str (char *);
 static void free_widget_value_tree (widget_value *);
 static widget_value *copy_widget_value_tree (widget_value *,
                                              change_type);
@@ -99,18 +98,6 @@
 static void lw_pop_all_widgets (LWLIB_ID, Boolean);
 static Boolean get_one_value (widget_instance *, widget_value *);
 static void show_one_widget_busy (Widget, Boolean);
-/* utility functions for widget_instance and widget_info */
-char *
-safe_strdup (const char *s)
-{
-  return s ? xstrdup (s) : 0;
-}
-
-static void
-safe_free_str (char *s)
-{
-  xfree (s);
-}
 
 static widget_value *widget_value_free_list = 0;
 static int malloc_cpt = 0;
@@ -199,9 +186,9 @@
     return val;
 
   copy = malloc_widget_value ();
-  copy->name = safe_strdup (val->name);
-  copy->value = safe_strdup (val->value);
-  copy->key = safe_strdup (val->key);
+  copy->name = xstrdup (val->name);
+  copy->value = val->value ? xstrdup (val->value) : NULL;
+  copy->key = val->key ? xstrdup (val->key) : NULL;
   copy->help = val->help;
   copy->enabled = val->enabled;
   copy->button_type = val->button_type;
@@ -228,8 +215,8 @@
                       lw_callback highlight_cb)
 {
   widget_info* info = (widget_info*) xmalloc (sizeof (widget_info));
-  info->type = safe_strdup (type);
-  info->name = safe_strdup (name);
+  info->type = xstrdup (type);
+  info->name = xstrdup (name);
   info->id = id;
   info->val = copy_widget_value_tree (val, STRUCTURAL_CHANGE);
   info->busy = False;
@@ -248,8 +235,8 @@
 static void
 free_widget_info (widget_info *info)
 {
-  safe_free_str (info->type);
-  safe_free_str (info->name);
+  xfree (info->type);
+  xfree (info->name);
   free_widget_value_tree (info->val);
   memset ((void*)info, 0xDEADBEEF, sizeof (widget_info));
   xfree (info);
@@ -431,24 +418,21 @@
       EXPLAIN (val1->name, change, STRUCTURAL_CHANGE, "name change",
               val1->name, val2->name);
       change = max (change, STRUCTURAL_CHANGE);
-      safe_free_str (val1->name);
-      val1->name = safe_strdup (val2->name);
+      dupstring (&val1->name, val2->name);
     }
   if (safe_strcmp (val1->value, val2->value))
     {
       EXPLAIN (val1->name, change, VISIBLE_CHANGE, "value change",
               val1->value, val2->value);
       change = max (change, VISIBLE_CHANGE);
-      safe_free_str (val1->value);
-      val1->value = safe_strdup (val2->value);
+      dupstring (&val1->value, val2->value);
     }
   if (safe_strcmp (val1->key, val2->key))
     {
       EXPLAIN (val1->name, change, VISIBLE_CHANGE, "key change",
               val1->key, val2->key);
       change = max (change, VISIBLE_CHANGE);
-      safe_free_str (val1->key);
-      val1->key = safe_strdup (val2->key);
+      dupstring (&val1->key, val2->key);
     }
   if (! EQ (val1->help, val2->help))
     {


reply via email to

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