[java-atk-wrapper] JNI: fix crash on java applications
- From: Magdalen Berns <mberns src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [java-atk-wrapper] JNI: fix crash on java applications
- Date: Tue, 2 Jun 2015 19:49:07 +0000 (UTC)
commit 236b9dda9b447d3d853f2ccbe6491f6000751894
Author: Magdalen Berns <m berns thismagpie com>
Date: Tue Jun 2 20:42:00 2015 +0100
JNI: fix crash on java applications
Some pointers were not being cast correctly causing
g_hash_tables to produce garbage. This has been
addressed by creating two macros and using glib
macros to cast types with.
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=698095
jni/src/AtkWrapper.c | 21 +++++++++------------
jni/src/jawhypertext.c | 2 +-
jni/src/jawimpl.c | 28 ++++++++++++----------------
jni/src/jawimpl.h | 9 ++++++++-
4 files changed, 30 insertions(+), 30 deletions(-)
---
diff --git a/jni/src/AtkWrapper.c b/jni/src/AtkWrapper.c
index 2dbd70f..c59724a 100644
--- a/jni/src/AtkWrapper.c
+++ b/jni/src/AtkWrapper.c
@@ -227,7 +227,7 @@ free_callback_para (CallbackPara *para)
if (para->global_ac == NULL)
{
if (jaw_debug)
- (stderr,"\n *** free_callback_para: para->global_ac == NULL *** \n");
+ g_warning("free_callback_para: para->global_ac == NULL");
free_callback_para(para);
return;
}
@@ -822,9 +822,8 @@ signal_emit_handler (gpointer p)
{
case Sig_Text_Caret_Moved:
{
- gint cursor_pos = get_int_value(
- jniEnv,
- (*jniEnv)->GetObjectArrayElement(jniEnv, args, 0));
+ gint cursor_pos = get_int_value(jniEnv,
+ (*jniEnv)->GetObjectArrayElement(jniEnv, args, 0));
g_signal_emit_by_name(atk_obj, "text_caret_moved", cursor_pos);
break;
}
@@ -931,7 +930,7 @@ signal_emit_handler (gpointer p)
case Sig_Object_Property_Change_Accessible_Actions:
{
gint oldValue = get_int_value(jniEnv,
- (*jniEnv)->GetObjectArrayElement(jniEnv, args, 0));
+ (*jniEnv)->GetObjectArrayElement(jniEnv, args, 0));
gint newValue = get_int_value(jniEnv,
(*jniEnv)->GetObjectArrayElement(jniEnv, args, 1));
AtkPropertyValues values = { NULL };
@@ -943,15 +942,13 @@ signal_emit_handler (gpointer p)
g_value_set_int(&values.old_value, oldValue);
if (jaw_debug)
printf ("%d\n", g_value_get_int(&values.old_value));
- g_value_unset(&values.old_value);
g_assert (!G_VALUE_HOLDS_INT (&values.new_value));
g_value_init(&values.new_value, G_TYPE_INT);
- g_assert (G_VALUE_HOLDS_INT (&values.old_value));
+ g_assert (G_VALUE_HOLDS_INT (&values.new_value));
g_value_set_int(&values.new_value, newValue);
if (jaw_debug)
printf ("%d\n", g_value_get_int(&values.new_value));
- g_value_unset(&values.new_value);
values.property_name = "accessible-actions";
@@ -1037,13 +1034,13 @@ signal_emit_handler (gpointer p)
gint newValue = get_int_value(jniEnv,
(*jniEnv)->GetObjectArrayElement(jniEnv, args, 0));
- gint prevCount = *(gint*)g_hash_table_lookup(jaw_obj->storedData,
- "Previous_Count");
+ gint prevCount = GPOINTER_TO_INT(g_hash_table_lookup(jaw_obj->storedData,
+ "Previous_Count"));
gint curCount = atk_text_get_character_count(ATK_TEXT(jaw_obj));
g_hash_table_insert(jaw_obj->storedData,
"Previous_Count",
- (gpointer)&curCount);
+ GINT_TO_POINTER(curCount));
if (curCount > prevCount)
{
@@ -1062,7 +1059,7 @@ signal_emit_handler (gpointer p)
break;
}
default:
- break;
+ break;
}
free_callback_para(para);
return FALSE;
diff --git a/jni/src/jawhypertext.c b/jni/src/jawhypertext.c
index 5622e82..f162a45 100644
--- a/jni/src/jawhypertext.c
+++ b/jni/src/jawhypertext.c
@@ -101,7 +101,7 @@ jaw_hypertext_get_link (AtkHypertext *hypertext, gint link_index)
}
JawHyperlink *jaw_hyperlink = jaw_hyperlink_new(jhyperlink);
- g_hash_table_insert(data->link_table, (gpointer)&link_index, (gpointer)jaw_hyperlink);
+ g_hash_table_insert(data->link_table, GINT_TO_POINTER(link_index), (gpointer)jaw_hyperlink);
return ATK_HYPERLINK(jaw_hyperlink);
}
diff --git a/jni/src/jawimpl.c b/jni/src/jawimpl.c
index db92970..d51178c 100644
--- a/jni/src/jawimpl.c
+++ b/jni/src/jawimpl.c
@@ -32,10 +32,6 @@
extern "C" {
#endif
-#ifdef GTYPE_TO_POINTER
- #define GTYPE_TO_POINTER (x) (GSIZE_TO_POINTER (x))
-#endif
-
static void jaw_impl_class_init (JawImplClass *klass);
//static void jaw_impl_init (JawImpl *impl);
static void jaw_impl_dispose(GObject *gobject);
@@ -106,7 +102,7 @@ object_table_insert (JNIEnv *jniEnv, jobject ac, JawImpl* jaw_impl)
"hashCode",
"()I");
gint hash_key = (gint)(*jniEnv)->CallIntMethod(jniEnv, ac, jmid);
- g_hash_table_insert(objectTable, (gpointer)&hash_key, (gpointer)&jaw_impl);
+ g_hash_table_insert(objectTable, GINT_TO_POINTER(hash_key), GINT_TO_POINTER(jaw_impl));
}
static JawImpl*
@@ -123,7 +119,7 @@ object_table_lookup (JNIEnv *jniEnv, jobject ac)
if (objectTable==NULL)
return NULL;
- value = g_hash_table_lookup(objectTable, (gpointer)&hash_key);
+ value = g_hash_table_lookup(objectTable, GINT_TO_POINTER(hash_key));
return (JawImpl*)value;
}
@@ -138,7 +134,7 @@ object_table_remove(JNIEnv *jniEnv, jobject ac)
"()I" );
gint hash_key = (gint)(*jniEnv)->CallIntMethod( jniEnv, ac, jmid );
- g_hash_table_remove(objectTable, (gpointer)&hash_key );
+ g_hash_table_remove(objectTable, GINT_TO_POINTER(hash_key));
}
static void
@@ -392,7 +388,7 @@ jaw_impl_get_type (guint tflag)
typeTable = g_hash_table_new( NULL, NULL );
}
- type = (GType)g_hash_table_lookup(typeTable, GINT_TO_POINTER(tflag));
+ type = GPOINTER_TO_GTYPE(g_hash_table_lookup(typeTable, GUINT_TO_POINTER(tflag)));
if (type == 0) {
GTypeInfo tinfo = {
sizeof(JawImplClass),
@@ -439,7 +435,7 @@ jaw_impl_get_type (guint tflag)
if (tflag & INTERFACE_TABLE)
g_type_add_interface_static (type, ATK_TYPE_TABLE, &atk_table_info);
- g_hash_table_insert(typeTable, GINT_TO_POINTER(tflag), (gpointer)type);
+ g_hash_table_insert(typeTable, GINT_TO_POINTER(tflag), GTYPE_TO_POINTER(type));
}
return type;
@@ -490,19 +486,19 @@ jaw_impl_finalize(GObject *gobject)
jaw_obj->acc_context = NULL;
/* Interface finalize */
- GHashTableIter iter;
- gpointer key;
- gpointer value;
+ GHashTableIter *iter;
+ gpointer *key;
+ gpointer *value;
- g_hash_table_iter_init(&iter, jaw_impl->ifaceTable);
- while (g_hash_table_iter_next(&iter, &key, &value))
+ g_hash_table_iter_init(iter, jaw_impl->ifaceTable);
+ while (g_hash_table_iter_next(iter, key, value))
{
JawInterfaceInfo *info = (JawInterfaceInfo*)value;
info->finalize(info->data);
g_free(info);
- g_hash_table_iter_remove(&iter);
+ g_hash_table_iter_remove(iter);
}
if (jaw_impl->ifaceTable != NULL)
{
@@ -521,7 +517,7 @@ jaw_impl_get_interface_data (JawObject *jaw_obj, guint iface)
if (jaw_impl->ifaceTable == NULL || jaw_impl == NULL)
return NULL;
- JawInterfaceInfo *info = g_hash_table_lookup(jaw_impl->ifaceTable, (gpointer)&iface);
+ JawInterfaceInfo *info = g_hash_table_lookup(jaw_impl->ifaceTable,GUINT_TO_POINTER(iface));
if (info != NULL)
return info->data;
diff --git a/jni/src/jawimpl.h b/jni/src/jawimpl.h
index dbca582..be88935 100644
--- a/jni/src/jawimpl.h
+++ b/jni/src/jawimpl.h
@@ -20,7 +20,7 @@
#ifndef _JAW_IMPL_H_
#define _JAW_IMPL_H_
-#include <glib-object.h>
+#include <glib.h>
#include "jawobject.h"
G_BEGIN_DECLS
@@ -32,6 +32,13 @@ G_BEGIN_DECLS
#define JAW_IS_IMPL_CLASS(tf, klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), JAW_TYPE_IMPL(tf)))
#define JAW_IMPL_GET_CLASS(tf, obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), JAW_TYPE_IMPL(tf), JawImplClass))
+#ifdef GPOINTER_TO_SIZE
+ #define GPOINTER_TO_GTYPE(gpointer) (GPOINTER_TO_SIZE (gpointer))
+#endif
+#ifdef GSIZE_TO_POINTER
+ #define GTYPE_TO_POINTER(gtype) (GSIZE_TO_POINTER(gtype))
+#endif
+
typedef struct _JawImpl JawImpl;
typedef struct _JawImplClass JawImplClass;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]