pygi-cache.c 46.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/* -*- Mode: C; c-basic-offset: 4 -*-
 * vim: tabstop=4 shiftwidth=4 expandtab
 *
 * Copyright (C) 2011 John (J5) Palmieri <johnp@redhat.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
 * USA
 */
21 22

#include "pygi-info.h"
23
#include "pygi-cache.h"
24
#include "pygi-marshal.h"
25
#include "pygi-marshal-cleanup.h"
26
#include "pygi-type.h"
27
#include <girepository.h>
28

29
PyGIArgCache * _arg_cache_new_from_type_info (GITypeInfo *type_info,
30
                                              PyGICallableCache *callable_cache,
31 32 33 34
                                              GIArgInfo *arg_info,
                                              GITypeTag type_tag,
                                              GITransfer transfer,
                                              GIDirection direction,
35 36
                                              gssize c_arg_index,
                                              gssize py_arg_index);
37

38
/* cleanup */
John (J5) Palmieri's avatar
John (J5) Palmieri committed
39
void
40
_pygi_arg_cache_free (PyGIArgCache *cache)
John (J5) Palmieri's avatar
John (J5) Palmieri committed
41 42 43 44
{
    if (cache == NULL)
        return;

45
    if (cache->type_info != NULL)
46
        g_base_info_unref ( (GIBaseInfo *)cache->type_info);
John (J5) Palmieri's avatar
John (J5) Palmieri committed
47
    if (cache->destroy_notify)
48
        cache->destroy_notify (cache);
John (J5) Palmieri's avatar
John (J5) Palmieri committed
49
    else
50
        g_slice_free (PyGIArgCache, cache);
John (J5) Palmieri's avatar
John (J5) Palmieri committed
51 52 53
}

static void
54
_interface_cache_free_func (PyGIInterfaceCache *cache)
55 56
{
    if (cache != NULL) {
57
        Py_XDECREF (cache->py_type);
58
        if (cache->type_name != NULL)
59
            g_free (cache->type_name);
60
        if (cache->interface_info != NULL)
61 62
            g_base_info_unref ( (GIBaseInfo *)cache->interface_info);
        g_slice_free (PyGIInterfaceCache, cache);
63 64 65
    }
}

John (J5) Palmieri's avatar
John (J5) Palmieri committed
66
static void
67
_hash_cache_free_func (PyGIHashCache *cache)
68
{
John (J5) Palmieri's avatar
John (J5) Palmieri committed
69
    if (cache != NULL) {
70 71 72
        _pygi_arg_cache_free (cache->key_cache);
        _pygi_arg_cache_free (cache->value_cache);
        g_slice_free (PyGIHashCache, cache);
John (J5) Palmieri's avatar
John (J5) Palmieri committed
73
    }
74 75
}

76
static void
77
_sequence_cache_free_func (PyGISequenceCache *cache)
78
{
John (J5) Palmieri's avatar
John (J5) Palmieri committed
79
    if (cache != NULL) {
80 81
        _pygi_arg_cache_free (cache->item_cache);
        g_slice_free (PyGISequenceCache, cache);
John (J5) Palmieri's avatar
John (J5) Palmieri committed
82
    }
83 84
}

85
static void
86
_callback_cache_free_func (PyGICallbackCache *cache)
87
{
88 89
    if (cache != NULL) {
        if (cache->interface_info != NULL)
90
            g_base_info_unref ( (GIBaseInfo *)cache->interface_info);
91

92
        g_slice_free (PyGICallbackCache, cache);
93
    }
94 95 96
}

void
97
_pygi_callable_cache_free (PyGICallableCache *cache)
98
{
99
    gssize i;
100

101 102 103
    if (cache == NULL)
        return;

104
    g_slist_free (cache->out_args);
105 106
    for (i = 0; i < cache->n_args; i++) {
        PyGIArgCache *tmp = cache->args_cache[i];
107
        _pygi_arg_cache_free (tmp);
108
    }
109
    if (cache->return_cache != NULL)
110
        _pygi_arg_cache_free (cache->return_cache);
111

112 113
    g_slice_free1 (cache->n_args * sizeof (PyGIArgCache *), cache->args_cache);
    g_slice_free (PyGICallableCache, cache);
114 115 116
}

