diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2019-09-25 22:20:25 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2019-09-25 22:20:25 (GMT) |
commit | 6ed1e4110eb19b78f76154aa095a74414531f04c (patch) | |
tree | d1c3562cb6e180baff3c388a3bb3574b0a02213b /plugins/pychrysalide/analysis/db/collection.c | |
parent | 3dc843b3f7991dcd738a30821ff56c7fe13f1094 (diff) |
Prepared history for database items.
Diffstat (limited to 'plugins/pychrysalide/analysis/db/collection.c')
-rw-r--r-- | plugins/pychrysalide/analysis/db/collection.c | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/plugins/pychrysalide/analysis/db/collection.c b/plugins/pychrysalide/analysis/db/collection.c index e62c17e..53cdccc 100644 --- a/plugins/pychrysalide/analysis/db/collection.c +++ b/plugins/pychrysalide/analysis/db/collection.c @@ -59,10 +59,9 @@ static PyObject *py_db_collection_get_items(PyObject *self, void *closure) { PyObject *result; /* Trouvailles à retourner */ GDbCollection *collec; /* Version native */ - size_t counter; /* Décompte des éléments */ - GList *items; /* Eléments déjà en place */ - GList *iter; /* Boucle de parcours */ - int ret; /* Bilan d'une extension */ + size_t count; /* Décompte des éléments */ + GDbItem **items; /* Eléments déjà en place */ + size_t i; /* Boucle de parcours */ #define DB_COLLECTION_ITEMS_ATTRIB PYTHON_GET_DEF_FULL \ ( \ @@ -74,22 +73,21 @@ static PyObject *py_db_collection_get_items(PyObject *self, void *closure) collec = G_DB_COLLECTION(pygobject_get(self)); - counter = 0; - result = PyTuple_New(counter); - g_db_collection_rlock(collec); - items = g_db_collection_get_items(G_DB_COLLECTION(collec)); - - for (iter = g_list_first(items); iter != NULL; iter = g_list_next(iter)) - { - ret = _PyTuple_Resize(&result, ++counter); - if (ret == -1) break; + items = g_db_collection_get_items(G_DB_COLLECTION(collec), &count); - PyTuple_SetItem(result, counter - 1, pygobject_new(G_OBJECT(iter->data))); + result = PyTuple_New(count); + for (i = 0; i < count; i++) + { + PyTuple_SetItem(result, i, pygobject_new(G_OBJECT(items[i]))); + g_object_unref(G_OBJECT(items[i])); } + if (items != NULL) + free(items); + g_db_collection_runlock(collec); return result; |