Don't copy strings which are marked as static. Don't allow non-canonical
authorMatthias Clasen <mclasen@redhat.com>
Mon, 21 Mar 2005 04:55:26 +0000 (04:55 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Mon, 21 Mar 2005 04:55:26 +0000 (04:55 +0000)
2005-03-20  Matthias Clasen  <mclasen@redhat.com>

* gparam.c (g_param_spec_internal): Don't copy strings
which are marked as static. Don't allow non-canonical static
names.

* gparam.h (GParamFlags): Add G_PARAM_STATIC_{NAME,NICK,BLURB}
flags.  (#160655, Ben Maurer)

docs/reference/ChangeLog
docs/reference/gobject/tmpl/gparamspec.sgml
gobject/ChangeLog
gobject/gparam.c
gobject/gparam.h

index d6ed02f..c23fe43 100644 (file)
@@ -1,3 +1,8 @@
+2005-03-20  Matthias Clasen  <mclasen@redhat.com>
+
+       * gobject/tmpl/gparamspec.sgml: Document G_PARAM_SPEC_STATIC_
+       flags.
+
 2005-03-08  Matthias Clasen  <mclasen@redhat.com>
 
        * glib/glib-sections.txt: 
index 9e06678..167ebc1 100644 (file)
@@ -140,7 +140,18 @@ can be configured.
 @G_PARAM_CONSTRUCT_ONLY: the parameter will only be set upon object construction
 @G_PARAM_LAX_VALIDATION: upon parameter conversion (see g_param_value_convert())
                          strict validation is not required
-@G_PARAM_PRIVATE: 
+@G_PARAM_STATIC_NAME:    the string used as name when constructing the 
+                         parameter is guaranteed to remain valid and
+                         unmodified for the lifetime of the parameter. 
+                         Since 2.8
+@G_PARAM_STATIC_NICK:    the string used as nick when constructing the 
+                         parameter is guaranteed to remain valid and 
+                         unmodified for the lifetime of the parameter. 
+                         Since 2.8
+@G_PARAM_STATIC_BLURB:   the string used as blurb when constructing the 
+                         parameter is guaranteed to remain valid and 
+                         unmodified for the lifetime of the parameter. 
+                         Since 2.8
 
 <!-- ##### MACRO G_PARAM_READWRITE ##### -->
 <para>
index 102b8a6..d52e576 100644 (file)
@@ -1,3 +1,12 @@
+2005-03-20  Matthias Clasen  <mclasen@redhat.com>
+
+       * gparam.c (g_param_spec_internal): Don't copy strings
+       which are marked as static. Don't allow non-canonical static 
+       names.
+
+       * gparam.h (GParamFlags): Add G_PARAM_STATIC_{NAME,NICK,BLURB}
+       flags.  (#160655, Ben Maurer)
+       
 2005-03-18  Hans Breuer  <hans@breuer.org>
 
        * makefile.msc.in : handle gobjectaliasdef.c
index 8aecc49..630c6be 100644 (file)
@@ -152,10 +152,15 @@ static void
 g_param_spec_finalize (GParamSpec *pspec)
 {
   g_datalist_clear (&pspec->qdata);
+
+  if (!(pspec->flags & G_PARAM_STATIC_NAME))
+    g_free (pspec->name);
   
-  g_free (pspec->name);
-  g_free (pspec->_nick);
-  g_free (pspec->_blurb);
+  if (!(pspec->flags & G_PARAM_STATIC_NICK))
+    g_free (pspec->_nick);
+
+  if (!(pspec->flags & G_PARAM_STATIC_BLURB))
+    g_free (pspec->_blurb);
 
   g_type_free_instance ((GTypeInstance*) pspec);
 }
@@ -297,6 +302,25 @@ canonicalize_key (gchar *key)
     }
 }
 
+static gboolean
+is_canonical (gchar *key)
+{
+  gchar *p;
+
+  for (p = key; *p != 0; p++)
+    {
+      gchar c = *p;
+      
+      if (c != '-' &&
+         (c < '0' || c > '9') &&
+         (c < 'A' || c > 'Z') &&
+         (c < 'a' || c > 'z'))
+       return FALSE;
+    }
+
+  return TRUE;
+}
+
 gpointer
 g_param_spec_internal (GType        param_type,
                       const gchar *name,
@@ -309,12 +333,28 @@ g_param_spec_internal (GType        param_type,
   g_return_val_if_fail (G_TYPE_IS_PARAM (param_type) && param_type != G_TYPE_PARAM, NULL);
   g_return_val_if_fail (name != NULL, NULL);
   g_return_val_if_fail ((name[0] >= 'A' && name[0] <= 'Z') || (name[0] >= 'a' && name[0] <= 'z'), NULL);
+  g_return_val_if_fail (!(flags & G_PARAM_STATIC_NAME) || is_canonical (name), NULL);
   
   pspec = (gpointer) g_type_create_instance (param_type);
-  pspec->name = g_strdup (name);
-  canonicalize_key (pspec->name);
-  pspec->_nick = g_strdup (nick);
-  pspec->_blurb = g_strdup (blurb);
+
+  if ((flags & G_PARAM_STATIC_NAME))
+    pspec->name = name;
+  else
+    {
+      pspec->name = g_strdup (name);
+      canonicalize_key (pspec->name);
+    }
+
+  if (flags & G_PARAM_STATIC_NICK)
+    pspec->_nick = nick;
+  else
+    pspec->_nick = g_strdup (nick);
+
+  if (flags & G_PARAM_STATIC_BLURB)
+    pspec->_blurb = blurb;
+  else
+    pspec->_blurb = g_strdup (blurb);
+
   pspec->flags = (flags & G_PARAM_USER_MASK) | (flags & G_PARAM_MASK);
   
   return pspec;
index 9cd33e1..f651c6c 100644 (file)
@@ -53,7 +53,9 @@ typedef enum
   G_PARAM_CONSTRUCT          = 1 << 2,
   G_PARAM_CONSTRUCT_ONLY      = 1 << 3,
   G_PARAM_LAX_VALIDATION      = 1 << 4,
-  G_PARAM_PRIVATE            = 1 << 5
+  G_PARAM_STATIC_NAME        = 1 << 5,
+  G_PARAM_STATIC_NICK        = 1 << 6,
+  G_PARAM_STATIC_BLURB       = 1 << 7
 } GParamFlags;
 #define        G_PARAM_READWRITE       (G_PARAM_READABLE | G_PARAM_WRITABLE)
 #define        G_PARAM_MASK            (0x000000ff)