/* cache generation */
117
static inline PyGICallableCache *
118
_callable_cache_new_from_callable_info (GICallableInfo *callable_info)
119
{
120
    PyGICallableCache *cache;
121

122
    cache = g_slice_new0 (PyGICallableCache);
123

124
    cache->name = g_base_info_get_name ((GIBaseInfo *)callable_info);
125

126 127
    if (g_base_info_get_type ( (GIBaseInfo *)callable_info) == GI_INFO_TYPE_FUNCTION) {
        GIFunctionInfoFlags flags;
128

129 130 131 132 133 134 135 136 137 138
        flags = g_function_info_get_flags ( (GIFunctionInfo *)callable_info);
        cache->is_method = flags & GI_FUNCTION_IS_METHOD;
        cache->is_constructor = flags & GI_FUNCTION_IS_CONSTRUCTOR;
    } else {
        cache->is_method = TRUE;
        cache->is_constructor = FALSE;
    }

    cache->n_args = g_callable_info_get_n_args (callable_info) + (cache->is_method ? 1: 0);
    if (cache->n_args > 0)
139
        cache->args_cache = g_slice_alloc0 (cache->n_args * sizeof (PyGIArgCache *));
140 141

    return cache;
142 143
}

144
static inline PyGIInterfaceCache *
145
_interface_cache_new_from_interface_info (GIInterfaceInfo *iface_info)
146 147
{
    PyGIInterfaceCache *ic;
John (J5) Palmieri's avatar
John (J5) Palmieri committed
148

149 150
    ic = g_slice_new0 (PyGIInterfaceCache);
    ( (PyGIArgCache *)ic)->destroy_notify = (GDestroyNotify)_interface_cache_free_func;
151
    ic->g_type = g_registered_type_info_get_g_type ( (GIRegisteredTypeInfo *)iface_info);
152
    ic->py_type = _pygi_type_import_by_gi_info ( (GIBaseInfo *) iface_info);
153 154 155 156

    if (ic->py_type == NULL)
        return NULL;

157
    ic->type_name = _pygi_g_base_info_get_fullname (iface_info);
158 159 160
    return ic;
}

161
static inline PyGISequenceCache *
162 163 164
_sequence_cache_new_from_type_info (GITypeInfo *type_info,
                                    GIDirection direction,
                                    GITransfer transfer,
165
                                    gssize aux_offset)
166 167 168
{
    PyGISequenceCache *sc;
    GITypeInfo *item_type_info;
169
    GITypeTag item_type_tag;
170
    GITransfer item_transfer;
171

172 173
    sc = g_slice_new0 (PyGISequenceCache);
    ( (PyGIArgCache *)sc)->destroy_notify = (GDestroyNotify)_sequence_cache_free_func;
174 175 176

    sc->fixed_size = -1;
    sc->len_arg_index = -1;
177
    sc->is_zero_terminated = g_type_info_is_zero_terminated (type_info);
178
    if (!sc->is_zero_terminated) {
179
        sc->fixed_size = g_type_info_get_array_fixed_size (type_info);
180 181 182
        if (sc->fixed_size < 0)
            sc->len_arg_index = g_type_info_get_array_length (type_info) + aux_offset;
    }
183

184
    item_type_info = g_type_info_get_param_type (type_info, 0);
185
    item_type_tag = g_type_info_get_tag (item_type_info);
186

187 188
    item_transfer =
        transfer == GI_TRANSFER_CONTAINER ? GI_TRANSFER_NOTHING : transfer;
189

190 191 192 193 194 195 196
    sc->item_cache = _arg_cache_new_from_type_info (item_type_info,
                                                    NULL,
                                                    NULL,
                                                    item_type_tag,
                                                    item_transfer,
                                                    direction,
                                                    0, 0);
197

198
    if (sc->item_cache == NULL) {
199
        _pygi_arg_cache_free ( (PyGIArgCache *)sc);
200 201
        return NULL;
    }
John (J5) Palmieri's avatar
John (J5) Palmieri committed
202

203
    sc->item_cache->type_tag = item_type_tag;
204 205
    sc->item_size = _pygi_g_type_info_size (item_type_info);
    g_base_info_unref ( (GIBaseInfo *)item_type_info);
206

207
    return sc;
208
}
John (J5) Palmieri's avatar
John (J5) Palmieri committed
209
static inline PyGIHashCache *
210 211 212
_hash_cache_new_from_type_info (GITypeInfo *type_info,
                                GIDirection direction,
                                GITransfer transfer)
