Update gspawn-win*helper* Visual C++ projects
[platform/upstream/glib.git] / gobject / gparamspecs.c
1 /* GObject - GLib Type, Object, Parameter and Signal Library
2  * Copyright (C) 1997-1999, 2000-2001 Tim Janik and Red Hat, Inc.
3  * Copyright (C) 2010 Christian Persch
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General
16  * Public License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 /*
22  * MT safe
23  */
24
25 #include "config.h"
26
27 #include <string.h>
28
29 #define GLIB_DISABLE_DEPRECATION_WARNINGS
30
31 #include "gparamspecs.h"
32 #include "gtype-private.h"
33 #include "gvaluecollector.h"
34
35 #include "gvaluearray.h"
36
37
38 /**
39  * SECTION:param_value_types
40  * @short_description: Standard Parameter and Value Types
41  * @see_also: #GParamSpec, #GValue, g_object_class_install_property().
42  * @title: Parameters and Values
43  *
44  * #GValue provides an abstract container structure which can be
45  * copied, transformed and compared while holding a value of any
46  * (derived) type, which is registered as a #GType with a
47  * #GTypeValueTable in its #GTypeInfo structure.  Parameter
48  * specifications for most value types can be created as #GParamSpec
49  * derived instances, to implement e.g. #GObject properties which
50  * operate on #GValue containers.
51  *
52  * Parameter names need to start with a letter (a-z or A-Z). Subsequent
53  * characters can be letters, numbers or a '-'.
54  * All other characters are replaced by a '-' during construction.
55  */
56
57
58 #define G_FLOAT_EPSILON         (1e-30)
59 #define G_DOUBLE_EPSILON        (1e-90)
60
61
62 /* --- param spec functions --- */
63 static void
64 param_char_init (GParamSpec *pspec)
65 {
66   GParamSpecChar *cspec = G_PARAM_SPEC_CHAR (pspec);
67   
68   cspec->minimum = 0x7f;
69   cspec->maximum = 0x80;
70   cspec->default_value = 0;
71 }
72
73 static void
74 param_char_set_default (GParamSpec *pspec,
75                         GValue     *value)
76 {
77   value->data[0].v_int = G_PARAM_SPEC_CHAR (pspec)->default_value;
78 }
79
80 static gboolean
81 param_char_validate (GParamSpec *pspec,
82                      GValue     *value)
83 {
84   GParamSpecChar *cspec = G_PARAM_SPEC_CHAR (pspec);
85   gint oval = value->data[0].v_int;
86   
87   value->data[0].v_int = CLAMP (value->data[0].v_int, cspec->minimum, cspec->maximum);
88   
89   return value->data[0].v_int != oval;
90 }
91
92 static void
93 param_uchar_init (GParamSpec *pspec)
94 {
95   GParamSpecUChar *uspec = G_PARAM_SPEC_UCHAR (pspec);
96   
97   uspec->minimum = 0;
98   uspec->maximum = 0xff;
99   uspec->default_value = 0;
100 }
101
102 static void
103 param_uchar_set_default (GParamSpec *pspec,
104                          GValue     *value)
105 {
106   value->data[0].v_uint = G_PARAM_SPEC_UCHAR (pspec)->default_value;
107 }
108
109 static gboolean
110 param_uchar_validate (GParamSpec *pspec,
111                       GValue     *value)
112 {
113   GParamSpecUChar *uspec = G_PARAM_SPEC_UCHAR (pspec);
114   guint oval = value->data[0].v_uint;
115   
116   value->data[0].v_uint = CLAMP (value->data[0].v_uint, uspec->minimum, uspec->maximum);
117   
118   return value->data[0].v_uint != oval;
119 }
120
121 static void
122 param_boolean_set_default (GParamSpec *pspec,
123                            GValue     *value)
124 {
125   value->data[0].v_int = G_PARAM_SPEC_BOOLEAN (pspec)->default_value;
126 }
127
128 static gboolean
129 param_boolean_validate (GParamSpec *pspec,
130                         GValue     *value)
131 {
132   gint oval = value->data[0].v_int;
133   
134   value->data[0].v_int = value->data[0].v_int != FALSE;
135   
136   return value->data[0].v_int != oval;
137 }
138
139 static void
140 param_int_init (GParamSpec *pspec)
141 {
142   GParamSpecInt *ispec = G_PARAM_SPEC_INT (pspec);
143   
144   ispec->minimum = 0x7fffffff;
145   ispec->maximum = 0x80000000;
146   ispec->default_value = 0;
147 }
148
149 static void
150 param_int_set_default (GParamSpec *pspec,
151                        GValue     *value)
152 {
153   value->data[0].v_int = G_PARAM_SPEC_INT (pspec)->default_value;
154 }
155
156 static gboolean
157 param_int_validate (GParamSpec *pspec,
158                     GValue     *value)
159 {
160   GParamSpecInt *ispec = G_PARAM_SPEC_INT (pspec);
161   gint oval = value->data[0].v_int;
162   
163   value->data[0].v_int = CLAMP (value->data[0].v_int, ispec->minimum, ispec->maximum);
164   
165   return value->data[0].v_int != oval;
166 }
167
168 static gint
169 param_int_values_cmp (GParamSpec   *pspec,
170                       const GValue *value1,
171                       const GValue *value2)
172 {
173   if (value1->data[0].v_int < value2->data[0].v_int)
174     return -1;
175   else
176     return value1->data[0].v_int > value2->data[0].v_int;
177 }
178
179 static void
180 param_uint_init (GParamSpec *pspec)
181 {
182   GParamSpecUInt *uspec = G_PARAM_SPEC_UINT (pspec);
183   
184   uspec->minimum = 0;
185   uspec->maximum = 0xffffffff;
186   uspec->default_value = 0;
187 }
188
189 static void
190 param_uint_set_default (GParamSpec *pspec,
191                         GValue     *value)
192 {
193   value->data[0].v_uint = G_PARAM_SPEC_UINT (pspec)->default_value;
194 }
195
196 static gboolean
197 param_uint_validate (GParamSpec *pspec,
198                      GValue     *value)
199 {
200   GParamSpecUInt *uspec = G_PARAM_SPEC_UINT (pspec);
201   guint oval = value->data[0].v_uint;
202   
203   value->data[0].v_uint = CLAMP (value->data[0].v_uint, uspec->minimum, uspec->maximum);
204   
205   return value->data[0].v_uint != oval;
206 }
207
208 static gint
209 param_uint_values_cmp (GParamSpec   *pspec,
210                        const GValue *value1,
211                        const GValue *value2)
212 {
213   if (value1->data[0].v_uint < value2->data[0].v_uint)
214     return -1;
215   else
216     return value1->data[0].v_uint > value2->data[0].v_uint;
217 }
218
219 static void
220 param_long_init (GParamSpec *pspec)
221 {
222   GParamSpecLong *lspec = G_PARAM_SPEC_LONG (pspec);
223   
224 #if SIZEOF_LONG == 4
225   lspec->minimum = 0x7fffffff;
226   lspec->maximum = 0x80000000;
227 #else /* SIZEOF_LONG != 4 (8) */
228   lspec->minimum = 0x7fffffffffffffff;
229   lspec->maximum = 0x8000000000000000;
230 #endif
231   lspec->default_value = 0;
232 }
233
234 static void
235 param_long_set_default (GParamSpec *pspec,
236                         GValue     *value)
237 {
238   value->data[0].v_long = G_PARAM_SPEC_LONG (pspec)->default_value;
239 }
240
241 static gboolean
242 param_long_validate (GParamSpec *pspec,
243                      GValue     *value)
244 {
245   GParamSpecLong *lspec = G_PARAM_SPEC_LONG (pspec);
246   glong oval = value->data[0].v_long;
247   
248   value->data[0].v_long = CLAMP (value->data[0].v_long, lspec->minimum, lspec->maximum);
249   
250   return value->data[0].v_long != oval;
251 }
252
253 static gint
254 param_long_values_cmp (GParamSpec   *pspec,
255                        const GValue *value1,
256                        const GValue *value2)
257 {
258   if (value1->data[0].v_long < value2->data[0].v_long)
259     return -1;
260   else
261     return value1->data[0].v_long > value2->data[0].v_long;
262 }
263
264 static void
265 param_ulong_init (GParamSpec *pspec)
266 {
267   GParamSpecULong *uspec = G_PARAM_SPEC_ULONG (pspec);
268   
269   uspec->minimum = 0;
270 #if SIZEOF_LONG == 4
271   uspec->maximum = 0xffffffff;
272 #else /* SIZEOF_LONG != 4 (8) */
273   uspec->maximum = 0xffffffffffffffff;
274 #endif
275   uspec->default_value = 0;
276 }
277
278 static void
279 param_ulong_set_default (GParamSpec *pspec,
280                          GValue     *value)
281 {
282   value->data[0].v_ulong = G_PARAM_SPEC_ULONG (pspec)->default_value;
283 }
284
285 static gboolean
286 param_ulong_validate (GParamSpec *pspec,
287                       GValue     *value)
288 {
289   GParamSpecULong *uspec = G_PARAM_SPEC_ULONG (pspec);
290   gulong oval = value->data[0].v_ulong;
291   
292   value->data[0].v_ulong = CLAMP (value->data[0].v_ulong, uspec->minimum, uspec->maximum);
293   
294   return value->data[0].v_ulong != oval;
295 }
296
297 static gint
298 param_ulong_values_cmp (GParamSpec   *pspec,
299                         const GValue *value1,
300                         const GValue *value2)
301 {
302   if (value1->data[0].v_ulong < value2->data[0].v_ulong)
303     return -1;
304   else
305     return value1->data[0].v_ulong > value2->data[0].v_ulong;
306 }
307
308 static void
309 param_int64_init (GParamSpec *pspec)
310 {
311   GParamSpecInt64 *lspec = G_PARAM_SPEC_INT64 (pspec);
312   
313   lspec->minimum = G_MININT64;
314   lspec->maximum = G_MAXINT64;
315   lspec->default_value = 0;
316 }
317
318 static void
319 param_int64_set_default (GParamSpec *pspec,
320                         GValue     *value)
321 {
322   value->data[0].v_int64 = G_PARAM_SPEC_INT64 (pspec)->default_value;
323 }
324
325 static gboolean
326 param_int64_validate (GParamSpec *pspec,
327                      GValue     *value)
328 {
329   GParamSpecInt64 *lspec = G_PARAM_SPEC_INT64 (pspec);
330   gint64 oval = value->data[0].v_int64;
331   
332   value->data[0].v_int64 = CLAMP (value->data[0].v_int64, lspec->minimum, lspec->maximum);
333   
334   return value->data[0].v_int64 != oval;
335 }
336
337 static gint
338 param_int64_values_cmp (GParamSpec   *pspec,
339                        const GValue *value1,
340                        const GValue *value2)
341 {
342   if (value1->data[0].v_int64 < value2->data[0].v_int64)
343     return -1;
344   else
345     return value1->data[0].v_int64 > value2->data[0].v_int64;
346 }
347
348 static void
349 param_uint64_init (GParamSpec *pspec)
350 {
351   GParamSpecUInt64 *uspec = G_PARAM_SPEC_UINT64 (pspec);
352   
353   uspec->minimum = 0;
354   uspec->maximum = G_MAXUINT64;
355   uspec->default_value = 0;
356 }
357
358 static void
359 param_uint64_set_default (GParamSpec *pspec,
360                          GValue     *value)
361 {
362   value->data[0].v_uint64 = G_PARAM_SPEC_UINT64 (pspec)->default_value;
363 }
364
365 static gboolean
366 param_uint64_validate (GParamSpec *pspec,
367                       GValue     *value)
368 {
369   GParamSpecUInt64 *uspec = G_PARAM_SPEC_UINT64 (pspec);
370   guint64 oval = value->data[0].v_uint64;
371   
372   value->data[0].v_uint64 = CLAMP (value->data[0].v_uint64, uspec->minimum, uspec->maximum);
373   
374   return value->data[0].v_uint64 != oval;
375 }
376
377 static gint
378 param_uint64_values_cmp (GParamSpec   *pspec,
379                         const GValue *value1,
380                         const GValue *value2)
381 {
382   if (value1->data[0].v_uint64 < value2->data[0].v_uint64)
383     return -1;
384   else
385     return value1->data[0].v_uint64 > value2->data[0].v_uint64;
386 }
387
388 static void
389 param_unichar_init (GParamSpec *pspec)
390 {
391   GParamSpecUnichar *uspec = G_PARAM_SPEC_UNICHAR (pspec);
392   
393   uspec->default_value = 0;
394 }
395
396 static void
397 param_unichar_set_default (GParamSpec *pspec,
398                          GValue     *value)
399 {
400   value->data[0].v_uint = G_PARAM_SPEC_UNICHAR (pspec)->default_value;
401 }
402
403 static gboolean
404 param_unichar_validate (GParamSpec *pspec,
405                         GValue     *value)
406 {
407   gunichar oval = value->data[0].v_uint;
408   gboolean changed = FALSE;
409
410   if (!g_unichar_validate (oval))
411     {
412       value->data[0].v_uint = 0;
413       changed = TRUE;
414     }
415
416   return changed;
417 }
418
419 static gint
420 param_unichar_values_cmp (GParamSpec   *pspec,
421                         const GValue *value1,
422                         const GValue *value2)
423 {
424   if (value1->data[0].v_uint < value2->data[0].v_uint)
425     return -1;
426   else
427     return value1->data[0].v_uint > value2->data[0].v_uint;
428 }
429
430 static void
431 param_enum_init (GParamSpec *pspec)
432 {
433   GParamSpecEnum *espec = G_PARAM_SPEC_ENUM (pspec);
434   
435   espec->enum_class = NULL;
436   espec->default_value = 0;
437 }
438
439 static void
440 param_enum_finalize (GParamSpec *pspec)
441 {
442   GParamSpecEnum *espec = G_PARAM_SPEC_ENUM (pspec);
443   GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_ENUM));
444   
445   if (espec->enum_class)
446     {
447       g_type_class_unref (espec->enum_class);
448       espec->enum_class = NULL;
449     }
450   
451   parent_class->finalize (pspec);
452 }
453
454 static void
455 param_enum_set_default (GParamSpec *pspec,
456                         GValue     *value)
457 {
458   value->data[0].v_long = G_PARAM_SPEC_ENUM (pspec)->default_value;
459 }
460
461 static gboolean
462 param_enum_validate (GParamSpec *pspec,
463                      GValue     *value)
464 {
465   GParamSpecEnum *espec = G_PARAM_SPEC_ENUM (pspec);
466   glong oval = value->data[0].v_long;
467   
468   if (!espec->enum_class ||
469       !g_enum_get_value (espec->enum_class, value->data[0].v_long))
470     value->data[0].v_long = espec->default_value;
471   
472   return value->data[0].v_long != oval;
473 }
474
475 static void
476 param_flags_init (GParamSpec *pspec)
477 {
478   GParamSpecFlags *fspec = G_PARAM_SPEC_FLAGS (pspec);
479   
480   fspec->flags_class = NULL;
481   fspec->default_value = 0;
482 }
483
484 static void
485 param_flags_finalize (GParamSpec *pspec)
486 {
487   GParamSpecFlags *fspec = G_PARAM_SPEC_FLAGS (pspec);
488   GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_FLAGS));
489   
490   if (fspec->flags_class)
491     {
492       g_type_class_unref (fspec->flags_class);
493       fspec->flags_class = NULL;
494     }
495   
496   parent_class->finalize (pspec);
497 }
498
499 static void
500 param_flags_set_default (GParamSpec *pspec,
501                          GValue     *value)
502 {
503   value->data[0].v_ulong = G_PARAM_SPEC_FLAGS (pspec)->default_value;
504 }
505
506 static gboolean
507 param_flags_validate (GParamSpec *pspec,
508                       GValue     *value)
509 {
510   GParamSpecFlags *fspec = G_PARAM_SPEC_FLAGS (pspec);
511   gulong oval = value->data[0].v_ulong;
512   
513   if (fspec->flags_class)
514     value->data[0].v_ulong &= fspec->flags_class->mask;
515   else
516     value->data[0].v_ulong = fspec->default_value;
517   
518   return value->data[0].v_ulong != oval;
519 }
520
521 static void
522 param_float_init (GParamSpec *pspec)
523 {
524   GParamSpecFloat *fspec = G_PARAM_SPEC_FLOAT (pspec);
525   
526   fspec->minimum = -G_MAXFLOAT;
527   fspec->maximum = G_MAXFLOAT;
528   fspec->default_value = 0;
529   fspec->epsilon = G_FLOAT_EPSILON;
530 }
531
532 static void
533 param_float_set_default (GParamSpec *pspec,
534                          GValue     *value)
535 {
536   value->data[0].v_float = G_PARAM_SPEC_FLOAT (pspec)->default_value;
537 }
538
539 static gboolean
540 param_float_validate (GParamSpec *pspec,
541                       GValue     *value)
542 {
543   GParamSpecFloat *fspec = G_PARAM_SPEC_FLOAT (pspec);
544   gfloat oval = value->data[0].v_float;
545   
546   value->data[0].v_float = CLAMP (value->data[0].v_float, fspec->minimum, fspec->maximum);
547   
548   return value->data[0].v_float != oval;
549 }
550
551 static gint
552 param_float_values_cmp (GParamSpec   *pspec,
553                         const GValue *value1,
554                         const GValue *value2)
555 {
556   gfloat epsilon = G_PARAM_SPEC_FLOAT (pspec)->epsilon;
557   
558   if (value1->data[0].v_float < value2->data[0].v_float)
559     return - (value2->data[0].v_float - value1->data[0].v_float > epsilon);
560   else
561     return value1->data[0].v_float - value2->data[0].v_float > epsilon;
562 }
563
564 static void
565 param_double_init (GParamSpec *pspec)
566 {
567   GParamSpecDouble *dspec = G_PARAM_SPEC_DOUBLE (pspec);
568   
569   dspec->minimum = -G_MAXDOUBLE;
570   dspec->maximum = G_MAXDOUBLE;
571   dspec->default_value = 0;
572   dspec->epsilon = G_DOUBLE_EPSILON;
573 }
574
575 static void
576 param_double_set_default (GParamSpec *pspec,
577                           GValue     *value)
578 {
579   value->data[0].v_double = G_PARAM_SPEC_DOUBLE (pspec)->default_value;
580 }
581
582 static gboolean
583 param_double_validate (GParamSpec *pspec,
584                        GValue     *value)
585 {
586   GParamSpecDouble *dspec = G_PARAM_SPEC_DOUBLE (pspec);
587   gdouble oval = value->data[0].v_double;
588   
589   value->data[0].v_double = CLAMP (value->data[0].v_double, dspec->minimum, dspec->maximum);
590   
591   return value->data[0].v_double != oval;
592 }
593
594 static gint
595 param_double_values_cmp (GParamSpec   *pspec,
596                          const GValue *value1,
597                          const GValue *value2)
598 {
599   gdouble epsilon = G_PARAM_SPEC_DOUBLE (pspec)->epsilon;
600   
601   if (value1->data[0].v_double < value2->data[0].v_double)
602     return - (value2->data[0].v_double - value1->data[0].v_double > epsilon);
603   else
604     return value1->data[0].v_double - value2->data[0].v_double > epsilon;
605 }
606
607 static void
608 param_string_init (GParamSpec *pspec)
609 {
610   GParamSpecString *sspec = G_PARAM_SPEC_STRING (pspec);
611   
612   sspec->default_value = NULL;
613   sspec->cset_first = NULL;
614   sspec->cset_nth = NULL;
615   sspec->substitutor = '_';
616   sspec->null_fold_if_empty = FALSE;
617   sspec->ensure_non_null = FALSE;
618 }
619
620 static void
621 param_string_finalize (GParamSpec *pspec)
622 {
623   GParamSpecString *sspec = G_PARAM_SPEC_STRING (pspec);
624   GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_STRING));
625   
626   g_free (sspec->default_value);
627   g_free (sspec->cset_first);
628   g_free (sspec->cset_nth);
629   sspec->default_value = NULL;
630   sspec->cset_first = NULL;
631   sspec->cset_nth = NULL;
632   
633   parent_class->finalize (pspec);
634 }
635
636 static void
637 param_string_set_default (GParamSpec *pspec,
638                           GValue     *value)
639 {
640   value->data[0].v_pointer = g_strdup (G_PARAM_SPEC_STRING (pspec)->default_value);
641 }
642
643 static gboolean
644 param_string_validate (GParamSpec *pspec,
645                        GValue     *value)
646 {
647   GParamSpecString *sspec = G_PARAM_SPEC_STRING (pspec);
648   gchar *string = value->data[0].v_pointer;
649   guint changed = 0;
650   
651   if (string && string[0])
652     {
653       gchar *s;
654       
655       if (sspec->cset_first && !strchr (sspec->cset_first, string[0]))
656         {
657           if (value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS)
658             {
659               value->data[0].v_pointer = g_strdup (string);
660               string = value->data[0].v_pointer;
661               value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS;
662             }
663           string[0] = sspec->substitutor;
664           changed++;
665         }
666       if (sspec->cset_nth)
667         for (s = string + 1; *s; s++)
668           if (!strchr (sspec->cset_nth, *s))
669             {
670               if (value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS)
671                 {
672                   value->data[0].v_pointer = g_strdup (string);
673                   s = (gchar*) value->data[0].v_pointer + (s - string);
674                   string = value->data[0].v_pointer;
675                   value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS;
676                 }
677               *s = sspec->substitutor;
678               changed++;
679             }
680     }
681   if (sspec->null_fold_if_empty && string && string[0] == 0)
682     {
683       if (!(value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS))
684         g_free (value->data[0].v_pointer);
685       else
686         value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS;
687       value->data[0].v_pointer = NULL;
688       changed++;
689       string = value->data[0].v_pointer;
690     }
691   if (sspec->ensure_non_null && !string)
692     {
693       value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS;
694       value->data[0].v_pointer = g_strdup ("");
695       changed++;
696       string = value->data[0].v_pointer;
697     }
698
699   return changed;
700 }
701
702 static gint
703 param_string_values_cmp (GParamSpec   *pspec,
704                          const GValue *value1,
705                          const GValue *value2)
706 {
707   if (!value1->data[0].v_pointer)
708     return value2->data[0].v_pointer != NULL ? -1 : 0;
709   else if (!value2->data[0].v_pointer)
710     return value1->data[0].v_pointer != NULL;
711   else
712     return strcmp (value1->data[0].v_pointer, value2->data[0].v_pointer);
713 }
714
715 static void
716 param_param_init (GParamSpec *pspec)
717 {
718   /* GParamSpecParam *spec = G_PARAM_SPEC_PARAM (pspec); */
719 }
720
721 static void
722 param_param_set_default (GParamSpec *pspec,
723                          GValue     *value)
724 {
725   value->data[0].v_pointer = NULL;
726 }
727
728 static gboolean
729 param_param_validate (GParamSpec *pspec,
730                       GValue     *value)
731 {
732   /* GParamSpecParam *spec = G_PARAM_SPEC_PARAM (pspec); */
733   GParamSpec *param = value->data[0].v_pointer;
734   guint changed = 0;
735   
736   if (param && !g_value_type_compatible (G_PARAM_SPEC_TYPE (param), G_PARAM_SPEC_VALUE_TYPE (pspec)))
737     {
738       g_param_spec_unref (param);
739       value->data[0].v_pointer = NULL;
740       changed++;
741     }
742   
743   return changed;
744 }
745
746 static void
747 param_boxed_init (GParamSpec *pspec)
748 {
749   /* GParamSpecBoxed *bspec = G_PARAM_SPEC_BOXED (pspec); */
750 }
751
752 static void
753 param_boxed_set_default (GParamSpec *pspec,
754                          GValue     *value)
755 {
756   value->data[0].v_pointer = NULL;
757 }
758
759 static gboolean
760 param_boxed_validate (GParamSpec *pspec,
761                       GValue     *value)
762 {
763   /* GParamSpecBoxed *bspec = G_PARAM_SPEC_BOXED (pspec); */
764   guint changed = 0;
765
766   /* can't do a whole lot here since we haven't even G_BOXED_TYPE() */
767   
768   return changed;
769 }
770
771 static gint
772 param_boxed_values_cmp (GParamSpec    *pspec,
773                          const GValue *value1,
774                          const GValue *value2)
775 {
776   guint8 *p1 = value1->data[0].v_pointer;
777   guint8 *p2 = value2->data[0].v_pointer;
778
779   /* not much to compare here, try to at least provide stable lesser/greater result */
780
781   return p1 < p2 ? -1 : p1 > p2;
782 }
783
784 static void
785 param_pointer_init (GParamSpec *pspec)
786 {
787   /* GParamSpecPointer *spec = G_PARAM_SPEC_POINTER (pspec); */
788 }
789
790 static void
791 param_pointer_set_default (GParamSpec *pspec,
792                            GValue     *value)
793 {
794   value->data[0].v_pointer = NULL;
795 }
796
797 static gboolean
798 param_pointer_validate (GParamSpec *pspec,
799                         GValue     *value)
800 {
801   /* GParamSpecPointer *spec = G_PARAM_SPEC_POINTER (pspec); */
802   guint changed = 0;
803   
804   return changed;
805 }
806
807 static gint
808 param_pointer_values_cmp (GParamSpec   *pspec,
809                           const GValue *value1,
810                           const GValue *value2)
811 {
812   guint8 *p1 = value1->data[0].v_pointer;
813   guint8 *p2 = value2->data[0].v_pointer;
814
815   /* not much to compare here, try to at least provide stable lesser/greater result */
816
817   return p1 < p2 ? -1 : p1 > p2;
818 }
819
820 static void
821 param_value_array_init (GParamSpec *pspec)
822 {
823   GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec);
824
825   aspec->element_spec = NULL;
826   aspec->fixed_n_elements = 0; /* disable */
827 }
828
829 static inline guint
830 value_array_ensure_size (GValueArray *value_array,
831                          guint        fixed_n_elements)
832 {
833   guint changed = 0;
834
835   if (fixed_n_elements)
836     {
837       while (value_array->n_values < fixed_n_elements)
838         {
839           g_value_array_append (value_array, NULL);
840           changed++;
841         }
842       while (value_array->n_values > fixed_n_elements)
843         {
844           g_value_array_remove (value_array, value_array->n_values - 1);
845           changed++;
846         }
847     }
848   return changed;
849 }
850
851 static void
852 param_value_array_finalize (GParamSpec *pspec)
853 {
854   GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec);
855   GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_VALUE_ARRAY));
856
857   if (aspec->element_spec)
858     {
859       g_param_spec_unref (aspec->element_spec);
860       aspec->element_spec = NULL;
861     }
862
863   parent_class->finalize (pspec);
864 }
865
866 static void
867 param_value_array_set_default (GParamSpec *pspec,
868                                GValue     *value)
869 {
870   GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec);
871
872   if (!value->data[0].v_pointer && aspec->fixed_n_elements)
873     value->data[0].v_pointer = g_value_array_new (aspec->fixed_n_elements);
874
875   if (value->data[0].v_pointer)
876     {
877       /* g_value_reset (value);  already done */
878       value_array_ensure_size (value->data[0].v_pointer, aspec->fixed_n_elements);
879     }
880 }
881
882 static gboolean
883 param_value_array_validate (GParamSpec *pspec,
884                             GValue     *value)
885 {
886   GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec);
887   GValueArray *value_array = value->data[0].v_pointer;
888   guint changed = 0;
889
890   if (!value->data[0].v_pointer && aspec->fixed_n_elements)
891     value->data[0].v_pointer = g_value_array_new (aspec->fixed_n_elements);
892
893   if (value->data[0].v_pointer)
894     {
895       /* ensure array size validity */
896       changed += value_array_ensure_size (value_array, aspec->fixed_n_elements);
897       
898       /* ensure array values validity against a present element spec */
899       if (aspec->element_spec)
900         {
901           GParamSpec *element_spec = aspec->element_spec;
902           guint i;
903           
904           for (i = 0; i < value_array->n_values; i++)
905             {
906               GValue *element = value_array->values + i;
907               
908               /* need to fixup value type, or ensure that the array value is initialized at all */
909               if (!g_value_type_compatible (G_VALUE_TYPE (element), G_PARAM_SPEC_VALUE_TYPE (element_spec)))
910                 {
911                   if (G_VALUE_TYPE (element) != 0)
912                     g_value_unset (element);
913                   g_value_init (element, G_PARAM_SPEC_VALUE_TYPE (element_spec));
914                   g_param_value_set_default (element_spec, element);
915                   changed++;
916                 }
917               /* validate array value against element_spec */
918               changed += g_param_value_validate (element_spec, element);
919             }
920         }
921     }
922
923   return changed;
924 }
925
926 static gint
927 param_value_array_values_cmp (GParamSpec   *pspec,
928                               const GValue *value1,
929                               const GValue *value2)
930 {
931   GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec);
932   GValueArray *value_array1 = value1->data[0].v_pointer;
933   GValueArray *value_array2 = value2->data[0].v_pointer;
934
935   if (!value_array1 || !value_array2)
936     return value_array2 ? -1 : value_array1 != value_array2;
937
938   if (value_array1->n_values != value_array2->n_values)
939     return value_array1->n_values < value_array2->n_values ? -1 : 1;
940   else if (!aspec->element_spec)
941     {
942       /* we need an element specification for comparisons, so there's not much
943        * to compare here, try to at least provide stable lesser/greater result
944        */
945       return value_array1->n_values < value_array2->n_values ? -1 : value_array1->n_values > value_array2->n_values;
946     }
947   else /* value_array1->n_values == value_array2->n_values */
948     {
949       guint i;
950
951       for (i = 0; i < value_array1->n_values; i++)
952         {
953           GValue *element1 = value_array1->values + i;
954           GValue *element2 = value_array2->values + i;
955           gint cmp;
956
957           /* need corresponding element types, provide stable result otherwise */
958           if (G_VALUE_TYPE (element1) != G_VALUE_TYPE (element2))
959             return G_VALUE_TYPE (element1) < G_VALUE_TYPE (element2) ? -1 : 1;
960           cmp = g_param_values_cmp (aspec->element_spec, element1, element2);
961           if (cmp)
962             return cmp;
963         }
964       return 0;
965     }
966 }
967
968 static void
969 param_object_init (GParamSpec *pspec)
970 {
971   /* GParamSpecObject *ospec = G_PARAM_SPEC_OBJECT (pspec); */
972 }
973
974 static void
975 param_object_set_default (GParamSpec *pspec,
976                           GValue     *value)
977 {
978   value->data[0].v_pointer = NULL;
979 }
980
981 static gboolean
982 param_object_validate (GParamSpec *pspec,
983                        GValue     *value)
984 {
985   GParamSpecObject *ospec = G_PARAM_SPEC_OBJECT (pspec);
986   GObject *object = value->data[0].v_pointer;
987   guint changed = 0;
988   
989   if (object && !g_value_type_compatible (G_OBJECT_TYPE (object), G_PARAM_SPEC_VALUE_TYPE (ospec)))
990     {
991       g_object_unref (object);
992       value->data[0].v_pointer = NULL;
993       changed++;
994     }
995   
996   return changed;
997 }
998
999 static gint
1000 param_object_values_cmp (GParamSpec   *pspec,
1001                          const GValue *value1,
1002                          const GValue *value2)
1003 {
1004   guint8 *p1 = value1->data[0].v_pointer;
1005   guint8 *p2 = value2->data[0].v_pointer;
1006
1007   /* not much to compare here, try to at least provide stable lesser/greater result */
1008
1009   return p1 < p2 ? -1 : p1 > p2;
1010 }
1011
1012 static void
1013 param_override_init (GParamSpec *pspec)
1014 {
1015   /* GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec); */
1016 }
1017
1018 static void
1019 param_override_finalize (GParamSpec *pspec)
1020 {
1021   GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec);
1022   GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_OVERRIDE));
1023   
1024   if (ospec->overridden)
1025     {
1026       g_param_spec_unref (ospec->overridden);
1027       ospec->overridden = NULL;
1028     }
1029   
1030   parent_class->finalize (pspec);
1031 }
1032
1033 static void
1034 param_override_set_default (GParamSpec *pspec,
1035                             GValue     *value)
1036 {
1037   GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec);
1038
1039   g_param_value_set_default (ospec->overridden, value);
1040 }
1041
1042 static gboolean
1043 param_override_validate (GParamSpec *pspec,
1044                          GValue     *value)
1045 {
1046   GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec);
1047   
1048   return g_param_value_validate (ospec->overridden, value);
1049 }
1050
1051 static gint
1052 param_override_values_cmp (GParamSpec   *pspec,
1053                            const GValue *value1,
1054                            const GValue *value2)
1055 {
1056   GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec);
1057
1058   return g_param_values_cmp (ospec->overridden, value1, value2);
1059 }
1060
1061 static void
1062 param_gtype_init (GParamSpec *pspec)
1063 {
1064 }
1065
1066 static void
1067 param_gtype_set_default (GParamSpec *pspec,
1068                          GValue     *value)
1069 {
1070   GParamSpecGType *tspec = G_PARAM_SPEC_GTYPE (pspec);
1071
1072   value->data[0].v_long = tspec->is_a_type;
1073 }
1074
1075 static gboolean
1076 param_gtype_validate (GParamSpec *pspec,
1077                       GValue     *value)
1078 {
1079   GParamSpecGType *tspec = G_PARAM_SPEC_GTYPE (pspec);
1080   GType gtype = value->data[0].v_long;
1081   guint changed = 0;
1082   
1083   if (tspec->is_a_type != G_TYPE_NONE && !g_type_is_a (gtype, tspec->is_a_type))
1084     {
1085       value->data[0].v_long = tspec->is_a_type;
1086       changed++;
1087     }
1088   
1089   return changed;
1090 }
1091
1092 static gint
1093 param_gtype_values_cmp (GParamSpec   *pspec,
1094                         const GValue *value1,
1095                         const GValue *value2)
1096 {
1097   GType p1 = value1->data[0].v_long;
1098   GType p2 = value2->data[0].v_long;
1099
1100   /* not much to compare here, try to at least provide stable lesser/greater result */
1101
1102   return p1 < p2 ? -1 : p1 > p2;
1103 }
1104
1105 static void
1106 param_variant_init (GParamSpec *pspec)
1107 {
1108   GParamSpecVariant *vspec = G_PARAM_SPEC_VARIANT (pspec);
1109
1110   vspec->type = NULL;
1111   vspec->default_value = NULL;
1112 }
1113
1114 static void
1115 param_variant_finalize (GParamSpec *pspec)
1116 {
1117   GParamSpecVariant *vspec = G_PARAM_SPEC_VARIANT (pspec);
1118   GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_VARIANT));
1119
1120   if (vspec->default_value)
1121     g_variant_unref (vspec->default_value);
1122   g_variant_type_free (vspec->type);
1123
1124   parent_class->finalize (pspec);
1125 }
1126
1127 static void
1128 param_variant_set_default (GParamSpec *pspec,
1129                            GValue     *value)
1130 {
1131   value->data[0].v_pointer = G_PARAM_SPEC_VARIANT (pspec)->default_value;
1132   value->data[1].v_uint |= G_VALUE_NOCOPY_CONTENTS;
1133 }
1134
1135 static gboolean
1136 param_variant_validate (GParamSpec *pspec,
1137                         GValue     *value)
1138 {
1139   GParamSpecVariant *vspec = G_PARAM_SPEC_VARIANT (pspec);
1140   GVariant *variant = value->data[0].v_pointer;
1141
1142   if ((variant == NULL && vspec->default_value != NULL) ||
1143       (variant != NULL && !g_variant_is_of_type (variant, vspec->type)))
1144     {
1145       g_param_value_set_default (pspec, value);
1146       return TRUE;
1147     }
1148
1149   return FALSE;
1150 }
1151
1152 static gint
1153 param_variant_values_cmp (GParamSpec   *pspec,
1154                           const GValue *value1,
1155                           const GValue *value2)
1156 {
1157   GVariant *v1 = value1->data[0].v_pointer;
1158   GVariant *v2 = value2->data[0].v_pointer;
1159
1160   return v1 < v2 ? -1 : v2 > v1;
1161 }
1162
1163 /* --- type initialization --- */
1164 GType *g_param_spec_types = NULL;
1165
1166 void
1167 _g_param_spec_types_init (void) 
1168 {
1169   const guint n_types = 23;
1170   GType type, *spec_types, *spec_types_bound;
1171
1172   g_param_spec_types = g_new0 (GType, n_types);
1173   spec_types = g_param_spec_types;
1174   spec_types_bound = g_param_spec_types + n_types;
1175   
1176   /* G_TYPE_PARAM_CHAR
1177    */
1178   {
1179     static const GParamSpecTypeInfo pspec_info = {
1180       sizeof (GParamSpecChar),  /* instance_size */
1181       16,                       /* n_preallocs */
1182       param_char_init,          /* instance_init */
1183       G_TYPE_CHAR,              /* value_type */
1184       NULL,                     /* finalize */
1185       param_char_set_default,   /* value_set_default */
1186       param_char_validate,      /* value_validate */
1187       param_int_values_cmp,     /* values_cmp */
1188     };
1189     type = g_param_type_register_static (g_intern_static_string ("GParamChar"), &pspec_info);
1190     *spec_types++ = type;
1191     g_assert (type == G_TYPE_PARAM_CHAR);
1192   }
1193   
1194   /* G_TYPE_PARAM_UCHAR
1195    */
1196   {
1197     static const GParamSpecTypeInfo pspec_info = {
1198       sizeof (GParamSpecUChar), /* instance_size */
1199       16,                       /* n_preallocs */
1200       param_uchar_init,         /* instance_init */
1201       G_TYPE_UCHAR,             /* value_type */
1202       NULL,                     /* finalize */
1203       param_uchar_set_default,  /* value_set_default */
1204       param_uchar_validate,     /* value_validate */
1205       param_uint_values_cmp,    /* values_cmp */
1206     };
1207     type = g_param_type_register_static (g_intern_static_string ("GParamUChar"), &pspec_info);
1208     *spec_types++ = type;
1209     g_assert (type == G_TYPE_PARAM_UCHAR);
1210   }
1211   
1212   /* G_TYPE_PARAM_BOOLEAN
1213    */
1214   {
1215     static const GParamSpecTypeInfo pspec_info = {
1216       sizeof (GParamSpecBoolean), /* instance_size */
1217       16,                         /* n_preallocs */
1218       NULL,                       /* instance_init */
1219       G_TYPE_BOOLEAN,             /* value_type */
1220       NULL,                       /* finalize */
1221       param_boolean_set_default,  /* value_set_default */
1222       param_boolean_validate,     /* value_validate */
1223       param_int_values_cmp,       /* values_cmp */
1224     };
1225     type = g_param_type_register_static (g_intern_static_string ("GParamBoolean"), &pspec_info);
1226     *spec_types++ = type;
1227     g_assert (type == G_TYPE_PARAM_BOOLEAN);
1228   }
1229   
1230   /* G_TYPE_PARAM_INT
1231    */
1232   {
1233     static const GParamSpecTypeInfo pspec_info = {
1234       sizeof (GParamSpecInt),   /* instance_size */
1235       16,                       /* n_preallocs */
1236       param_int_init,           /* instance_init */
1237       G_TYPE_INT,               /* value_type */
1238       NULL,                     /* finalize */
1239       param_int_set_default,    /* value_set_default */
1240       param_int_validate,       /* value_validate */
1241       param_int_values_cmp,     /* values_cmp */
1242     };
1243     type = g_param_type_register_static (g_intern_static_string ("GParamInt"), &pspec_info);
1244     *spec_types++ = type;
1245     g_assert (type == G_TYPE_PARAM_INT);
1246   }
1247   
1248   /* G_TYPE_PARAM_UINT
1249    */
1250   {
1251     static const GParamSpecTypeInfo pspec_info = {
1252       sizeof (GParamSpecUInt),  /* instance_size */
1253       16,                       /* n_preallocs */
1254       param_uint_init,          /* instance_init */
1255       G_TYPE_UINT,              /* value_type */
1256       NULL,                     /* finalize */
1257       param_uint_set_default,   /* value_set_default */
1258       param_uint_validate,      /* value_validate */
1259       param_uint_values_cmp,    /* values_cmp */
1260     };
1261     type = g_param_type_register_static (g_intern_static_string ("GParamUInt"), &pspec_info);
1262     *spec_types++ = type;
1263     g_assert (type == G_TYPE_PARAM_UINT);
1264   }
1265   
1266   /* G_TYPE_PARAM_LONG
1267    */
1268   {
1269     static const GParamSpecTypeInfo pspec_info = {
1270       sizeof (GParamSpecLong),  /* instance_size */
1271       16,                       /* n_preallocs */
1272       param_long_init,          /* instance_init */
1273       G_TYPE_LONG,              /* value_type */
1274       NULL,                     /* finalize */
1275       param_long_set_default,   /* value_set_default */
1276       param_long_validate,      /* value_validate */
1277       param_long_values_cmp,    /* values_cmp */
1278     };
1279     type = g_param_type_register_static (g_intern_static_string ("GParamLong"), &pspec_info);
1280     *spec_types++ = type;
1281     g_assert (type == G_TYPE_PARAM_LONG);
1282   }
1283   
1284   /* G_TYPE_PARAM_ULONG
1285    */
1286   {
1287     static const GParamSpecTypeInfo pspec_info = {
1288       sizeof (GParamSpecULong), /* instance_size */
1289       16,                       /* n_preallocs */
1290       param_ulong_init,         /* instance_init */
1291       G_TYPE_ULONG,             /* value_type */
1292       NULL,                     /* finalize */
1293       param_ulong_set_default,  /* value_set_default */
1294       param_ulong_validate,     /* value_validate */
1295       param_ulong_values_cmp,   /* values_cmp */
1296     };
1297     type = g_param_type_register_static (g_intern_static_string ("GParamULong"), &pspec_info);
1298     *spec_types++ = type;
1299     g_assert (type == G_TYPE_PARAM_ULONG);
1300   }
1301
1302   /* G_TYPE_PARAM_INT64
1303    */
1304   {
1305     static const GParamSpecTypeInfo pspec_info = {
1306       sizeof (GParamSpecInt64),  /* instance_size */
1307       16,                       /* n_preallocs */
1308       param_int64_init,         /* instance_init */
1309       G_TYPE_INT64,             /* value_type */
1310       NULL,                     /* finalize */
1311       param_int64_set_default,  /* value_set_default */
1312       param_int64_validate,     /* value_validate */
1313       param_int64_values_cmp,   /* values_cmp */
1314     };
1315     type = g_param_type_register_static (g_intern_static_string ("GParamInt64"), &pspec_info);
1316     *spec_types++ = type;
1317     g_assert (type == G_TYPE_PARAM_INT64);
1318   }
1319   
1320   /* G_TYPE_PARAM_UINT64
1321    */
1322   {
1323     static const GParamSpecTypeInfo pspec_info = {
1324       sizeof (GParamSpecUInt64), /* instance_size */
1325       16,                       /* n_preallocs */
1326       param_uint64_init,        /* instance_init */
1327       G_TYPE_UINT64,            /* value_type */
1328       NULL,                     /* finalize */
1329       param_uint64_set_default, /* value_set_default */
1330       param_uint64_validate,    /* value_validate */
1331       param_uint64_values_cmp,  /* values_cmp */
1332     };
1333     type = g_param_type_register_static (g_intern_static_string ("GParamUInt64"), &pspec_info);
1334     *spec_types++ = type;
1335     g_assert (type == G_TYPE_PARAM_UINT64);
1336   }
1337
1338   /* G_TYPE_PARAM_UNICHAR
1339    */
1340   {
1341     static const GParamSpecTypeInfo pspec_info = {
1342       sizeof (GParamSpecUnichar), /* instance_size */
1343       16,                        /* n_preallocs */
1344       param_unichar_init,        /* instance_init */
1345       G_TYPE_UINT,               /* value_type */
1346       NULL,                      /* finalize */
1347       param_unichar_set_default, /* value_set_default */
1348       param_unichar_validate,    /* value_validate */
1349       param_unichar_values_cmp,  /* values_cmp */
1350     };
1351     type = g_param_type_register_static (g_intern_static_string ("GParamUnichar"), &pspec_info);
1352     *spec_types++ = type;
1353     g_assert (type == G_TYPE_PARAM_UNICHAR);
1354   }
1355
1356  /* G_TYPE_PARAM_ENUM
1357    */
1358   {
1359     static const GParamSpecTypeInfo pspec_info = {
1360       sizeof (GParamSpecEnum),  /* instance_size */
1361       16,                       /* n_preallocs */
1362       param_enum_init,          /* instance_init */
1363       G_TYPE_ENUM,              /* value_type */
1364       param_enum_finalize,      /* finalize */
1365       param_enum_set_default,   /* value_set_default */
1366       param_enum_validate,      /* value_validate */
1367       param_long_values_cmp,    /* values_cmp */
1368     };
1369     type = g_param_type_register_static (g_intern_static_string ("GParamEnum"), &pspec_info);
1370     *spec_types++ = type;
1371     g_assert (type == G_TYPE_PARAM_ENUM);
1372   }
1373   
1374   /* G_TYPE_PARAM_FLAGS
1375    */
1376   {
1377     static const GParamSpecTypeInfo pspec_info = {
1378       sizeof (GParamSpecFlags), /* instance_size */
1379       16,                       /* n_preallocs */
1380       param_flags_init,         /* instance_init */
1381       G_TYPE_FLAGS,             /* value_type */
1382       param_flags_finalize,     /* finalize */
1383       param_flags_set_default,  /* value_set_default */
1384       param_flags_validate,     /* value_validate */
1385       param_ulong_values_cmp,   /* values_cmp */
1386     };
1387     type = g_param_type_register_static (g_intern_static_string ("GParamFlags"), &pspec_info);
1388     *spec_types++ = type;
1389     g_assert (type == G_TYPE_PARAM_FLAGS);
1390   }
1391   
1392   /* G_TYPE_PARAM_FLOAT
1393    */
1394   {
1395     static const GParamSpecTypeInfo pspec_info = {
1396       sizeof (GParamSpecFloat), /* instance_size */
1397       16,                       /* n_preallocs */
1398       param_float_init,         /* instance_init */
1399       G_TYPE_FLOAT,             /* value_type */
1400       NULL,                     /* finalize */
1401       param_float_set_default,  /* value_set_default */
1402       param_float_validate,     /* value_validate */
1403       param_float_values_cmp,   /* values_cmp */
1404     };
1405     type = g_param_type_register_static (g_intern_static_string ("GParamFloat"), &pspec_info);
1406     *spec_types++ = type;
1407     g_assert (type == G_TYPE_PARAM_FLOAT);
1408   }
1409   
1410   /* G_TYPE_PARAM_DOUBLE
1411    */
1412   {
1413     static const GParamSpecTypeInfo pspec_info = {
1414       sizeof (GParamSpecDouble),        /* instance_size */
1415       16,                               /* n_preallocs */
1416       param_double_init,                /* instance_init */
1417       G_TYPE_DOUBLE,                    /* value_type */
1418       NULL,                             /* finalize */
1419       param_double_set_default,         /* value_set_default */
1420       param_double_validate,            /* value_validate */
1421       param_double_values_cmp,          /* values_cmp */
1422     };
1423     type = g_param_type_register_static (g_intern_static_string ("GParamDouble"), &pspec_info);
1424     *spec_types++ = type;
1425     g_assert (type == G_TYPE_PARAM_DOUBLE);
1426   }
1427   
1428   /* G_TYPE_PARAM_STRING
1429    */
1430   {
1431     static const GParamSpecTypeInfo pspec_info = {
1432       sizeof (GParamSpecString),        /* instance_size */
1433       16,                               /* n_preallocs */
1434       param_string_init,                /* instance_init */
1435       G_TYPE_STRING,                    /* value_type */
1436       param_string_finalize,            /* finalize */
1437       param_string_set_default,         /* value_set_default */
1438       param_string_validate,            /* value_validate */
1439       param_string_values_cmp,          /* values_cmp */
1440     };
1441     type = g_param_type_register_static (g_intern_static_string ("GParamString"), &pspec_info);
1442     *spec_types++ = type;
1443     g_assert (type == G_TYPE_PARAM_STRING);
1444   }
1445   
1446   /* G_TYPE_PARAM_PARAM
1447    */
1448   {
1449     static const GParamSpecTypeInfo pspec_info = {
1450       sizeof (GParamSpecParam), /* instance_size */
1451       16,                       /* n_preallocs */
1452       param_param_init,         /* instance_init */
1453       G_TYPE_PARAM,             /* value_type */
1454       NULL,                     /* finalize */
1455       param_param_set_default,  /* value_set_default */
1456       param_param_validate,     /* value_validate */
1457       param_pointer_values_cmp, /* values_cmp */
1458     };
1459     type = g_param_type_register_static (g_intern_static_string ("GParamParam"), &pspec_info);
1460     *spec_types++ = type;
1461     g_assert (type == G_TYPE_PARAM_PARAM);
1462   }
1463   
1464   /* G_TYPE_PARAM_BOXED
1465    */
1466   {
1467     static const GParamSpecTypeInfo pspec_info = {
1468       sizeof (GParamSpecBoxed), /* instance_size */
1469       4,                        /* n_preallocs */
1470       param_boxed_init,         /* instance_init */
1471       G_TYPE_BOXED,             /* value_type */
1472       NULL,                     /* finalize */
1473       param_boxed_set_default,  /* value_set_default */
1474       param_boxed_validate,     /* value_validate */
1475       param_boxed_values_cmp,   /* values_cmp */
1476     };
1477     type = g_param_type_register_static (g_intern_static_string ("GParamBoxed"), &pspec_info);
1478     *spec_types++ = type;
1479     g_assert (type == G_TYPE_PARAM_BOXED);
1480   }
1481
1482   /* G_TYPE_PARAM_POINTER
1483    */
1484   {
1485     static const GParamSpecTypeInfo pspec_info = {
1486       sizeof (GParamSpecPointer),  /* instance_size */
1487       0,                           /* n_preallocs */
1488       param_pointer_init,          /* instance_init */
1489       G_TYPE_POINTER,              /* value_type */
1490       NULL,                        /* finalize */
1491       param_pointer_set_default,   /* value_set_default */
1492       param_pointer_validate,      /* value_validate */
1493       param_pointer_values_cmp,    /* values_cmp */
1494     };
1495     type = g_param_type_register_static (g_intern_static_string ("GParamPointer"), &pspec_info);
1496     *spec_types++ = type;
1497     g_assert (type == G_TYPE_PARAM_POINTER);
1498   }
1499   
1500   /* G_TYPE_PARAM_VALUE_ARRAY
1501    */
1502   {
1503     static /* const */ GParamSpecTypeInfo pspec_info = {
1504       sizeof (GParamSpecValueArray),    /* instance_size */
1505       0,                                /* n_preallocs */
1506       param_value_array_init,           /* instance_init */
1507       0xdeadbeef,                       /* value_type, assigned further down */
1508       param_value_array_finalize,       /* finalize */
1509       param_value_array_set_default,    /* value_set_default */
1510       param_value_array_validate,       /* value_validate */
1511       param_value_array_values_cmp,     /* values_cmp */
1512     };
1513     pspec_info.value_type = G_TYPE_VALUE_ARRAY;
1514     type = g_param_type_register_static (g_intern_static_string ("GParamValueArray"), &pspec_info);
1515     *spec_types++ = type;
1516     g_assert (type == G_TYPE_PARAM_VALUE_ARRAY);
1517   }
1518
1519   /* G_TYPE_PARAM_OBJECT
1520    */
1521   {
1522     static const GParamSpecTypeInfo pspec_info = {
1523       sizeof (GParamSpecObject), /* instance_size */
1524       16,                        /* n_preallocs */
1525       param_object_init,         /* instance_init */
1526       G_TYPE_OBJECT,             /* value_type */
1527       NULL,                      /* finalize */
1528       param_object_set_default,  /* value_set_default */
1529       param_object_validate,     /* value_validate */
1530       param_object_values_cmp,   /* values_cmp */
1531     };
1532     type = g_param_type_register_static (g_intern_static_string ("GParamObject"), &pspec_info);
1533     *spec_types++ = type;
1534     g_assert (type == G_TYPE_PARAM_OBJECT);
1535   }
1536
1537   /* G_TYPE_PARAM_OVERRIDE
1538    */
1539   {
1540     static const GParamSpecTypeInfo pspec_info = {
1541       sizeof (GParamSpecOverride), /* instance_size */
1542       16,                        /* n_preallocs */
1543       param_override_init,       /* instance_init */
1544       G_TYPE_NONE,               /* value_type */
1545       param_override_finalize,   /* finalize */
1546       param_override_set_default, /* value_set_default */
1547       param_override_validate,    /* value_validate */
1548       param_override_values_cmp,  /* values_cmp */
1549     };
1550     type = g_param_type_register_static (g_intern_static_string ("GParamOverride"), &pspec_info);
1551     *spec_types++ = type;
1552     g_assert (type == G_TYPE_PARAM_OVERRIDE);
1553   }
1554
1555   /* G_TYPE_PARAM_GTYPE
1556    */
1557   {
1558     GParamSpecTypeInfo pspec_info = {
1559       sizeof (GParamSpecGType), /* instance_size */
1560       0,                        /* n_preallocs */
1561       param_gtype_init,         /* instance_init */
1562       0xdeadbeef,               /* value_type, assigned further down */
1563       NULL,                     /* finalize */
1564       param_gtype_set_default,  /* value_set_default */
1565       param_gtype_validate,     /* value_validate */
1566       param_gtype_values_cmp,   /* values_cmp */
1567     };
1568     pspec_info.value_type = G_TYPE_GTYPE;
1569     type = g_param_type_register_static (g_intern_static_string ("GParamGType"), &pspec_info);
1570     *spec_types++ = type;
1571     g_assert (type == G_TYPE_PARAM_GTYPE);
1572   }
1573
1574   /* G_TYPE_PARAM_VARIANT
1575    */
1576   {
1577     const GParamSpecTypeInfo pspec_info = {
1578       sizeof (GParamSpecVariant), /* instance_size */
1579       0,                          /* n_preallocs */
1580       param_variant_init,         /* instance_init */
1581       G_TYPE_VARIANT,             /* value_type */
1582       param_variant_finalize,     /* finalize */
1583       param_variant_set_default,  /* value_set_default */
1584       param_variant_validate,     /* value_validate */
1585       param_variant_values_cmp,   /* values_cmp */
1586     };
1587     type = g_param_type_register_static (g_intern_static_string ("GParamVariant"), &pspec_info);
1588     *spec_types++ = type;
1589     g_assert (type == G_TYPE_PARAM_VARIANT);
1590   }
1591
1592   g_assert (spec_types == spec_types_bound);
1593 }
1594
1595 /* --- GParamSpec initialization --- */
1596
1597 /**
1598  * g_param_spec_char: (skip)
1599  * @name: canonical name of the property specified
1600  * @nick: nick name for the property specified
1601  * @blurb: description of the property specified
1602  * @minimum: minimum value for the property specified
1603  * @maximum: maximum value for the property specified
1604  * @default_value: default value for the property specified
1605  * @flags: flags for the property specified
1606  *
1607  * Creates a new #GParamSpecChar instance specifying a %G_TYPE_CHAR property.
1608  *
1609  * Returns: a newly created parameter specification
1610  */
1611 GParamSpec*
1612 g_param_spec_char (const gchar *name,
1613                    const gchar *nick,
1614                    const gchar *blurb,
1615                    gint8        minimum,
1616                    gint8        maximum,
1617                    gint8        default_value,
1618                    GParamFlags  flags)
1619 {
1620   GParamSpecChar *cspec;
1621
1622   g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1623
1624   cspec = g_param_spec_internal (G_TYPE_PARAM_CHAR,
1625                                  name,
1626                                  nick,
1627                                  blurb,
1628                                  flags);
1629   
1630   cspec->minimum = minimum;
1631   cspec->maximum = maximum;
1632   cspec->default_value = default_value;
1633   
1634   return G_PARAM_SPEC (cspec);
1635 }
1636
1637 /**
1638  * g_param_spec_uchar: (skip)
1639  * @name: canonical name of the property specified
1640  * @nick: nick name for the property specified
1641  * @blurb: description of the property specified
1642  * @minimum: minimum value for the property specified
1643  * @maximum: maximum value for the property specified
1644  * @default_value: default value for the property specified
1645  * @flags: flags for the property specified
1646  *
1647  * Creates a new #GParamSpecUChar instance specifying a %G_TYPE_UCHAR property.
1648  *
1649  * Returns: a newly created parameter specification
1650  */
1651 GParamSpec*
1652 g_param_spec_uchar (const gchar *name,
1653                     const gchar *nick,
1654                     const gchar *blurb,
1655                     guint8       minimum,
1656                     guint8       maximum,
1657                     guint8       default_value,
1658                     GParamFlags  flags)
1659 {
1660   GParamSpecUChar *uspec;
1661
1662   g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1663
1664   uspec = g_param_spec_internal (G_TYPE_PARAM_UCHAR,
1665                                  name,
1666                                  nick,
1667                                  blurb,
1668                                  flags);
1669   
1670   uspec->minimum = minimum;
1671   uspec->maximum = maximum;
1672   uspec->default_value = default_value;
1673   
1674   return G_PARAM_SPEC (uspec);
1675 }
1676
1677 /**
1678  * g_param_spec_boolean: (skip)
1679  * @name: canonical name of the property specified
1680  * @nick: nick name for the property specified
1681  * @blurb: description of the property specified
1682  * @default_value: default value for the property specified
1683  * @flags: flags for the property specified
1684  *
1685  * Creates a new #GParamSpecBoolean instance specifying a %G_TYPE_BOOLEAN
1686  * property.
1687  *
1688  * See g_param_spec_internal() for details on property names.
1689  *
1690  * Returns: a newly created parameter specification
1691  */
1692 GParamSpec*
1693 g_param_spec_boolean (const gchar *name,
1694                       const gchar *nick,
1695                       const gchar *blurb,
1696                       gboolean     default_value,
1697                       GParamFlags  flags)
1698 {
1699   GParamSpecBoolean *bspec;
1700
1701   g_return_val_if_fail (default_value == TRUE || default_value == FALSE, NULL);
1702
1703   bspec = g_param_spec_internal (G_TYPE_PARAM_BOOLEAN,
1704                                  name,
1705                                  nick,
1706                                  blurb,
1707                                  flags);
1708   
1709   bspec->default_value = default_value;
1710   
1711   return G_PARAM_SPEC (bspec);
1712 }
1713
1714 /**
1715  * g_param_spec_int: (skip)
1716  * @name: canonical name of the property specified
1717  * @nick: nick name for the property specified
1718  * @blurb: description of the property specified
1719  * @minimum: minimum value for the property specified
1720  * @maximum: maximum value for the property specified
1721  * @default_value: default value for the property specified
1722  * @flags: flags for the property specified
1723  *
1724  * Creates a new #GParamSpecInt instance specifying a %G_TYPE_INT property.
1725  *
1726  * See g_param_spec_internal() for details on property names.
1727  *
1728  * Returns: a newly created parameter specification
1729  */
1730 GParamSpec*
1731 g_param_spec_int (const gchar *name,
1732                   const gchar *nick,
1733                   const gchar *blurb,
1734                   gint         minimum,
1735                   gint         maximum,
1736                   gint         default_value,
1737                   GParamFlags  flags)
1738 {
1739   GParamSpecInt *ispec;
1740
1741   g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1742
1743   ispec = g_param_spec_internal (G_TYPE_PARAM_INT,
1744                                  name,
1745                                  nick,
1746                                  blurb,
1747                                  flags);
1748   
1749   ispec->minimum = minimum;
1750   ispec->maximum = maximum;
1751   ispec->default_value = default_value;
1752   
1753   return G_PARAM_SPEC (ispec);
1754 }
1755
1756 /**
1757  * g_param_spec_uint: (skip)
1758  * @name: canonical name of the property specified
1759  * @nick: nick name for the property specified
1760  * @blurb: description of the property specified
1761  * @minimum: minimum value for the property specified
1762  * @maximum: maximum value for the property specified
1763  * @default_value: default value for the property specified
1764  * @flags: flags for the property specified
1765  *
1766  * Creates a new #GParamSpecUInt instance specifying a %G_TYPE_UINT property.
1767  *
1768  * See g_param_spec_internal() for details on property names.
1769  *
1770  * Returns: a newly created parameter specification
1771  */
1772 GParamSpec*
1773 g_param_spec_uint (const gchar *name,
1774                    const gchar *nick,
1775                    const gchar *blurb,
1776                    guint        minimum,
1777                    guint        maximum,
1778                    guint        default_value,
1779                    GParamFlags  flags)
1780 {
1781   GParamSpecUInt *uspec;
1782
1783   g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1784
1785   uspec = g_param_spec_internal (G_TYPE_PARAM_UINT,
1786                                  name,
1787                                  nick,
1788                                  blurb,
1789                                  flags);
1790   
1791   uspec->minimum = minimum;
1792   uspec->maximum = maximum;
1793   uspec->default_value = default_value;
1794   
1795   return G_PARAM_SPEC (uspec);
1796 }
1797
1798 /**
1799  * g_param_spec_long: (skip)
1800  * @name: canonical name of the property specified
1801  * @nick: nick name for the property specified
1802  * @blurb: description of the property specified
1803  * @minimum: minimum value for the property specified
1804  * @maximum: maximum value for the property specified
1805  * @default_value: default value for the property specified
1806  * @flags: flags for the property specified
1807  *
1808  * Creates a new #GParamSpecLong instance specifying a %G_TYPE_LONG property.
1809  *
1810  * See g_param_spec_internal() for details on property names.
1811  *
1812  * Returns: a newly created parameter specification
1813  */
1814 GParamSpec*
1815 g_param_spec_long (const gchar *name,
1816                    const gchar *nick,
1817                    const gchar *blurb,
1818                    glong        minimum,
1819                    glong        maximum,
1820                    glong        default_value,
1821                    GParamFlags  flags)
1822 {
1823   GParamSpecLong *lspec;
1824
1825   g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1826
1827   lspec = g_param_spec_internal (G_TYPE_PARAM_LONG,
1828                                  name,
1829                                  nick,
1830                                  blurb,
1831                                  flags);
1832   
1833   lspec->minimum = minimum;
1834   lspec->maximum = maximum;
1835   lspec->default_value = default_value;
1836   
1837   return G_PARAM_SPEC (lspec);
1838 }
1839
1840 /**
1841  * g_param_spec_ulong: (skip)
1842  * @name: canonical name of the property specified
1843  * @nick: nick name for the property specified
1844  * @blurb: description of the property specified
1845  * @minimum: minimum value for the property specified
1846  * @maximum: maximum value for the property specified
1847  * @default_value: default value for the property specified
1848  * @flags: flags for the property specified
1849  *
1850  * Creates a new #GParamSpecULong instance specifying a %G_TYPE_ULONG
1851  * property.
1852  *
1853  * See g_param_spec_internal() for details on property names.
1854  *
1855  * Returns: a newly created parameter specification
1856  */
1857 GParamSpec*
1858 g_param_spec_ulong (const gchar *name,
1859                     const gchar *nick,
1860                     const gchar *blurb,
1861                     gulong       minimum,
1862                     gulong       maximum,
1863                     gulong       default_value,
1864                     GParamFlags  flags)
1865 {
1866   GParamSpecULong *uspec;
1867
1868   g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1869
1870   uspec = g_param_spec_internal (G_TYPE_PARAM_ULONG,
1871                                  name,
1872                                  nick,
1873                                  blurb,
1874                                  flags);
1875   
1876   uspec->minimum = minimum;
1877   uspec->maximum = maximum;
1878   uspec->default_value = default_value;
1879   
1880   return G_PARAM_SPEC (uspec);
1881 }
1882
1883 /**
1884  * g_param_spec_int64: (skip)
1885  * @name: canonical name of the property specified
1886  * @nick: nick name for the property specified
1887  * @blurb: description of the property specified
1888  * @minimum: minimum value for the property specified
1889  * @maximum: maximum value for the property specified
1890  * @default_value: default value for the property specified
1891  * @flags: flags for the property specified
1892  *
1893  * Creates a new #GParamSpecInt64 instance specifying a %G_TYPE_INT64 property.
1894  *
1895  * See g_param_spec_internal() for details on property names.
1896  *
1897  * Returns: a newly created parameter specification
1898  */
1899 GParamSpec*
1900 g_param_spec_int64 (const gchar *name,
1901                     const gchar *nick,
1902                     const gchar *blurb,
1903                     gint64       minimum,
1904                     gint64       maximum,
1905                     gint64       default_value,
1906                     GParamFlags  flags)
1907 {
1908   GParamSpecInt64 *lspec;
1909   
1910   g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1911
1912   lspec = g_param_spec_internal (G_TYPE_PARAM_INT64,
1913                                  name,
1914                                  nick,
1915                                  blurb,
1916                                  flags);
1917   
1918   lspec->minimum = minimum;
1919   lspec->maximum = maximum;
1920   lspec->default_value = default_value;
1921   
1922   return G_PARAM_SPEC (lspec);
1923 }
1924
1925 /**
1926  * g_param_spec_uint64: (skip)
1927  * @name: canonical name of the property specified
1928  * @nick: nick name for the property specified
1929  * @blurb: description of the property specified
1930  * @minimum: minimum value for the property specified
1931  * @maximum: maximum value for the property specified
1932  * @default_value: default value for the property specified
1933  * @flags: flags for the property specified
1934  *
1935  * Creates a new #GParamSpecUInt64 instance specifying a %G_TYPE_UINT64
1936  * property.
1937  *
1938  * See g_param_spec_internal() for details on property names.
1939  *
1940  * Returns: a newly created parameter specification
1941  */
1942 GParamSpec*
1943 g_param_spec_uint64 (const gchar *name,
1944                      const gchar *nick,
1945                      const gchar *blurb,
1946                      guint64      minimum,
1947                      guint64      maximum,
1948                      guint64      default_value,
1949                      GParamFlags  flags)
1950 {
1951   GParamSpecUInt64 *uspec;
1952   
1953   g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1954   
1955   uspec = g_param_spec_internal (G_TYPE_PARAM_UINT64,
1956                                  name,
1957                                  nick,
1958                                  blurb,
1959                                  flags);
1960   
1961   uspec->minimum = minimum;
1962   uspec->maximum = maximum;
1963   uspec->default_value = default_value;
1964   
1965   return G_PARAM_SPEC (uspec);
1966 }
1967
1968 /**
1969  * g_param_spec_unichar: (skip)
1970  * @name: canonical name of the property specified
1971  * @nick: nick name for the property specified
1972  * @blurb: description of the property specified
1973  * @default_value: default value for the property specified
1974  * @flags: flags for the property specified
1975  *
1976  * Creates a new #GParamSpecUnichar instance specifying a %G_TYPE_UINT
1977  * property. #GValue structures for this property can be accessed with
1978  * g_value_set_uint() and g_value_get_uint().
1979  *
1980  * See g_param_spec_internal() for details on property names.
1981  *
1982  * Returns: a newly created parameter specification
1983  */
1984 GParamSpec*
1985 g_param_spec_unichar (const gchar *name,
1986                       const gchar *nick,
1987                       const gchar *blurb,
1988                       gunichar     default_value,
1989                       GParamFlags  flags)
1990 {
1991   GParamSpecUnichar *uspec;
1992
1993   uspec = g_param_spec_internal (G_TYPE_PARAM_UNICHAR,
1994                                  name,
1995                                  nick,
1996                                  blurb,
1997                                  flags);
1998   
1999   uspec->default_value = default_value;
2000   
2001   return G_PARAM_SPEC (uspec);
2002 }
2003
2004 /**
2005  * g_param_spec_enum: (skip)
2006  * @name: canonical name of the property specified
2007  * @nick: nick name for the property specified
2008  * @blurb: description of the property specified
2009  * @enum_type: a #GType derived from %G_TYPE_ENUM
2010  * @default_value: default value for the property specified
2011  * @flags: flags for the property specified
2012  *
2013  * Creates a new #GParamSpecEnum instance specifying a %G_TYPE_ENUM
2014  * property.
2015  *
2016  * See g_param_spec_internal() for details on property names.
2017  *
2018  * Returns: a newly created parameter specification
2019  */
2020 GParamSpec*
2021 g_param_spec_enum (const gchar *name,
2022                    const gchar *nick,
2023                    const gchar *blurb,
2024                    GType        enum_type,
2025                    gint         default_value,
2026                    GParamFlags  flags)
2027 {
2028   GParamSpecEnum *espec;
2029   GEnumClass *enum_class;
2030   
2031   g_return_val_if_fail (G_TYPE_IS_ENUM (enum_type), NULL);
2032
2033   enum_class = g_type_class_ref (enum_type);
2034
2035   g_return_val_if_fail (g_enum_get_value (enum_class, default_value) != NULL, NULL);
2036   
2037   espec = g_param_spec_internal (G_TYPE_PARAM_ENUM,
2038                                  name,
2039                                  nick,
2040                                  blurb,
2041                                  flags);
2042   
2043   espec->enum_class = enum_class;
2044   espec->default_value = default_value;
2045   G_PARAM_SPEC (espec)->value_type = enum_type;
2046   
2047   return G_PARAM_SPEC (espec);
2048 }
2049
2050 /**
2051  * g_param_spec_flags: (skip)
2052  * @name: canonical name of the property specified
2053  * @nick: nick name for the property specified
2054  * @blurb: description of the property specified
2055  * @flags_type: a #GType derived from %G_TYPE_FLAGS
2056  * @default_value: default value for the property specified
2057  * @flags: flags for the property specified
2058  *
2059  * Creates a new #GParamSpecFlags instance specifying a %G_TYPE_FLAGS
2060  * property.
2061  *
2062  * See g_param_spec_internal() for details on property names.
2063  *
2064  * Returns: a newly created parameter specification
2065  */
2066 GParamSpec*
2067 g_param_spec_flags (const gchar *name,
2068                     const gchar *nick,
2069                     const gchar *blurb,
2070                     GType        flags_type,
2071                     guint        default_value,
2072                     GParamFlags  flags)
2073 {
2074   GParamSpecFlags *fspec;
2075   GFlagsClass *flags_class;
2076   
2077   g_return_val_if_fail (G_TYPE_IS_FLAGS (flags_type), NULL);
2078
2079   flags_class = g_type_class_ref (flags_type);
2080
2081   g_return_val_if_fail ((default_value & flags_class->mask) == default_value, NULL);
2082   
2083   fspec = g_param_spec_internal (G_TYPE_PARAM_FLAGS,
2084                                  name,
2085                                  nick,
2086                                  blurb,
2087                                  flags);
2088   
2089   fspec->flags_class = flags_class;
2090   fspec->default_value = default_value;
2091   G_PARAM_SPEC (fspec)->value_type = flags_type;
2092   
2093   return G_PARAM_SPEC (fspec);
2094 }
2095
2096 /**
2097  * g_param_spec_float: (skip)
2098  * @name: canonical name of the property specified
2099  * @nick: nick name for the property specified
2100  * @blurb: description of the property specified
2101  * @minimum: minimum value for the property specified
2102  * @maximum: maximum value for the property specified
2103  * @default_value: default value for the property specified
2104  * @flags: flags for the property specified
2105  *
2106  * Creates a new #GParamSpecFloat instance specifying a %G_TYPE_FLOAT property.
2107  *
2108  * See g_param_spec_internal() for details on property names.
2109  *
2110  * Returns: a newly created parameter specification
2111  */
2112 GParamSpec*
2113 g_param_spec_float (const gchar *name,
2114                     const gchar *nick,
2115                     const gchar *blurb,
2116                     gfloat       minimum,
2117                     gfloat       maximum,
2118                     gfloat       default_value,
2119                     GParamFlags  flags)
2120 {
2121   GParamSpecFloat *fspec;
2122
2123   g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
2124
2125   fspec = g_param_spec_internal (G_TYPE_PARAM_FLOAT,
2126                                  name,
2127                                  nick,
2128                                  blurb,
2129                                  flags);
2130   
2131   fspec->minimum = minimum;
2132   fspec->maximum = maximum;
2133   fspec->default_value = default_value;
2134   
2135   return G_PARAM_SPEC (fspec);
2136 }
2137
2138 /**
2139  * g_param_spec_double: (skip)
2140  * @name: canonical name of the property specified
2141  * @nick: nick name for the property specified
2142  * @blurb: description of the property specified
2143  * @minimum: minimum value for the property specified
2144  * @maximum: maximum value for the property specified
2145  * @default_value: default value for the property specified
2146  * @flags: flags for the property specified
2147  *
2148  * Creates a new #GParamSpecDouble instance specifying a %G_TYPE_DOUBLE
2149  * property.
2150  *
2151  * See g_param_spec_internal() for details on property names.
2152  *
2153  * Returns: a newly created parameter specification
2154  */
2155 GParamSpec*
2156 g_param_spec_double (const gchar *name,
2157                      const gchar *nick,
2158                      const gchar *blurb,
2159                      gdouble      minimum,
2160                      gdouble      maximum,
2161                      gdouble      default_value,
2162                      GParamFlags  flags)
2163 {
2164   GParamSpecDouble *dspec;
2165
2166   g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
2167
2168   dspec = g_param_spec_internal (G_TYPE_PARAM_DOUBLE,
2169                                  name,
2170                                  nick,
2171                                  blurb,
2172                                  flags);
2173   
2174   dspec->minimum = minimum;
2175   dspec->maximum = maximum;
2176   dspec->default_value = default_value;
2177   
2178   return G_PARAM_SPEC (dspec);
2179 }
2180
2181 /**
2182  * g_param_spec_string: (skip)
2183  * @name: canonical name of the property specified
2184  * @nick: nick name for the property specified
2185  * @blurb: description of the property specified
2186  * @default_value: default value for the property specified
2187  * @flags: flags for the property specified
2188  *
2189  * Creates a new #GParamSpecString instance.
2190  *
2191  * See g_param_spec_internal() for details on property names.
2192  *
2193  * Returns: a newly created parameter specification
2194  */
2195 GParamSpec*
2196 g_param_spec_string (const gchar *name,
2197                      const gchar *nick,
2198                      const gchar *blurb,
2199                      const gchar *default_value,
2200                      GParamFlags  flags)
2201 {
2202   GParamSpecString *sspec = g_param_spec_internal (G_TYPE_PARAM_STRING,
2203                                                    name,
2204                                                    nick,
2205                                                    blurb,
2206                                                    flags);
2207   g_free (sspec->default_value);
2208   sspec->default_value = g_strdup (default_value);
2209   
2210   return G_PARAM_SPEC (sspec);
2211 }
2212
2213 /**
2214  * g_param_spec_param: (skip)
2215  * @name: canonical name of the property specified
2216  * @nick: nick name for the property specified
2217  * @blurb: description of the property specified
2218  * @param_type: a #GType derived from %G_TYPE_PARAM
2219  * @flags: flags for the property specified
2220  *
2221  * Creates a new #GParamSpecParam instance specifying a %G_TYPE_PARAM
2222  * property.
2223  *
2224  * See g_param_spec_internal() for details on property names.
2225  *
2226  * Returns: a newly created parameter specification
2227  */
2228 GParamSpec*
2229 g_param_spec_param (const gchar *name,
2230                     const gchar *nick,
2231                     const gchar *blurb,
2232                     GType        param_type,
2233                     GParamFlags  flags)
2234 {
2235   GParamSpecParam *pspec;
2236   
2237   g_return_val_if_fail (G_TYPE_IS_PARAM (param_type), NULL);
2238   
2239   pspec = g_param_spec_internal (G_TYPE_PARAM_PARAM,
2240                                  name,
2241                                  nick,
2242                                  blurb,
2243                                  flags);
2244   G_PARAM_SPEC (pspec)->value_type = param_type;
2245   
2246   return G_PARAM_SPEC (pspec);
2247 }
2248
2249 /**
2250  * g_param_spec_boxed: (skip)
2251  * @name: canonical name of the property specified
2252  * @nick: nick name for the property specified
2253  * @blurb: description of the property specified
2254  * @boxed_type: %G_TYPE_BOXED derived type of this property
2255  * @flags: flags for the property specified
2256  *
2257  * Creates a new #GParamSpecBoxed instance specifying a %G_TYPE_BOXED
2258  * derived property.
2259  *
2260  * See g_param_spec_internal() for details on property names.
2261  *
2262  * Returns: a newly created parameter specification
2263  */
2264 GParamSpec*
2265 g_param_spec_boxed (const gchar *name,
2266                     const gchar *nick,
2267                     const gchar *blurb,
2268                     GType        boxed_type,
2269                     GParamFlags  flags)
2270 {
2271   GParamSpecBoxed *bspec;
2272   
2273   g_return_val_if_fail (G_TYPE_IS_BOXED (boxed_type), NULL);
2274   g_return_val_if_fail (G_TYPE_IS_VALUE_TYPE (boxed_type), NULL);
2275   
2276   bspec = g_param_spec_internal (G_TYPE_PARAM_BOXED,
2277                                  name,
2278                                  nick,
2279                                  blurb,
2280                                  flags);
2281   G_PARAM_SPEC (bspec)->value_type = boxed_type;
2282   
2283   return G_PARAM_SPEC (bspec);
2284 }
2285
2286 /**
2287  * g_param_spec_pointer: (skip)
2288  * @name: canonical name of the property specified
2289  * @nick: nick name for the property specified
2290  * @blurb: description of the property specified
2291  * @flags: flags for the property specified
2292  *
2293  * Creates a new #GParamSpecPointer instance specifying a pointer property.
2294  *
2295  * See g_param_spec_internal() for details on property names.
2296  *
2297  * Returns: a newly created parameter specification
2298  */
2299 GParamSpec*
2300 g_param_spec_pointer (const gchar *name,
2301                       const gchar *nick,
2302                       const gchar *blurb,
2303                       GParamFlags  flags)
2304 {
2305   GParamSpecPointer *pspec;
2306   
2307   pspec = g_param_spec_internal (G_TYPE_PARAM_POINTER,
2308                                  name,
2309                                  nick,
2310                                  blurb,
2311                                  flags);
2312   return G_PARAM_SPEC (pspec);
2313 }
2314
2315 /**
2316  * g_param_spec_gtype: (skip)
2317  * @name: canonical name of the property specified
2318  * @nick: nick name for the property specified
2319  * @blurb: description of the property specified
2320  * @is_a_type: a #GType whose subtypes are allowed as values
2321  *  of the property (use %G_TYPE_NONE for any type)
2322  * @flags: flags for the property specified
2323  *
2324  * Creates a new #GParamSpecGType instance specifying a
2325  * %G_TYPE_GTYPE property.
2326  *
2327  * See g_param_spec_internal() for details on property names.
2328  *
2329  * Since: 2.10
2330  *
2331  * Returns: a newly created parameter specification
2332  */
2333 GParamSpec*
2334 g_param_spec_gtype (const gchar *name,
2335                     const gchar *nick,
2336                     const gchar *blurb,
2337                     GType        is_a_type,
2338                     GParamFlags  flags)
2339 {
2340   GParamSpecGType *tspec;
2341   
2342   tspec = g_param_spec_internal (G_TYPE_PARAM_GTYPE,
2343                                  name,
2344                                  nick,
2345                                  blurb,
2346                                  flags);
2347
2348   tspec->is_a_type = is_a_type;
2349
2350   return G_PARAM_SPEC (tspec);
2351 }
2352
2353 /**
2354  * g_param_spec_value_array: (skip)
2355  * @name: canonical name of the property specified
2356  * @nick: nick name for the property specified
2357  * @blurb: description of the property specified
2358  * @element_spec: a #GParamSpec describing the elements contained in
2359  *  arrays of this property, may be %NULL
2360  * @flags: flags for the property specified
2361  *
2362  * Creates a new #GParamSpecValueArray instance specifying a
2363  * %G_TYPE_VALUE_ARRAY property. %G_TYPE_VALUE_ARRAY is a
2364  * %G_TYPE_BOXED type, as such, #GValue structures for this property
2365  * can be accessed with g_value_set_boxed() and g_value_get_boxed().
2366  *
2367  * See g_param_spec_internal() for details on property names.
2368  *
2369  * Returns: a newly created parameter specification
2370  */
2371 GParamSpec*
2372 g_param_spec_value_array (const gchar *name,
2373                           const gchar *nick,
2374                           const gchar *blurb,
2375                           GParamSpec  *element_spec,
2376                           GParamFlags  flags)
2377 {
2378   GParamSpecValueArray *aspec;
2379   
2380   if (element_spec)
2381     g_return_val_if_fail (G_IS_PARAM_SPEC (element_spec), NULL);
2382   
2383   aspec = g_param_spec_internal (G_TYPE_PARAM_VALUE_ARRAY,
2384                                  name,
2385                                  nick,
2386                                  blurb,
2387                                  flags);
2388   if (element_spec)
2389     {
2390       aspec->element_spec = g_param_spec_ref (element_spec);
2391       g_param_spec_sink (element_spec);
2392     }
2393
2394   return G_PARAM_SPEC (aspec);
2395 }
2396
2397 /**
2398  * g_param_spec_object: (skip)
2399  * @name: canonical name of the property specified
2400  * @nick: nick name for the property specified
2401  * @blurb: description of the property specified
2402  * @object_type: %G_TYPE_OBJECT derived type of this property
2403  * @flags: flags for the property specified
2404  *
2405  * Creates a new #GParamSpecBoxed instance specifying a %G_TYPE_OBJECT
2406  * derived property.
2407  *
2408  * See g_param_spec_internal() for details on property names.
2409  *
2410  * Returns: a newly created parameter specification
2411  */
2412 GParamSpec*
2413 g_param_spec_object (const gchar *name,
2414                      const gchar *nick,
2415                      const gchar *blurb,
2416                      GType        object_type,
2417                      GParamFlags  flags)
2418 {
2419   GParamSpecObject *ospec;
2420   
2421   g_return_val_if_fail (g_type_is_a (object_type, G_TYPE_OBJECT), NULL);
2422   
2423   ospec = g_param_spec_internal (G_TYPE_PARAM_OBJECT,
2424                                  name,
2425                                  nick,
2426                                  blurb,
2427                                  flags);
2428   G_PARAM_SPEC (ospec)->value_type = object_type;
2429   
2430   return G_PARAM_SPEC (ospec);
2431 }
2432
2433 /**
2434  * g_param_spec_override: (skip)
2435  * @name: the name of the property.
2436  * @overridden: The property that is being overridden
2437  *
2438  * Creates a new property of type #GParamSpecOverride. This is used
2439  * to direct operations to another paramspec, and will not be directly
2440  * useful unless you are implementing a new base type similar to GObject.
2441  *
2442  * Since: 2.4
2443  *
2444  * Returns: the newly created #GParamSpec
2445  */
2446 GParamSpec*
2447 g_param_spec_override (const gchar *name,
2448                        GParamSpec  *overridden)
2449 {
2450   GParamSpec *pspec;
2451   
2452   g_return_val_if_fail (name != NULL, NULL);
2453   g_return_val_if_fail (G_IS_PARAM_SPEC (overridden), NULL);
2454   
2455   /* Dereference further redirections for property that was passed in
2456    */
2457   while (TRUE)
2458     {
2459       GParamSpec *indirect = g_param_spec_get_redirect_target (overridden);
2460       if (indirect)
2461         overridden = indirect;
2462       else
2463         break;
2464     }
2465
2466   pspec = g_param_spec_internal (G_TYPE_PARAM_OVERRIDE,
2467                                  name, NULL, NULL,
2468                                  overridden->flags);
2469   
2470   pspec->value_type = G_PARAM_SPEC_VALUE_TYPE (overridden);
2471   G_PARAM_SPEC_OVERRIDE (pspec)->overridden = g_param_spec_ref (overridden);
2472
2473   return pspec;
2474 }
2475
2476 /**
2477  * g_param_spec_variant: (skip)
2478  * @name: canonical name of the property specified
2479  * @nick: nick name for the property specified
2480  * @blurb: description of the property specified
2481  * @type: a #GVariantType
2482  * @default_value: (allow-none): a #GVariant of type @type to use as the
2483  *                 default value, or %NULL
2484  * @flags: flags for the property specified
2485  *
2486  * Creates a new #GParamSpecVariant instance specifying a #GVariant
2487  * property.
2488  *
2489  * If @default_value is floating, it is consumed.
2490  *
2491  * See g_param_spec_internal() for details on property names.
2492  *
2493  * Returns: the newly created #GParamSpec
2494  *
2495  * Since: 2.26
2496  */
2497 GParamSpec*
2498 g_param_spec_variant (const gchar        *name,
2499                       const gchar        *nick,
2500                       const gchar        *blurb,
2501                       const GVariantType *type,
2502                       GVariant           *default_value,
2503                       GParamFlags         flags)
2504 {
2505   GParamSpecVariant *vspec;
2506
2507   g_return_val_if_fail (type != NULL, NULL);
2508   g_return_val_if_fail (default_value == NULL ||
2509                         g_variant_is_of_type (default_value, type), NULL);
2510
2511   vspec = g_param_spec_internal (G_TYPE_PARAM_VARIANT,
2512                                  name,
2513                                  nick,
2514                                  blurb,
2515                                  flags);
2516
2517   vspec->type = g_variant_type_copy (type);
2518   if (default_value)
2519     vspec->default_value = g_variant_ref_sink (default_value);
2520
2521   return G_PARAM_SPEC (vspec);
2522 }