summaryrefslogtreecommitdiff
path: root/contrib/python/jsonglib.override
blob: 121ea5ad01fefa2493797ecc7ead7fdd3d690601 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* -*- Mode: C; c-basic-offset: 4 -*- */
%%
headers
#include <Python.h>
#include <stdio.h>

#define NO_IMPORT_PYGOBJECT
#include "pygobject.h"

#include <json-glib/json-glib.h>
#include <json-glib/json-gobject.h>

static PyObject *
_helper_wrap_pointer_gslist (GType type, GSList *list)
{
    GSList *tmp;
    PyObject *py_list;

    if ((py_list = PyList_New(0)) == NULL) {
        return NULL;
    }
    for (tmp = list; tmp != NULL; tmp = tmp->next) {
        PyObject *obj = pyg_pointer_new (type, tmp->data);
        PyList_Append(py_list, obj);
        Py_DECREF(obj);
    }
    return py_list;
}

static PyObject *
_helper_wrap_string_gslist (GSList *list)
{
    GSList *tmp;
    PyObject *py_list;

    if ((py_list = PyList_New(0)) == NULL) {
        return NULL;
    }
    for (tmp = list; tmp != NULL; tmp = tmp->next) {
        PyObject *str_obj =  PyString_FromString ((char*)tmp->data);

        if (str_obj == NULL) {
            Py_DECREF(py_list);
            return NULL;
        }
        PyList_Append(py_list, str_obj);
        Py_DECREF(str_obj);
    }
    return py_list;
}
%%
modulename json_glib
%%
import gobject.GObject as PyGObject_Type