| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
#include "config.h" |
| 23 |
|
| 24 |
#include <stdatomic.h> |
| 25 |
|
| 26 |
#include <gobject/gvaluecollector.h> |
| 27 |
|
| 28 |
#include "dex-object-private.h" |
| 29 |
#include "dex-profiler.h" |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
static GType dex_object_type = G_TYPE_INVALID; |
| 46 |
static GType dex_param_spec_object_type = G_TYPE_INVALID; |
| 47 |
|
| 48 |
#undef DEX_TYPE_OBJECT |
| 49 |
#define DEX_TYPE_OBJECT dex_object_type |
| 50 |
|
| 51 |
#define DEX_TYPE_PARAM_OBJECT (dex_param_spec_object_type) |
| 52 |
|
| 53 |
static void |
| 54 |
dex_object_finalize (DexObject *object) |
| 55 |
{ |
| 56 |
g_assert (object != NULL); |
| 57 |
g_assert (atomic_load_explicit (&object->ref_count, memory_order_relaxed) == 0); |
| 58 |
|
| 59 |
#ifdef HAVE_SYSPROF |
| 60 |
DEX_PROFILER_MARK (0, DEX_OBJECT_TYPE_NAME (object), "dex_object_finalize()"); |
| 61 |
DEX_PROFILER_MARK (SYSPROF_CAPTURE_CURRENT_TIME - object->ctime, DEX_OBJECT_TYPE_NAME (object), "lifetime"); |
| 62 |
#endif |
| 63 |
|
| 64 |
g_type_free_instance ((GTypeInstance *)object); |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
gpointer |
| 76 |
dex_ref (gpointer object) |
| 77 |
{ |
| 78 |
DexObject *self = object; |
| 79 |
atomic_fetch_add_explicit (&self->ref_count, 1, memory_order_relaxed); |
| 80 |
return object; |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
void |
| 92 |
dex_unref (gpointer object) |
| 93 |
{ |
| 94 |
DexObject *obj = object; |
| 95 |
DexObjectClass *object_class; |
| 96 |
DexWeakRef *weak_refs; |
| 97 |
guint watermark; |
| 98 |
|
| 99 |
g_return_if_fail (object != NULL); |
| 100 |
g_return_if_fail (DEX_IS_OBJECT (object)); |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
watermark = atomic_load_explicit (&obj->weak_refs_watermark, memory_order_acquire); |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
if G_LIKELY (atomic_fetch_sub_explicit (&obj->ref_count, 1, memory_order_release) != 1) |
| 113 |
return; |
| 114 |
|
| 115 |
atomic_thread_fence (memory_order_acquire); |
| 116 |
|
| 117 |
object_class = DEX_OBJECT_GET_CLASS (object); |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
dex_object_lock (object); |
| 129 |
for (DexWeakRef *wr = obj->weak_refs; wr; wr = wr->next) |
| 130 |
g_mutex_lock (&wr->mutex); |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
if (atomic_load_explicit (&obj->ref_count, memory_order_acquire) > 0 || |
| 138 |
atomic_load_explicit (&obj->weak_refs_watermark, memory_order_acquire) != watermark) |
| 139 |
{ |
| 140 |
for (DexWeakRef *wr = obj->weak_refs; wr; wr = wr->next) |
| 141 |
g_mutex_unlock (&wr->mutex); |
| 142 |
dex_object_unlock (object); |
| 143 |
return; |
| 144 |
} |
| 145 |
|
| 146 |
weak_refs = g_steal_pointer (&obj->weak_refs); |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
while (weak_refs != NULL) |
| 153 |
{ |
| 154 |
DexWeakRef *wr = weak_refs; |
| 155 |
|
| 156 |
weak_refs = weak_refs->next; |
| 157 |
|
| 158 |
wr->prev = NULL; |
| 159 |
wr->next = NULL; |
| 160 |
wr->mem_block = NULL; |
| 161 |
|
| 162 |
g_mutex_unlock (&wr->mutex); |
| 163 |
} |
| 164 |
|
| 165 |
dex_object_unlock (object); |
| 166 |
|
| 167 |
|
| 168 |
if (atomic_load_explicit (&obj->ref_count, memory_order_acquire) == 0) |
| 169 |
object_class->finalize (object); |
| 170 |
} |
| 171 |
|
| 172 |
static void |
| 173 |
dex_object_class_init (DexObjectClass *klass) |
| 174 |
{ |
| 175 |
klass->finalize = dex_object_finalize; |
| 176 |
} |
| 177 |
|
| 178 |
static void |
| 179 |
dex_object_init (DexObject *self, |
| 180 |
DexObjectClass *object_class) |
| 181 |
{ |
| 182 |
#ifdef HAVE_SYSPROF |
| 183 |
self->ctime = SYSPROF_CAPTURE_CURRENT_TIME; |
| 184 |
DEX_PROFILER_MARK (0, |
| 185 |
g_type_name (G_TYPE_FROM_CLASS (object_class)), |
| 186 |
"dex_object_init()"); |
| 187 |
#endif |
| 188 |
|
| 189 |
atomic_init (&self->ref_count, 1); |
| 190 |
g_mutex_init (&self->mutex); |
| 191 |
atomic_init (&self->weak_refs_watermark, 1); |
| 192 |
} |
| 193 |
|
| 194 |
static void |
| 195 |
dex_object_add_weak (gpointer mem_block, |
| 196 |
DexWeakRef *weak_ref) |
| 197 |
{ |
| 198 |
DexObject *object = mem_block; |
| 199 |
|
| 200 |
g_assert (object != NULL); |
| 201 |
g_assert (weak_ref != NULL); |
| 202 |
g_assert (weak_ref->prev == NULL); |
| 203 |
g_assert (weak_ref->next == NULL); |
| 204 |
g_assert (weak_ref->mem_block == mem_block); |
| 205 |
|
| 206 |
|
| 207 |
g_return_if_fail (atomic_load_explicit (&object->ref_count, memory_order_relaxed) > 0); |
| 208 |
|
| 209 |
dex_object_lock (object); |
| 210 |
weak_ref->prev = NULL; |
| 211 |
weak_ref->next = object->weak_refs; |
| 212 |
if (object->weak_refs != NULL) |
| 213 |
object->weak_refs->prev = weak_ref; |
| 214 |
object->weak_refs = weak_ref; |
| 215 |
dex_object_unlock (object); |
| 216 |
} |
| 217 |
|
| 218 |
static void |
| 219 |
dex_object_unlink_weak (gpointer mem_block, |
| 220 |
DexWeakRef *weak_ref) |
| 221 |
{ |
| 222 |
DexObject *object = mem_block; |
| 223 |
|
| 224 |
g_assert (object != NULL); |
| 225 |
g_assert (weak_ref != NULL); |
| 226 |
|
| 227 |
|
| 228 |
g_return_if_fail (atomic_load_explicit (&object->ref_count, memory_order_relaxed) > 0); |
| 229 |
|
| 230 |
dex_object_lock (object); |
| 231 |
|
| 232 |
if (weak_ref->prev != NULL) |
| 233 |
weak_ref->prev->next = weak_ref->next; |
| 234 |
|
| 235 |
if (weak_ref->next != NULL) |
| 236 |
weak_ref->next->prev = weak_ref->prev; |
| 237 |
|
| 238 |
if (object->weak_refs == weak_ref) |
| 239 |
object->weak_refs = weak_ref->next; |
| 240 |
|
| 241 |
g_assert (object->weak_refs == NULL || |
| 242 |
object->weak_refs->prev == NULL); |
| 243 |
|
| 244 |
weak_ref->next = NULL; |
| 245 |
weak_ref->prev = NULL; |
| 246 |
|
| 247 |
dex_object_unlock (object); |
| 248 |
} |
| 249 |
|
| 250 |
static void |
| 251 |
dex_object_remove_weak (gpointer mem_block, |
| 252 |
DexWeakRef *weak_ref) |
| 253 |
{ |
| 254 |
dex_object_unlink_weak (mem_block, weak_ref); |
| 255 |
weak_ref->mem_block = NULL; |
| 256 |
} |
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
void |
| 273 |
dex_weak_ref_init (DexWeakRef *weak_ref, |
| 274 |
gpointer mem_block) |
| 275 |
{ |
| 276 |
g_return_if_fail (weak_ref != NULL); |
| 277 |
g_return_if_fail (!mem_block || DEX_IS_OBJECT (mem_block)); |
| 278 |
g_return_if_fail (!mem_block || |
| 279 |
atomic_load_explicit (&DEX_OBJECT (mem_block)->ref_count, |
| 280 |
memory_order_relaxed) > 0); |
| 281 |
|
| 282 |
memset (weak_ref, 0, sizeof *weak_ref); |
| 283 |
g_mutex_init (&weak_ref->mutex); |
| 284 |
|
| 285 |
if (mem_block) |
| 286 |
dex_weak_ref_set (weak_ref, mem_block); |
| 287 |
} |
| 288 |
|
| 289 |
static inline gpointer |
| 290 |
dex_weak_ref_get_locked (DexWeakRef *weak_ref) |
| 291 |
{ |
| 292 |
if (weak_ref->mem_block != NULL) |
| 293 |
{ |
| 294 |
guint watermark; |
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
DexObject *object = weak_ref->mem_block; |
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
watermark = atomic_fetch_add_explicit (&object->weak_refs_watermark, |
| 311 |
1, |
| 312 |
memory_order_acq_rel); |
| 313 |
atomic_fetch_add_explicit (&object->ref_count, |
| 314 |
1 + (watermark == G_MAXUINT32), |
| 315 |
memory_order_relaxed); |
| 316 |
|
| 317 |
#ifdef HAVE_SYSPROF |
| 318 |
{ |
| 319 |
char *message = g_strdup_printf ("%s@%p converted to full", |
| 320 |
DEX_OBJECT_TYPE_NAME (weak_ref->mem_block), |
| 321 |
weak_ref->mem_block); |
| 322 |
DEX_PROFILER_MARK (0, "DexWeakRef", message); |
| 323 |
g_free (message); |
| 324 |
} |
| 325 |
#endif |
| 326 |
|
| 327 |
return weak_ref->mem_block; |
| 328 |
} |
| 329 |
|
| 330 |
return NULL; |
| 331 |
} |
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
gpointer |
| 350 |
dex_weak_ref_get (DexWeakRef *weak_ref) |
| 351 |
{ |
| 352 |
gpointer ret; |
| 353 |
|
| 354 |
g_return_val_if_fail (weak_ref != NULL, NULL); |
| 355 |
|
| 356 |
g_mutex_lock (&weak_ref->mutex); |
| 357 |
ret = dex_weak_ref_get_locked (weak_ref); |
| 358 |
g_mutex_unlock (&weak_ref->mutex); |
| 359 |
|
| 360 |
return ret; |
| 361 |
} |
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
void |
| 376 |
dex_weak_ref_clear (DexWeakRef *weak_ref) |
| 377 |
{ |
| 378 |
gpointer mem_block; |
| 379 |
|
| 380 |
g_return_if_fail (weak_ref != NULL); |
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
mem_block = dex_weak_ref_get (weak_ref); |
| 389 |
|
| 390 |
if (mem_block != NULL) |
| 391 |
{ |
| 392 |
dex_object_remove_weak (mem_block, weak_ref); |
| 393 |
dex_clear (&mem_block); |
| 394 |
} |
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
g_assert (weak_ref->prev == NULL); |
| 400 |
g_assert (weak_ref->next == NULL); |
| 401 |
g_assert (weak_ref->mem_block == NULL); |
| 402 |
|
| 403 |
g_mutex_clear (&weak_ref->mutex); |
| 404 |
} |
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
void |
| 422 |
dex_weak_ref_set (DexWeakRef *weak_ref, |
| 423 |
gpointer mem_block) |
| 424 |
{ |
| 425 |
gpointer old_mem_block; |
| 426 |
|
| 427 |
g_return_if_fail (weak_ref != NULL); |
| 428 |
g_return_if_fail (!mem_block || DEX_IS_OBJECT (mem_block)); |
| 429 |
g_return_if_fail (!mem_block || |
| 430 |
atomic_load_explicit (&DEX_OBJECT (mem_block)->ref_count, |
| 431 |
memory_order_relaxed) > 0); |
| 432 |
|
| 433 |
g_mutex_lock (&weak_ref->mutex); |
| 434 |
|
| 435 |
old_mem_block = dex_weak_ref_get_locked (weak_ref); |
| 436 |
|
| 437 |
if (old_mem_block != mem_block) |
| 438 |
weak_ref->mem_block = mem_block; |
| 439 |
|
| 440 |
g_mutex_unlock (&weak_ref->mutex); |
| 441 |
|
| 442 |
if (old_mem_block != mem_block) |
| 443 |
{ |
| 444 |
if (old_mem_block != NULL) |
| 445 |
dex_object_unlink_weak (old_mem_block, weak_ref); |
| 446 |
|
| 447 |
if (mem_block != NULL) |
| 448 |
dex_object_add_weak (mem_block, weak_ref); |
| 449 |
} |
| 450 |
|
| 451 |
dex_clear (&old_mem_block); |
| 452 |
} |
| 453 |
|
| 454 |
static void |
| 455 |
value_init (GValue *value) |
| 456 |
{ |
| 457 |
value->data[0].v_pointer = NULL; |
| 458 |
} |
| 459 |
|
| 460 |
static void |
| 461 |
value_free_value (GValue *value) |
| 462 |
{ |
| 463 |
dex_clear (&value->data[0].v_pointer); |
| 464 |
} |
| 465 |
|
| 466 |
static void |
| 467 |
value_copy_value (const GValue *src, |
| 468 |
GValue *dst) |
| 469 |
{ |
| 470 |
if (src->data[0].v_pointer != NULL) |
| 471 |
dst->data[0].v_pointer = dex_ref (src->data[0].v_pointer); |
| 472 |
else |
| 473 |
dst->data[0].v_pointer = NULL; |
| 474 |
} |
| 475 |
|
| 476 |
static gpointer |
| 477 |
value_peek_pointer (const GValue *value) |
| 478 |
{ |
| 479 |
return value->data[0].v_pointer; |
| 480 |
} |
| 481 |
|
| 482 |
static char * |
| 483 |
value_collect_value (GValue *value, |
| 484 |
guint n_collect_values, |
| 485 |
GTypeCValue *collect_values, |
| 486 |
guint collect_flags) |
| 487 |
{ |
| 488 |
DexObject *object = collect_values[0].v_pointer; |
| 489 |
|
| 490 |
if (object == NULL) |
| 491 |
{ |
| 492 |
value->data[0].v_pointer = NULL; |
| 493 |
return NULL; |
| 494 |
} |
| 495 |
|
| 496 |
if (object->parent_instance.g_class == NULL) |
| 497 |
return g_strconcat ("invalid unclassed DexObject pointer for value type '", |
| 498 |
G_VALUE_TYPE_NAME (value), |
| 499 |
"'", |
| 500 |
NULL); |
| 501 |
|
| 502 |
value->data[0].v_pointer = dex_ref (object); |
| 503 |
|
| 504 |
return NULL; |
| 505 |
} |
| 506 |
|
| 507 |
static char * |
| 508 |
value_lcopy_value (const GValue *value, |
| 509 |
guint n_collect_values, |
| 510 |
GTypeCValue *collect_values, |
| 511 |
guint collect_flags) |
| 512 |
{ |
| 513 |
const DexObject **object_p = collect_values[0].v_pointer; |
| 514 |
|
| 515 |
if G_UNLIKELY (object_p == NULL) |
| 516 |
return g_strconcat ("value location for '", |
| 517 |
G_VALUE_TYPE_NAME (value), |
| 518 |
"' passed as NULL", |
| 519 |
NULL); |
| 520 |
|
| 521 |
if (value->data[0].v_pointer == NULL) |
| 522 |
*object_p = NULL; |
| 523 |
else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) |
| 524 |
*object_p = value->data[0].v_pointer; |
| 525 |
else |
| 526 |
*object_p = dex_ref (value->data[0].v_pointer); |
| 527 |
|
| 528 |
return NULL; |
| 529 |
} |
| 530 |
|
| 531 |
static void |
| 532 |
dex_param_object_set_default (GParamSpec *pspec, |
| 533 |
GValue *value) |
| 534 |
{ |
| 535 |
value->data[0].v_pointer = NULL; |
| 536 |
} |
| 537 |
|
| 538 |
static gboolean |
| 539 |
dex_param_object_is_valid (GParamSpec *pspec, |
| 540 |
const GValue *value) |
| 541 |
{ |
| 542 |
DexObject *object = value->data[0].v_pointer; |
| 543 |
|
| 544 |
return object != NULL && |
| 545 |
g_value_type_compatible (DEX_OBJECT_TYPE (object), G_PARAM_SPEC_VALUE_TYPE (pspec)); |
| 546 |
} |
| 547 |
|
| 548 |
static gboolean |
| 549 |
dex_param_object_validate (GParamSpec *pspec, |
| 550 |
GValue *value) |
| 551 |
{ |
| 552 |
DexObject *object = value->data[0].v_pointer; |
| 553 |
|
| 554 |
if (object != NULL && |
| 555 |
!g_value_type_compatible (DEX_OBJECT_TYPE (object), G_PARAM_SPEC_VALUE_TYPE (pspec))) |
| 556 |
{ |
| 557 |
dex_unref (object); |
| 558 |
value->data[0].v_pointer = NULL; |
| 559 |
|
| 560 |
return TRUE; |
| 561 |
} |
| 562 |
|
| 563 |
return FALSE; |
| 564 |
} |
| 565 |
|
| 566 |
static int |
| 567 |
dex_param_object_values_cmp (GParamSpec *pspec, |
| 568 |
const GValue *value1, |
| 569 |
const GValue *value2) |
| 570 |
{ |
| 571 |
const guint8 *p1 = value1->data[0].v_pointer; |
| 572 |
const guint8 *p2 = value2->data[0].v_pointer; |
| 573 |
|
| 574 |
return p1 < p2 ? -1 : p1 > p2; |
| 575 |
} |
| 576 |
|
| 577 |
static GType |
| 578 |
dex_param_spec_object_get_type (void) |
| 579 |
{ |
| 580 |
if (g_once_init_enter (&dex_param_spec_object_type)) |
| 581 |
{ |
| 582 |
GType gtype = |
| 583 |
g_param_type_register_static (g_intern_static_string ("DexParamObject"), |
| 584 |
&(const GParamSpecTypeInfo) { |
| 585 |
sizeof (GParamSpec), |
| 586 |
16, |
| 587 |
NULL, |
| 588 |
DEX_TYPE_OBJECT, |
| 589 |
NULL, |
| 590 |
dex_param_object_set_default, |
| 591 |
dex_param_object_validate, |
| 592 |
dex_param_object_values_cmp, |
| 593 |
}); |
| 594 |
GParamSpecClass *klass = g_type_class_get (gtype); |
| 595 |
|
| 596 |
klass->value_is_valid = dex_param_object_is_valid; |
| 597 |
|
| 598 |
g_assert (gtype != G_TYPE_INVALID); |
| 599 |
g_once_init_leave (&dex_param_spec_object_type, gtype); |
| 600 |
} |
| 601 |
|
| 602 |
return dex_param_spec_object_type; |
| 603 |
} |
| 604 |
|
| 605 |
GType |
| 606 |
dex_object_get_type (void) |
| 607 |
{ |
| 608 |
if (g_once_init_enter (&dex_object_type)) |
| 609 |
{ |
| 610 |
GType gtype = |
| 611 |
g_type_register_fundamental (g_type_fundamental_next (), |
| 612 |
g_intern_static_string ("DexObject"), |
| 613 |
&(const GTypeInfo) { |
| 614 |
sizeof (DexObjectClass), |
| 615 |
(GBaseInitFunc) NULL, |
| 616 |
(GBaseFinalizeFunc) NULL, |
| 617 |
(GClassInitFunc) dex_object_class_init, |
| 618 |
(GClassFinalizeFunc) NULL, |
| 619 |
NULL, |
| 620 |
|
| 621 |
sizeof (DexObject), |
| 622 |
0, |
| 623 |
(GInstanceInitFunc) dex_object_init, |
| 624 |
|
| 625 |
|
| 626 |
&(const GTypeValueTable) { |
| 627 |
value_init, |
| 628 |
value_free_value, |
| 629 |
value_copy_value, |
| 630 |
value_peek_pointer, |
| 631 |
"p", |
| 632 |
value_collect_value, |
| 633 |
"p", |
| 634 |
value_lcopy_value, |
| 635 |
}, |
| 636 |
}, |
| 637 |
&(const GTypeFundamentalInfo) { |
| 638 |
(G_TYPE_FLAG_INSTANTIATABLE | |
| 639 |
G_TYPE_FLAG_CLASSED | |
| 640 |
G_TYPE_FLAG_DERIVABLE | |
| 641 |
G_TYPE_FLAG_DEEP_DERIVABLE), |
| 642 |
}, |
| 643 |
G_TYPE_FLAG_ABSTRACT); |
| 644 |
g_assert (gtype != G_TYPE_INVALID); |
| 645 |
g_once_init_leave (&dex_object_type, gtype); |
| 646 |
} |
| 647 |
|
| 648 |
return dex_object_type; |
| 649 |
} |
| 650 |
|
| 651 |
DexObject * |
| 652 |
dex_object_create_instance (GType instance_type) |
| 653 |
{ |
| 654 |
return (DexObject *)(gpointer)g_type_create_instance (instance_type); |
| 655 |
} |
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
GParamSpec * |
| 676 |
dex_param_spec_object (const char *name, |
| 677 |
const char *nick, |
| 678 |
const char *blurb, |
| 679 |
GType object_type, |
| 680 |
GParamFlags flags) |
| 681 |
{ |
| 682 |
GParamSpec *pspec; |
| 683 |
|
| 684 |
g_return_val_if_fail (g_type_is_a (object_type, DEX_TYPE_OBJECT), NULL); |
| 685 |
|
| 686 |
pspec = g_param_spec_internal (dex_param_spec_object_get_type (), |
| 687 |
name, |
| 688 |
nick, |
| 689 |
blurb, |
| 690 |
flags); |
| 691 |
pspec->value_type = object_type; |
| 692 |
|
| 693 |
return pspec; |
| 694 |
} |
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
DexObject * |
| 707 |
dex_value_dup_object (const GValue *value) |
| 708 |
{ |
| 709 |
g_return_val_if_fail (G_VALUE_HOLDS (value, DEX_TYPE_OBJECT), NULL); |
| 710 |
|
| 711 |
if (value->data[0].v_pointer != NULL) |
| 712 |
return dex_ref (value->data[0].v_pointer); |
| 713 |
|
| 714 |
return NULL; |
| 715 |
} |
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
DexObject * |
| 728 |
dex_value_get_object (const GValue *value) |
| 729 |
{ |
| 730 |
g_return_val_if_fail (G_VALUE_HOLDS (value, DEX_TYPE_OBJECT), NULL); |
| 731 |
|
| 732 |
return value->data[0].v_pointer; |
| 733 |
} |
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
void |
| 747 |
dex_value_set_object (GValue *value, |
| 748 |
DexObject *object) |
| 749 |
{ |
| 750 |
if (object != NULL) |
| 751 |
dex_ref (object); |
| 752 |
|
| 753 |
dex_value_take_object (value, object); |
| 754 |
} |
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
void |
| 768 |
dex_value_take_object (GValue *value, |
| 769 |
DexObject *object) |
| 770 |
{ |
| 771 |
DexObject *old_object; |
| 772 |
|
| 773 |
g_return_if_fail (G_VALUE_HOLDS (value, DEX_TYPE_OBJECT)); |
| 774 |
|
| 775 |
old_object = value->data[0].v_pointer; |
| 776 |
|
| 777 |
if (object != NULL) |
| 778 |
{ |
| 779 |
g_return_if_fail (DEX_IS_OBJECT (object)); |
| 780 |
g_return_if_fail (g_value_type_compatible (DEX_OBJECT_TYPE (object), G_VALUE_TYPE (value))); |
| 781 |
|
| 782 |
value->data[0].v_pointer = object; |
| 783 |
} |
| 784 |
else |
| 785 |
{ |
| 786 |
value->data[0].v_pointer = NULL; |
| 787 |
} |
| 788 |
|
| 789 |
if (old_object != NULL) |
| 790 |
dex_unref (old_object); |
| 791 |
} |