Re: gtk_label_get_text() string duping



On 25 Jun 2000, Owen Taylor wrote:

> 
> To provide some hard data, here is most (I.e., what I could find
> quickly) of the functions from glib/pango/gtk+ that return char *.

> The allocing functions outnumber the non-allocing functions about 44
> to 30, though it could be argued that most of the allocing functions
> alloc because they have to. (Only 10 or so are just g_strdup's of an
> internal field.)

hm, some of those will vanish (the gtk_arg related stuff for instance)
and quite some of them are new API (havoc's text widget).
i think it can be argued that glib is pretty specific, for one it
tries to mimick various libc flavours, for another it is pretty lowlevel,
thus usually lacking an object to copy fields from ;)

> However, I don't think that rational gives the user much sense of
> consistency - is it obvious that gtk_widget_name() doesn't need to
> copy, but gtk_container_composite_child_name() does? is it obvious
> that g_module_error() doesn't need to copy but g_win32_error_message()
> does?
> 
> (This was one of two reasons that I thought we had decided on
> copy-everything - in many cases you _do_ need to copy and the user
> can't always know which ones. The other reason was thread safety,
> especially in glib where we don't have a global lock.)

but that really makes sense for glib only, and glib has actually very
few functions that would need s/get/dup/ changing.

> I'm not going to give an opinion on what we should do tonight - just
> thought I'd throw some data out there.

thanks, i apprechiate that _very_ much.

> 
> Regards,
>                                         Owen
> 


ok, i'm commenting a bit on what i think are the appropriate actions
to take. for functions established in 1.2.x we'll need aprpriate
compat defines, but for the rest, which is really a minor portion of
pango and mostly the text widget, doing an sed job shouldn't hurt
that much.


> No-alloc
> =======


> Alloc
> =====

> gchar *gtk_frame_get_label    (GtkFrame     *frame);
> gchar *gtk_label_get_text     (GtkLabel     *label);
for these two it should be save to just eliminate the g_strdup(),
they are sufficiently new.

> gchar* gtk_rc_get_theme_dir   (void);
> gchar* gtk_rc_get_module_dir  (void);
> char * pango_context_get_lang (PangoContext *context);
> char * gtk_text_mark_get_name (GtkTextMark  *mark);
> gchar* gtk_editable_get_chars (GtkEditable  *editable,
> gchar* gtk_font_selection_get_font_name (GtkFontSelection *fontsel);
> gchar*	 gtk_font_selection_dialog_get_font_name    (GtkFontSelectionDialog *fsd);
> gchar* gtk_progress_get_current_text    (GtkProgress *progress);
> gchar* gtk_progress_get_text_from_value (GtkProgress *progress,
> gchar* gtk_container_child_arg_get_info   (GtkType        object_type,
> gchar* gtk_text_buffer_get_text_chars (GtkTextBuffer     *buffer,
> gchar* gtk_text_buffer_get_text       (GtkTextBuffer     *buffer,
> gchar* gtk_text_buffer_get_text_from_line (GtkTextBuffer     *buffer,
> gchar* gtk_text_buffer_get_slice          (GtkTextBuffer     *buffer,
> gchar* gtk_text_buffer_get_slice_chars     (GtkTextBuffer     *buffer,
> gchar* gtk_text_buffer_get_slice_from_line (GtkTextBuffer     *buffer,
> char * gtk_text_iter_get_slice         (const GtkTextIter *start,
> gchar *gtk_text_iter_get_text          (const GtkTextIter *start,
> gchar *gtk_text_iter_get_visible_slice (const GtkTextIter *start,
> gchar *gtk_text_iter_get_visible_text  (const GtkTextIter *start,
> gchar* g_get_current_dir     (void);
> gchar *g_get_codeset         (void);
s/get/dup/ for these

> gchar *g_win32_getlocale     (void);
s/_get/_dup_/


> gchar* gtk_args_collect     (GtkType           object_type,
> gchar* gtk_arg_get_info     (GtkType           object_type,
> gchar* gtk_object_args_collect (GtkType       object_type,
> gchar*	gtk_object_arg_get_info (GtkType      object_type,
> gchar* gtk_arg_name_strip_type             (const gchar       *arg_name);
these will all vanish anyway

> gchar* gtk_container_child_args_collect   (GtkType        object_type,
> 					   GSList       **arg_list_p,
> 					   GSList       **info_list_p,
> 					   const gchar   *first_arg_name,
> 					   va_list        args);
this i'm a bit in doubt, i guess it should stay as it already denotes
an action.

> gchar* gdk_atom_name          (GdkAtom       atom);
> gchar* gtk_accelerator_name (guint             accelerator_key,
> gchar* gtk_container_child_composite_name (GtkContainer*, GtkWidget*);
> gchar* g_dirname             (const gchar  *file_name);
> gchar *g_win32_error_message (gint          error);
need to insert create/make/dup here

> gchar* gtk_rc_find_pixmap_in_path       (GScanner    *scanner,
> gchar* gtk_rc_find_module_in_path       (const gchar *module_file);
> char *pango_x_make_matching_xlfd (PangoFontMap  *fontmap,
> char *pango_x_font_subfont_xlfd  (PangoFont     *font,
> gchar* g_module_build_path   (const gchar  *directory,
for these it should be obvious that they return new strings, no?

> Obvious no-copy
> ===============

> Obvious copy
> ============

Modify-in-place-and-return
> ===========================

> gchar*	 g_strdelimit		(gchar	     *string,
> 				 const gchar *delimiters,
> 				 gchar	      new_delimiter);
> gchar*	 g_strcanon		(gchar       *string,
> 				 const gchar *valid_chars,
> 				 gchar        subsitutor);
> gchar*	 g_strup		(gchar	     *string);
> gchar* g_strdown        (gchar       *string);
> gchar*	 g_strreverse		(gchar	     *string);
> gchar*   g_strchug              (gchar        *string);
> gchar*  g_strchomp              (gchar        *string);
> #define g_strstrip( string )	g_strchomp (g_strchug (string))

that's fine, no? the docs should even state that these do
string modifications, and they don't take const gchar* for that
purpose.

---
ciaoTJ





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