MOO_ASSIGN_STRING, MOO_OBJECT_REF_SINK

master
Yevgen Muntyan 2007-12-19 14:02:42 -06:00
parent a797478846
commit 70d5fbc914
24 changed files with 45 additions and 105 deletions

View File

@ -1294,14 +1294,9 @@ moo_command_data_set (MooCommandData *data,
guint index, guint index,
const char *value) const char *value)
{ {
char *tmp;
g_return_if_fail (data != NULL); g_return_if_fail (data != NULL);
g_return_if_fail (index < data->len); g_return_if_fail (index < data->len);
MOO_ASSIGN_STRING (data->data[index], value);
tmp = data->data[index];
data->data[index] = g_strdup (value);
g_free (tmp);
} }
@ -1319,13 +1314,8 @@ static void
moo_command_data_take_code (MooCommandData *data, moo_command_data_take_code (MooCommandData *data,
char *code) char *code)
{ {
char *tmp;
g_return_if_fail (data != NULL); g_return_if_fail (data != NULL);
MOO_ASSIGN_STRING (data->code, code);
tmp = data->code;
data->code = code;
g_free (tmp);
} }

View File

@ -13,7 +13,7 @@
#define MOOEDIT_COMPILATION #define MOOEDIT_COMPILATION
#include "mooedit/moocommanddisplay.h" #include "mooedit/moocommanddisplay.h"
#include "mooedit/moocommand-private.h" #include "mooedit/moocommand-private.h"
#include "mooutils/mooutils-gobject.h" #include "mooutils/mooutils-misc.h"
#include <string.h> #include <string.h>

View File

@ -22,7 +22,6 @@
#include "mooedit/mooeditfiltersettings.h" #include "mooedit/mooeditfiltersettings.h"
#include "mooedit/mooeditor-private.h" #include "mooedit/mooeditor-private.h"
#include "mooutils/moomarshals.h" #include "mooutils/moomarshals.h"
#include "mooutils/mooutils-gobject.h"
#include "mooutils/mooglade.h" #include "mooutils/mooglade.h"
#include "mooutils/mooi18n.h" #include "mooutils/mooi18n.h"
#include "mooutils/mooutils-misc.h" #include "mooutils/mooutils-misc.h"
@ -694,9 +693,7 @@ _moo_edit_set_encoding (MooEdit *edit,
if (!_moo_str_equal (encoding, edit->priv->encoding)) if (!_moo_str_equal (encoding, edit->priv->encoding))
{ {
char *tmp = edit->priv->encoding; MOO_ASSIGN_STRING (edit->priv->encoding, encoding);
edit->priv->encoding = g_strdup (encoding);
g_free (tmp);
g_object_notify (G_OBJECT (edit), "encoding"); g_object_notify (G_OBJECT (edit), "encoding");
} }
} }

View File

@ -698,16 +698,9 @@ void
moo_editor_set_app_name (MooEditor *editor, moo_editor_set_app_name (MooEditor *editor,
const char *name) const char *name)
{ {
char *tmp;
g_return_if_fail (MOO_IS_EDITOR (editor)); g_return_if_fail (MOO_IS_EDITOR (editor));
MOO_ASSIGN_STRING (editor->priv->app_name, name);
tmp = editor->priv->app_name;
editor->priv->app_name = g_strdup (name);
_moo_edit_window_update_title (); _moo_edit_window_update_title ();
g_free (tmp);
} }
const char * const char *

View File