John (J5) Palmieri's avatar
John (J5) Palmieri committed
213 214 215 216 217 218
{
    PyGIHashCache *hc;
    GITypeInfo *key_type_info;
    GITypeTag key_type_tag;
    GITypeInfo *value_type_info;
    GITypeTag value_type_tag;
219
    GITransfer item_transfer;
John (J5) Palmieri's avatar
John (J5) Palmieri committed
220

221 222
    hc = g_slice_new0 (PyGIHashCache);
    ( (PyGIArgCache *)hc)->destroy_notify = (GDestroyNotify)_hash_cache_free_func;
John (J5) Palmieri's avatar
John (J5) Palmieri committed
223 224 225 226 227
    key_type_info = g_type_info_get_param_type (type_info, 0);
    key_type_tag = g_type_info_get_tag (key_type_info);
    value_type_info = g_type_info_get_param_type (type_info, 1);
    value_type_tag = g_type_info_get_tag (value_type_info);

228 229
    item_transfer =
        transfer == GI_TRANSFER_CONTAINER ? GI_TRANSFER_NOTHING : transfer;
230

231 232 233 234 235 236 237
    hc->key_cache = _arg_cache_new_from_type_info (key_type_info,
                                                   NULL,
                                                   NULL,
                                                   key_type_tag,
                                                   item_transfer,
                                                   direction,
                                                   0, 0);
John (J5) Palmieri's avatar
John (J5) Palmieri committed
238 239

    if (hc->key_cache == NULL) {
240
        _pygi_arg_cache_free ( (PyGIArgCache *)hc);
John (J5) Palmieri's avatar
John (J5) Palmieri committed
241 242 243
        return NULL;
    }

244 245 246 247 248 249 250
    hc->value_cache = _arg_cache_new_from_type_info (value_type_info,
                                                     NULL,
                                                     NULL,
                                                     value_type_tag,
                                                     item_transfer,
                                                     direction,
                                                     0, 0);
John (J5) Palmieri's avatar
John (J5) Palmieri committed
251 252

    if (hc->value_cache == NULL) {
253
        _pygi_arg_cache_free ( (PyGIArgCache *)hc);
John (J5) Palmieri's avatar
John (J5) Palmieri committed
254 255 256 257 258 259 260 261 262 263 264
        return NULL;
    }

    hc->key_cache->type_tag = key_type_tag;
    hc->value_cache->type_tag = value_type_tag;

    g_base_info_unref( (GIBaseInfo *)key_type_info);
    g_base_info_unref( (GIBaseInfo *)value_type_info);

    return hc;
}
265

John (J5) Palmieri's avatar
John (J5) Palmieri committed
266
static inline PyGICallbackCache *
267 268
_callback_cache_new_from_arg_info (GIArgInfo *arg_info,
                                   GIInterfaceInfo *iface_info,
269
                                   gssize aux_offset)
