On Tue, 9 Nov,  Havoc Pennington wrote:
        >On Tue, 9 Nov 1999, Marc Verwerft wrote:
        >> I have a question about glib datalists :
        >>     Why does 'g_datalist_id_set_data_full'  not accept items when
the
        >> datavalue is NULL or zero ?
        >> 
        >> I thought datalists had the same function as name/value pairs in
CORBA.
        >> Am I wrong ? Am I trying to 'abuse' datalists or is there another
        >> explanation ?
        >> 
        >
        >It looks to me like it will take a NULL value for the data as long
as your
        >destroy notify function is NULL. The reason is that "NULL value"
and
        >"unset" are equivalent (to set something to NULL, datalist just
deletes it
        >from the list; if you set something to NULL, it's the same as
removing
        >it). So you can't have a destroy func for something that's not in
the
        >datalist.
        >
        >Havoc

        No, it will never take a NULL value, not even when the destroy
notify function is NULL.
        I've made a small, but otherwise useless ;-}, program that shows the
behaviour.

        Is there another way to save a set of name/value pairs with NULL
values using glib ?


----------Cut Here--------------
/* * Testing of datalists */
#include <stdio.h>
#include <stdlib.h>
#include <glib.h>

struct _prop_st {
    char *id;
    gpointer val;
};

typedef struct _prop_st prop_st;

prop_st props[] = { {"first", (gpointer) 1},
                    {"second", (gpointer) 0},
                    {"third", (gpointer) 2},
                    {"fourth", (gpointer) 1000 },
                    {"fifth", (gpointer) 2000 },
                    {NULL, NULL}};

void print_vals(GQuark id, gpointer data, gpointer user_Data)
{
    printf("%s : %d\n", g_quark_to_string(id), (int) data);
}

int main(int argc, char *argv[])
{
    GData *dl;
    int i, j;
    g_datalist_init(&dl);
    for (i=0; props[i].id != NULL; i++) {
        quarks[i] = g_quark_from_string(props[i].id);
        g_datalist_id_set_data_full(&dl, quarks[i], props[i].val, NULL);
    }

    printf("---- 'foreach' iteration ----\n");
    g_datalist_foreach(&dl, print_vals, NULL);
    exit(0);
}      
----------Cut Here--------------

-- 
To unsubscribe: mail -s unsubscribe [EMAIL PROTECTED] < /dev/null

Reply via email to