Bug Summary

File:_build/../libbean/cparam.c
Warning:line 1230, column 15
This statement is never executed

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name cparam.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/rootdir/_build -fcoverage-compilation-dir=/rootdir/_build -resource-dir /usr/lib/llvm-19/lib/clang/19 -I libbean/libean-2.0.so.0.0.0.p -I libbean -I ../libbean -I . -I .. -I /usr/include/glib-2.0 -I /usr/lib/x86_64-linux-gnu/glib-2.0/include -I /usr/include/sysprof-6 -I /usr/include/libmount -I /usr/include/blkid -I /usr/include/gobject-introspection-1.0 -D _FILE_OFFSET_BITS=64 -D HAVE_CONFIG_H -D G_LOG_DOMAIN="libbean" -D DATADIR="/usr/local/share" -D LIBDIR="/usr/local/lib/x86_64-linux-gnu" -internal-isystem /usr/lib/llvm-19/lib/clang/19/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -ferror-limit 19 -fvisibility=hidden -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -vectorize-loops -vectorize-slp -analyzer-checker deadcode.DeadStores -analyzer-checker alpha.deadcode.UnreachableCode -analyzer-checker alpha.core.CastSize -analyzer-checker alpha.core.CastToStruct -analyzer-checker alpha.core.IdenticalExpr -analyzer-checker alpha.security.ArrayBoundV2 -analyzer-checker alpha.security.MallocOverflow -analyzer-checker alpha.security.ReturnPtrRange -analyzer-checker alpha.unix.SimpleStream -analyzer-checker alpha.unix.cstring.BufferOverlap -analyzer-checker alpha.unix.cstring.NotNullTerminated -analyzer-checker alpha.unix.cstring.OutOfBounds -analyzer-checker alpha.core.FixedAddr -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /rootdir/html-report/2025-08-01-114332-13713-1 -x c ../libbean/cparam.c
1/* GObject - GLib Type, Object, Parameter and Signal Library
2 * Copyright (C) 1997-1999, 2000-2001 Tim Janik and Red Hat, Inc.
3 *
4 * SPDX-License-Identifier: LGPL-2.1-or-later
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General
17 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 */
19
20/*
21 * MT safe
22 */
23
24#include "config.h"
25
26#include <string.h>
27
28//#include "cparam.h"
29#include "cparamspecs.h"
30//#include "gvaluecollector.h"
31//#include "gtype-private.h"
32
33/**
34 * CParamSpec: (ref-func c_param_spec_ref_sink) (unref-func c_param_spec_unref) (set-value-func c_value_set_param) (get-value-func c_value_get_param)
35 * @g_type_instance: private `GTypeInstance` portion
36 * @name: name of this parameter: always an interned string
37 * @flags: `CParamFlags` flags for this parameter
38 * @value_type: the `GValue` type for this parameter
39 * @owner_type: `GType` type that uses (introduces) this parameter
40 *
41 * `CParamSpec` encapsulates the metadata required to specify parameters, such as `GObject` properties.
42 *
43 * ## Parameter names
44 *
45 * A property name consists of one or more segments consisting of ASCII letters
46 * and digits, separated by either the `-` or `_` character. The first
47 * character of a property name must be a letter. These are the same rules as
48 * for signal naming (see [func@GObject.signal_new]).
49 *
50 * When creating and looking up a `CParamSpec`, either separator can be
51 * used, but they cannot be mixed. Using `-` is considerably more
52 * efficient, and is the ‘canonical form’. Using `_` is discouraged.
53 */
54
55/* --- defines --- */
56#define PARAM_FLOATING_FLAG0x2 0x2
57#define C_PARAM_USER_MASK(~0U << (8)) (~0U << C_PARAM_USER_SHIFT(8))
58#define PSPEC_APPLIES_TO_VALUE(pspec, value)(((__extension__ ({ const GValue *__val = (const GValue*) ((value
)); GType __t = ((((((CParamSpec*) (void *) ((pspec)))))->
value_type)); gboolean __r; if (!__val) __r = (0); else if (__val
->g_type == __t) __r = (!(0)); else __r = g_type_check_value_holds
(__val, __t); __r; }))))
(G_TYPE_CHECK_VALUE_TYPE ((value), C_PARAM_SPEC_VALUE_TYPE (pspec))((__extension__ ({ const GValue *__val = (const GValue*) ((value
)); GType __t = ((((((CParamSpec*) (void *) ((pspec)))))->
value_type)); gboolean __r; if (!__val) __r = (0); else if (__val
->g_type == __t) __r = (!(0)); else __r = g_type_check_value_holds
(__val, __t); __r; })))
)
59
60/* --- prototypes --- */
61static void c_param_spec_class_base_init (CParamSpecClass *class);
62static void c_param_spec_class_base_finalize (CParamSpecClass *class);
63static void c_param_spec_class_init (CParamSpecClass *class,
64 gpointer class_data);
65static void c_param_spec_init (CParamSpec *pspec,
66 CParamSpecClass *class);
67static void c_param_spec_finalize (CParamSpec *pspec);
68static void value_param_init (GValue *value);
69static void value_param_free_value (GValue *value);
70static void value_param_copy_value (const GValue *src_value,
71 GValue *dest_value);
72static void value_param_transform_value (const GValue *src_value,
73 GValue *dest_value);
74static gpointer value_param_peek_pointer (const GValue *value);
75static gchar* value_param_collect_value (GValue *value,
76 guint n_collect_values,
77 GTypeCValue *collect_values,
78 guint collect_flags);
79static gchar* value_param_lcopy_value (const GValue *value,
80 guint n_collect_values,
81 GTypeCValue *collect_values,
82 guint collect_flags);
83
84typedef struct
85{
86 GValue default_value;
87 GQuark name_quark;
88} CParamSpecPrivate;
89
90static gint c_param_private_offset;
91
92/* --- functions --- */
93static inline CParamSpecPrivate *
94c_param_spec_get_private (CParamSpec *pspec)
95{
96 return &G_STRUCT_MEMBER (CParamSpecPrivate, pspec, c_param_private_offset)(*(CParamSpecPrivate*) ((gpointer) ((guint8*) ((pspec)) + (glong
) ((c_param_private_offset)))))
;
97}
98
99void
100_c_param_type_init (void)
101{
102 static const GTypeFundamentalInfo finfo = {
103 (G_TYPE_FLAG_CLASSED |
104 G_TYPE_FLAG_INSTANTIATABLE |
105 G_TYPE_FLAG_DERIVABLE |
106 G_TYPE_FLAG_DEEP_DERIVABLE),
107 };
108 static const GTypeValueTable param_value_table = {
109 value_param_init, /* value_init */
110 value_param_free_value, /* value_free */
111 value_param_copy_value, /* value_copy */
112 value_param_peek_pointer, /* value_peek_pointer */
113 "p", /* collect_format */
114 value_param_collect_value, /* collect_value */
115 "p", /* lcopy_format */
116 value_param_lcopy_value, /* lcopy_value */
117 };
118 const GTypeInfo param_spec_info = {
119 sizeof (CParamSpecClass),
120
121 (GBaseInitFunc) c_param_spec_class_base_init,
122 (GBaseFinalizeFunc) c_param_spec_class_base_finalize,
123 (GClassInitFunc) c_param_spec_class_init,
124 (GClassFinalizeFunc) NULL((void*)0),
125 NULL((void*)0), /* class_data */
126
127 sizeof (CParamSpec),
128 0, /* n_preallocs */
129 (GInstanceInitFunc) c_param_spec_init,
130
131 &param_value_table,
132 };
133 GType type;
134
135 /* This should be registered as CParamSpec instead of CParam, for
136 * consistency sake, so that type name can be mapped to struct name,
137 * However, some language bindings, most noticeable the python ones
138 * depends on the "CParam" identifier, see #548689
139 */
140 type = g_type_register_fundamental (C_TYPE_PARAM((GType) ((19) << (2))), g_intern_static_string ("CParam"), &param_spec_info, &finfo, G_TYPE_FLAG_ABSTRACT);
141 g_assert (type == C_TYPE_PARAM)do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_76
= 0; if (type == ((GType) ((19) << (2)))) _g_boolean_var_76
= 1; _g_boolean_var_76; }), 1)) ; else g_assertion_message_expr
("libbean", "../libbean/cparam.c", 141, ((const char*) (__func__
)), "type == C_TYPE_PARAM"); } while (0)
;
142 c_param_private_offset = g_type_add_instance_private (type, sizeof (CParamSpecPrivate));
143 g_value_register_transform_func (C_TYPE_PARAM((GType) ((19) << (2))), C_TYPE_PARAM((GType) ((19) << (2))), value_param_transform_value);
144}
145
146static void
147c_param_spec_class_base_init (CParamSpecClass *class)
148{
149}
150
151static void
152c_param_spec_class_base_finalize (CParamSpecClass *class)
153{
154}
155
156static void
157c_param_spec_class_init (CParamSpecClass *class,
158 gpointer class_data)
159{
160 class->value_type = G_TYPE_NONE((GType) ((1) << (2)));
161 class->finalize = c_param_spec_finalize;
162 class->value_set_default = NULL((void*)0);
163 class->value_validate = NULL((void*)0);
164 class->values_cmp = NULL((void*)0);
165
166 g_type_class_adjust_private_offset (class, &c_param_private_offset);
167}
168
169static void
170c_param_spec_init (CParamSpec *pspec,
171 CParamSpecClass *class)
172{
173 pspec->name = NULL((void*)0);
174 pspec->_nick = NULL((void*)0);
175 pspec->_blurb = NULL((void*)0);
176 pspec->flags = 0;
177 pspec->value_type = class->value_type;
178 pspec->owner_type = 0;
179 pspec->qdata = NULL((void*)0);
180 g_datalist_set_flags (&pspec->qdata, PARAM_FLOATING_FLAG0x2);
181 pspec->ref_count = 1;
182 pspec->param_id = 0;
183}
184
185static void
186c_param_spec_finalize (CParamSpec *pspec)
187{
188 CParamSpecPrivate *priv = c_param_spec_get_private (pspec);
189
190 if (priv->default_value.g_type)
191 g_value_reset (&priv->default_value);
192
193 g_datalist_clear (&pspec->qdata);
194
195 if (!(pspec->flags & C_PARAM_STATIC_NICK))
196 g_free (pspec->_nick);
197
198 if (!(pspec->flags & C_PARAM_STATIC_BLURB))
199 g_free (pspec->_blurb);
200
201 g_type_free_instance ((GTypeInstance*) pspec);
202}
203
204/**
205 * c_param_spec_ref: (skip)
206 * @pspec: (transfer none) (not nullable): a valid #CParamSpec
207 *
208 * Increments the reference count of @pspec.
209 *
210 * Returns: (transfer full) (not nullable): the #CParamSpec that was passed into this function
211 */
212CParamSpec*
213c_param_spec_ref (CParamSpec *pspec)
214{
215 g_return_val_if_fail (C_IS_PARAM_SPEC (pspec), NULL)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_77
= 0; if ((((g_type_check_instance_is_fundamentally_a ((GTypeInstance
*) ((pspec)), (((GType) ((19) << (2))))))))) _g_boolean_var_77
= 1; _g_boolean_var_77; }), 1))) { } else { g_return_if_fail_warning
("libbean", ((const char*) (__func__)), "C_IS_PARAM_SPEC (pspec)"
); return (((void*)0)); } } while (0)
;
216
217 g_atomic_int_inc ((int *)&pspec->ref_count)(__extension__ ({ _Static_assert (sizeof *((int *)&pspec->
ref_count) == sizeof (gint), "Expression evaluates to false")
; (void) (0 ? *((int *)&pspec->ref_count) ^ *((int *)&
pspec->ref_count) : 1); (void) __atomic_fetch_add (((int *
)&pspec->ref_count), 1, 5); }))
;
218
219 return pspec;
220}
221
222/**
223 * c_param_spec_unref: (skip)
224 * @pspec: a valid #CParamSpec
225 *
226 * Decrements the reference count of a @pspec.
227 */
228void
229c_param_spec_unref (CParamSpec *pspec)
230{
231 gboolean is_zero;
232
233 g_return_if_fail (C_IS_PARAM_SPEC (pspec))do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_78
= 0; if ((((g_type_check_instance_is_fundamentally_a ((GTypeInstance
*) ((pspec)), (((GType) ((19) << (2))))))))) _g_boolean_var_78
= 1; _g_boolean_var_78; }), 1))) { } else { g_return_if_fail_warning
("libbean", ((const char*) (__func__)), "C_IS_PARAM_SPEC (pspec)"
); return; } } while (0)
;
234
235 is_zero = g_atomic_int_dec_and_test ((int *)&pspec->ref_count)(__extension__ ({ _Static_assert (sizeof *((int *)&pspec->
ref_count) == sizeof (gint), "Expression evaluates to false")
; (void) (0 ? *((int *)&pspec->ref_count) ^ *((int *)&
pspec->ref_count) : 1); __atomic_fetch_sub (((int *)&pspec
->ref_count), 1, 5) == 1; }))
;
236
237 if (G_UNLIKELY (is_zero)(__builtin_expect (__extension__ ({ int _g_boolean_var_79 = 0
; if (is_zero) _g_boolean_var_79 = 1; _g_boolean_var_79; }), 0
))
)
238 {
239 C_PARAM_SPEC_GET_CLASS (pspec)((((CParamSpecClass*) (((GTypeInstance*) ((pspec)))->g_class
))))
->finalize (pspec);
240 }
241}
242
243/**
244 * c_param_spec_sink:
245 * @pspec: a valid #CParamSpec
246 *
247 * The initial reference count of a newly created #CParamSpec is 1,
248 * even though no one has explicitly called c_param_spec_ref() on it
249 * yet. So the initial reference count is flagged as "floating", until
250 * someone calls `c_param_spec_ref (pspec); c_param_spec_sink
251 * (pspec);` in sequence on it, taking over the initial
252 * reference count (thus ending up with a @pspec that has a reference
253 * count of 1 still, but is not flagged "floating" anymore).
254 */
255void
256c_param_spec_sink (CParamSpec *pspec)
257{
258 guintptr oldvalue;
259 g_return_if_fail (C_IS_PARAM_SPEC (pspec))do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_80
= 0; if ((((g_type_check_instance_is_fundamentally_a ((GTypeInstance
*) ((pspec)), (((GType) ((19) << (2))))))))) _g_boolean_var_80
= 1; _g_boolean_var_80; }), 1))) { } else { g_return_if_fail_warning
("libbean", ((const char*) (__func__)), "C_IS_PARAM_SPEC (pspec)"
); return; } } while (0)
;
260
261 oldvalue = g_atomic_pointer_and (&pspec->qdata, ~(gsize)PARAM_FLOATING_FLAG)(__extension__ ({ guintptr *gapa_atomic = (guintptr *) (&
pspec->qdata); _Static_assert (sizeof *(&pspec->qdata
) == sizeof (gpointer), "Expression evaluates to false"); _Static_assert
(sizeof *(&pspec->qdata) == sizeof (guintptr), "Expression evaluates to false"
); (void) (0 ? (gpointer) *(&pspec->qdata) : ((void*)0
)); (void) (0 ? (~(gsize)0x2) ^ (~(gsize)0x2) : 1); (guintptr
) __atomic_fetch_and (gapa_atomic, (~(gsize)0x2), 5); }))
;
262 if (oldvalue & PARAM_FLOATING_FLAG0x2)
263 c_param_spec_unref (pspec);
264}
265
266/**
267 * c_param_spec_ref_sink: (skip)
268 * @pspec: a valid #CParamSpec
269 *
270 * Convenience function to ref and sink a #CParamSpec.
271 *
272 * Since: 2.10
273 * Returns: (transfer full) (not nullable): the #CParamSpec that was passed into this function
274 */
275CParamSpec*
276c_param_spec_ref_sink (CParamSpec *pspec)
277{
278 guintptr oldvalue;
279 g_return_val_if_fail (C_IS_PARAM_SPEC (pspec), NULL)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_81
= 0; if ((((g_type_check_instance_is_fundamentally_a ((GTypeInstance
*) ((pspec)), (((GType) ((19) << (2))))))))) _g_boolean_var_81
= 1; _g_boolean_var_81; }), 1))) { } else { g_return_if_fail_warning
("libbean", ((const char*) (__func__)), "C_IS_PARAM_SPEC (pspec)"
); return (((void*)0)); } } while (0)
;
280
281 oldvalue = g_atomic_pointer_and (&pspec->qdata, ~(gsize)PARAM_FLOATING_FLAG)(__extension__ ({ guintptr *gapa_atomic = (guintptr *) (&
pspec->qdata); _Static_assert (sizeof *(&pspec->qdata
) == sizeof (gpointer), "Expression evaluates to false"); _Static_assert
(sizeof *(&pspec->qdata) == sizeof (guintptr), "Expression evaluates to false"
); (void) (0 ? (gpointer) *(&pspec->qdata) : ((void*)0
)); (void) (0 ? (~(gsize)0x2) ^ (~(gsize)0x2) : 1); (guintptr
) __atomic_fetch_and (gapa_atomic, (~(gsize)0x2), 5); }))
;
282 if (!(oldvalue & PARAM_FLOATING_FLAG0x2))
283 c_param_spec_ref (pspec);
284
285 return pspec;
286}
287
288/**
289 * c_param_spec_get_name:
290 * @pspec: a valid #CParamSpec
291 *
292 * Get the name of a #CParamSpec.
293 *
294 * The name is always an "interned" string (as per g_intern_string()).
295 * This allows for pointer-value comparisons.
296 *
297 * Returns: the name of @pspec.
298 */
299const gchar *
300c_param_spec_get_name (CParamSpec *pspec)
301{
302 g_return_val_if_fail (C_IS_PARAM_SPEC (pspec), NULL)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_82
= 0; if ((((g_type_check_instance_is_fundamentally_a ((GTypeInstance
*) ((pspec)), (((GType) ((19) << (2))))))))) _g_boolean_var_82
= 1; _g_boolean_var_82; }), 1))) { } else { g_return_if_fail_warning
("libbean", ((const char*) (__func__)), "C_IS_PARAM_SPEC (pspec)"
); return (((void*)0)); } } while (0)
;
303
304 return pspec->name;
305}
306
307/**
308 * c_param_spec_get_nick:
309 * @pspec: a valid #CParamSpec
310 *
311 * Get the nickname of a #CParamSpec.
312 *
313 * Returns: the nickname of @pspec.
314 */
315const gchar *
316c_param_spec_get_nick (CParamSpec *pspec)
317{
318 g_return_val_if_fail (C_IS_PARAM_SPEC (pspec), NULL)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_83
= 0; if ((((g_type_check_instance_is_fundamentally_a ((GTypeInstance
*) ((pspec)), (((GType) ((19) << (2))))))))) _g_boolean_var_83
= 1; _g_boolean_var_83; }), 1))) { } else { g_return_if_fail_warning
("libbean", ((const char*) (__func__)), "C_IS_PARAM_SPEC (pspec)"
); return (((void*)0)); } } while (0)
;
319
320 if (pspec->_nick)
321 return pspec->_nick;
322 else
323 {
324 CParamSpec *redirect_target;
325
326 redirect_target = c_param_spec_get_redirect_target (pspec);
327 if (redirect_target && redirect_target->_nick)
328 return redirect_target->_nick;
329 }
330
331 return pspec->name;
332}
333
334/**
335 * c_param_spec_get_blurb:
336 * @pspec: a valid #CParamSpec
337 *
338 * Get the short description of a #CParamSpec.
339 *
340 * Returns: (nullable): the short description of @pspec.
341 */
342const gchar *
343c_param_spec_get_blurb (CParamSpec *pspec)
344{
345 g_return_val_if_fail (C_IS_PARAM_SPEC (pspec), NULL)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_84
= 0; if ((((g_type_check_instance_is_fundamentally_a ((GTypeInstance
*) ((pspec)), (((GType) ((19) << (2))))))))) _g_boolean_var_84
= 1; _g_boolean_var_84; }), 1))) { } else { g_return_if_fail_warning
("libbean", ((const char*) (__func__)), "C_IS_PARAM_SPEC (pspec)"
); return (((void*)0)); } } while (0)
;
346
347 if (pspec->_blurb)
348 return pspec->_blurb;
349 else
350 {
351 CParamSpec *redirect_target;
352
353 redirect_target = c_param_spec_get_redirect_target (pspec);
354 if (redirect_target && redirect_target->_blurb)
355 return redirect_target->_blurb;
356 }
357
358 return NULL((void*)0);
359}
360
361/* @key must have already been validated with is_valid()
362 * Modifies @key in place. */
363static void
364canonicalize_key (gchar *key)
365{
366 gchar *p;
367
368 for (p = key; *p != 0; p++)
369 {
370 gchar c = *p;
371
372 if (c == '_')
373 *p = '-';
374 }
375}
376
377/* @key must have already been validated with is_valid() */
378static gboolean
379is_canonical (const gchar *key)
380{
381 return (strchr (key, '_') == NULL((void*)0));
382}
383
384/**
385 * c_param_spec_is_valid_name:
386 * @name: the canonical name of the property
387 *
388 * Validate a property name for a #CParamSpec. This can be useful for
389 * dynamically-generated properties which need to be validated at run-time
390 * before actually trying to create them.
391 *
392 * See [canonical parameter names][class@GObject.ParamSpec#parameter-names]
393 * for details of the rules for valid names.
394 *
395 * Returns: %TRUE if @name is a valid property name, %FALSE otherwise.
396 * Since: 2.66
397 */
398gboolean
399c_param_spec_is_valid_name (const gchar *name)
400{
401 const gchar *p;
402
403 /* First character must be a letter. */
404 if ((name[0] < 'A' || name[0] > 'Z') &&
405 (name[0] < 'a' || name[0] > 'z'))
406 return FALSE(0);
407
408 for (p = name; *p != 0; p++)
409 {
410 const gchar c = *p;
411
412 if (c != '-' && c != '_' &&
413 (c < '0' || c > '9') &&
414 (c < 'A' || c > 'Z') &&
415 (c < 'a' || c > 'z'))
416 return FALSE(0);
417 }
418
419 return TRUE(!(0));
420}
421
422/**
423 * c_param_spec_internal: (skip)
424 * @param_type: the #GType for the property; must be derived from %C_TYPE_PARAM
425 * @name: the canonical name of the property
426 * @nick: (nullable): the nickname of the property
427 * @blurb: (nullable): a short description of the property
428 * @flags: a combination of #CParamFlags
429 *
430 * Creates a new #CParamSpec instance.
431 *
432 * See [canonical parameter names][class@GObject.ParamSpec#parameter-names]
433 * for details of the rules for @name. Names which violate these rules lead
434 * to undefined behaviour.
435 *
436 * Beyond the name, #CParamSpecs have two more descriptive strings, the
437 * @nick and @blurb, which may be used as a localized label and description.
438 * For GTK and related libraries these are considered deprecated and may be
439 * omitted, while for other libraries such as GStreamer and its plugins they
440 * are essential. When in doubt, follow the conventions used in the
441 * surrounding code and supporting libraries.
442 *
443 * Returns: (type GObject.ParamSpec): (transfer floating): a newly allocated
444 * #CParamSpec instance, which is initially floating
445 */
446gpointer
447c_param_spec_internal (GType param_type,
448 const gchar *name,
449 const gchar *nick,
450 const gchar *blurb,
451 CParamFlags flags)
452{
453 CParamSpec *pspec;
454 CParamSpecPrivate *priv;
455
456 g_return_val_if_fail (C_TYPE_IS_PARAM (param_type) && param_type != C_TYPE_PARAM, NULL)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_85
= 0; if (((g_type_fundamental (param_type)) == ((GType) ((19
) << (2)))) && param_type != ((GType) ((19) <<
(2)))) _g_boolean_var_85 = 1; _g_boolean_var_85; }), 1))) { }
else { g_return_if_fail_warning ("libbean", ((const char*) (
__func__)), "C_TYPE_IS_PARAM (param_type) && param_type != C_TYPE_PARAM"
); return (((void*)0)); } } while (0)
;
457 g_return_val_if_fail (name != NULL, NULL)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_86
= 0; if (name != ((void*)0)) _g_boolean_var_86 = 1; _g_boolean_var_86
; }), 1))) { } else { g_return_if_fail_warning ("libbean", ((
const char*) (__func__)), "name != NULL"); return (((void*)0)
); } } while (0)
;
458 g_return_val_if_fail (c_param_spec_is_valid_name (name), NULL)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_87
= 0; if (c_param_spec_is_valid_name (name)) _g_boolean_var_87
= 1; _g_boolean_var_87; }), 1))) { } else { g_return_if_fail_warning
("libbean", ((const char*) (__func__)), "c_param_spec_is_valid_name (name)"
); return (((void*)0)); } } while (0)
;
459 g_return_val_if_fail (!(flags & C_PARAM_STATIC_NAME) || is_canonical (name), NULL)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_88
= 0; if (!(flags & C_PARAM_STATIC_NAME) || is_canonical (
name)) _g_boolean_var_88 = 1; _g_boolean_var_88; }), 1))) { }
else { g_return_if_fail_warning ("libbean", ((const char*) (
__func__)), "!(flags & C_PARAM_STATIC_NAME) || is_canonical (name)"
); return (((void*)0)); } } while (0)
;
460
461 pspec = (gpointer) g_type_create_instance (param_type);
462
463 if (flags & C_PARAM_STATIC_NAME)
464 {
465 /* pspec->name is not freed if (flags & C_PARAM_STATIC_NAME) */
466 pspec->name = (gchar *) g_intern_static_string (name);
467 if (!is_canonical (pspec->name))
468 g_warning ("C_PARAM_STATIC_NAME used with non-canonical pspec name: %s", pspec->name);
469 }
470 else
471 {
472 if (is_canonical (name))
473 pspec->name = (gchar *) g_intern_string (name);
474 else
475 {
476 gchar *tmp = g_strdup (name)g_strdup_inline (name);
477 canonicalize_key (tmp);
478 pspec->name = (gchar *) g_intern_string (tmp);
479 g_free (tmp);
480 }
481 }
482
483 priv = c_param_spec_get_private (pspec);
484 priv->name_quark = g_quark_from_string (pspec->name);
485
486 if (flags & C_PARAM_STATIC_NICK)
487 pspec->_nick = (gchar*) nick;
488 else
489 pspec->_nick = g_strdup (nick)g_strdup_inline (nick);
490
491 if (flags & C_PARAM_STATIC_BLURB)
492 pspec->_blurb = (gchar*) blurb;
493 else
494 pspec->_blurb = g_strdup (blurb)g_strdup_inline (blurb);
495
496 pspec->flags = (flags & C_PARAM_USER_MASK(~0U << (8))) | (flags & C_PARAM_MASK(0x000000ff));
497
498 return pspec;
499}
500
501/**
502 * c_param_spec_get_qdata:
503 * @pspec: a valid #CParamSpec
504 * @quark: a #GQuark, naming the user data pointer
505 *
506 * Gets back user data pointers stored via c_param_spec_set_qdata().
507 *
508 * Returns: (transfer none) (nullable): the user data pointer set, or %NULL
509 */
510gpointer
511c_param_spec_get_qdata (CParamSpec *pspec,
512 GQuark quark)
513{
514 g_return_val_if_fail (C_IS_PARAM_SPEC (pspec), NULL)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_89
= 0; if ((((g_type_check_instance_is_fundamentally_a ((GTypeInstance
*) ((pspec)), (((GType) ((19) << (2))))))))) _g_boolean_var_89
= 1; _g_boolean_var_89; }), 1))) { } else { g_return_if_fail_warning
("libbean", ((const char*) (__func__)), "C_IS_PARAM_SPEC (pspec)"
); return (((void*)0)); } } while (0)
;
515
516 return quark ? g_datalist_id_get_data (&pspec->qdata, quark) : NULL((void*)0);
517}
518
519/**
520 * c_param_spec_set_qdata:
521 * @pspec: the #CParamSpec to set store a user data pointer
522 * @quark: a #GQuark, naming the user data pointer
523 * @data: (nullable): an opaque user data pointer
524 *
525 * Sets an opaque, named pointer on a #CParamSpec. The name is
526 * specified through a #GQuark (retrieved e.g. via
527 * g_quark_from_static_string()), and the pointer can be gotten back
528 * from the @pspec with c_param_spec_get_qdata(). Setting a
529 * previously set user data pointer, overrides (frees) the old pointer
530 * set, using %NULL as pointer essentially removes the data stored.
531 */
532void
533c_param_spec_set_qdata (CParamSpec *pspec,
534 GQuark quark,
535 gpointer data)
536{
537 g_return_if_fail (C_IS_PARAM_SPEC (pspec))do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_90
= 0; if ((((g_type_check_instance_is_fundamentally_a ((GTypeInstance
*) ((pspec)), (((GType) ((19) << (2))))))))) _g_boolean_var_90
= 1; _g_boolean_var_90; }), 1))) { } else { g_return_if_fail_warning
("libbean", ((const char*) (__func__)), "C_IS_PARAM_SPEC (pspec)"
); return; } } while (0)
;
538 g_return_if_fail (quark > 0)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_91
= 0; if (quark > 0) _g_boolean_var_91 = 1; _g_boolean_var_91
; }), 1))) { } else { g_return_if_fail_warning ("libbean", ((
const char*) (__func__)), "quark > 0"); return; } } while (
0)
;
539
540 g_datalist_id_set_data (&pspec->qdata, quark, data)g_datalist_id_set_data_full ((&pspec->qdata), (quark),
(data), ((void*)0))
;
541}
542
543/**
544 * c_param_spec_set_qdata_full: (skip)
545 * @pspec: the #CParamSpec to set store a user data pointer
546 * @quark: a #GQuark, naming the user data pointer
547 * @data: (nullable): an opaque user data pointer
548 * @destroy: (nullable): function to invoke with @data as argument, when @data needs to
549 * be freed
550 *
551 * This function works like c_param_spec_set_qdata(), but in addition,
552 * a `void (*destroy) (gpointer)` function may be
553 * specified which is called with @data as argument when the @pspec is
554 * finalized, or the data is being overwritten by a call to
555 * c_param_spec_set_qdata() with the same @quark.
556 */
557void
558c_param_spec_set_qdata_full (CParamSpec *pspec,
559 GQuark quark,
560 gpointer data,
561 GDestroyNotify destroy)
562{
563 g_return_if_fail (C_IS_PARAM_SPEC (pspec))do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_92
= 0; if ((((g_type_check_instance_is_fundamentally_a ((GTypeInstance
*) ((pspec)), (((GType) ((19) << (2))))))))) _g_boolean_var_92
= 1; _g_boolean_var_92; }), 1))) { } else { g_return_if_fail_warning
("libbean", ((const char*) (__func__)), "C_IS_PARAM_SPEC (pspec)"
); return; } } while (0)
;
564 g_return_if_fail (quark > 0)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_93
= 0; if (quark > 0) _g_boolean_var_93 = 1; _g_boolean_var_93
; }), 1))) { } else { g_return_if_fail_warning ("libbean", ((
const char*) (__func__)), "quark > 0"); return; } } while (
0)
;
565
566 g_datalist_id_set_data_full (&pspec->qdata, quark, data, data ? destroy : (GDestroyNotify) NULL((void*)0));
567}
568
569/**
570 * c_param_spec_steal_qdata:
571 * @pspec: the #CParamSpec to get a stored user data pointer from
572 * @quark: a #GQuark, naming the user data pointer
573 *
574 * Gets back user data pointers stored via c_param_spec_set_qdata()
575 * and removes the @data from @pspec without invoking its destroy()
576 * function (if any was set). Usually, calling this function is only
577 * required to update user data pointers with a destroy notifier.
578 *
579 * Returns: (transfer none) (nullable): the user data pointer set, or %NULL
580 */
581gpointer
582c_param_spec_steal_qdata (CParamSpec *pspec,
583 GQuark quark)
584{
585 g_return_val_if_fail (C_IS_PARAM_SPEC (pspec), NULL)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_94
= 0; if ((((g_type_check_instance_is_fundamentally_a ((GTypeInstance
*) ((pspec)), (((GType) ((19) << (2))))))))) _g_boolean_var_94
= 1; _g_boolean_var_94; }), 1))) { } else { g_return_if_fail_warning
("libbean", ((const char*) (__func__)), "C_IS_PARAM_SPEC (pspec)"
); return (((void*)0)); } } while (0)
;
586 g_return_val_if_fail (quark > 0, NULL)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_95
= 0; if (quark > 0) _g_boolean_var_95 = 1; _g_boolean_var_95
; }), 1))) { } else { g_return_if_fail_warning ("libbean", ((
const char*) (__func__)), "quark > 0"); return (((void*)0)
); } } while (0)
;
587
588 return g_datalist_id_remove_no_notify (&pspec->qdata, quark);
589}
590
591/**
592 * c_param_spec_get_redirect_target:
593 * @pspec: a #CParamSpec
594 *
595 * If the paramspec redirects operations to another paramspec,
596 * returns that paramspec. Redirect is used typically for
597 * providing a new implementation of a property in a derived
598 * type while preserving all the properties from the parent
599 * type. Redirection is established by creating a property
600 * of type #CParamSpecOverride. See g_object_class_override_property()
601 * for an example of the use of this capability.
602 *
603 * Since: 2.4
604 *
605 * Returns: (transfer none) (nullable): paramspec to which requests on this
606 * paramspec should be redirected, or %NULL if none.
607 */
608CParamSpec*
609c_param_spec_get_redirect_target (CParamSpec *pspec)
610{
611 GTypeInstance *inst = (GTypeInstance *)pspec;
612
613 if (inst && inst->g_class && inst->g_class->g_type == C_TYPE_PARAM_OVERRIDE(c_param_spec_types[20]))
614 return ((CParamSpecOverride*)pspec)->overridden;
615 else
616 return NULL((void*)0);
617}
618
619/**
620 * c_param_value_set_default:
621 * @pspec: a valid #CParamSpec
622 * @value: a #GValue of correct type for @pspec; since 2.64, you
623 * can also pass an empty #GValue, initialized with %G_VALUE_INIT
624 *
625 * Sets @value to its default value as specified in @pspec.
626 */
627void
628c_param_value_set_default (CParamSpec *pspec,
629 GValue *value)
630{
631 g_return_if_fail (C_IS_PARAM_SPEC (pspec))do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_96
= 0; if ((((g_type_check_instance_is_fundamentally_a ((GTypeInstance
*) ((pspec)), (((GType) ((19) << (2))))))))) _g_boolean_var_96
= 1; _g_boolean_var_96; }), 1))) { } else { g_return_if_fail_warning
("libbean", ((const char*) (__func__)), "C_IS_PARAM_SPEC (pspec)"
); return; } } while (0)
;
632
633 if (G_VALUE_TYPE (value)(((GValue*) (value))->g_type) == G_TYPE_INVALID((GType) ((0) << (2))))
634 {
635 g_value_init (value, C_PARAM_SPEC_VALUE_TYPE (pspec)(((((CParamSpec*) (void *) ((pspec)))))->value_type));
636 }
637 else
638 {
639 g_return_if_fail (G_IS_VALUE (value))do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_97
= 0; if ((((g_type_check_value ((GValue*) (value)))))) _g_boolean_var_97
= 1; _g_boolean_var_97; }), 1))) { } else { g_return_if_fail_warning
("libbean", ((const char*) (__func__)), "G_IS_VALUE (value)"
); return; } } while (0)
;
640 g_return_if_fail (PSPEC_APPLIES_TO_VALUE (pspec, value))do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_98
= 0; if ((((__extension__ ({ const GValue *__val = (const GValue
*) ((value)); GType __t = ((((((CParamSpec*) (void *) ((pspec
)))))->value_type)); gboolean __r; if (!__val) __r = (0); else
if (__val->g_type == __t) __r = (!(0)); else __r = g_type_check_value_holds
(__val, __t); __r; }))))) _g_boolean_var_98 = 1; _g_boolean_var_98
; }), 1))) { } else { g_return_if_fail_warning ("libbean", ((
const char*) (__func__)), "PSPEC_APPLIES_TO_VALUE (pspec, value)"
); return; } } while (0)
;
641 g_value_reset (value);
642 }
643
644 C_PARAM_SPEC_GET_CLASS (pspec)((((CParamSpecClass*) (((GTypeInstance*) ((pspec)))->g_class
))))
->value_set_default (pspec, value);
645}
646
647/**
648 * c_param_value_defaults:
649 * @pspec: a valid #CParamSpec
650 * @value: a #GValue of correct type for @pspec
651 *
652 * Checks whether @value contains the default value as specified in @pspec.
653 *
654 * Returns: whether @value contains the canonical default for this @pspec
655 */
656gboolean
657c_param_value_defaults (CParamSpec *pspec,
658 const GValue *value)
659{
660 GValue dflt_value = G_VALUE_INIT{ 0, { { 0 } } };
661 gboolean defaults;
662
663 g_return_val_if_fail (C_IS_PARAM_SPEC (pspec), FALSE)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_99
= 0; if ((((g_type_check_instance_is_fundamentally_a ((GTypeInstance
*) ((pspec)), (((GType) ((19) << (2))))))))) _g_boolean_var_99
= 1; _g_boolean_var_99; }), 1))) { } else { g_return_if_fail_warning
("libbean", ((const char*) (__func__)), "C_IS_PARAM_SPEC (pspec)"
); return ((0)); } } while (0)
;
664 g_return_val_if_fail (G_IS_VALUE (value), FALSE)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_100
= 0; if ((((g_type_check_value ((GValue*) (value)))))) _g_boolean_var_100
= 1; _g_boolean_var_100; }), 1))) { } else { g_return_if_fail_warning
("libbean", ((const char*) (__func__)), "G_IS_VALUE (value)"
); return ((0)); } } while (0)
;
665 g_return_val_if_fail (PSPEC_APPLIES_TO_VALUE (pspec, value), FALSE)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_101
= 0; if ((((__extension__ ({ const GValue *__val = (const GValue
*) ((value)); GType __t = ((((((CParamSpec*) (void *) ((pspec
)))))->value_type)); gboolean __r; if (!__val) __r = (0); else
if (__val->g_type == __t) __r = (!(0)); else __r = g_type_check_value_holds
(__val, __t); __r; }))))) _g_boolean_var_101 = 1; _g_boolean_var_101
; }), 1))) { } else { g_return_if_fail_warning ("libbean", ((
const char*) (__func__)), "PSPEC_APPLIES_TO_VALUE (pspec, value)"
); return ((0)); } } while (0)
;
666
667 g_value_init (&dflt_value, C_PARAM_SPEC_VALUE_TYPE (pspec)(((((CParamSpec*) (void *) ((pspec)))))->value_type));
668 C_PARAM_SPEC_GET_CLASS (pspec)((((CParamSpecClass*) (((GTypeInstance*) ((pspec)))->g_class
))))
->value_set_default (pspec, &dflt_value);
669 defaults = C_PARAM_SPEC_GET_CLASS (pspec)((((CParamSpecClass*) (((GTypeInstance*) ((pspec)))->g_class
))))
->values_cmp (pspec, value, &dflt_value) == 0;
670 g_value_unset (&dflt_value);
671
672 return defaults;
673}
674
675/**
676 * c_param_value_validate:
677 * @pspec: a valid #CParamSpec
678 * @value: a #GValue of correct type for @pspec
679 *
680 * Ensures that the contents of @value comply with the specifications
681 * set out by @pspec. For example, a #CParamSpecInt might require
682 * that integers stored in @value may not be smaller than -42 and not be
683 * greater than +42. If @value contains an integer outside of this range,
684 * it is modified accordingly, so the resulting value will fit into the
685 * range -42 .. +42.
686 *
687 * Returns: whether modifying @value was necessary to ensure validity
688 */
689gboolean
690c_param_value_validate (CParamSpec *pspec,
691 GValue *value)
692{
693 g_return_val_if_fail (C_IS_PARAM_SPEC (pspec), FALSE)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_102
= 0; if ((((g_type_check_instance_is_fundamentally_a ((GTypeInstance
*) ((pspec)), (((GType) ((19) << (2))))))))) _g_boolean_var_102
= 1; _g_boolean_var_102; }), 1))) { } else { g_return_if_fail_warning
("libbean", ((const char*) (__func__)), "C_IS_PARAM_SPEC (pspec)"
); return ((0)); } } while (0)
;
694 g_return_val_if_fail (G_IS_VALUE (value), FALSE)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_103
= 0; if ((((g_type_check_value ((GValue*) (value)))))) _g_boolean_var_103
= 1; _g_boolean_var_103; }), 1))) { } else { g_return_if_fail_warning
("libbean", ((const char*) (__func__)), "G_IS_VALUE (value)"
); return ((0)); } } while (0)
;
695 g_return_val_if_fail (PSPEC_APPLIES_TO_VALUE (pspec, value), FALSE)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_104
= 0; if ((((__extension__ ({ const GValue *__val = (const GValue
*) ((value)); GType __t = ((((((CParamSpec*) (void *) ((pspec
)))))->value_type)); gboolean __r; if (!__val) __r = (0); else
if (__val->g_type == __t) __r = (!(0)); else __r = g_type_check_value_holds
(__val, __t); __r; }))))) _g_boolean_var_104 = 1; _g_boolean_var_104
; }), 1))) { } else { g_return_if_fail_warning ("libbean", ((
const char*) (__func__)), "PSPEC_APPLIES_TO_VALUE (pspec, value)"
); return ((0)); } } while (0)
;
696
697 if (C_PARAM_SPEC_GET_CLASS (pspec)((((CParamSpecClass*) (((GTypeInstance*) ((pspec)))->g_class
))))
->value_validate)
698 {
699 GValue oval = *value;
700
701 if (C_PARAM_SPEC_GET_CLASS (pspec)((((CParamSpecClass*) (((GTypeInstance*) ((pspec)))->g_class
))))
->value_validate (pspec, value) ||
702 memcmp (&oval.data, &value->data, sizeof (oval.data)))
703 return TRUE(!(0));
704 }
705
706 return FALSE(0);
707}
708
709/**
710 * c_param_value_is_valid:
711 * @pspec: a valid #CParamSpec
712 * @value: a #GValue of correct type for @pspec
713 *
714 * Return whether the contents of @value comply with the specifications
715 * set out by @pspec.
716 *
717 * Returns: whether the contents of @value comply with the specifications
718 * set out by @pspec.
719 *
720 * Since: 2.74
721 */
722gboolean
723c_param_value_is_valid (CParamSpec *pspec,
724 const GValue *value)
725{
726 CParamSpecClass *class;
727
728 g_return_val_if_fail (C_IS_PARAM_SPEC (pspec), TRUE)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_105
= 0; if ((((g_type_check_instance_is_fundamentally_a ((GTypeInstance
*) ((pspec)), (((GType) ((19) << (2))))))))) _g_boolean_var_105
= 1; _g_boolean_var_105; }), 1))) { } else { g_return_if_fail_warning
("libbean", ((const char*) (__func__)), "C_IS_PARAM_SPEC (pspec)"
); return ((!(0))); } } while (0)
;
729 g_return_val_if_fail (G_IS_VALUE (value), TRUE)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_106
= 0; if ((((g_type_check_value ((GValue*) (value)))))) _g_boolean_var_106
= 1; _g_boolean_var_106; }), 1))) { } else { g_return_if_fail_warning
("libbean", ((const char*) (__func__)), "G_IS_VALUE (value)"
); return ((!(0))); } } while (0)
;
730 g_return_val_if_fail (PSPEC_APPLIES_TO_VALUE (pspec, value), TRUE)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_107
= 0; if ((((__extension__ ({ const GValue *__val = (const GValue
*) ((value)); GType __t = ((((((CParamSpec*) (void *) ((pspec
)))))->value_type)); gboolean __r; if (!__val) __r = (0); else
if (__val->g_type == __t) __r = (!(0)); else __r = g_type_check_value_holds
(__val, __t); __r; }))))) _g_boolean_var_107 = 1; _g_boolean_var_107
; }), 1))) { } else { g_return_if_fail_warning ("libbean", ((
const char*) (__func__)), "PSPEC_APPLIES_TO_VALUE (pspec, value)"
); return ((!(0))); } } while (0)
;
731
732 class = C_PARAM_SPEC_GET_CLASS (pspec)((((CParamSpecClass*) (((GTypeInstance*) ((pspec)))->g_class
))))
;
733
734 if (class->value_is_valid)
735 return class->value_is_valid (pspec, value);
736 else if (class->value_validate)
737 {
738 GValue val = G_VALUE_INIT{ 0, { { 0 } } };
739 gboolean changed;
740
741 g_value_init (&val, G_VALUE_TYPE (value)(((GValue*) (value))->g_type));
742 g_value_copy (value, &val);
743
744 changed = class->value_validate (pspec, &val);
745
746 g_value_unset (&val);
747
748 return !changed;
749 }
750
751 return TRUE(!(0));
752}
753
754/**
755 * c_param_value_convert:
756 * @pspec: a valid #CParamSpec
757 * @src_value: source #GValue
758 * @dest_value: destination #GValue of correct type for @pspec
759 * @strict_validation: %TRUE requires @dest_value to conform to @pspec
760 * without modifications
761 *
762 * Transforms @src_value into @dest_value if possible, and then
763 * validates @dest_value, in order for it to conform to @pspec. If
764 * @strict_validation is %TRUE this function will only succeed if the
765 * transformed @dest_value complied to @pspec without modifications.
766 *
767 * See also g_value_type_transformable(), g_value_transform() and
768 * c_param_value_validate().
769 *
770 * Returns: %TRUE if transformation and validation were successful,
771 * %FALSE otherwise and @dest_value is left untouched.
772 */
773gboolean
774c_param_value_convert (CParamSpec *pspec,
775 const GValue *src_value,
776 GValue *dest_value,
777 gboolean strict_validation)
778{
779 GValue tmp_value = G_VALUE_INIT{ 0, { { 0 } } };
780
781 g_return_val_if_fail (C_IS_PARAM_SPEC (pspec), FALSE)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_108
= 0; if ((((g_type_check_instance_is_fundamentally_a ((GTypeInstance
*) ((pspec)), (((GType) ((19) << (2))))))))) _g_boolean_var_108
= 1; _g_boolean_var_108; }), 1))) { } else { g_return_if_fail_warning
("libbean", ((const char*) (__func__)), "C_IS_PARAM_SPEC (pspec)"
); return ((0)); } } while (0)
;
782 g_return_val_if_fail (G_IS_VALUE (src_value), FALSE)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_109
= 0; if ((((g_type_check_value ((GValue*) (src_value)))))) _g_boolean_var_109
= 1; _g_boolean_var_109; }), 1))) { } else { g_return_if_fail_warning
("libbean", ((const char*) (__func__)), "G_IS_VALUE (src_value)"
); return ((0)); } } while (0)
;
783 g_return_val_if_fail (G_IS_VALUE (dest_value), FALSE)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_110
= 0; if ((((g_type_check_value ((GValue*) (dest_value)))))) _g_boolean_var_110
= 1; _g_boolean_var_110; }), 1))) { } else { g_return_if_fail_warning
("libbean", ((const char*) (__func__)), "G_IS_VALUE (dest_value)"
); return ((0)); } } while (0)
;
784 g_return_val_if_fail (PSPEC_APPLIES_TO_VALUE (pspec, dest_value), FALSE)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_111
= 0; if ((((__extension__ ({ const GValue *__val = (const GValue
*) ((dest_value)); GType __t = ((((((CParamSpec*) (void *) ((
pspec)))))->value_type)); gboolean __r; if (!__val) __r = (
0); else if (__val->g_type == __t) __r = (!(0)); else __r =
g_type_check_value_holds (__val, __t); __r; }))))) _g_boolean_var_111
= 1; _g_boolean_var_111; }), 1))) { } else { g_return_if_fail_warning
("libbean", ((const char*) (__func__)), "PSPEC_APPLIES_TO_VALUE (pspec, dest_value)"
); return ((0)); } } while (0)
;
785
786 /* better leave dest_value untouched when returning FALSE */
787
788 g_value_init (&tmp_value, G_VALUE_TYPE (dest_value)(((GValue*) (dest_value))->g_type));
789 if (g_value_transform (src_value, &tmp_value) &&
790 (!c_param_value_validate (pspec, &tmp_value) || !strict_validation))
791 {
792 g_value_unset (dest_value);
793
794 /* values are relocatable */
795 memcpy (dest_value, &tmp_value, sizeof (tmp_value));
796
797 return TRUE(!(0));
798 }
799 else
800 {
801 g_value_unset (&tmp_value);
802
803 return FALSE(0);
804 }
805}
806
807/**
808 * c_param_values_cmp:
809 * @pspec: a valid #CParamSpec
810 * @value1: a #GValue of correct type for @pspec
811 * @value2: a #GValue of correct type for @pspec
812 *
813 * Compares @value1 with @value2 according to @pspec, and return -1, 0 or +1,
814 * if @value1 is found to be less than, equal to or greater than @value2,
815 * respectively.
816 *
817 * Returns: -1, 0 or +1, for a less than, equal to or greater than result
818 */
819gint
820c_param_values_cmp (CParamSpec *pspec,
821 const GValue *value1,
822 const GValue *value2)
823{
824 gint cmp;
825
826 /* param_values_cmp() effectively does: value1 - value2
827 * so the return values are:
828 * -1) value1 < value2
829 * 0) value1 == value2
830 * 1) value1 > value2
831 */
832 g_return_val_if_fail (C_IS_PARAM_SPEC (pspec), 0)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_112
= 0; if ((((g_type_check_instance_is_fundamentally_a ((GTypeInstance
*) ((pspec)), (((GType) ((19) << (2))))))))) _g_boolean_var_112
= 1; _g_boolean_var_112; }), 1))) { } else { g_return_if_fail_warning
("libbean", ((const char*) (__func__)), "C_IS_PARAM_SPEC (pspec)"
); return (0); } } while (0)
;
833 g_return_val_if_fail (G_IS_VALUE (value1), 0)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_113
= 0; if ((((g_type_check_value ((GValue*) (value1)))))) _g_boolean_var_113
= 1; _g_boolean_var_113; }), 1))) { } else { g_return_if_fail_warning
("libbean", ((const char*) (__func__)), "G_IS_VALUE (value1)"
); return (0); } } while (0)
;
834 g_return_val_if_fail (G_IS_VALUE (value2), 0)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_114
= 0; if ((((g_type_check_value ((GValue*) (value2)))))) _g_boolean_var_114
= 1; _g_boolean_var_114; }), 1))) { } else { g_return_if_fail_warning
("libbean", ((const char*) (__func__)), "G_IS_VALUE (value2)"
); return (0); } } while (0)
;
835 g_return_val_if_fail (PSPEC_APPLIES_TO_VALUE (pspec, value1), 0)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_115
= 0; if ((((__extension__ ({ const GValue *__val = (const GValue
*) ((value1)); GType __t = ((((((CParamSpec*) (void *) ((pspec
)))))->value_type)); gboolean __r; if (!__val) __r = (0); else
if (__val->g_type == __t) __r = (!(0)); else __r = g_type_check_value_holds
(__val, __t); __r; }))))) _g_boolean_var_115 = 1; _g_boolean_var_115
; }), 1))) { } else { g_return_if_fail_warning ("libbean", ((
const char*) (__func__)), "PSPEC_APPLIES_TO_VALUE (pspec, value1)"
); return (0); } } while (0)
;
836 g_return_val_if_fail (PSPEC_APPLIES_TO_VALUE (pspec, value2), 0)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_116
= 0; if ((((__extension__ ({ const GValue *__val = (const GValue
*) ((value2)); GType __t = ((((((CParamSpec*) (void *) ((pspec
)))))->value_type)); gboolean __r; if (!__val) __r = (0); else
if (__val->g_type == __t) __r = (!(0)); else __r = g_type_check_value_holds
(__val, __t); __r; }))))) _g_boolean_var_116 = 1; _g_boolean_var_116
; }), 1))) { } else { g_return_if_fail_warning ("libbean", ((
const char*) (__func__)), "PSPEC_APPLIES_TO_VALUE (pspec, value2)"
); return (0); } } while (0)
;
837
838 cmp = C_PARAM_SPEC_GET_CLASS (pspec)((((CParamSpecClass*) (((GTypeInstance*) ((pspec)))->g_class
))))
->values_cmp (pspec, value1, value2);
839
840 return CLAMP (cmp, -1, 1)(((cmp) > (1)) ? (1) : (((cmp) < (-1)) ? (-1) : (cmp)));
841}
842
843static void
844value_param_init (GValue *value)
845{
846 value->data[0].v_pointer = NULL((void*)0);
847}
848
849static void
850value_param_free_value (GValue *value)
851{
852 if (value->data[0].v_pointer)
853 c_param_spec_unref (value->data[0].v_pointer);
854}
855
856static void
857value_param_copy_value (const GValue *src_value,
858 GValue *dest_value)
859{
860 if (src_value->data[0].v_pointer)
861 dest_value->data[0].v_pointer = c_param_spec_ref (src_value->data[0].v_pointer);
862 else
863 dest_value->data[0].v_pointer = NULL((void*)0);
864}
865
866static void
867value_param_transform_value (const GValue *src_value,
868 GValue *dest_value)
869{
870 if (src_value->data[0].v_pointer &&
871 g_type_is_a (C_PARAM_SPEC_TYPE (dest_value->data[0].v_pointer), G_VALUE_TYPE (dest_value))(((((((GTypeClass*) (((GTypeInstance*) (dest_value->data[0
].v_pointer))->g_class))->g_type)))) == ((((GValue*) (dest_value
))->g_type)) || (g_type_is_a) (((((((GTypeClass*) (((GTypeInstance
*) (dest_value->data[0].v_pointer))->g_class))->g_type
)))), ((((GValue*) (dest_value))->g_type))))
)
872 dest_value->data[0].v_pointer = c_param_spec_ref (src_value->data[0].v_pointer);
873 else
874 dest_value->data[0].v_pointer = NULL((void*)0);
875}
876
877static gpointer
878value_param_peek_pointer (const GValue *value)
879{
880 return value->data[0].v_pointer;
881}
882
883static gchar*
884value_param_collect_value (GValue *value,
885 guint n_collect_values,
886 GTypeCValue *collect_values,
887 guint collect_flags)
888{
889 if (collect_values[0].v_pointer)
890 {
891 CParamSpec *param = collect_values[0].v_pointer;
892
893 if (param->g_type_instance.g_class == NULL((void*)0))
894 return g_strconcat ("invalid unclassed param spec pointer for value type '",
895 G_VALUE_TYPE_NAME (value)(g_type_name ((((GValue*) (value))->g_type))),
896 "'",
897 NULL((void*)0));
898 else if (!g_value_type_compatible (C_PARAM_SPEC_TYPE (param)(((((GTypeClass*) (((GTypeInstance*) (param))->g_class))->
g_type)))
, G_VALUE_TYPE (value)(((GValue*) (value))->g_type)))
899 return g_strconcat ("invalid param spec type '",
900 C_PARAM_SPEC_TYPE_NAME (param)(g_type_name ((((((GTypeClass*) (((GTypeInstance*) (param))->
g_class))->g_type)))))
,
901 "' for value type '",
902 G_VALUE_TYPE_NAME (value)(g_type_name ((((GValue*) (value))->g_type))),
903 "'",
904 NULL((void*)0));
905 value->data[0].v_pointer = c_param_spec_ref (param);
906 }
907 else
908 value->data[0].v_pointer = NULL((void*)0);
909
910 return NULL((void*)0);
911}
912
913static gchar*
914value_param_lcopy_value (const GValue *value,
915 guint n_collect_values,
916 GTypeCValue *collect_values,
917 guint collect_flags)
918{
919 CParamSpec **param_p = collect_values[0].v_pointer;
920
921 g_return_val_if_fail (param_p != NULL, g_strdup_printf ("value location for '%s' passed as NULL", G_VALUE_TYPE_NAME (value)))do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_117
= 0; if (param_p != ((void*)0)) _g_boolean_var_117 = 1; _g_boolean_var_117
; }), 1))) { } else { g_return_if_fail_warning ("libbean", ((
const char*) (__func__)), "param_p != NULL"); return (g_strdup_printf
("value location for '%s' passed as NULL", (g_type_name ((((
GValue*) (value))->g_type))))); } } while (0)
;
922
923 if (!value->data[0].v_pointer)
924 *param_p = NULL((void*)0);
925 else if (collect_flags & G_VALUE_NOCOPY_CONTENTS(1 << 27))
926 *param_p = value->data[0].v_pointer;
927 else
928 *param_p = c_param_spec_ref (value->data[0].v_pointer);
929
930 return NULL((void*)0);
931}
932
933
934/* --- param spec pool --- */
935/**
936 * CParamSpecPool:
937 *
938 * A #CParamSpecPool maintains a collection of #CParamSpecs which can be
939 * quickly accessed by owner and name.
940 *
941 * The implementation of the #GObject property system uses such a pool to
942 * store the #CParamSpecs of the properties all object types.
943 */
944struct _CParamSpecPool
945{
946 GMutex mutex;
947 gboolean type_prefixing;
948 GHashTable *hash_table;
949};
950
951static guint
952param_spec_pool_hash (gconstpointer key_spec)
953{
954 const CParamSpec *key = key_spec;
955 const gchar *p;
956 guint h = (guint) key->owner_type;
957
958 for (p = key->name; *p; p++)
959 h = (h << 5) - h + *p;
960
961 return h;
962}
963
964static gboolean
965param_spec_pool_equals (gconstpointer key_spec_1,
966 gconstpointer key_spec_2)
967{
968 const CParamSpec *key1 = key_spec_1;
969 const CParamSpec *key2 = key_spec_2;
970
971 return (key1->owner_type == key2->owner_type &&
972 (key1->name == key2->name ||
973 strcmp (key1->name, key2->name) == 0));
974}
975
976/**
977 * c_param_spec_pool_new:
978 * @type_prefixing: Whether the pool will support type-prefixed property names.
979 *
980 * Creates a new #CParamSpecPool.
981 *
982 * If @type_prefixing is %TRUE, lookups in the newly created pool will
983 * allow to specify the owner as a colon-separated prefix of the
984 * property name, like "GtkContainer:border-width". This feature is
985 * deprecated, so you should always set @type_prefixing to %FALSE.
986 *
987 * Returns: (transfer full): a newly allocated #CParamSpecPool.
988 */
989CParamSpecPool*
990c_param_spec_pool_new (gboolean type_prefixing)
991{
992 static GMutex init_mutex;
993 CParamSpecPool *pool = g_new (CParamSpecPool, 1)(CParamSpecPool *) (__extension__ ({ gsize __n = (gsize) (1);
gsize __s = sizeof (CParamSpecPool); gpointer __p; if (__s ==
1) __p = g_malloc (__n); else if (__builtin_constant_p (__n)
&& (__s == 0 || __n <= (9223372036854775807L *2UL
+1UL) / __s)) __p = g_malloc (__n * __s); else __p = g_malloc_n
(__n, __s); __p; }))
;
994
995 memcpy (&pool->mutex, &init_mutex, sizeof (init_mutex));
996 pool->type_prefixing = type_prefixing != FALSE(0);
997 pool->hash_table = g_hash_table_new_full (param_spec_pool_hash,
998 param_spec_pool_equals,
999 (GDestroyNotify) c_param_spec_unref,
1000 NULL((void*)0));
1001
1002 return pool;
1003}
1004
1005/**
1006 * c_param_spec_pool_free:
1007 * @pool: (transfer full): a #CParamSpecPool
1008 *
1009 * Frees the resources allocated by a #CParamSpecPool.
1010 *
1011 * Since: 2.80
1012 */
1013void
1014c_param_spec_pool_free (CParamSpecPool *pool)
1015{
1016 g_mutex_lock (&pool->mutex);
1017 g_hash_table_unref (pool->hash_table);
1018 g_mutex_unlock (&pool->mutex);
1019 g_mutex_clear (&pool->mutex);
1020 g_free (pool);
1021}
1022
1023/**
1024 * c_param_spec_pool_insert:
1025 * @pool: a #CParamSpecPool.
1026 * @pspec: (transfer none) (not nullable): the #CParamSpec to insert
1027 * @owner_type: a #GType identifying the owner of @pspec
1028 *
1029 * Inserts a #CParamSpec in the pool.
1030 */
1031void
1032c_param_spec_pool_insert (CParamSpecPool *pool,
1033 CParamSpec *pspec,
1034 GType owner_type)
1035{
1036 const gchar *p;
1037
1038 if (pool && pspec && owner_type > 0 && pspec->owner_type == 0)
1039 {
1040 for (p = pspec->name; *p; p++)
1041 {
1042 if (!strchr (G_CSET_A_2_Z"ABCDEFGHIJKLMNOPQRSTUVWXYZ" G_CSET_a_2_z"abcdefghijklmnopqrstuvwxyz" G_CSET_DIGITS"0123456789" "-_", *p))
1043 {
1044 g_critical (G_STRLOC"../libbean/cparam.c" ":" "1044" ": pspec name \"%s\" contains invalid characters", pspec->name);
1045 return;
1046 }
1047 }
1048 g_mutex_lock (&pool->mutex);
1049 pspec->owner_type = owner_type;
1050 c_param_spec_ref (pspec);
1051 g_hash_table_add (pool->hash_table, pspec);
1052 g_mutex_unlock (&pool->mutex);
1053 }
1054 else
1055 {
1056 g_return_if_fail (pool != NULL)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_118
= 0; if (pool != ((void*)0)) _g_boolean_var_118 = 1; _g_boolean_var_118
; }), 1))) { } else { g_return_if_fail_warning ("libbean", ((
const char*) (__func__)), "pool != NULL"); return; } } while (
0)
;
1057 g_return_if_fail (pspec)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_119
= 0; if (pspec) _g_boolean_var_119 = 1; _g_boolean_var_119; }
), 1))) { } else { g_return_if_fail_warning ("libbean", ((const
char*) (__func__)), "pspec"); return; } } while (0)
;
1058 g_return_if_fail (owner_type > 0)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_120
= 0; if (owner_type > 0) _g_boolean_var_120 = 1; _g_boolean_var_120
; }), 1))) { } else { g_return_if_fail_warning ("libbean", ((
const char*) (__func__)), "owner_type > 0"); return; } } while
(0)
;
1059 g_return_if_fail (pspec->owner_type == 0)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_121
= 0; if (pspec->owner_type == 0) _g_boolean_var_121 = 1; _g_boolean_var_121
; }), 1))) { } else { g_return_if_fail_warning ("libbean", ((
const char*) (__func__)), "pspec->owner_type == 0"); return
; } } while (0)
;
1060 }
1061}
1062
1063/**
1064 * c_param_spec_pool_remove:
1065 * @pool: a #CParamSpecPool
1066 * @pspec: (transfer none) (not nullable): the #CParamSpec to remove
1067 *
1068 * Removes a #CParamSpec from the pool.
1069 */
1070void
1071c_param_spec_pool_remove (CParamSpecPool *pool,
1072 CParamSpec *pspec)
1073{
1074 if (pool && pspec)
1075 {
1076 g_mutex_lock (&pool->mutex);
1077 if (!g_hash_table_remove (pool->hash_table, pspec))
1078 g_critical (G_STRLOC"../libbean/cparam.c" ":" "1078" ": attempt to remove unknown pspec '%s' from pool", pspec->name);
1079 g_mutex_unlock (&pool->mutex);
1080 }
1081 else
1082 {
1083 g_return_if_fail (pool != NULL)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_122
= 0; if (pool != ((void*)0)) _g_boolean_var_122 = 1; _g_boolean_var_122
; }), 1))) { } else { g_return_if_fail_warning ("libbean", ((
const char*) (__func__)), "pool != NULL"); return; } } while (
0)
;
1084 g_return_if_fail (pspec)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_123
= 0; if (pspec) _g_boolean_var_123 = 1; _g_boolean_var_123; }
), 1))) { } else { g_return_if_fail_warning ("libbean", ((const
char*) (__func__)), "pspec"); return; } } while (0)
;
1085 }
1086}
1087
1088static inline CParamSpec*
1089param_spec_ht_lookup (GHashTable *hash_table,
1090 const gchar *param_name,
1091 GType owner_type,
1092 gboolean walk_ancestors)
1093{
1094 CParamSpec key, *pspec;
1095
1096 key.owner_type = owner_type;
1097 key.name = (gchar*) param_name;
1098 if (walk_ancestors)
1099 do
1100 {
1101 pspec = g_hash_table_lookup (hash_table, &key);
1102 if (pspec)
1103 return pspec;
1104 key.owner_type = g_type_parent (key.owner_type);
1105 }
1106 while (key.owner_type);
1107 else
1108 pspec = g_hash_table_lookup (hash_table, &key);
1109
1110 if (!pspec && !is_canonical (param_name))
1111 {
1112 gchar *canonical;
1113
1114 canonical = g_strdup (key.name)g_strdup_inline (key.name);
1115 canonicalize_key (canonical);
1116
1117 /* try canonicalized form */
1118 key.name = canonical;
1119 key.owner_type = owner_type;
1120
1121 if (walk_ancestors)
1122 do
1123 {
1124 pspec = g_hash_table_lookup (hash_table, &key);
1125 if (pspec)
1126 {
1127 g_free (canonical);
1128 return pspec;
1129 }
1130 key.owner_type = g_type_parent (key.owner_type);
1131 }
1132 while (key.owner_type);
1133 else
1134 pspec = g_hash_table_lookup (hash_table, &key);
1135
1136 g_free (canonical);
1137 }
1138
1139 return pspec;
1140}
1141
1142/**
1143 * c_param_spec_pool_lookup:
1144 * @pool: a #CParamSpecPool
1145 * @param_name: the name to look for
1146 * @owner_type: the owner to look for
1147 * @walk_ancestors: If %TRUE, also try to find a #CParamSpec with @param_name
1148 * owned by an ancestor of @owner_type.
1149 *
1150 * Looks up a #CParamSpec in the pool.
1151 *
1152 * Returns: (transfer none) (nullable): The found #CParamSpec, or %NULL if no
1153 * matching #CParamSpec was found.
1154 */
1155CParamSpec*
1156c_param_spec_pool_lookup (CParamSpecPool *pool,
1157 const gchar *param_name,
1158 GType owner_type,
1159 gboolean walk_ancestors)
1160{
1161 CParamSpec *pspec;
1162
1163 g_return_val_if_fail (pool != NULL, NULL)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_124
= 0; if (pool != ((void*)0)) _g_boolean_var_124 = 1; _g_boolean_var_124
; }), 1))) { } else { g_return_if_fail_warning ("libbean", ((
const char*) (__func__)), "pool != NULL"); return (((void*)0)
); } } while (0)
;
1164 g_return_val_if_fail (param_name != NULL, NULL)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_125
= 0; if (param_name != ((void*)0)) _g_boolean_var_125 = 1; _g_boolean_var_125
; }), 1))) { } else { g_return_if_fail_warning ("libbean", ((
const char*) (__func__)), "param_name != NULL"); return (((void
*)0)); } } while (0)
;
1165
1166 g_mutex_lock (&pool->mutex);
1167
1168 /* try quick and away, i.e. without prefix */
1169 pspec = param_spec_ht_lookup (pool->hash_table, param_name, owner_type, walk_ancestors);
1170 if (pspec)
1171 {
1172 g_mutex_unlock (&pool->mutex);
1173 return pspec;
1174 }
1175
1176 if (pool->type_prefixing)
1177 {
1178 char *delim;
1179
1180 delim = strchr (param_name, ':');
1181
1182 /* strip type prefix */
1183 if (delim && delim[1] == ':')
1184 {
1185 guint l = delim - param_name;
1186 gchar stack_buffer[32], *buffer = l < 32 ? stack_buffer : g_new (gchar, l + 1)(gchar *) (__extension__ ({ gsize __n = (gsize) (l + 1); gsize
__s = sizeof (gchar); gpointer __p; if (__s == 1) __p = g_malloc
(__n); else if (__builtin_constant_p (__n) && (__s ==
0 || __n <= (9223372036854775807L *2UL+1UL) / __s)) __p =
g_malloc (__n * __s); else __p = g_malloc_n (__n, __s); __p;
}))
;
1187 GType type;
1188
1189 strncpy (buffer, param_name, delim - param_name);
1190 buffer[l] = 0;
1191 type = g_type_from_name (buffer);
1192 if (l >= 32)
1193 g_free (buffer);
1194 if (type) /* type==0 isn't a valid type pefix */
1195 {
1196 /* sanity check, these cases don't make a whole lot of sense */
1197 if ((!walk_ancestors && type != owner_type) || !g_type_is_a (owner_type, type)((owner_type) == (type) || (g_type_is_a) ((owner_type), (type
)))
)
1198 {
1199 g_mutex_unlock (&pool->mutex);
1200
1201 return NULL((void*)0);
1202 }
1203 owner_type = type;
1204 param_name += l + 2;
1205 pspec = param_spec_ht_lookup (pool->hash_table, param_name, owner_type, walk_ancestors);
1206 g_mutex_unlock (&pool->mutex);
1207
1208 return pspec;
1209 }
1210 }
1211 }
1212
1213 /* malformed param_name */
1214
1215 g_mutex_unlock (&pool->mutex);
1216
1217 return NULL((void*)0);
1218}
1219
1220static void
1221pool_list (gpointer key,
1222 gpointer value,
1223 gpointer user_data)
1224{
1225 CParamSpec *pspec = value;
1226 gpointer *data = user_data;
1227 GType owner_type = (GType) data[1];
1228
1229 if (owner_type == pspec->owner_type)
1230 data[0] = g_list_prepend (data[0], pspec);
This statement is never executed
1231}
1232
1233/**
1234 * c_param_spec_pool_list_owned:
1235 * @pool: a #CParamSpecPool
1236 * @owner_type: the owner to look for
1237 *
1238 * Gets an #GList of all #CParamSpecs owned by @owner_type in
1239 * the pool.
1240 *
1241 * Returns: (transfer container) (element-type GObject.ParamSpec): a
1242 * #GList of all #CParamSpecs owned by @owner_type in
1243 * the pool#CParamSpecs.
1244 */
1245GList*
1246c_param_spec_pool_list_owned (CParamSpecPool *pool,
1247 GType owner_type)
1248{
1249 gpointer data[2];
1250
1251 g_return_val_if_fail (pool != NULL, NULL)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_126
= 0; if (pool != ((void*)0)) _g_boolean_var_126 = 1; _g_boolean_var_126
; }), 1))) { } else { g_return_if_fail_warning ("libbean", ((
const char*) (__func__)), "pool != NULL"); return (((void*)0)
); } } while (0)
;
1252 g_return_val_if_fail (owner_type > 0, NULL)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_127
= 0; if (owner_type > 0) _g_boolean_var_127 = 1; _g_boolean_var_127
; }), 1))) { } else { g_return_if_fail_warning ("libbean", ((
const char*) (__func__)), "owner_type > 0"); return (((void
*)0)); } } while (0)
;
1253
1254 g_mutex_lock (&pool->mutex);
1255 data[0] = NULL((void*)0);
1256 data[1] = GTYPE_TO_POINTER (owner_type)((gpointer) (guintptr) (owner_type));
1257 g_hash_table_foreach (pool->hash_table, pool_list, &data);
1258 g_mutex_unlock (&pool->mutex);
1259
1260 return data[0];
1261}
1262
1263static gint
1264pspec_compare_id (gconstpointer a,
1265 gconstpointer b)
1266{
1267 const CParamSpec *pspec1 = a, *pspec2 = b;
1268
1269 if (pspec1->param_id < pspec2->param_id)
1270 return -1;
1271
1272 if (pspec1->param_id > pspec2->param_id)
1273 return 1;
1274
1275 return strcmp (pspec1->name, pspec2->name);
1276}
1277
1278static inline gboolean
1279should_list_pspec (CParamSpec *pspec,
1280 GType owner_type,
1281 GHashTable *ht)
1282{
1283 CParamSpec *found;
1284
1285 /* Remove paramspecs that are redirected, and also paramspecs
1286 * that have are overridden by non-redirected properties.
1287 * The idea is to get the single paramspec for each name that
1288 * best corresponds to what the application sees.
1289 */
1290 if (c_param_spec_get_redirect_target (pspec))
1291 return FALSE(0);
1292
1293 found = param_spec_ht_lookup (ht, pspec->name, owner_type, TRUE(!(0)));
1294 if (found != pspec)
1295 {
1296 CParamSpec *redirect = c_param_spec_get_redirect_target (found);
1297 if (redirect != pspec)
1298 return FALSE(0);
1299 }
1300
1301 return TRUE(!(0));
1302}
1303
1304static void
1305pool_depth_list (gpointer key,
1306 gpointer value,
1307 gpointer user_data)
1308{
1309 CParamSpec *pspec = value;
1310 gpointer *data = user_data;
1311 GSList **slists = data[0];
1312 GType owner_type = (GType) data[1];
1313 GHashTable *ht = data[2];
1314 int *count = data[3];
1315
1316 if (g_type_is_a (owner_type, pspec->owner_type)((owner_type) == (pspec->owner_type) || (g_type_is_a) ((owner_type
), (pspec->owner_type)))
&&
1317 should_list_pspec (pspec, owner_type, ht))
1318 {
1319 if (G_TYPE_IS_INTERFACE (pspec->owner_type)((g_type_fundamental (pspec->owner_type)) == ((GType) ((2)
<< (2))))
)
1320 {
1321 slists[0] = g_slist_prepend (slists[0], pspec);
1322 *count = *count + 1;
1323 }
1324 else
1325 {
1326 guint d = g_type_depth (pspec->owner_type);
1327
1328 slists[d - 1] = g_slist_prepend (slists[d - 1], pspec);
1329 *count = *count + 1;
1330 }
1331 }
1332}
1333
1334/* We handle interfaces specially since we don't want to
1335 * count interface prerequisites like normal inheritance;
1336 * the property comes from the direct inheritance from
1337 * the prerequisite class, not from the interface that
1338 * prerequires it.
1339 *
1340 * Also 'depth' isn't a meaningful concept for interface
1341 * prerequisites.
1342 */
1343static void
1344pool_depth_list_for_interface (gpointer key,
1345 gpointer value,
1346 gpointer user_data)
1347{
1348 CParamSpec *pspec = value;
1349 gpointer *data = user_data;
1350 GSList **slists = data[0];
1351 GType owner_type = (GType) data[1];
1352 GHashTable *ht = data[2];
1353 int *count = data[3];
1354
1355 if (pspec->owner_type == owner_type &&
1356 should_list_pspec (pspec, owner_type, ht))
1357 {
1358 slists[0] = g_slist_prepend (slists[0], pspec);
1359 *count = *count + 1;
1360 }
1361}
1362
1363/**
1364 * c_param_spec_pool_list:
1365 * @pool: a #CParamSpecPool
1366 * @owner_type: the owner to look for
1367 * @n_pspecs_p: (out): return location for the length of the returned array
1368 *
1369 * Gets an array of all #CParamSpecs owned by @owner_type in
1370 * the pool.
1371 *
1372 * Returns: (array length=n_pspecs_p) (transfer container): a newly
1373 * allocated array containing pointers to all #CParamSpecs
1374 * owned by @owner_type in the pool
1375 */
1376CParamSpec**
1377c_param_spec_pool_list (CParamSpecPool *pool,
1378 GType owner_type,
1379 guint *n_pspecs_p)
1380{
1381 CParamSpec **pspecs, **p;
1382 GSList **slists, *node;
1383 gpointer data[4];
1384 guint d, i;
1385 int n_pspecs = 0;
1386
1387 g_return_val_if_fail (pool != NULL, NULL)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_128
= 0; if (pool != ((void*)0)) _g_boolean_var_128 = 1; _g_boolean_var_128
; }), 1))) { } else { g_return_if_fail_warning ("libbean", ((
const char*) (__func__)), "pool != NULL"); return (((void*)0)
); } } while (0)
;
1388 g_return_val_if_fail (owner_type > 0, NULL)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_129
= 0; if (owner_type > 0) _g_boolean_var_129 = 1; _g_boolean_var_129
; }), 1))) { } else { g_return_if_fail_warning ("libbean", ((
const char*) (__func__)), "owner_type > 0"); return (((void
*)0)); } } while (0)
;
1389 g_return_val_if_fail (n_pspecs_p != NULL, NULL)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_130
= 0; if (n_pspecs_p != ((void*)0)) _g_boolean_var_130 = 1; _g_boolean_var_130
; }), 1))) { } else { g_return_if_fail_warning ("libbean", ((
const char*) (__func__)), "n_pspecs_p != NULL"); return (((void
*)0)); } } while (0)
;
1390
1391 g_mutex_lock (&pool->mutex);
1392 d = g_type_depth (owner_type);
1393 slists = g_new0 (GSList*, d)(GSList* *) (__extension__ ({ gsize __n = (gsize) (d); gsize __s
= sizeof (GSList*); gpointer __p; if (__s == 1) __p = g_malloc0
(__n); else if (__builtin_constant_p (__n) && (__s ==
0 || __n <= (9223372036854775807L *2UL+1UL) / __s)) __p =
g_malloc0 (__n * __s); else __p = g_malloc0_n (__n, __s); __p
; }))
;
1394 data[0] = slists;
1395 data[1] = GTYPE_TO_POINTER (owner_type)((gpointer) (guintptr) (owner_type));
1396 data[2] = pool->hash_table;
1397 data[3] = &n_pspecs;
1398
1399 g_hash_table_foreach (pool->hash_table,
1400 G_TYPE_IS_INTERFACE (owner_type)((g_type_fundamental (owner_type)) == ((GType) ((2) << (
2))))
?
1401 pool_depth_list_for_interface :
1402 pool_depth_list,
1403 &data);
1404
1405 pspecs = g_new (CParamSpec*, n_pspecs + 1)(CParamSpec* *) (__extension__ ({ gsize __n = (gsize) (n_pspecs
+ 1); gsize __s = sizeof (CParamSpec*); gpointer __p; if (__s
== 1) __p = g_malloc (__n); else if (__builtin_constant_p (__n
) && (__s == 0 || __n <= (9223372036854775807L *2UL
+1UL) / __s)) __p = g_malloc (__n * __s); else __p = g_malloc_n
(__n, __s); __p; }))
;
1406 p = pspecs;
1407 for (i = 0; i < d; i++)
1408 {
1409 slists[i] = g_slist_sort (slists[i], pspec_compare_id);
1410 for (node = slists[i]; node; node = node->next)
1411 *p++ = node->data;
1412 g_slist_free (slists[i]);
1413 }
1414 *p++ = NULL((void*)0);
1415 g_free (slists);
1416 g_mutex_unlock (&pool->mutex);
1417
1418 *n_pspecs_p = n_pspecs;
1419
1420 return pspecs;
1421}
1422
1423/* --- auxiliary functions --- */
1424typedef struct
1425{
1426 /* class portion */
1427 GType value_type;
1428 void (*finalize) (CParamSpec *pspec);
1429 void (*value_set_default) (CParamSpec *pspec,
1430 GValue *value);
1431 gboolean (*value_validate) (CParamSpec *pspec,
1432 GValue *value);
1433 gint (*values_cmp) (CParamSpec *pspec,
1434 const GValue *value1,
1435 const GValue *value2);
1436} ParamSpecClassInfo;
1437
1438static void
1439param_spec_generic_class_init (gpointer g_class,
1440 gpointer class_data)
1441{
1442 CParamSpecClass *class = g_class;
1443 ParamSpecClassInfo *info = class_data;
1444
1445 class->value_type = info->value_type;
1446 if (info->finalize)
1447 class->finalize = info->finalize; /* optional */
1448 class->value_set_default = info->value_set_default;
1449 if (info->value_validate)
1450 class->value_validate = info->value_validate; /* optional */
1451 class->values_cmp = info->values_cmp;
1452 g_free (class_data);
1453}
1454
1455static void
1456default_value_set_default (CParamSpec *pspec,
1457 GValue *value)
1458{
1459 /* value is already zero initialized */
1460}
1461
1462static gint
1463default_values_cmp (CParamSpec *pspec,
1464 const GValue *value1,
1465 const GValue *value2)
1466{
1467 return memcmp (&value1->data, &value2->data, sizeof (value1->data));
1468}
1469
1470/**
1471 * c_param_type_register_static:
1472 * @name: 0-terminated string used as the name of the new #CParamSpec type.
1473 * @pspec_info: The #CParamSpecTypeInfo for this #CParamSpec type.
1474 *
1475 * Registers @name as the name of a new static type derived
1476 * from %C_TYPE_PARAM.
1477 *
1478 * The type system uses the information contained in the #CParamSpecTypeInfo
1479 * structure pointed to by @info to manage the #CParamSpec type and its
1480 * instances.
1481 *
1482 * Returns: The new type identifier.
1483 */
1484GType
1485c_param_type_register_static (const gchar *name,
1486 const CParamSpecTypeInfo *pspec_info)
1487{
1488 GTypeInfo info = {
1489 sizeof (CParamSpecClass), /* class_size */
1490 NULL((void*)0), /* base_init */
1491 NULL((void*)0), /* base_destroy */
1492 param_spec_generic_class_init, /* class_init */
1493 NULL((void*)0), /* class_destroy */
1494 NULL((void*)0), /* class_data */
1495 0, /* instance_size */
1496 16, /* n_preallocs */
1497 NULL((void*)0), /* instance_init */
1498 NULL((void*)0), /* value_table */
1499 };
1500 ParamSpecClassInfo *cinfo;
1501
1502 g_return_val_if_fail (name != NULL, 0)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_131
= 0; if (name != ((void*)0)) _g_boolean_var_131 = 1; _g_boolean_var_131
; }), 1))) { } else { g_return_if_fail_warning ("libbean", ((
const char*) (__func__)), "name != NULL"); return (0); } } while
(0)
;
1503 g_return_val_if_fail (pspec_info != NULL, 0)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_132
= 0; if (pspec_info != ((void*)0)) _g_boolean_var_132 = 1; _g_boolean_var_132
; }), 1))) { } else { g_return_if_fail_warning ("libbean", ((
const char*) (__func__)), "pspec_info != NULL"); return (0); }
} while (0)
;
1504 g_return_val_if_fail (g_type_from_name (name) == 0, 0)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_133
= 0; if (g_type_from_name (name) == 0) _g_boolean_var_133 = 1
; _g_boolean_var_133; }), 1))) { } else { g_return_if_fail_warning
("libbean", ((const char*) (__func__)), "g_type_from_name (name) == 0"
); return (0); } } while (0)
;
1505 g_return_val_if_fail (pspec_info->instance_size >= sizeof (CParamSpec), 0)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_134
= 0; if (pspec_info->instance_size >= sizeof (CParamSpec
)) _g_boolean_var_134 = 1; _g_boolean_var_134; }), 1))) { } else
{ g_return_if_fail_warning ("libbean", ((const char*) (__func__
)), "pspec_info->instance_size >= sizeof (CParamSpec)")
; return (0); } } while (0)
;
1506 g_return_val_if_fail (g_type_name (pspec_info->value_type) != NULL, 0)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_135
= 0; if (g_type_name (pspec_info->value_type) != ((void*)
0)) _g_boolean_var_135 = 1; _g_boolean_var_135; }), 1))) { } else
{ g_return_if_fail_warning ("libbean", ((const char*) (__func__
)), "g_type_name (pspec_info->value_type) != NULL"); return
(0); } } while (0)
;
1507 /* default: g_return_val_if_fail (pspec_info->value_set_default != NULL, 0); */
1508 /* optional: g_return_val_if_fail (pspec_info->value_validate != NULL, 0); */
1509 /* default: g_return_val_if_fail (pspec_info->values_cmp != NULL, 0); */
1510
1511 info.instance_size = pspec_info->instance_size;
1512 info.n_preallocs = pspec_info->n_preallocs;
1513 info.instance_init = (GInstanceInitFunc) pspec_info->instance_init;
1514 cinfo = g_new (ParamSpecClassInfo, 1)(ParamSpecClassInfo *) (__extension__ ({ gsize __n = (gsize) (
1); gsize __s = sizeof (ParamSpecClassInfo); gpointer __p; if
(__s == 1) __p = g_malloc (__n); else if (__builtin_constant_p
(__n) && (__s == 0 || __n <= (9223372036854775807L
*2UL+1UL) / __s)) __p = g_malloc (__n * __s); else __p = g_malloc_n
(__n, __s); __p; }))
;
1515 cinfo->value_type = pspec_info->value_type;
1516 cinfo->finalize = pspec_info->finalize;
1517 cinfo->value_set_default = pspec_info->value_set_default ? pspec_info->value_set_default : default_value_set_default;
1518 cinfo->value_validate = pspec_info->value_validate;
1519 cinfo->values_cmp = pspec_info->values_cmp ? pspec_info->values_cmp : default_values_cmp;
1520 info.class_data = cinfo;
1521
1522 return g_type_register_static (C_TYPE_PARAM((GType) ((19) << (2))), name, &info, 0);
1523}
1524
1525/**
1526 * c_value_set_param:
1527 * @value: a valid #GValue of type %C_TYPE_PARAM
1528 * @param: (nullable): the #CParamSpec to be set
1529 *
1530 * Set the contents of a %C_TYPE_PARAM #GValue to @param.
1531 */
1532void
1533c_value_set_param (GValue *value,
1534 CParamSpec *param)
1535{
1536 g_return_if_fail (C_VALUE_HOLDS_PARAM (value))do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_136
= 0; if ((((__extension__ ({ const GValue *__val = (const GValue
*) ((value)); GType __t = (((GType) ((19) << (2)))); gboolean
__r; if (!__val) __r = (0); else if (__val->g_type == __t
) __r = (!(0)); else __r = g_type_check_value_holds (__val, __t
); __r; }))))) _g_boolean_var_136 = 1; _g_boolean_var_136; })
, 1))) { } else { g_return_if_fail_warning ("libbean", ((const
char*) (__func__)), "C_VALUE_HOLDS_PARAM (value)"); return; }
} while (0)
;
1537 if (param)
1538 g_return_if_fail (C_IS_PARAM_SPEC (param))do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_137
= 0; if ((((g_type_check_instance_is_fundamentally_a ((GTypeInstance
*) ((param)), (((GType) ((19) << (2))))))))) _g_boolean_var_137
= 1; _g_boolean_var_137; }), 1))) { } else { g_return_if_fail_warning
("libbean", ((const char*) (__func__)), "C_IS_PARAM_SPEC (param)"
); return; } } while (0)
;
1539
1540 if (value->data[0].v_pointer)
1541 c_param_spec_unref (value->data[0].v_pointer);
1542 value->data[0].v_pointer = param;
1543 if (value->data[0].v_pointer)
1544 c_param_spec_ref (value->data[0].v_pointer);
1545}
1546
1547/**
1548 * c_value_set_param_take_ownership: (skip)
1549 * @value: a valid #GValue of type %C_TYPE_PARAM
1550 * @param: (nullable): the #CParamSpec to be set
1551 *
1552 * This is an internal function introduced mainly for C marshallers.
1553 *
1554 * Deprecated: 2.4: Use c_value_take_param() instead.
1555 */
1556void
1557c_value_set_param_take_ownership (GValue *value,
1558 CParamSpec *param)
1559{
1560 c_value_take_param (value, param);
1561}
1562
1563/**
1564 * c_value_take_param: (skip)
1565 * @value: a valid #GValue of type %C_TYPE_PARAM
1566 * @param: (nullable): the #CParamSpec to be set
1567 *
1568 * Sets the contents of a %C_TYPE_PARAM #GValue to @param and takes
1569 * over the ownership of the caller’s reference to @param; the caller
1570 * doesn’t have to unref it any more.
1571 *
1572 * Since: 2.4
1573 */
1574void
1575c_value_take_param (GValue *value,
1576 CParamSpec *param)
1577{
1578 g_return_if_fail (C_VALUE_HOLDS_PARAM (value))do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_138
= 0; if ((((__extension__ ({ const GValue *__val = (const GValue
*) ((value)); GType __t = (((GType) ((19) << (2)))); gboolean
__r; if (!__val) __r = (0); else if (__val->g_type == __t
) __r = (!(0)); else __r = g_type_check_value_holds (__val, __t
); __r; }))))) _g_boolean_var_138 = 1; _g_boolean_var_138; })
, 1))) { } else { g_return_if_fail_warning ("libbean", ((const
char*) (__func__)), "C_VALUE_HOLDS_PARAM (value)"); return; }
} while (0)
;
1579 if (param)
1580 g_return_if_fail (C_IS_PARAM_SPEC (param))do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_139
= 0; if ((((g_type_check_instance_is_fundamentally_a ((GTypeInstance
*) ((param)), (((GType) ((19) << (2))))))))) _g_boolean_var_139
= 1; _g_boolean_var_139; }), 1))) { } else { g_return_if_fail_warning
("libbean", ((const char*) (__func__)), "C_IS_PARAM_SPEC (param)"
); return; } } while (0)
;
1581
1582 if (value->data[0].v_pointer)
1583 c_param_spec_unref (value->data[0].v_pointer);
1584 value->data[0].v_pointer = param; /* we take over the reference count */
1585}
1586
1587/**
1588 * c_value_get_param:
1589 * @value: a valid #GValue whose type is derived from %C_TYPE_PARAM
1590 *
1591 * Get the contents of a %C_TYPE_PARAM #GValue.
1592 *
1593 * Returns: (transfer none): #CParamSpec content of @value
1594 */
1595CParamSpec*
1596c_value_get_param (const GValue *value)
1597{
1598 g_return_val_if_fail (C_VALUE_HOLDS_PARAM (value), NULL)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_140
= 0; if ((((__extension__ ({ const GValue *__val = (const GValue
*) ((value)); GType __t = (((GType) ((19) << (2)))); gboolean
__r; if (!__val) __r = (0); else if (__val->g_type == __t
) __r = (!(0)); else __r = g_type_check_value_holds (__val, __t
); __r; }))))) _g_boolean_var_140 = 1; _g_boolean_var_140; })
, 1))) { } else { g_return_if_fail_warning ("libbean", ((const
char*) (__func__)), "C_VALUE_HOLDS_PARAM (value)"); return (
((void*)0)); } } while (0)
;
1599
1600 return value->data[0].v_pointer;
1601}
1602
1603/**
1604 * c_value_dup_param: (skip)
1605 * @value: a valid #GValue whose type is derived from %C_TYPE_PARAM
1606 *
1607 * Get the contents of a %C_TYPE_PARAM #GValue, increasing its
1608 * reference count.
1609 *
1610 * Returns: (transfer full): #CParamSpec content of @value, should be
1611 * unreferenced when no longer needed.
1612 */
1613CParamSpec*
1614c_value_dup_param (const GValue *value)
1615{
1616 g_return_val_if_fail (C_VALUE_HOLDS_PARAM (value), NULL)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_141
= 0; if ((((__extension__ ({ const GValue *__val = (const GValue
*) ((value)); GType __t = (((GType) ((19) << (2)))); gboolean
__r; if (!__val) __r = (0); else if (__val->g_type == __t
) __r = (!(0)); else __r = g_type_check_value_holds (__val, __t
); __r; }))))) _g_boolean_var_141 = 1; _g_boolean_var_141; })
, 1))) { } else { g_return_if_fail_warning ("libbean", ((const
char*) (__func__)), "C_VALUE_HOLDS_PARAM (value)"); return (
((void*)0)); } } while (0)
;
1617
1618 return value->data[0].v_pointer ? c_param_spec_ref (value->data[0].v_pointer) : NULL((void*)0);
1619}
1620
1621/**
1622 * c_param_spec_get_default_value:
1623 * @pspec: a #CParamSpec
1624 *
1625 * Gets the default value of @pspec as a pointer to a #GValue.
1626 *
1627 * The #GValue will remain valid for the life of @pspec.
1628 *
1629 * Returns: a pointer to a #GValue which must not be modified
1630 *
1631 * Since: 2.38
1632 **/
1633const GValue *
1634c_param_spec_get_default_value (CParamSpec *pspec)
1635{
1636 CParamSpecPrivate *priv = c_param_spec_get_private (pspec);
1637
1638 /* We use the type field of the GValue as the key for the once because
1639 * it will be zero before it is initialised and non-zero after. We
1640 * have to take care that we don't write a non-zero value to the type
1641 * field before we are completely done, however, because then another
1642 * thread could come along and find the value partially-initialised.
1643 *
1644 * In order to accomplish this we store the default value in a
1645 * stack-allocated GValue. We then set the type field in that value
1646 * to zero and copy the contents into place. We then end by storing
1647 * the type as the last step in order to ensure that we're completely
1648 * done before a g_once_init_enter() could take the fast path in
1649 * another thread.
1650 */
1651 if (g_once_init_enter_pointer (&priv->default_value.g_type)(__extension__ ({ _Static_assert (sizeof *(&priv->default_value
.g_type) == sizeof (gpointer), "Expression evaluates to false"
); (void) (0 ? (gpointer) * (&priv->default_value.g_type
) : ((void*)0)); (!(__extension__ ({ _Static_assert (sizeof *
(&priv->default_value.g_type) == sizeof (gpointer), "Expression evaluates to false"
); __typeof__ (*(&priv->default_value.g_type)) gapg_temp_newval
; __typeof__ ((&priv->default_value.g_type)) gapg_temp_atomic
= (&priv->default_value.g_type); __atomic_load (gapg_temp_atomic
, &gapg_temp_newval, 5); gapg_temp_newval; })) &&
g_once_init_enter_pointer (&priv->default_value.g_type
)); }))
)
1652 {
1653 GValue default_value = G_VALUE_INIT{ 0, { { 0 } } };
1654
1655 g_value_init (&default_value, pspec->value_type);
1656 c_param_value_set_default (pspec, &default_value);
1657
1658 /* store all but the type */
1659 memcpy (priv->default_value.data, default_value.data, sizeof (default_value.data));
1660
1661 g_once_init_leave_pointer (&priv->default_value.g_type, pspec->value_type)(__extension__ ({ _Static_assert (sizeof *(&priv->default_value
.g_type) == sizeof (gpointer), "Expression evaluates to false"
); 0 ? (void) (*(&priv->default_value.g_type) = (pspec
->value_type)) : (void) 0; g_once_init_leave_pointer ((&
priv->default_value.g_type), (gpointer) (guintptr) (pspec->
value_type)); }))
;
1662 }
1663
1664 return &priv->default_value;
1665}
1666
1667/**
1668 * c_param_spec_get_name_quark:
1669 * @pspec: a #CParamSpec
1670 *
1671 * Gets the GQuark for the name.
1672 *
1673 * Returns: the GQuark for @pspec->name.
1674 *
1675 * Since: 2.46
1676 */
1677GQuark
1678c_param_spec_get_name_quark (CParamSpec *pspec)
1679{
1680 CParamSpecPrivate *priv = c_param_spec_get_private (pspec);
1681
1682 /* Return the quark that we've stashed away at creation time.
1683 * This lets us avoid a lock and a hash table lookup when
1684 * dispatching property change notification.
1685 */
1686
1687 return priv->name_quark;
1688}