John (J5) Palmieri's avatar
John (J5) Palmieri committed
270 271 272
{
   PyGICallbackCache *cc;

273 274
   cc = g_slice_new0 (PyGICallbackCache);
   cc->user_data_index = g_arg_info_get_closure (arg_info);
275 276
   if (cc->user_data_index != -1)
       cc->user_data_index += aux_offset;
277
   cc->destroy_notify_index = g_arg_info_get_destroy (arg_info);
278 279
   if (cc->destroy_notify_index != -1)
       cc->destroy_notify_index += aux_offset;
280
   cc->scope = g_arg_info_get_scope (arg_info);
281 282
   g_base_info_ref( (GIBaseInfo *)iface_info);
   cc->interface_info = iface_info;
John (J5) Palmieri's avatar
John (J5) Palmieri committed
283 284 285
   return cc;
}

286
static inline PyGIArgCache *
287
_arg_cache_new (void)
288
{
289
    return g_slice_new0 (PyGIArgCache);
290
}
291

John (J5) Palmieri's avatar
John (J5) Palmieri committed
292
static inline void
293
_arg_cache_in_void_setup (PyGIArgCache *arg_cache)
294
{
295 296
    arg_cache->in_marshaller = _pygi_marshal_in_void;
}
297

John (J5) Palmieri's avatar
John (J5) Palmieri committed
298
static inline void
299
_arg_cache_out_void_setup (PyGIArgCache *arg_cache)
300 301
{
    arg_cache->out_marshaller = _pygi_marshal_out_void;
302 303
}

304
static inline void
305
_arg_cache_in_boolean_setup (PyGIArgCache *arg_cache)
306
{
307
    arg_cache->in_marshaller = _pygi_marshal_in_boolean;
308 309
}

John (J5) Palmieri's avatar
John (J5) Palmieri committed
310
static inline void
311
_arg_cache_out_boolean_setup (PyGIArgCache *arg_cache)
312 313 314 315 316
{
    arg_cache->out_marshaller = _pygi_marshal_out_boolean;
}

static inline void
317
_arg_cache_in_int8_setup (PyGIArgCache *arg_cache)
318
{
319
    arg_cache->in_marshaller = _pygi_marshal_in_int8;
320 321
}

322
static inline void
323
_arg_cache_out_int8_setup (PyGIArgCache *arg_cache)
324 325 326 327 328
{
    arg_cache->out_marshaller = _pygi_marshal_out_int8;
}

static inline void
329
_arg_cache_in_uint8_setup (PyGIArgCache *arg_cache)
330
{
331
    arg_cache->in_marshaller = _pygi_marshal_in_uint8;
332 333
}

334
static inline void
335
_arg_cache_out_uint8_setup (PyGIArgCache *arg_cache)
336 337 338 339 340
{
    arg_cache->out_marshaller = _pygi_marshal_out_uint8;
}

static inline void
341
_arg_cache_in_int16_setup (PyGIArgCache *arg_cache)
342
{
343
    arg_cache->in_marshaller = _pygi_marshal_in_int16;
344 345
}

346
static inline void
347
_arg_cache_out_int16_setup (PyGIArgCache *arg_cache)
348 349 350 351 352
{
    arg_cache->out_marshaller = _pygi_marshal_out_int16;
}

static inline void
353
_arg_cache_in_uint16_setup (PyGIArgCache *arg_cache)
354
{
355
    arg_cache->in_marshaller = _pygi_marshal_in_uint16;
356 357
}

358
static inline void
359
_arg_cache_out_uint16_setup (PyGIArgCache *arg_cache)
360 361 362 363 364
{
    arg_cache->out_marshaller = _pygi_marshal_out_uint16;
}

static inline void
365
_arg_cache_in_int32_setup (PyGIArgCache *arg_cache)
366
{
367
    arg_cache->in_marshaller = _pygi_marshal_in_int32;
368 369
}

370
static inline void
371
_arg_cache_out_int32_setup (PyGIArgCache *arg_cache)
372 373 374 375 376
{
    arg_cache->out_marshaller = _pygi_marshal_out_int32;
}

static inline void
377
_arg_cache_in_uint32_setup (PyGIArgCache *arg_cache)
378
{
379
    arg_cache->in_marshaller = _pygi_marshal_in_uint32;
380 381
}

