Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » GTK+
  • » help for problem in g_cache_insert() example code? [RSS Feed]

#1 Dec. 19, 2010 19:32:38

Biswajeet D.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

help for problem in g_cache_insert() example code?


#undef G_DISABLE_ASSERT
#undef G_LOG_DOMAIN

#include <stdio.h>
#include <string.h>
#include "glib.h"

void function(gchar *key,gchar *value,gint *user_data)
{
// give the count of the number of times the function was called

(*user_data)++;
}

void cache_test()
{
gchar *str1,*str2,*str3;
GCache *cache = NULL;
gint user_data = 0;

g_assert((cache = g_cache_new( (GCacheNewFunc) g_ascii_strup,
g_free, (GCacheDupFunc) g_strdup, g_free, g_str_hash,
g_str_hash, g_str_equal)) != NULL);
str1 = g_cache_insert(cache,"test");
g_assert(!strcmp("TEST",str1));
str2 = g_cache_insert(cache,"test");
g_assert(!strcmp("TEST",str1));
str3 = g_cache_insert(cache,"glib");
g_assert(!strcmp("GLIB",str3));
g_cache_key_foreach (cache,(GHFunc)function,&user_data);
//g_cache_key_foreach would call function twice and make user_data == 2
g_assert(user_data == 2);
g_cache_value_foreach (cache,(GHFunc)function,&user_data);
//g_cache_value_foreach would call function twice and make user_data == 4
g_assert(user_data == 4);
g_cache_remove(cache,str1);
g_cache_remove(cache,str2);
g_cache_remove(cache,str3);
g_cache_destroy(cache);
}


int main (int argc,
char *argv)
{
cache_test();
return 0;

}

Now my test example crashes at str1 = g_cache_insert(cache,"test");
because of null pointer dereferencing.
Any help where i could be going wrong?

Regards

Biswajeet_______________________________________________
gtk-list mailing list
gtk-list@gnome.orghttp://mail.gnome.org/mailman/listinfo/gtk-list

Offline

  • Root
  • » GTK+
  • » help for problem in g_cache_insert() example code? [RSS Feed]

Board footer

Moderator control

Enjoy the 24th of August
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support