Imported Upstream version 3.4.0
[platform/upstream/python-gobject.git] / gi / pygi-foreign-gvariant.c
1 /* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
2 /*
3  * Copyright (c) 2010  Collabora Ltd. <http://www.collabora.co.uk/>
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy
6  * of this software and associated documentation files (the "Software"), to
7  * deal in the Software without restriction, including without limitation the
8  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9  * sell copies of the Software, and to permit persons to whom the Software is
10  * furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21  * IN THE SOFTWARE.
22  */
23
24 #include "pygobject.h"
25
26 #include "pygi-private.h"
27 #include "pygi-foreign-gvariant.h"
28
29 PyObject *
30 g_variant_to_arg (PyObject        *value,
31                   GIInterfaceInfo *interface_info,
32                   GITransfer       transfer,
33                   GIArgument      *arg)
34 {
35     g_assert (transfer == GI_TRANSFER_NOTHING);
36
37     /* TODO check that value is a PyGPointer */
38
39     arg->v_pointer = (GVariant *) ( (PyGPointer *) value)->pointer;
40     Py_RETURN_NONE;
41 }
42
43 PyObject *
44 g_variant_from_arg (GIInterfaceInfo *interface_info,
45                     gpointer         data)
46 {
47     GVariant *variant = (GVariant *) data;
48
49     PyObject *type = _pygi_type_import_by_gi_info (interface_info);
50
51     g_variant_ref_sink (variant);
52
53     return _pygi_struct_new ( (PyTypeObject *) type, variant, FALSE);
54 }
55
56 PyObject *
57 g_variant_release_foreign (GIBaseInfo *base_info,
58                            gpointer struct_)
59 {
60     g_variant_unref ( (GVariant *) struct_);
61     Py_RETURN_NONE;
62 }
63