382
static inline void
383
_arg_cache_out_uint32_setup (PyGIArgCache *arg_cache)
384 385 386 387 388
{
    arg_cache->out_marshaller = _pygi_marshal_out_uint32;
}

static inline void
389
_arg_cache_in_int64_setup (PyGIArgCache *arg_cache)
390
{
391
    arg_cache->in_marshaller = _pygi_marshal_in_int64;
392 393
}

394
static inline void
395
_arg_cache_out_int64_setup (PyGIArgCache *arg_cache)
396 397 398 399 400
{
    arg_cache->out_marshaller = _pygi_marshal_out_int64;
}

static inline void
401
_arg_cache_in_uint64_setup (PyGIArgCache *arg_cache)
402
{
403
    arg_cache->in_marshaller = _pygi_marshal_in_uint64;
404 405
}

406
static inline void
407
_arg_cache_out_uint64_setup (PyGIArgCache *arg_cache)
408 409 410 411 412
{
    arg_cache->out_marshaller = _pygi_marshal_out_uint64;
}

static inline void
413
_arg_cache_in_float_setup (PyGIArgCache *arg_cache)
414
{
415
    arg_cache->in_marshaller = _pygi_marshal_in_float;
416 417
}

418
static inline void
419
_arg_cache_out_float_setup (PyGIArgCache *arg_cache)
420 421 422 423 424
{
    arg_cache->out_marshaller = _pygi_marshal_out_float;
}

static inline void
425
_arg_cache_in_double_setup (PyGIArgCache *arg_cache)
426
{
427
    arg_cache->in_marshaller = _pygi_marshal_in_double;
428 429
}

430
static inline void
431
_arg_cache_out_double_setup (PyGIArgCache *arg_cache)
432 433 434 435 436
{
    arg_cache->out_marshaller = _pygi_marshal_out_double;
}

static inline void
437
_arg_cache_in_unichar_setup (PyGIArgCache *arg_cache)
438
{
439
    arg_cache->in_marshaller = _pygi_marshal_in_unichar;
440 441
}

442
static inline void
443
_arg_cache_out_unichar_setup (PyGIArgCache *arg_cache)
444 445 446 447 448
{
    arg_cache->out_marshaller = _pygi_marshal_out_unichar;
}

static inline void
449
_arg_cache_in_gtype_setup (PyGIArgCache *arg_cache)
450
{
451
    arg_cache->in_marshaller = _pygi_marshal_in_gtype;
452 453
}

454
static inline void
455
_arg_cache_out_gtype_setup (PyGIArgCache *arg_cache)
456 457 458 459 460
{
    arg_cache->out_marshaller = _pygi_marshal_out_gtype;
}

static inline void
461 462
_arg_cache_in_utf8_setup (PyGIArgCache *arg_cache,
                          GITransfer transfer)
463
{
464
    arg_cache->in_marshaller = _pygi_marshal_in_utf8;
465
    arg_cache->in_cleanup = _pygi_marshal_cleanup_in_utf8;
466
}
467

468
static inline void
469 470
_arg_cache_out_utf8_setup (PyGIArgCache *arg_cache,
                           GITransfer transfer)
471 472
{
    arg_cache->out_marshaller = _pygi_marshal_out_utf8;
473
    arg_cache->out_cleanup = _pygi_marshal_cleanup_out_utf8;
474 475
}

476
static inline void
477 478
_arg_cache_in_filename_setup (PyGIArgCache *arg_cache,
                              GITransfer transfer)
479
{
480
    arg_cache->in_marshaller = _pygi_marshal_in_filename;
481
    arg_cache->in_cleanup = _pygi_marshal_cleanup_in_utf8;
482 483
}

484
static inline void
485 486
_arg_cache_out_filename_setup (PyGIArgCache *arg_cache,
                               GITransfer transfer)
