Пример #1
0
void comps_objrtree_copy_shallow(COMPS_ObjRTree *rt1, COMPS_ObjRTree *rt2) {
    COMPS_HSList *to_clone, *tmplist, *new_subnodes;
    COMPS_HSListItem *it, *it2;
    COMPS_ObjRTreeData *rtdata;
    COMPS_Object *new_data;

    rt1->subnodes = comps_hslist_create();
    comps_hslist_init(rt1->subnodes, NULL, NULL, &comps_objrtree_data_destroy_v);
    if (rt1->subnodes == NULL) {
        COMPS_OBJECT_DESTROY(rt1);
        return;
    }
    rt1->len = 0;

    to_clone = comps_hslist_create();
    comps_hslist_init(to_clone, NULL, NULL, NULL);

    for (it = rt2->subnodes->first; it != NULL; it = it->next) {
        rtdata = comps_objrtree_data_create(
                     ((COMPS_ObjRTreeData*)it->data)->key, NULL);
        if (((COMPS_ObjRTreeData*)it->data)->data != NULL)
            new_data = COMPS_OBJECT_INCREF(((COMPS_ObjRTreeData*)it->data)->data);
        else
            new_data = NULL;
        comps_hslist_destroy(&rtdata->subnodes);
        rtdata->subnodes = ((COMPS_ObjRTreeData*)it->data)->subnodes;
        rtdata->data = new_data;
        comps_hslist_append(rt1->subnodes, rtdata, 0);
        comps_hslist_append(to_clone, rtdata, 0);
    }

    while (to_clone->first) {
        it2 = to_clone->first;
        tmplist = ((COMPS_ObjRTreeData*)it2->data)->subnodes;
        comps_hslist_remove(to_clone, to_clone->first);

        new_subnodes = comps_hslist_create();
        comps_hslist_init(new_subnodes, NULL, NULL, &comps_objrtree_data_destroy_v);
        for (it = tmplist->first; it != NULL; it = it->next) {
            rtdata = comps_objrtree_data_create(
                         ((COMPS_ObjRTreeData*)it->data)->key, NULL);
            if (((COMPS_ObjRTreeData*)it->data)->data != NULL)
                new_data = comps_object_incref(((COMPS_ObjRTreeData*)it->data)->data);
            else
                new_data = NULL;
            comps_hslist_destroy(&rtdata->subnodes);
            rtdata->subnodes = ((COMPS_ObjRTreeData*)it->data)->subnodes;
            rtdata->data = new_data;
            comps_hslist_append(new_subnodes, rtdata, 0);
            comps_hslist_append(to_clone, rtdata, 0);
        }
        ((COMPS_ObjRTreeData*)it2->data)->subnodes = new_subnodes;
        free(it2);
    }
    comps_hslist_destroy(&to_clone);
}
Пример #2
0
PyObject* PyCOMPS_clear(PyObject *self) {

    COMPS_Str *enc;
    enc = (COMPS_Str*)
          comps_object_incref((COMPS_Object*)((PyCOMPS*)self)->comps_doc->encoding);

    COMPS_OBJECT_DESTROY(((PyCOMPS*)self)->comps_doc);
    ((PyCOMPS*)self)->comps_doc = COMPS_OBJECT_CREATE(COMPS_Doc, NULL);
    ((PyCOMPS*)self)->comps_doc->encoding = enc;
    Py_RETURN_NONE;
}
Пример #3
0
COMPS_DocCategory* comps_doccategory_union(COMPS_DocCategory *c1,
                                           COMPS_DocCategory *c2) {
    COMPS_DocCategory *res;
    COMPS_ObjListIt *it;
    COMPS_Set *set;
    COMPS_Object *obj;
    void *data;
    int index;

    res = COMPS_OBJECT_CREATE(COMPS_DocCategory,NULL);
    COMPS_OBJECT_DESTROY(res->properties);

    res->properties = comps_objdict_union(c1->properties, c2->properties);
    set = comps_set_create();
    comps_set_init(set, NULL, NULL, &comps_object_destroy_v,
                                    &__comps_docgroupid_cmp_set);
    it = c1->group_ids?c1->group_ids->first:NULL;
    for (; it != NULL; it = it->next) {
        obj = comps_object_copy(it->comps_obj);
        comps_set_add(set, (void*)comps_object_incref(obj));
        comps_doccategory_add_groupid(res, (COMPS_DocGroupId*)obj);
    }
    it = c2->group_ids ? c2->group_ids->first : NULL;
    for (; it != NULL; it = it->next) {
        if ((data = comps_set_data_at(set, (void*)it->comps_obj)) != NULL) {
            index = comps_objlist_index(res->group_ids, (COMPS_Object*)data);
            comps_objlist_remove_at(res->group_ids, index);
            comps_objlist_insert_at_x(res->group_ids, index,
                                      comps_object_copy(it->comps_obj));
        } else {
            comps_doccategory_add_groupid(res, (COMPS_DocGroupId*)
                                            comps_object_copy(it->comps_obj));
        }
    }
    comps_set_destroy(&set);
    COMPS_OBJECT_DESTROY(res->name_by_lang);
    COMPS_OBJECT_DESTROY(res->desc_by_lang);
    res->name_by_lang = comps_objdict_union(c1->name_by_lang, c2->name_by_lang);
    res->desc_by_lang = comps_objdict_union(c1->desc_by_lang, c2->desc_by_lang);
    return res;
}
COMPS_DocGroup* comps_docgroup_union(COMPS_DocGroup *g1, COMPS_DocGroup *g2) {
    COMPS_DocGroup *res;
    COMPS_ObjListIt *it;
    COMPS_Set *set;
    COMPS_DocGroupPackage *pkg;

    res = COMPS_OBJECT_CREATE(COMPS_DocGroup, NULL);
    COMPS_OBJECT_DESTROY(res->properties);

    res->properties = comps_objdict_union(g1->properties, g2->properties);
    set = comps_set_create();
    comps_set_init(set, NULL, NULL, (void(*)(void*))&comps_object_destroy,
                                    &comps_docpackage_cmp_set);
    it = g1->packages?g1->packages->first:NULL;
    for (; it != NULL; it = it->next) {
        pkg = (COMPS_DocGroupPackage*) comps_object_copy(it->comps_obj);
        comps_set_add(set, (void*)comps_object_incref((COMPS_Object*)pkg));
        comps_docgroup_add_package(res, pkg);
    }
    void *data;
    int index;
    it = g2->packages?g2->packages->first:NULL;
    for (; it != NULL; it = it->next) {
        if ((data = comps_set_data_at(set, (void*)it->comps_obj)) != NULL) {
            index = comps_objlist_index(res->packages, (COMPS_Object*)data);
            comps_objlist_remove_at(res->packages, index);
            comps_objlist_insert_at_x(res->packages, index,
                                      comps_object_copy(it->comps_obj));
        } else {
            comps_docgroup_add_package(res, (COMPS_DocGroupPackage*)
                                            comps_object_copy(it->comps_obj));
        }
    }
    comps_set_destroy(&set);
    comps_object_destroy((COMPS_Object*)res->name_by_lang);
    comps_object_destroy((COMPS_Object*)res->desc_by_lang);
    res->name_by_lang = comps_objdict_union(g1->name_by_lang, g2->name_by_lang);
    res->desc_by_lang = comps_objdict_union(g1->desc_by_lang, g2->desc_by_lang);
    return res;
}
Пример #5
0
COMPS_ObjList * comps_objmrtree_get(COMPS_ObjMRTree * rt, const char * key) {
    COMPS_HSList * subnodes;
    COMPS_HSListItem * it = NULL;
    COMPS_ObjMRTreeData * rtdata;
    unsigned int offset, len, x;
    char found, ended;

    len = strlen(key);
    offset = 0;
    subnodes = rt->subnodes;
    while (offset != len) {
        found = 0;
        for (it = subnodes->first; it != NULL; it=it->next) {
            if (((COMPS_ObjMRTreeData*)it->data)->key[0] == key[offset]) {
                found = 1;
                break;
            }
        }
        if (!found)
            return NULL;
        rtdata = (COMPS_ObjMRTreeData*)it->data;

        for (x=1; ;x++) {
            ended=0;
            if (rtdata->key[x] == 0) ended += 1;
            if (x == len - offset) ended += 2;
            if (ended != 0) break;
            if (key[offset+x] != rtdata->key[x]) break;
        }
        if (ended == 3) return (COMPS_ObjList*)
                               comps_object_incref((COMPS_Object*)rtdata->data);
        else if (ended == 1) offset+=x;
        else return NULL;
        subnodes = ((COMPS_ObjMRTreeData*)it->data)->subnodes;
    }
    if (it)
        return ((COMPS_ObjMRTreeData*)it->data)->data;
    else return NULL;
}
Пример #6
0
COMPS_Object* comps_pkgs_in(PyObject *item) {
    return comps_object_incref((COMPS_Object*)((PyCOMPS_Package*)item)->package);
}
Пример #7
0
COMPS_Object* comps_groups_in(PyObject *item) {
    return comps_object_incref((COMPS_Object*)((PyCOMPS_Group*)item)->group);
}
Пример #8
0
COMPS_ObjList* comps_docgroupid_arches(COMPS_DocGroupId *gid) {
    return (COMPS_ObjList*)comps_object_incref((COMPS_Object*)gid->arches);
}
Пример #9
0
COMPS_Object* comps_docgroupid_get_name(COMPS_DocGroupId *gid) {
    return comps_object_incref((COMPS_Object*)gid->name);
}
Пример #10
0
COMPS_Object* comps_objrtree_get(COMPS_ObjRTree * rt, const char * key) {
    return comps_object_incref(__comps_objrtree_get(rt, key));
}
Пример #11
0
void comps_objrtree_set_nx(COMPS_ObjRTree *rt, char *key, size_t len,
                           COMPS_Object *data) {
    __comps_objrtree_set(rt, key, len, comps_object_incref(data));
}
Пример #12
0
COMPS_Object* comps_envs_in(PyObject *item) {
    return comps_object_incref((COMPS_Object*)((PyCOMPS_Env*)item)->c_obj);
}
Пример #13
0
COMPS_Object* comps_docpackage_get_basearchonly(COMPS_DocGroupPackage *pkg) {
    return comps_object_incref((COMPS_Object*)pkg->basearchonly);
}
Пример #14
0
COMPS_Object* comps_docpackage_get_requires(COMPS_DocGroupPackage *pkg) {
    return comps_object_incref((COMPS_Object*)pkg->requires);
}
Пример #15
0
COMPS_Object* comps_docpackage_get_name(COMPS_DocGroupPackage *pkg) {
    return comps_object_incref((COMPS_Object*)pkg->name);
}
Пример #16
0
void comps_objrtree_set(COMPS_ObjRTree *rt, char *key, COMPS_Object *data) {
    __comps_objrtree_set(rt, key, strlen(key), comps_object_incref(data));
}
Пример #17
0
void comps_objmrtree_set(COMPS_ObjMRTree *rt, char *key, COMPS_Object *data) {
    COMPS_Object *ndata = ndata = comps_object_incref(data);
    __comps_objmrtree_set(rt, key, ndata);
}