Re: Consensus on getter conventions?
- From: Dan Winship <danw helixcode com>
- To: gtk-devel-list gnome org
- Subject: Re: Consensus on getter conventions?
- Date: Thu, 24 Aug 2000 19:58:22 -0400
OK, here's a patch to "gconst"ify glib, since a few people mentioned
they liked that idea regardless of what other solutions were adopted.
"gconst - it's not just for return values any more!". I also added it
to GIOFuncs.io_write, which ought to have it, but presumably didn't
for the same reason return values didn't (to let the glib user be
lazy).
I also fixed a few not really related warnings along the way.
I've checked that this compiles both with and without
G_CONST_LAZINESS, but haven't looked at what fallout there is in
pango, gtk 1.3, etc yet.
Note that this is a "diff -w", and that in the real diff, prototypes
have been reformatted to preserve alignment after the "gconst"
additions.
Index: glib.h
===================================================================
RCS file: /cvs/gnome/glib/glib.h,v
retrieving revision 1.187
diff -u -w -r1.187 glib.h
--- glib.h 2000/08/21 18:46:52 1.187
+++ glib.h 2000/08/24 23:45:59
@@ -524,6 +524,11 @@
#endif /* !G_DISABLE_CHECKS */
+#ifdef G_CONST_LAZINESS
+# define gconst
+#else
+# define gconst const
+#endif
/* Provide type definitions for commonly used types.
* These are useful because a "gint8" can be adjusted
@@ -1606,7 +1611,7 @@
#define G_ALLOC_ONLY 1
#define G_ALLOC_AND_FREE 2
-GMemChunk* g_mem_chunk_new (gchar *name,
+GMemChunk* g_mem_chunk_new (const gchar *name,
gint atom_size,
gulong area_size,
gint type);
@@ -1657,8 +1662,8 @@
gchar subsitutor);
gdouble g_strtod (const gchar *nptr,
gchar **endptr);
-gchar* g_strerror (gint errnum);
-gchar* g_strsignal (gint signum);
+gconst gchar* g_strerror (gint errnum);
+gconst gchar* g_strsignal (gint signum);
gint g_strcasecmp (const gchar *s1,
const gchar *s2);
gint g_strncasecmp (const gchar *s1,
@@ -1746,11 +1751,11 @@
/* Retrive static string info
*/
-gchar* g_get_user_name (void);
-gchar* g_get_real_name (void);
-gchar* g_get_home_dir (void);
-gchar* g_get_tmp_dir (void);
-gchar* g_get_prgname (void);
+gconst gchar* g_get_user_name (void);
+gconst gchar* g_get_real_name (void);
+gconst gchar* g_get_home_dir (void);
+gconst gchar* g_get_tmp_dir (void);
+gconst gchar* g_get_prgname (void);
void g_set_prgname (const gchar *prgname);
@@ -1774,9 +1779,8 @@
/* These two functions are deprecated and will be removed in the next
* major release of GLib. Use g_path_get_dirname/g_path_get_basename
- * instead. Whatch out! The string returned by g_path_get_basename
- * must be g_freed, while the string returned by g_basename must not.*/
-gchar* g_basename (const gchar *file_name);
+ * instead. */
+gconst gchar* g_basename (const gchar *file_name);
gchar* g_dirname (const gchar *file_name);
/* The returned strings are newly allocated with g_malloc() */
@@ -1787,9 +1791,8 @@
/* Get the codeset for the current locale */
/* gchar * g_get_codeset (void); */
-/* return the environment string for the variable. The returned memory
- * must not be freed. */
-gchar* g_getenv (const gchar *variable);
+/* return the environment string for the variable. */
+gconst gchar* g_getenv (const gchar *variable);
/* we use a GLib function as a replacement for ATEXIT, so
* the programmer is not required to check the return value
@@ -2091,7 +2094,7 @@
GQuark g_quark_try_string (const gchar *string);
GQuark g_quark_from_static_string (const gchar *string);
GQuark g_quark_from_string (const gchar *string);
-gchar* g_quark_to_string (GQuark quark);
+gconst gchar* g_quark_to_string (GQuark quark);
/* Keyed Data List
@@ -2728,7 +2731,7 @@
guint count,
guint *bytes_read);
GIOError (*io_write) (GIOChannel *channel,
- gchar *buf,
+ gconst gchar *buf,
guint count,
guint *bytes_written);
GIOError (*io_seek) (GIOChannel *channel,
@@ -2752,7 +2755,7 @@
guint count,
guint *bytes_read);
GIOError g_io_channel_write (GIOChannel *channel,
- gchar *buf,
+ gconst gchar *buf,
guint count,
guint *bytes_written);
GIOError g_io_channel_seek (GIOChannel *channel,
Index: gdataset.c
===================================================================
RCS file: /cvs/gnome/glib/gdataset.c,v
retrieving revision 1.16
diff -u -w -r1.16 gdataset.c
--- gdataset.c 2000/07/26 11:01:59 1.16
+++ gdataset.c 2000/08/24 23:45:57
@@ -595,7 +595,7 @@
return quark;
}
-gchar*
+gconst gchar*
g_quark_to_string (GQuark quark)
{
gchar* result = NULL;
Index: giochannel.c
===================================================================
RCS file: /cvs/gnome/glib/giochannel.c,v
retrieving revision 1.7
diff -u -w -r1.7 giochannel.c
--- giochannel.c 2000/07/26 11:01:59 1.7
+++ giochannel.c 2000/08/24 23:45:58
@@ -77,7 +77,7 @@
GIOError
g_io_channel_write (GIOChannel *channel,
- gchar *buf,
+ gconst gchar *buf,
guint count,
guint *bytes_written)
{
Index: giounix.c
===================================================================
RCS file: /cvs/gnome/glib/giounix.c,v
retrieving revision 1.11
diff -u -w -r1.11 giounix.c
--- giounix.c 2000/07/26 11:01:59 1.11
+++ giounix.c 2000/08/24 23:45:58
@@ -62,7 +62,7 @@
guint *bytes_written);
static GIOError g_io_unix_write(GIOChannel *channel,
- gchar *buf,
+ gconst gchar *buf,
guint count,
guint *bytes_written);
static GIOError g_io_unix_seek (GIOChannel *channel,
@@ -181,7 +181,7 @@
static GIOError
g_io_unix_write(GIOChannel *channel,
- gchar *buf,
+ gconst gchar *buf,
guint count,
guint *bytes_written)
{
Index: gmem.c
===================================================================
RCS file: /cvs/gnome/glib/gmem.c,v
retrieving revision 1.22
diff -u -w -r1.22 gmem.c
--- gmem.c 2000/07/26 11:01:59 1.22
+++ gmem.c 2000/08/24 23:45:59
@@ -108,7 +108,7 @@
struct _GRealMemChunk
{
- gchar *name; /* name of this MemChunk...used for debugging output */
+ const gchar *name; /* name of this MemChunk...used for debugging output */
gint type; /* the type of MemChunk: ALLOC_ONLY or ALLOC_AND_FREE */
gint num_mem_areas; /* the number of memory areas */
gint num_marked_areas; /* the number of areas marked for deletion */
@@ -461,7 +461,7 @@
}
GMemChunk*
-g_mem_chunk_new (gchar *name,
+g_mem_chunk_new (const gchar *name,
gint atom_size,
gulong area_size,
gint type)
Index: gmessages.c
===================================================================
RCS file: /cvs/gnome/glib/gmessages.c,v
retrieving revision 1.19
diff -u -w -r1.19 gmessages.c
--- gmessages.c 2000/08/06 18:09:32 1.19
+++ gmessages.c 2000/08/24 23:45:59
@@ -449,7 +449,8 @@
GErrorFunc local_glib_error_func;
GWarningFunc local_glib_warning_func;
GPrintFunc local_glib_message_func;
- gchar prg_pid[64], *prg_name = g_get_prgname ();
+ gchar prg_pid[64];
+ gconst gchar *prg_name = g_get_prgname ();
in_recursion = (log_level & G_LOG_FLAG_RECURSION) != 0;
is_fatal = (log_level & G_LOG_FLAG_FATAL) != 0;
@@ -853,7 +854,7 @@
GDoubleIEEE754 u_double;
guint v_uint;
gint v_int;
- gchar *v_string;
+ gconst gchar *v_string;
/* beware of positional parameters
*/
@@ -1059,7 +1060,7 @@
spec.mod_long = TRUE;
/* fall through */
case 's':
- v_string = va_arg (args, char*);
+ v_string = va_arg (args, gconst char*);
if (!v_string)
conv_len += 8; /* hold "(null)" */
else if (spec.seen_precision)
Index: gstrfuncs.c
===================================================================
RCS file: /cvs/gnome/glib/gstrfuncs.c,v
retrieving revision 1.43
diff -u -w -r1.43 gstrfuncs.c
--- gstrfuncs.c 2000/07/27 03:16:15 1.43
+++ gstrfuncs.c 2000/08/24 23:46:00
@@ -226,7 +226,7 @@
}
}
-gchar*
+gconst gchar*
g_strerror (gint errnum)
{
static GStaticPrivate msg_private = G_STATIC_PRIVATE_INIT;
@@ -669,7 +669,7 @@
return msg;
}
-gchar*
+gconst gchar*
g_strsignal (gint signum)
{
static GStaticPrivate msg_private = G_STATIC_PRIVATE_INIT;
Index: gstring.c
===================================================================
RCS file: /cvs/gnome/glib/gstring.c,v
retrieving revision 1.18
diff -u -w -r1.18 gstring.c
--- gstring.c 2000/08/17 21:37:18 1.18
+++ gstring.c 2000/08/24 23:46:00
@@ -257,7 +257,7 @@
{
gchar *segment;
- g_return_if_fail (string != NULL);
+ g_return_val_if_fail (string != NULL, NULL);
if (free_segment)
{
Index: gunicode.h
===================================================================
RCS file: /cvs/gnome/glib/gunicode.h,v
retrieving revision 1.5
diff -u -w -r1.5 gunicode.h
--- gunicode.h 2000/07/31 18:52:11 1.5
+++ gunicode.h 2000/08/24 23:46:00
@@ -70,7 +70,7 @@
* not null, sets *CHARSET to the name of the current locale's
* charset. This value is statically allocated.
*/
-gboolean g_get_charset (char **charset);
+gboolean g_get_charset (gconst char **charset);
/* These are all analogs of the <ctype.h> functions.
*/
Index: gutf8.c
===================================================================
RCS file: /cvs/gnome/glib/gutf8.c,v
retrieving revision 1.4
diff -u -w -r1.4 gutf8.c
--- gutf8.c 2000/07/31 18:52:11 1.4
+++ gutf8.c 2000/08/24 23:46:00
@@ -328,7 +328,7 @@
static char *utf8_charset_cache = NULL;
gboolean
-g_get_charset (char **charset)
+g_get_charset (gconst char **charset)
{
if (utf8_locale_cache != -1)
{
Index: gutils.c
===================================================================
RCS file: /cvs/gnome/glib/gutils.c,v
retrieving revision 1.66
diff -u -w -r1.66 gutils.c
--- gutils.c 2000/07/26 11:01:59 1.66
+++ gutils.c 2000/08/24 23:46:00
@@ -112,7 +112,7 @@
g_atexit (GVoidFunc func)
{
gint result;
- gchar *error = NULL;
+ gconst gchar *error = NULL;
/* keep this in sync with glib.h */
@@ -274,7 +274,7 @@
return result;
}
-gchar*
+gconst gchar*
g_basename (const gchar *file_name)
{
register gchar *base;
@@ -464,7 +464,7 @@
return dir;
}
-gchar*
+gconst gchar*
g_getenv (const gchar *variable)
{
#ifndef G_OS_WIN32
@@ -725,7 +725,7 @@
}
}
-gchar*
+gconst gchar*
g_get_user_name (void)
{
G_LOCK (g_utils_global);
@@ -736,7 +736,7 @@
return g_user_name;
}
-gchar*
+gconst gchar*
g_get_real_name (void)
{
G_LOCK (g_utils_global);
@@ -753,7 +753,7 @@
* deduced, return NULL.
*/
-gchar*
+gconst gchar*
g_get_home_dir (void)
{
G_LOCK (g_utils_global);
@@ -771,7 +771,7 @@
* and C:\ on Windows.
*/
-gchar*
+gconst gchar*
g_get_tmp_dir (void)
{
G_LOCK (g_utils_global);
@@ -784,7 +784,7 @@
static gchar *g_prgname = NULL;
-gchar*
+gconst gchar*
g_get_prgname (void)
{
gchar* retval;
Index: gmodule/gmodule.c
===================================================================
RCS file: /cvs/gnome/glib/gmodule/gmodule.c,v
retrieving revision 1.28
diff -u -w -r1.28 gmodule.c
--- gmodule/gmodule.c 2000/07/26 11:02:01 1.28
+++ gmodule/gmodule.c 2000/08/24 23:46:00
@@ -338,7 +338,7 @@
module->is_resident = TRUE;
}
-gchar*
+gconst gchar*
g_module_error (void)
{
return g_static_private_get (&module_error_private);
@@ -349,7 +349,7 @@
const gchar *symbol_name,
gpointer *symbol)
{
- gchar *module_error;
+ gconst gchar *module_error;
if (symbol)
*symbol = NULL;
Index: gmodule/gmodule.h
===================================================================
RCS file: /cvs/gnome/glib/gmodule/gmodule.h,v
retrieving revision 1.16
diff -u -w -r1.16 gmodule.h
--- gmodule/gmodule.h 2000/07/26 11:02:01 1.16
+++ gmodule/gmodule.h 2000/08/24 23:46:00
@@ -70,7 +70,7 @@
void g_module_make_resident (GModule *module);
/* query the last module error as a string */
-gchar* g_module_error (void);
+gconst gchar* g_module_error (void);
/* retrive a symbol pointer from `module', returns TRUE on success */
gboolean g_module_symbol (GModule *module,
Index: gobject/gobject-query.c
===================================================================
RCS file: /cvs/gnome/glib/gobject/gobject-query.c,v
retrieving revision 1.3
diff -u -w -r1.3 gobject-query.c
--- gobject/gobject-query.c 2000/08/21 23:06:11 1.3
+++ gobject/gobject-query.c 2000/08/24 23:46:01
@@ -213,7 +213,7 @@
root = ~0;
for (i = 0; i < 256; i++)
{
- gchar *name = g_type_name (i);
+ gconst gchar *name = g_type_name (i);
if (name)
show_nodes (i, 0, iindent);
Index: gobject/gtype.c
===================================================================
RCS file: /cvs/gnome/glib/gobject/gtype.c,v
retrieving revision 1.8
diff -u -w -r1.8 gtype.c
--- gobject/gtype.c 2000/07/25 22:47:41 1.8
+++ gobject/gtype.c 2000/08/24 23:46:01
@@ -358,12 +358,12 @@
return NULL;
}
-static inline gchar*
+static inline gconst gchar*
type_descriptive_name (GType type)
{
if (type)
{
- gchar *name = g_type_name (type);
+ gconst gchar *name = g_type_name (type);
return name ? name : "<unknown>";
}
@@ -1565,7 +1565,7 @@
return NULL;
}
-gchar*
+gconst gchar*
g_type_name (GType type)
{
TypeNode *node = LOOKUP_TYPE_NODE (type);
Index: gobject/gtype.h
===================================================================
RCS file: /cvs/gnome/glib/gobject/gtype.h,v
retrieving revision 1.6
diff -u -w -r1.6 gtype.h
--- gobject/gtype.h 2000/07/25 22:47:41 1.6
+++ gobject/gtype.h 2000/08/24 23:46:01
@@ -157,7 +157,7 @@
/* --- prototypes --- */
void g_type_init (void);
-gchar* g_type_name (GType type);
+gconst gchar* g_type_name (GType type);
GQuark g_type_qname (GType type);
GType g_type_from_name (const gchar *name);
GType g_type_parent (GType type);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]