487
{
488
    arg_cache->out_marshaller = _pygi_marshal_out_filename;
489
    arg_cache->out_cleanup = _pygi_marshal_cleanup_out_utf8;
490
}
491

492
static inline gboolean
493 494 495 496 497
_arg_cache_in_array_setup (PyGIArgCache *arg_cache,
                           PyGICallableCache *callable_cache,
                           GITypeInfo *type_info,
                           GITransfer transfer,
                           GIDirection direction)
498
{
John (J5) Palmieri's avatar
John (J5) Palmieri committed
499
    PyGISequenceCache *seq_cache = (PyGISequenceCache *)arg_cache;
500
    seq_cache->array_type = g_type_info_get_array_type (type_info);
501

502
    arg_cache->in_marshaller = _pygi_marshal_in_array;
503

504 505 506
    if (seq_cache->len_arg_index >= 0 &&
        direction == GI_DIRECTION_IN) {
        PyGIArgCache *aux_cache = 
507
            callable_cache->args_cache[seq_cache->len_arg_index];
508 509 510 511 512 513 514

        if (aux_cache == NULL) {
            aux_cache = _arg_cache_new();
        } else if (aux_cache->aux_type == PYGI_AUX_TYPE_IGNORE) {
            return TRUE;
        }

John (J5) Palmieri's avatar
John (J5) Palmieri committed
515
        aux_cache->aux_type = PYGI_AUX_TYPE_IGNORE;
516
        aux_cache->direction = direction;
517 518
        aux_cache->in_marshaller = NULL;
        aux_cache->out_marshaller = NULL;
519

520
        callable_cache->args_cache[seq_cache->len_arg_index] = aux_cache;
521 522
    }

523
    arg_cache->in_cleanup = _pygi_marshal_cleanup_in_array;
524 525

    return TRUE;
526 527
}

528
static inline gboolean
529 530 531 532 533 534
_arg_cache_out_array_setup (PyGIArgCache *arg_cache,
                            PyGICallableCache *callable_cache,
                            GITypeInfo *type_info,
                            GITransfer transfer,
                            GIDirection direction,
                            gssize arg_index)
535
{
John (J5) Palmieri's avatar
John (J5) Palmieri committed
536
    PyGISequenceCache *seq_cache = (PyGISequenceCache *)arg_cache;
537
    arg_cache->out_marshaller = _pygi_marshal_out_array;
538
    arg_cache->out_cleanup = _pygi_marshal_cleanup_out_array;
539

540
    seq_cache->array_type = g_type_info_get_array_type (type_info);
541 542

    if (seq_cache->len_arg_index >= 0) {
543
        PyGIArgCache *aux_cache = callable_cache->args_cache[seq_cache->len_arg_index];
544
        if (seq_cache->len_arg_index < arg_index)
545
             callable_cache->n_out_aux_args++;
546

547 548 549 550
        if (aux_cache != NULL) {
            if (aux_cache->aux_type == PYGI_AUX_TYPE_IGNORE)
                return TRUE;

551 552
            callable_cache->out_args = 
                g_slist_remove (callable_cache->out_args, aux_cache);
553
        } else {
554
            aux_cache = _arg_cache_new ();
555
        }
556 557

        aux_cache->aux_type = PYGI_AUX_TYPE_IGNORE;
558 559 560
        aux_cache->direction = direction;
        aux_cache->in_marshaller = NULL;
        aux_cache->out_marshaller = NULL;
561

562
        callable_cache->args_cache[seq_cache->len_arg_index] = aux_cache;
563 564 565 566 567 568
    }

    return TRUE;
}

static inline void
569 570
_arg_cache_in_glist_setup (PyGIArgCache *arg_cache,
                           GITransfer transfer)
571
{
572
    arg_cache->in_marshaller = _pygi_marshal_in_glist;
573
    arg_cache->in_cleanup = _pygi_marshal_cleanup_in_glist;
574
}
575

576
static inline void
577 578
_arg_cache_out_glist_setup (PyGIArgCache *arg_cache,
                            GITransfer transfer)
