pango_font_description_copy Segmentation fault

2012-07-09 Thread Weitian Leung

Hi,
I wonder how pango_font_description_copy make a segmentation 
fault,  I use it like this:

/pango_font_description_free(priv-current_font);
priv-current_font = 
pango_font_description_copy(priv-default_font);/


default_font comes from:
/priv-default_font = gtk_style_context_get_font(context, 
GTK_STATE_FLAG_NORMAL);/


almost everytime I want to change to default font, it cause a 
segmentation fault:


/  Program terminated with signal 11, Segmentation fault.
#0  0x7ff7e2e86b91 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
(gdb) bt
#0  0x7ff7e2e86b91 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#1  0x7ff7e321d2d2 in g_strdup ()
from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#2  0x7ff7e21834ee in pango_font_description_copy ()
from /usr/lib/x86_64-linux-gnu/libpango-1.0.so.0
#3  0x7ff7e4d0e84b in xmr_label_set_font (label=0x19baea0, 
font=0x0)

at /media/workspace/projects/xmradio/src/xmrlabel.c:390/

I try to check out the pango source code:

/PangoFontDescription *
pango_font_description_copy  (const PangoFontDescription  *desc)
{
  PangoFontDescription *result;

  if (desc == NULL)
return NULL;

  result = g_slice_new (PangoFontDescription);

  *result = *desc;

  if (result-family_name)
{
  result-family_name = g_strdup (result-family_name);
  result-static_family = FALSE;
}

  return result;
}/

but nothing odd.

Any idea?
Thanks in advance.

--
Weitian

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Open file from menu

2012-07-09 Thread Rudra Banerjee
Will anyone kindly show the way?
-- 
Sent from my Android phone with K-9 Mail. Please excuse my brevity.

Rudra Banerjee bnrj.ru...@yahoo.com wrote:

Dear friends,
I am trying to create a textview that will show the file opens.
I have managed to make it read the commandline argument as:

stat(argv[1], filestat);
buffer = (char *) malloc(filestat.st_size * sizeof (char));
efile = fopen(argv[1], r);
fread(buffer, filestat.st_size, 1, efile);
gtk_text_buffer_set_text(textbuffer, buffer, filestat.st_size);
free(buffer);

But I am facing 2 problem(2nd problem is more important to solve). 
1) putting the above block inside if (argv[1] != NULL) is giving a
segmentation fault:
[Thread debugging using libthread_db enabled]
Using host libthread_db library /lib64/libthread_db.so.1.
Program received signal SIGSEGV, Segmentation fault.
0x00364066c81e in fread () from /lib64/libc.so.6

and 2) How I can open the file using file menu, instead of commandline
argument? I have defined the menu as follows:

file = gtk_menu_item_new_with_mnemonic(_File);
new = gtk_image_menu_item_new_from_stock(GTK_STOCK_NEW,
accel_group);
open = gtk_image_menu_item_new_from_stock(GTK_STOCK_OPEN,
accel_group);
sep = gtk_separator_menu_item_new();
quit = gtk_image_menu_item_new_from_stock(GTK_STOCK_QUIT,
accel_group);

gtk_menu_item_set_submenu(GTK_MENU_ITEM(file), filemenu);
gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), new);
gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), open);
gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), sep);
gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), quit);
gtk_menu_shell_append(GTK_MENU_SHELL(menubar), file);
gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, FALSE, 3);

g_signal_connect(G_OBJECT(new), activate,
G_CALLBACK(filenew_activated), (gpointer) window);


g_signal_connect(G_OBJECT(open), activate,
G_CALLBACK(fileopen_activated), (gpointer) window);

g_signal_connect_swapped(G_OBJECT(window), destroy,
G_CALLBACK(gtk_main_quit), NULL);

g_signal_connect(G_OBJECT(quit), activate,
G_CALLBACK(gtk_main_quit), NULL);



which is opening the file selector, but *NOT* writing it in the
textview. I wish to open the file in textview and save it aswell after I
edit that.

If anyone kindly show the how-to, I can put problem (1) to solve later.
Please help.

_

gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Open file from menu

2012-07-09 Thread Michael Cronenworth
Rudra Banerjee wrote:
 1) putting the above block inside if (argv[1] != NULL) is giving a
 segmentation fault:

Are you checking argc? If you are not passing an argument argv[1] does
not exist so, yes, you will get a segfault for running beyond the argv[]
array.

if ( argc  1  argv[1] != NULL )
   foo
else
   return 0;

 and 2) How I can open the file using file menu, instead of commandline
 argument? I have defined the menu as follows:
[snip]
 which is opening the file selector, but *NOT* writing it in the
 textview. I wish to open the file in textview and save it aswell after I
 edit that.

Are you checking for a filename returned from the file chooser dialog?
You are going to need more code to do what you want. GTK won't do it
automatically for you.
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Open file from menu

2012-07-09 Thread Liam R E Quin
On Tue, 2012-07-10 at 00:55 +0530, Rudra Banerjee wrote:
 Will anyone kindly show the way?


 stat(argv[1], filestat);
 buffer = (char *) malloc(filestat.st_size * sizeof (char));
 efile = fopen(argv[1], r);
 fread(buffer, filestat.st_size, 1, efile);
 gtk_text_buffer_set_text(textbuffer, buffer, filestat.st_size);
 free(buffer);

In C you need to check the return status of all system calls.

As Michael already said, first make sure argc  1;
if a filename was given, make sure that filestat is a struct stat:

struct stat filestat;

Make sure the malloc() successed - if there's not enoug hmemory it'll
return NULL.

Make sure the fopen() succeeded; it too will return NULL on failure.

Strictly speaking you should close the file, too, with fclose(efile),
and check that worked and also check that the free() was OK, if only to
help you catch programming errors!

Liam

-- 
Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/
Pictures from old books: http://fromoldbooks.org/
Ankh: irc.sorcery.net irc.gnome.org freenode/#xml

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Open file from menu

2012-07-09 Thread David Nečas
On Mon, Jul 09, 2012 at 03:40:11PM -0400, Liam R E Quin wrote:
 also check that the free() was OK

I wonder how you do that (apart from not getting any glibc MALLOC_CHECK_
error message or similar).

Yeti

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Open file from menu

2012-07-09 Thread Liam R E Quin
On Mon, 2012-07-09 at 22:01 +0200, David Nečas wrote:
 On Mon, Jul 09, 2012 at 03:40:11PM -0400, Liam R E Quin wrote:
  also check that the free() was OK
 
 I wonder how you do that (apart from not getting any glibc MALLOC_CHECK_
 error message or similar).

There's no portable way to do it really, you're right. In the past I've
written wrappers for malloc() and free() and realloc() to make sure
everything passed to free actually came from malloc or one of her
friends, and on some systems there are also calls to check the heap.

Liam

-- 
Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/
Pictures from old books: http://fromoldbooks.org/
Ankh: irc.sorcery.net irc.gnome.org freenode/#xml

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list