Re: Problem with AtkText get_text offset arguments



Ashutosh,

The text returned by my_image_get_text() should be freeable by a call to g_free. Thus, you should return g_strdup (messg).

The convention is that if a function, e.g. atk_object_get_name() retuyrns a G_CONST gchar* then the value should not be freed. If the function returns just a gchar* the return value can be freed and probably will be to avoid a memory leak. 

If this is not the cause of the problem can you send me a stack trace of the crash.

Padraig

Ashutosh Sharma wrote:
> 
> Hi,
> 
> I have defined a type implementing the AtkText
> interface. I have implemented only get_text() and
> get_character_count() for now. When atk_get_text gets
> called, the arguments start_offset is 0 and end_offset
> is -1. And if I try to return anything non-NULL, it
> crashes with a segmentation fault when I try to poke
> it with at-poke.
> What am I doing wrong? Do I have to implement the
> other functions too? What would be the minimal
> implementation required for it to work?
> 
> When I poke the object, my_image_get_text() gets
> called first and then my_image_get_character_count. Is
> this okay?
> 
> Its atk_text_interface_init, the implementation of the
> functions and the debugging output are as follows:
> ____________________________________________________
> 
> static void atk_text_interface_init (AtkTextIface
> *iface)
> {
>   fprintf(stderr, "Function:
> atk_text_interface_init\n");
> 
>   g_return_if_fail (iface != NULL);
> 
>   iface->get_text = my_image_get_text;
>   iface->get_character_count =
> my_image_get_character_count;
> }
> ____________________________________________________
> 
> static gchar messg[] = "Hello back there!";
> 
> static gchar* my_image_get_text(AtkText *text, gint
> start_offset, gint end_offset)
> {
>         fprintf(stderr, "Function:
> my_image_get_text\n");
>         fprintf(stderr, "(my_image_get_text) Request:
> start=%d, end=%d\n", start_offset, end_offset);
>         fprintf(stderr, "(my_image_get_text) AtkText
> *text = %u\n", text);
>         if(start_offset > end_offset)
>                 return NULL;
>         return messg;
> }
> 
> static gint my_image_get_character_count (AtkText
> *text)
> {
>         gint textlen;
> 
>         fprintf(stderr, "Function:
> my_image_get_character_count\n");
>         textlen = strlen(messg);
>         fprintf(stderr,
> "(my_image_get_character_count) Returning textlen =
> %d\n", textlen);
> 
>         return textlen;
> }
> ____________________________________________________
> 
> Debugging output:
> 
> Function: my_image_factory_class_init
> Function: my_image_factory_create_accessible
> (my_image_factory_create_accessible) widget =
> 135363816
> Function: my_image_new
> Function: my_image_get_type
> Function: my_image_class_init
> Function: atk_text_interface_init
> Function: my_image_instance_init
> Function: my_image_get_text
> (my_image_get_text) Request: start=0, end=-1
> (my_image_get_text) AtkText *text = 135364608
> Function: my_image_get_character_count
> (my_image_get_character_count) Returning textlen = 17
> ____________________________________________________
> 
> Thanks.
> 
> Regards,
> Ashutosh
> 
> 
> 
> 
> ___________________________________________________________
> BT Yahoo! Broadband - Free modem offer, sign up online today and save £80 http://btyahoo.yahoo.co.uk
> _______________________________________________
> gnome-accessibility-list mailing list
> gnome-accessibility-list gnome org
> http://mail.gnome.org/mailman/listinfo/gnome-accessibility-list



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]