579 580
{
    arg_cache->out_marshaller = _pygi_marshal_out_glist;
581
    arg_cache->in_cleanup = _pygi_marshal_cleanup_out_glist;
582 583
}

584
static inline void
585 586
_arg_cache_in_gslist_setup (PyGIArgCache *arg_cache,
                            GITransfer transfer)
587
{
588
    arg_cache->in_marshaller = _pygi_marshal_in_gslist;
589
    arg_cache->in_cleanup = _pygi_marshal_cleanup_in_glist;
590
}
591

592
static inline void
593 594
_arg_cache_out_gslist_setup (PyGIArgCache *arg_cache,
                             GITransfer transfer)
595 596
{
    arg_cache->out_marshaller = _pygi_marshal_out_gslist;
597
    arg_cache->out_cleanup = _pygi_marshal_cleanup_out_glist;
598 599
}

600
static inline void
601
_arg_cache_in_ghash_setup (PyGIArgCache *arg_cache)
602
{
John (J5) Palmieri's avatar
John (J5) Palmieri committed
603
    arg_cache->in_marshaller = _pygi_marshal_in_ghash;
604
    arg_cache->in_cleanup = _pygi_marshal_cleanup_in_ghash;
605 606
}

John (J5) Palmieri's avatar
John (J5) Palmieri committed
607
static inline void
608
_arg_cache_out_ghash_setup (PyGIArgCache *arg_cache)
609
{
610
    arg_cache->out_marshaller = _pygi_marshal_out_ghash;
611
    arg_cache->out_cleanup = _pygi_marshal_cleanup_out_ghash;
612 613 614
}

static inline void
615
_arg_cache_in_gerror_setup (PyGIArgCache *arg_cache)
616
{
617
    arg_cache->in_marshaller = _pygi_marshal_in_gerror;
John (J5) Palmieri's avatar
John (J5) Palmieri committed
618
    arg_cache->aux_type = PYGI_AUX_TYPE_IGNORE;
619 620
}

621
static inline void
622
_arg_cache_out_gerror_setup (PyGIArgCache *arg_cache)
623 624 625 626 627 628
{
    arg_cache->out_marshaller = _pygi_marshal_out_gerror;
    arg_cache->aux_type = PYGI_AUX_TYPE_IGNORE;
}

static inline void
629 630
_arg_cache_in_interface_union_setup (PyGIArgCache *arg_cache,
                                     GITransfer transfer)
631
{
John (J5) Palmieri's avatar
John (J5) Palmieri committed
632
    arg_cache->in_marshaller = _pygi_marshal_in_interface_struct;
633 634 635
}

static inline void
636 637
_arg_cache_out_interface_union_setup (PyGIArgCache *arg_cache,
                                      GITransfer transfer)
638 639
{
    arg_cache->out_marshaller = _pygi_marshal_out_interface_struct;
640 641
}

642
static inline void
643 644 645
_arg_cache_in_interface_struct_setup (PyGIArgCache *arg_cache,
                                      GIInterfaceInfo *iface_info,
                                      GITransfer transfer)
646
{
647
    PyGIInterfaceCache *iface_cache = (PyGIInterfaceCache *)arg_cache;
648
    iface_cache->is_foreign = g_struct_info_is_foreign ( (GIStructInfo*)iface_info);
649
    arg_cache->in_marshaller = _pygi_marshal_in_interface_struct;
650 651

    if (iface_cache->g_type == G_TYPE_VALUE)
652 653 654
        arg_cache->in_cleanup = _pygi_marshal_cleanup_in_interface_struct_gvalue;
    else if (iface_cache->is_foreign)
        arg_cache->in_cleanup = _pygi_marshal_cleanup_in_interface_struct_foreign;
655
}
656

657
static inline void
658 659 660
_arg_cache_out_interface_struct_setup (PyGIArgCache *arg_cache,
                                       GIInterfaceInfo *iface_info,
                                       GITransfer transfer)