@ -14,6 +14,7 @@
#include "mooedit/mootext-private.h" #include "mooedit/mootext-private.h"
#include "mooedit/mootextbuffer.h" #include "mooedit/mootextbuffer.h"
#include "mooutils/moomarshals.h" #include "mooutils/moomarshals.h"
#include "mooutils/mooutils-misc.h"
struct _MooLineMarkPrivate { struct _MooLineMarkPrivate {
@ -367,16 +368,12 @@ void
moo_line_mark_set_markup (MooLineMark *mark, moo_line_mark_set_markup (MooLineMark *mark,
const char *markup) const char *markup)
{ {
char *tmp;
g_return_if_fail (MOO_IS_LINE_MARK (mark)); g_return_if_fail (MOO_IS_LINE_MARK (mark));
if (!markup || !markup[0]) if (!markup || !markup[0])
markup = NULL; markup = NULL;
tmp = mark->priv->markup; MOO_ASSIGN_STRING (mark->priv->markup, markup);
mark->priv->markup = g_strdup (markup);
g_free (tmp);
} }

View File

@ -14,6 +14,7 @@
#include "mooedit/mooeditor.h" #include "mooedit/mooeditor.h"
#include "mooutils/moomarshals.h" #include "mooutils/moomarshals.h"
#include "mooutils/mooutils-debug.h" #include "mooutils/mooutils-debug.h"
#include "mooutils/mooutils-misc.h"
#include <string.h> #include <string.h>
@ -220,14 +221,8 @@ void
moo_output_filter_cmd_start (MooOutputFilter *filter, moo_output_filter_cmd_start (MooOutputFilter *filter,
const char *active_dir) const char *active_dir)
{ {
char *tmp;
g_return_if_fail (MOO_IS_OUTPUT_FILTER (filter)); g_return_if_fail (MOO_IS_OUTPUT_FILTER (filter));
MOO_ASSIGN_STRING (filter->priv->active_dir, active_dir);
tmp = filter->priv->active_dir;
filter->priv->active_dir = g_strdup (active_dir);
g_free (tmp);
g_signal_emit (filter, signals[CMD_START], 0); g_signal_emit (filter, signals[CMD_START], 0);
} }
@ -314,13 +309,8 @@ void
moo_output_filter_set_active_file (MooOutputFilter *filter, moo_output_filter_set_active_file (MooOutputFilter *filter,
const char *filename) const char *filename)
{ {
char *tmp;
g_return_if_fail (MOO_IS_OUTPUT_FILTER (filter)); g_return_if_fail (MOO_IS_OUTPUT_FILTER (filter));
MOO_ASSIGN_STRING (filter->priv->active_file, filename);
tmp = filter->priv->active_file;
filter->priv->active_file = g_strdup (filename);
g_free (tmp);
} }

View File

@ -1580,17 +1580,9 @@ moo_print_operation_set_filename (MooPrintOperation *op,
const char *filename, const char *filename,
const char *basename) const char *basename)
{ {
char *tmp;
g_return_if_fail (MOO_IS_PRINT_OPERATION (op)); g_return_if_fail (MOO_IS_PRINT_OPERATION (op));
MOO_ASSIGN_STRING (op->priv->filename, filename);
tmp = op->priv->filename; MOO_ASSIGN_STRING (op->priv->basename, basename);
op->priv->filename = g_strdup (filename);
g_free (tmp);
tmp = op->priv->basename;
op->priv->basename = g_strdup (basename);
g_free (tmp);
} }

View File

@ -21,7 +21,6 @@
#include "mooedit/mooeditprefs.h" #include "mooedit/mooeditprefs.h"
#include "mooedit/mootextbox.h" #include "mooedit/mootextbox.h"
#include "mooutils/moomarshals.h" #include "mooutils/moomarshals.h"
#include "mooutils/mooutils-gobject.h"
#include "mooutils/mooutils-misc.h" #include "mooutils/mooutils-misc.h"
#include "mooutils/mooundo.h" #include "mooutils/mooundo.h"
#include "mooutils/mooentry.h" #include "mooutils/mooentry.h"
@ -1612,14 +1611,10 @@ moo_text_view_set_color (MooTextView *view,
const char *color, const char *color,
const char *propname) const char *propname)
{ {
char *tmp;
g_return_if_fail (MOO_IS_TEXT_VIEW (view)); g_return_if_fail (MOO_IS_TEXT_VIEW (view));
g_return_if_fail (color_num < MOO_TEXT_VIEW_N_COLORS); g_return_if_fail (color_num < MOO_TEXT_VIEW_N_COLORS);
tmp = view->priv->colors[color_num]; MOO_ASSIGN_STRING (view->priv->colors[color_num], color);
view->priv->colors[color_num] = g_strdup (color);
g_free (tmp);
invalidate_gcs (view); invalidate_gcs (view);

View File

@ -22,7 +22,6 @@
#include "mooutils/mooprefs.h" #include "mooutils/mooprefs.h"
#include "mooutils/moomarshals.h" #include "mooutils/moomarshals.h"
#include "mooutils/mooactionfactory.h" #include "mooutils/mooactionfactory.h"
#include "mooutils/mooutils-gobject.h"
#include "mooutils/mooutils-misc.h" #include "mooutils/mooutils-misc.h"
#include "mooutils/moostock.h" #include "mooutils/moostock.h"
#include <string.h> #include <string.h>

View File

@ -18,7 +18,6 @@
#include "mooterm/mootermbuffer-private.h" #include "mooterm/mootermbuffer-private.h"
#include "mooterm/mooterm-text.h" #include "mooterm/mooterm-text.h"
#include "mooutils/moomarshals.h" #include "mooutils/moomarshals.h"
#include "mooutils/mooutils-gobject.h"
#include "mooutils/mooutils-misc.h" #include "mooutils/mooutils-misc.h"
#include "mooutils/mooutils-debug.h" #include "mooutils/mooutils-debug.h"
#include <string.h> #include <string.h>

View File

@ -12,6 +12,7 @@
#include "mooutils/mooactiongroup.h" #include "mooutils/mooactiongroup.h"
#include "mooutils/mooactionbase.h" #include "mooutils/mooactionbase.h"
#include "mooutils/mooutils-misc.h"
#include "mooutils/moowindow.h" #include "mooutils/moowindow.h"
#include <string.h> #include <string.h>
@ -74,14 +75,11 @@ moo_action_collection_set_property (GObject *object,
GParamSpec *pspec) GParamSpec *pspec)
{ {
MooActionCollection *coll = MOO_ACTION_COLLECTION (object); MooActionCollection *coll = MOO_ACTION_COLLECTION (object);
char *tmp;
switch (property_id) switch (property_id)
{ {
case PROP_NAME: case PROP_NAME:
tmp = coll->priv->name; MOO_ASSIGN_STRING (coll->priv->name, g_value_get_string (value));
coll->priv->name = g_strdup (g_value_get_string (value));
g_free (tmp);
break; break;
case PROP_DISPLAY_NAME: case PROP_DISPLAY_NAME:
moo_action_collection_set_display_name (coll, g_value_get_string (value)); moo_action_collection_set_display_name (coll, g_value_get_string (value));

View File

@ -11,6 +11,7 @@
*/ */
#include "mooutils/mooactiongroup.h" #include "mooutils/mooactiongroup.h"
#include "mooutils/mooutils-misc.h"
G_DEFINE_TYPE (MooActionGroup, _moo_action_group, GTK_TYPE_ACTION_GROUP) G_DEFINE_TYPE (MooActionGroup, _moo_action_group, GTK_TYPE_ACTION_GROUP)
@ -39,13 +40,8 @@ void
_moo_action_group_set_display_name (MooActionGroup *group, _moo_action_group_set_display_name (MooActionGroup *group,
const char *display_name) const char *display_name)
{ {
char *tmp;
g_return_if_fail (MOO_IS_ACTION_GROUP (group)); g_return_if_fail (MOO_IS_ACTION_GROUP (group));
MOO_ASSIGN_STRING (group->display_name, display_name);
tmp = group->display_name;
group->display_name = g_strdup (display_name);
g_free (tmp);
} }

View File

@ -18,7 +18,7 @@
#include "moomarshals.h" #include "moomarshals.h"
#ifdef MOO_COMPILATION #ifdef MOO_COMPILATION
#include "mooutils-gobject.h" #include "mooutils-misc.h"
#else #else
#if GLIB_CHECK_VERSION(2,10,0) #if GLIB_CHECK_VERSION(2,10,0)
#define MOO_OBJECT_REF_SINK(obj) g_object_ref_sink (obj) #define MOO_OBJECT_REF_SINK(obj) g_object_ref_sink (obj)

View File

@ -108,16 +108,12 @@ moo_file_dialog_set_property (GObject *object,
break; break;
case PROP_DIR: case PROP_DIR:
tmp = dialog->priv->dir; MOO_ASSIGN_STRING (dialog->priv->dir, g_value_get_string (value));
dialog->priv->dir = g_value_dup_string (value);
g_free (tmp);
g_object_notify (object, "dir"); g_object_notify (object, "dir");
break; break;
case PROP_NAME: case PROP_NAME:
tmp = dialog->priv->name; MOO_ASSIGN_STRING (dialog->priv->name, g_value_get_string (value));
dialog->priv->name = g_value_dup_string (value);
g_free (tmp);
g_object_notify (object, "name"); g_object_notify (object, "name");
break; break;
@ -518,9 +514,7 @@ static void
set_encoding (MooFileDialog *dialog, set_encoding (MooFileDialog *dialog,
const char *encoding) const char *encoding)
{ {
char *tmp = dialog->priv->encoding; MOO_ASSIGN_STRING (dialog->priv->encoding, encoding);
dialog->priv->encoding = g_strdup (encoding);
g_free (tmp);
} }
void void

View File

@ -12,7 +12,6 @@
#include "mooutils/moofiltermgr.h" #include "mooutils/moofiltermgr.h"
#include "mooutils/mooprefs.h" #include "mooutils/mooprefs.h"
#include "mooutils/mooutils-gobject.h"
#include "mooutils/mooutils-misc.h" #include "mooutils/mooutils-misc.h"
#include <string.h> #include <string.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>

View File

@ -319,13 +319,8 @@ static void
moo_markup_doc_set_name (MooMarkupDoc *doc, moo_markup_doc_set_name (MooMarkupDoc *doc,
const char *name) const char *name)
{ {
char *tmp;
g_return_if_fail (MOO_MARKUP_IS_DOC (doc)); g_return_if_fail (MOO_MARKUP_IS_DOC (doc));
MOO_ASSIGN_STRING (doc->name, name ? name : "");
tmp = doc->name;
doc->name = g_strdup (name ? name : "");
g_free (tmp);
} }

View File

@ -11,7 +11,7 @@
*/ */
#include "mooutils/moomenutoolbutton.h" #include "mooutils/moomenutoolbutton.h"
#include "mooutils/mooutils-gobject.h" #include "mooutils/mooutils-misc.h"
#include <gtk/gtk.h> #include <gtk/gtk.h>

View File

@ -16,7 +16,6 @@
#include "mooutils/moomarshals.h" #include "mooutils/moomarshals.h"
#include "mooutils/moonotebook.h" #include "mooutils/moonotebook.h"
#include "mooutils/mooutils-gobject.h"
#include "mooutils/mooutils-misc.h" #include "mooutils/mooutils-misc.h"
#include <gdk/gdkkeysyms.h> #include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>

View File

@ -23,7 +23,7 @@
#ifdef MOO_COMPILATION #ifdef MOO_COMPILATION
# include "mooutils-gobject.h" # include "mooutils-misc.h"
#else #else
# if GLIB_CHECK_VERSION(2,10,0) # if GLIB_CHECK_VERSION(2,10,0)
# define MOO_OBJECT_REF_SINK(obj) g_object_ref_sink (obj) # define MOO_OBJECT_REF_SINK(obj) g_object_ref_sink (obj)

View File

@ -15,6 +15,7 @@
#include "mooutils/moostock.h" #include "mooutils/moostock.h"
#include "mooutils/mooprefs.h" #include "mooutils/mooprefs.h"
#include "mooutils/mooprefsdialogpage.h" #include "mooutils/mooprefsdialogpage.h"
#include "mooutils/mooutils-misc.h"
#include "mooutils/mooutils-gobject.h" #include "mooutils/mooutils-gobject.h"
#include "mooutils/moofontsel.h" #include "mooutils/moofontsel.h"
#include "mooutils/mooi18n.h" #include "mooutils/mooi18n.h"

View File

@ -27,13 +27,6 @@
G_BEGIN_DECLS G_BEGIN_DECLS
#if GLIB_CHECK_VERSION(2,10,0)
#define MOO_OBJECT_REF_SINK(obj) g_object_ref_sink (obj)
#else
#define MOO_OBJECT_REF_SINK(obj) gtk_object_sink (g_object_ref (obj))
#endif
/*****************************************************************************/ /*****************************************************************************/
/* GType type /* GType type
*/ */

View File

@ -124,6 +124,17 @@ _moo_str_equal_inline (const char *s1,
#define _moo_str_equal(s1, s2) (_moo_str_equal_inline ((s1), (s2))) #define _moo_str_equal(s1, s2) (_moo_str_equal_inline ((s1), (s2)))
static inline void
moo_assign_string (char **where,
const char *value)
{
char *tmp = *where;
*where = g_strdup (value);
g_free (tmp);
}
#define MOO_ASSIGN_STRING(where, value) moo_assign_string (&(where), (value))
const char *_moo_get_pid_string (void); const char *_moo_get_pid_string (void);
const char *_moo_intern_string (const char *string); const char *_moo_intern_string (const char *string);
@ -169,6 +180,12 @@ gboolean _moo_regex_escape (const char *string,
#define _moo_free(type,mem) g_free (mem) #define _moo_free(type,mem) g_free (mem)
#endif #endif
#if GLIB_CHECK_VERSION(2,10,0)
#define MOO_OBJECT_REF_SINK(obj) g_object_ref_sink (obj)
#else
#define MOO_OBJECT_REF_SINK(obj) gtk_object_sink (g_object_ref (obj))
#endif
G_END_DECLS G_END_DECLS

View File

@ -11,6 +11,7 @@
*/ */
#include "mooutils/mooutils-treeview.h" #include "mooutils/mooutils-treeview.h"
#include "mooutils/mooutils-misc.h"
#include "mooutils/mooutils-gobject.h" #include "mooutils/mooutils-gobject.h"
#include "mooutils/moomarshals.h" #include "mooutils/moomarshals.h"
#include <string.h> #include <string.h>

View File

@ -499,25 +499,20 @@ moo_window_set_property (GObject *object,
const GValue *value, const GValue *value,
GParamSpec *pspec) GParamSpec *pspec)
{ {
char *tmp;
const char *name = NULL; const char *name = NULL;
MooWindow *window = MOO_WINDOW (object); MooWindow *window = MOO_WINDOW (object);
switch (prop_id) switch (prop_id)
{ {
case PROP_TOOLBAR_UI_NAME: case PROP_TOOLBAR_UI_NAME:
tmp = window->priv->toolbar_ui_name;
name = g_value_get_string (value); name = g_value_get_string (value);
window->priv->toolbar_ui_name = name ? g_strdup (name) : g_strdup (""); MOO_ASSIGN_STRING (window->priv->toolbar_ui_name, name ? name : "");
g_free (tmp);
g_object_notify (object, "toolbar-ui-name"); g_object_notify (object, "toolbar-ui-name");
break; break;
case PROP_MENUBAR_UI_NAME: case PROP_MENUBAR_UI_NAME:
tmp = window->priv->menubar_ui_name;
name = g_value_get_string (value); name = g_value_get_string (value);
window->priv->menubar_ui_name = name ? g_strdup (name) : g_strdup (""); MOO_ASSIGN_STRING (window->priv->menubar_ui_name, name ? name : "");
g_free (tmp);
g_object_notify (object, "menubar-ui-name"); g_object_notify (object, "menubar-ui-name");
break; break;