661 662
{
    PyGIInterfaceCache *iface_cache = (PyGIInterfaceCache *)arg_cache;
663
    iface_cache->is_foreign = g_struct_info_is_foreign ( (GIStructInfo*)iface_info);
664
    arg_cache->out_marshaller = _pygi_marshal_out_interface_struct;
665 666 667

    if (iface_cache->is_foreign)
        arg_cache->in_cleanup = _pygi_marshal_cleanup_out_interface_struct_foreign;
668 669
}

670
static inline void
671 672
_arg_cache_in_interface_object_setup (PyGIArgCache *arg_cache,
                                      GITransfer transfer)
673 674
{
    arg_cache->in_marshaller = _pygi_marshal_in_interface_object;
675
    arg_cache->in_cleanup = _pygi_marshal_cleanup_in_interface_object;
676 677
}

John (J5) Palmieri's avatar
John (J5) Palmieri committed
678
static inline void
679 680
_arg_cache_out_interface_object_setup (PyGIArgCache *arg_cache,
                                       GITransfer transfer)
681
{
682
    arg_cache->out_marshaller = _pygi_marshal_out_interface_object;
683
    arg_cache->out_cleanup = _pygi_marshal_cleanup_out_interface_object;
684 685 686
}

static inline void
687 688
_arg_cache_in_interface_callback_setup (PyGIArgCache *arg_cache,
                                        PyGICallableCache *callable_cache)
John (J5) Palmieri's avatar
John (J5) Palmieri committed
689
{
690
    PyGICallbackCache *callback_cache = (PyGICallbackCache *)arg_cache;
John (J5) Palmieri's avatar
John (J5) Palmieri committed
691
    if (callback_cache->user_data_index >= 0) {
692
        PyGIArgCache *user_data_arg_cache = _arg_cache_new ();
John (J5) Palmieri's avatar
John (J5) Palmieri committed
693
        user_data_arg_cache->aux_type = PYGI_AUX_TYPE_HAS_PYARG;
694
        callable_cache->args_cache[callback_cache->user_data_index] = user_data_arg_cache;
John (J5) Palmieri's avatar
John (J5) Palmieri committed
695
    }
696 697

    if (callback_cache->destroy_notify_index >= 0) {
698
        PyGIArgCache *destroy_arg_cache = _arg_cache_new ();
John (J5) Palmieri's avatar
John (J5) Palmieri committed
699
        destroy_arg_cache->aux_type = PYGI_AUX_TYPE_IGNORE;
700
        callable_cache->args_cache[callback_cache->destroy_notify_index] = destroy_arg_cache;
John (J5) Palmieri's avatar
John (J5) Palmieri committed
701 702
    }
    arg_cache->in_marshaller = _pygi_marshal_in_interface_callback;
703 704
}

John (J5) Palmieri's avatar
John (J5) Palmieri committed
705
static inline void
706
_arg_cache_out_interface_callback_setup (void)
707
{
708 709 710
    PyErr_Format(PyExc_NotImplementedError,
                 "Callback returns are not supported");
}
711

John (J5) Palmieri's avatar
John (J5) Palmieri committed
712
static inline void
713 714
_arg_cache_in_interface_enum_setup (PyGIArgCache *arg_cache,
                                    GITransfer transfer)
715
{
716
    arg_cache->in_marshaller = _pygi_marshal_in_interface_enum;
717 718
}

719
static inline void
720 721
_arg_cache_out_interface_enum_setup (PyGIArgCache *arg_cache,
                                     GITransfer transfer)
722
{
723 724
    arg_cache->out_marshaller = _pygi_marshal_out_interface_enum;
}
725

John (J5) Palmieri's avatar
John (J5) Palmieri committed
726
static inline void
727 728
_arg_cache_in_interface_flags_setup (PyGIArgCache *arg_cache,
                                     GITransfer transfer)
729
{
730
    arg_cache->in_marshaller = _pygi_marshal_in_interface_flags;