[libgda/LIBGDA_4.2] More GINT_TO_POINTER corrections
- From: Vivien Malerba <vivien src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda/LIBGDA_4.2] More GINT_TO_POINTER corrections
- Date: Thu, 28 Apr 2011 20:15:15 +0000 (UTC)
commit 1af8404c6b58a85177ccf390f44a4381cd7b5331
Author: Vivien Malerba <malerba gnome-db org>
Date: Thu Apr 28 21:54:50 2011 +0200
More GINT_TO_POINTER corrections
libgda/gda-data-access-wrapper.c | 34 ++++++++-----
libgda/gda-data-access-wrapper.h | 5 +-
libgda/gda-data-model-array.c | 15 ++++--
libgda/gda-data-model.c | 15 +++++-
libgda/gda-data-proxy.c | 95 ++++++++++++++++++++++++++------------
libgda/gda-data-select.c | 60 ++++++++++++++----------
6 files changed, 145 insertions(+), 79 deletions(-)
---
diff --git a/libgda/gda-data-access-wrapper.c b/libgda/gda-data-access-wrapper.c
index 3590711..904ae09 100644
--- a/libgda/gda-data-access-wrapper.c
+++ b/libgda/gda-data-access-wrapper.c
@@ -302,8 +302,9 @@ gda_data_access_wrapper_set_property (GObject *object,
g_signal_connect (G_OBJECT (model->priv->iter), "end-of-data",
G_CALLBACK (iter_end_of_data_cb), model);
model->priv->iter_row = -1; /* because model->priv->iter is invalid */
- model->priv->rows = g_hash_table_new_full (g_direct_hash, g_direct_equal,
- NULL, (GDestroyNotify) g_object_unref);
+ model->priv->rows = g_hash_table_new_full (g_int_hash, g_int_equal,
+ g_free,
+ (GDestroyNotify) g_object_unref);
}
else {
g_signal_connect (G_OBJECT (mod), "row-inserted",
@@ -465,7 +466,10 @@ create_new_row (GdaDataAccessWrapper *model)
gda_row_invalidate_value (row, dest);
}
- g_hash_table_insert (model->priv->rows, GINT_TO_POINTER (model->priv->iter_row), row);
+ gint *ptr;
+ ptr = g_new (gint, 1);
+ *ptr = model->priv->iter_row;
+ g_hash_table_insert (model->priv->rows, ptr, row);
/*g_print ("%s(%d)\n", __FUNCTION__, model->priv->iter_row);*/
return row;
@@ -493,8 +497,9 @@ gda_data_access_wrapper_get_value_at (GdaDataModel *model, gint col, gint row, G
return gda_data_model_get_value_at (imodel->priv->model, col, row, error);
else {
GdaRow *gda_row;
-
- gda_row = g_hash_table_lookup (imodel->priv->rows, GINT_TO_POINTER (row));
+ gint tmp;
+ tmp = row;
+ gda_row = g_hash_table_lookup (imodel->priv->rows, &tmp);
if (gda_row) {
GValue *val = gda_row_get_value (gda_row, col);
if (gda_row_value_is_valid (gda_row, val))
@@ -506,7 +511,8 @@ gda_data_access_wrapper_get_value_at (GdaDataModel *model, gint col, gint row, G
g_assert (imodel->priv->iter);
if (imodel->priv->iter_row < 0) {
if (gda_data_model_iter_move_next (imodel->priv->iter)) {
- gda_row = g_hash_table_lookup (imodel->priv->rows, GINT_TO_POINTER (row));
+ tmp = row;
+ gda_row = g_hash_table_lookup (imodel->priv->rows, &tmp);
if (row == imodel->priv->iter_row) {
GValue *val = gda_row_get_value (gda_row, col);
if (gda_row_value_is_valid (gda_row, val))
@@ -539,7 +545,8 @@ gda_data_access_wrapper_get_value_at (GdaDataModel *model, gint col, gint row, G
if (! (imodel->priv->model_access_flags & GDA_DATA_MODEL_ACCESS_CURSOR_BACKWARD) ||
! (imodel->priv->model_access_flags & GDA_DATA_MODEL_ACCESS_CURSOR_FORWARD)) {
- gda_row = g_hash_table_lookup (imodel->priv->rows, GINT_TO_POINTER (row));
+ tmp = row;
+ gda_row = g_hash_table_lookup (imodel->priv->rows, &tmp);
if (gda_row) {
GValue *val = gda_row_get_value (gda_row, col);
@@ -552,7 +559,8 @@ gda_data_access_wrapper_get_value_at (GdaDataModel *model, gint col, gint row, G
else {
/* in this case iter can be moved forward and backward at will => we only
* need to keep a pool of GdaRow for performances reasons */
- gda_row = g_hash_table_lookup (imodel->priv->rows, GINT_TO_POINTER (row));
+ tmp = row;
+ gda_row = g_hash_table_lookup (imodel->priv->rows, &tmp);
if (!gda_row) {
if (! imodel->priv->rows_buffer_array) {
@@ -573,7 +581,7 @@ gda_data_access_wrapper_get_value_at (GdaDataModel *model, gint col, gint row, G
ROWS_POOL_SIZE - 1);
g_array_remove_index (imodel->priv->rows_buffer_index,
ROWS_POOL_SIZE - 1);
- g_hash_table_remove (imodel->priv->rows, GINT_TO_POINTER (index_row));
+ g_hash_table_remove (imodel->priv->rows, &index_row);
}
gda_row = create_new_row (imodel);
@@ -609,11 +617,11 @@ iter_row_changed_cb (GdaDataModelIter *iter, gint row, GdaDataAccessWrapper *mod
! (model->priv->model_access_flags & GDA_DATA_MODEL_ACCESS_CURSOR_FORWARD)) {
/* keep the changes in rows */
GdaRow *gda_row;
-
- gda_row = g_hash_table_lookup (model->priv->rows, GINT_TO_POINTER (row));
- if (!gda_row) {
+ gint tmp;
+ tmp = row;
+ gda_row = g_hash_table_lookup (model->priv->rows, &tmp);
+ if (!gda_row)
create_new_row (model);
- }
}
}
}
diff --git a/libgda/gda-data-access-wrapper.h b/libgda/gda-data-access-wrapper.h
index 2b55a64..a408d41 100644
--- a/libgda/gda-data-access-wrapper.h
+++ b/libgda/gda-data-access-wrapper.h
@@ -1,5 +1,5 @@
-/* GDA common library
- * Copyright (C) 2006 - 2009 The GNOME Foundation.
+/*
+ * Copyright (C) 2006 - 2011 The GNOME Foundation.
*
* AUTHORS:
* Vivien Malerba <malerba gnome-db org>
@@ -46,6 +46,7 @@ struct _GdaDataAccessWrapperClass {
GObjectClass parent_class;
/* Padding for future expansion */
+ /*< private >*/
void (*_gda_reserved1) (void);
void (*_gda_reserved2) (void);
void (*_gda_reserved3) (void);
diff --git a/libgda/gda-data-model-array.c b/libgda/gda-data-model-array.c
index 278d89a..7968579 100644
--- a/libgda/gda-data-model-array.c
+++ b/libgda/gda-data-model-array.c
@@ -182,7 +182,7 @@ gda_data_model_array_init (GdaDataModelArray *model, G_GNUC_UNUSED GdaDataModelA
/* allocate internal structure */
model->priv = g_new0 (GdaDataModelArrayPrivate, 1);
model->priv->notify_changes = TRUE;
- model->priv->column_spec = g_hash_table_new (g_direct_hash, g_direct_equal);
+ model->priv->column_spec = g_hash_table_new_full (g_int_hash, g_int_equal, g_free, NULL);
model->priv->read_only = FALSE;
model->priv->number_of_columns = 0;
model->priv->rows = g_array_new (FALSE, FALSE, sizeof (GdaRow *));
@@ -198,7 +198,6 @@ hash_free_column (G_GNUC_UNUSED gpointer key, GdaColumn *column, GdaDataModelArr
g_object_unref (column);
}
-
static void
gda_data_model_array_finalize (GObject *object)
{
@@ -491,15 +490,19 @@ gda_data_model_array_describe_column (GdaDataModel *model, gint col)
return NULL;
}
- column = g_hash_table_lookup (((GdaDataModelArray*) model)->priv->column_spec,
- GINT_TO_POINTER (col));
+ gint tmp;
+ tmp = col;
+ column = g_hash_table_lookup (((GdaDataModelArray*) model)->priv->column_spec, &tmp);
if (!column) {
column = gda_column_new ();
g_signal_connect (G_OBJECT (column), "g-type-changed",
G_CALLBACK (column_g_type_changed_cb), model);
gda_column_set_position (column, col);
- g_hash_table_insert (((GdaDataModelArray*) model)->priv->column_spec,
- GINT_TO_POINTER (col), column);
+
+ gint *ptr;
+ ptr = g_new (gint, 1);
+ *ptr = col;
+ g_hash_table_insert (((GdaDataModelArray*) model)->priv->column_spec, ptr, column);
}
return column;
diff --git a/libgda/gda-data-model.c b/libgda/gda-data-model.c
index 0218960..d9ce3d2 100644
--- a/libgda/gda-data-model.c
+++ b/libgda/gda-data-model.c
@@ -1726,7 +1726,16 @@ gda_data_model_add_data_from_xml_node (GdaDataModel *model, xmlNodePtr node, GEr
*
* The @cols_trans is a hash table for which keys are @to columns numbers and the values are
* the corresponding column numbers in the @from data model. To set the values of a column in @to to NULL,
- * create an entry in the hash table with a negative value.
+ * create an entry in the hash table with a negative value. For example:
+ * <programlisting><![CDATA[GHashTable *hash;
+ * gint *ptr;
+ * hash = g_hash_table_new_full (g_int_hash, g_int_equal, g_free, NULL);
+ * ptr = g_new (gint, 1);
+ * *ptr = 2;
+ * g_hash_table_insert (hash, ptr, GINT_TO_POINTER (3));
+ * gda_data_model_import_from_model (...);
+ * g_hash_table_free (hash);
+ * ]]></programlisting>
*
* Upon errors FALSE will be returned and @error will be assigned a
* #GError from the #GDA_DATA_MODEL_ERROR domain.
@@ -1775,8 +1784,8 @@ gda_data_model_import_from_model (GdaDataModel *to, GdaDataModel *from,
GdaColumn *column;
if (cols_trans) {
- col = GPOINTER_TO_INT (g_hash_table_lookup (cols_trans, GINT_TO_POINTER (i)));
- if (col >= from_nb_cols) {
+ col = GPOINTER_TO_INT (g_hash_table_lookup (cols_trans, &i));
+ if ((col < 0) || (col >= from_nb_cols)) {
g_slist_free (copy_params);
g_set_error (error, GDA_DATA_MODEL_ERROR, GDA_DATA_MODEL_COLUMN_OUT_OF_RANGE_ERROR,
_("Inexistent column in source data model: %d"), col);
diff --git a/libgda/gda-data-proxy.c b/libgda/gda-data-proxy.c
index c38eba7..ddce9db 100644
--- a/libgda/gda-data-proxy.c
+++ b/libgda/gda-data-proxy.c
@@ -1,6 +1,5 @@
-/* gda-data-proxy.c
- *
- * Copyright (C) 2005 - 2010 Vivien Malerba
+/*
+ * Copyright (C) 2005 - 2011 Vivien Malerba
*
* This Library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public License as
@@ -288,8 +287,11 @@ absolute_row_to_model_row (GdaDataProxy *proxy, gint abs_row, RowModif **rm)
if (abs_row < 0)
return -1;
if ((abs_row < proxy->priv->model_nb_rows) || (proxy->priv->model_nb_rows < 0)) {
- if (rm)
- *rm = g_hash_table_lookup (proxy->priv->modify_rows, GINT_TO_POINTER (abs_row));
+ if (rm) {
+ gint tmp;
+ tmp = abs_row;
+ *rm = g_hash_table_lookup (proxy->priv->modify_rows, &tmp);
+ }
return abs_row;
}
else {
@@ -724,7 +726,7 @@ gda_data_proxy_init (GdaDataProxy *proxy)
proxy->priv->mutex = gda_mutex_new ();
- proxy->priv->modify_rows = g_hash_table_new (NULL, NULL);
+ proxy->priv->modify_rows = g_hash_table_new_full (g_int_hash, g_int_equal, g_free, NULL);
proxy->priv->notify_changes = TRUE;
proxy->priv->add_null_entry = FALSE;
@@ -1055,11 +1057,15 @@ proxied_model_row_inserted_cb (G_GNUC_UNUSED GdaDataModel *model, gint row, GdaD
RowModif *tmprm;
tmprm = ROW_MODIF (list->data);
if (tmprm->model_row > row) {
- g_hash_table_remove (proxy->priv->modify_rows,
- GINT_TO_POINTER (tmprm->model_row));
+ gint tmp;
+ tmp = tmprm->model_row;
+ g_hash_table_remove (proxy->priv->modify_rows, &tmp);
tmprm->model_row ++;
- g_hash_table_insert (proxy->priv->modify_rows,
- GINT_TO_POINTER (tmprm->model_row), tmprm);
+
+ gint *ptr;
+ ptr = g_new (gint, 1);
+ *ptr = tmprm->model_row;
+ g_hash_table_insert (proxy->priv->modify_rows, ptr, tmprm);
}
}
}
@@ -1076,16 +1082,17 @@ proxied_model_row_inserted_cb (G_GNUC_UNUSED GdaDataModel *model, gint row, GdaD
static void
proxied_model_row_updated_cb (G_GNUC_UNUSED GdaDataModel *model, gint row, GdaDataProxy *proxy)
{
- gint proxy_row;
+ gint proxy_row, tmp;
RowModif *rm;
/* destroy any RowModif associated ro @row */
- rm = g_hash_table_lookup (proxy->priv->modify_rows, GINT_TO_POINTER (row));
+ tmp = row;
+ rm = g_hash_table_lookup (proxy->priv->modify_rows, &tmp);
if (rm) {
/* FIXME: compare with the new value of the updated row and remove RowModif only if there
* are no more differences. For now we only get rid of that RowModif.
*/
- g_hash_table_remove (proxy->priv->modify_rows, GINT_TO_POINTER (row));
+ g_hash_table_remove (proxy->priv->modify_rows, &tmp);
proxy->priv->all_modifs = g_slist_remove (proxy->priv->all_modifs, rm);
row_modifs_free (rm);
}
@@ -1144,9 +1151,11 @@ proxied_model_row_removed_cb (G_GNUC_UNUSED GdaDataModel *model, gint row, GdaDa
proxy->priv->model_nb_rows --;
/* destroy any RowModif associated ro @row */
- rm = g_hash_table_lookup (proxy->priv->modify_rows, GINT_TO_POINTER (row));
+ gint tmp;
+ tmp = row;
+ rm = g_hash_table_lookup (proxy->priv->modify_rows, &tmp);
if (rm) {
- g_hash_table_remove (proxy->priv->modify_rows, GINT_TO_POINTER (row));
+ g_hash_table_remove (proxy->priv->modify_rows, &tmp);
proxy->priv->all_modifs = g_slist_remove (proxy->priv->all_modifs, rm);
row_modifs_free (rm);
}
@@ -1158,11 +1167,14 @@ proxied_model_row_removed_cb (G_GNUC_UNUSED GdaDataModel *model, gint row, GdaDa
RowModif *tmprm;
tmprm = ROW_MODIF (list->data);
if (tmprm->model_row > row) {
- g_hash_table_remove (proxy->priv->modify_rows,
- GINT_TO_POINTER (tmprm->model_row));
+ tmp = tmprm->model_row;
+ g_hash_table_remove (proxy->priv->modify_rows, &tmp);
tmprm->model_row --;
- g_hash_table_insert (proxy->priv->modify_rows,
- GINT_TO_POINTER (tmprm->model_row), tmprm);
+
+ gint *ptr;
+ ptr = g_new (gint, 1);
+ *ptr = tmprm->model_row;
+ g_hash_table_insert (proxy->priv->modify_rows, ptr, tmprm);
}
}
}
@@ -1294,7 +1306,11 @@ find_or_create_row_modif (GdaDataProxy *proxy, gint proxy_row, gint col, RowValu
g_assert (model_row >= 0);
rm = row_modifs_new (proxy, proxy_row);
rm->model_row = model_row;
- g_hash_table_insert (proxy->priv->modify_rows, GINT_TO_POINTER (model_row), rm);
+
+ gint *ptr;
+ ptr = g_new (gint, 1);
+ *ptr = model_row;
+ g_hash_table_insert (proxy->priv->modify_rows, ptr, rm);
proxy->priv->all_modifs = g_slist_prepend (proxy->priv->all_modifs, rm);
}
else {
@@ -1593,7 +1609,11 @@ gda_data_proxy_delete (GdaDataProxy *proxy, gint proxy_row)
/* the row is an existing row in the data model, create a new RowModif */
rm = row_modifs_new (proxy, proxy_row);
rm->model_row = model_row;
- g_hash_table_insert (proxy->priv->modify_rows, GINT_TO_POINTER (model_row), rm);
+
+ gint *ptr;
+ ptr = g_new (gint, 1);
+ *ptr = model_row;
+ g_hash_table_insert (proxy->priv->modify_rows, ptr, rm);
proxy->priv->all_modifs = g_slist_prepend (proxy->priv->all_modifs, rm);
rm->to_be_deleted = TRUE;
do_signal = TRUE;
@@ -1640,7 +1660,9 @@ gda_data_proxy_undelete (GdaDataProxy *proxy, gint proxy_row)
/* get rid of that RowModif */
do_signal= TRUE;
- g_hash_table_remove (proxy->priv->modify_rows, GINT_TO_POINTER (model_row));
+ gint tmp;
+ tmp = model_row;
+ g_hash_table_remove (proxy->priv->modify_rows, &tmp);
proxy->priv->all_modifs = g_slist_remove (proxy->priv->all_modifs, rm);
row_modifs_free (rm);
}
@@ -1860,9 +1882,11 @@ gda_data_proxy_cancel_row_changes (GdaDataProxy *proxy, gint proxy_row, gint col
signal_delete = TRUE;
proxy->priv->new_rows = g_slist_remove (proxy->priv->new_rows, rm);
}
- else
- g_hash_table_remove (proxy->priv->modify_rows,
- GINT_TO_POINTER (rm->model_row));
+ else {
+ gint tmp;
+ tmp = rm->model_row;
+ g_hash_table_remove (proxy->priv->modify_rows, &tmp);
+ }
row_modifs_free (rm);
rm = NULL;
}
@@ -2067,7 +2091,10 @@ commit_row_modif (GdaDataProxy *proxy, RowModif *rm, gboolean adjust_display, GE
proxy->priv->new_rows = g_slist_remove (proxy->priv->new_rows, rm);
proxy->priv->all_modifs = g_slist_remove (proxy->priv->all_modifs, rm);
- g_hash_table_remove (proxy->priv->modify_rows, GINT_TO_POINTER (rm->model_row));
+
+ gint tmp;
+ tmp = rm->model_row;
+ g_hash_table_remove (proxy->priv->modify_rows, &tmp);
row_modifs_free (rm);
rm = NULL;
@@ -2101,7 +2128,10 @@ commit_row_modif (GdaDataProxy *proxy, RowModif *rm, gboolean adjust_display, GE
G_OBJECT_TYPE_NAME (proxy->priv->model));
proxy->priv->new_rows = g_slist_remove (proxy->priv->new_rows, rm);
proxy->priv->all_modifs = g_slist_remove (proxy->priv->all_modifs, rm);
- g_hash_table_remove (proxy->priv->modify_rows, GINT_TO_POINTER (rm->model_row));
+
+ gint tmp;
+ tmp = rm->model_row;
+ g_hash_table_remove (proxy->priv->modify_rows, &tmp);
row_modifs_free (rm);
}
}
@@ -2855,8 +2885,11 @@ gda_data_proxy_cancel_all_changes (GdaDataProxy *proxy)
proxy_row = row_modif_to_proxy_row (proxy, (ROW_MODIF (proxy->priv->all_modifs->data)));
row_modifs_free (ROW_MODIF (proxy->priv->all_modifs->data));
- if (model_row >= 0)
- g_hash_table_remove (proxy->priv->modify_rows, GINT_TO_POINTER (model_row));
+ if (model_row >= 0) {
+ gint tmp;
+ tmp = model_row;
+ g_hash_table_remove (proxy->priv->modify_rows, &tmp);
+ }
proxy->priv->all_modifs = g_slist_delete_link (proxy->priv->all_modifs, proxy->priv->all_modifs);
if ((proxy_row >= 0) && proxy->priv->notify_changes)
@@ -3791,7 +3824,9 @@ gda_data_proxy_set_value_at (GdaDataModel *model, gint col, gint proxy_row, cons
if (!rm->to_be_deleted && !rm->modify_values && (rm->model_row >= 0)) {
/* remove that RowModif, it's useless */
- g_hash_table_remove (proxy->priv->modify_rows, GINT_TO_POINTER (rm->model_row));
+ gint tmp;
+ tmp = rm->model_row;
+ g_hash_table_remove (proxy->priv->modify_rows, &tmp);
proxy->priv->all_modifs = g_slist_remove (proxy->priv->all_modifs, rm);
row_modifs_free (rm);
}
diff --git a/libgda/gda-data-select.c b/libgda/gda-data-select.c
index 92293c3..6cdc6cb 100644
--- a/libgda/gda-data-select.c
+++ b/libgda/gda-data-select.c
@@ -63,7 +63,7 @@ static gint external_to_internal_row (GdaDataSelect *model, gint ext_row, GError
typedef struct {
GSList *columns; /* list of GdaColumn objects */
GArray *rows; /* Array of GdaRow pointers */
- GHashTable *index; /* key = model row number + 1, value = index in @rows array + 1*/
+ GHashTable *index; /* key = model row number, value = index in @rows array*/
/* Internal iterator's information, if GDA_DATA_MODEL_CURSOR_* based access */
gint iter_row; /* G_MININT if at start, G_MAXINT if at end, "external" row number */
@@ -330,7 +330,7 @@ gda_data_select_init (GdaDataSelect *model, G_GNUC_UNUSED GdaDataSelectClass *kl
model->priv->sh = g_new0 (PrivateShareable, 1);
model->priv->sh-> notify_changes = TRUE;
model->priv->sh->rows = g_array_new (FALSE, FALSE, sizeof (GdaRow *));
- model->priv->sh->index = g_hash_table_new (g_direct_hash, g_direct_equal);
+ model->priv->sh->index = g_hash_table_new_full (g_int_hash, g_int_equal, g_free, NULL);
model->prep_stmt = NULL;
model->priv->sh->columns = NULL;
model->nb_stored_rows = 0;
@@ -785,14 +785,18 @@ gda_data_select_get_property (GObject *object,
void
gda_data_select_take_row (GdaDataSelect *model, GdaRow *row, gint rownum)
{
+ gint tmp, *ptr;
g_return_if_fail (GDA_IS_DATA_SELECT (model));
g_return_if_fail (GDA_IS_ROW (row));
- if (g_hash_table_lookup (model->priv->sh->index, GINT_TO_POINTER (rownum + 1)))
+ tmp = rownum;
+ if (g_hash_table_lookup (model->priv->sh->index, &tmp))
g_error ("INTERNAL error: row %d already exists, aborting", rownum);
- g_hash_table_insert (model->priv->sh->index, GINT_TO_POINTER (rownum + 1),
- GINT_TO_POINTER (model->priv->sh->rows->len + 1));
+ ptr = g_new (gint, 2);
+ ptr [0] = rownum;
+ ptr [1] = model->priv->sh->rows->len;
+ g_hash_table_insert (model->priv->sh->index, ptr, ptr+1);
g_array_append_val (model->priv->sh->rows, row);
model->nb_stored_rows = model->priv->sh->rows->len;
}
@@ -809,15 +813,16 @@ gda_data_select_take_row (GdaDataSelect *model, GdaRow *row, gint rownum)
GdaRow *
gda_data_select_get_stored_row (GdaDataSelect *model, gint rownum)
{
- gint irow;
+ gint irow, *ptr;
g_return_val_if_fail (GDA_IS_DATA_SELECT (model), NULL);
g_return_val_if_fail (model->priv, NULL);
- irow = GPOINTER_TO_INT (g_hash_table_lookup (model->priv->sh->index, GINT_TO_POINTER (rownum + 1)));
- if (irow <= 0)
- return NULL;
+ irow = rownum;
+ ptr = g_hash_table_lookup (model->priv->sh->index, &irow);
+ if (ptr)
+ return g_array_index (model->priv->sh->rows, GdaRow *, *ptr);
else
- return g_array_index (model->priv->sh->rows, GdaRow *, irow - 1);
+ return NULL;
}
/**
@@ -1831,16 +1836,17 @@ gda_data_select_get_value_at (GdaDataModel *model, gint col, gint row, GError **
prow = dstmt->row;
}
else {
- irow = GPOINTER_TO_INT (g_hash_table_lookup (imodel->priv->sh->index,
- GINT_TO_POINTER (int_row + 1)));
- if (irow <= 0) {
+ gint *ptr;
+ irow = int_row;
+ ptr = g_hash_table_lookup (imodel->priv->sh->index, &irow);
+ if (!ptr) {
prow = NULL;
if (CLASS (model)->fetch_random &&
!CLASS (model)->fetch_random (imodel, &prow, int_row, error))
return NULL;
}
else
- prow = g_array_index (imodel->priv->sh->rows, GdaRow *, irow - 1);
+ prow = g_array_index (imodel->priv->sh->rows, GdaRow *, *ptr);
}
g_assert (prow);
@@ -1930,9 +1936,11 @@ gda_data_select_iter_next (GdaDataModel *model, GdaDataModelIter *iter)
target_iter_row = imodel->priv->sh->iter_row + 1;
int_row = external_to_internal_row (imodel, target_iter_row, NULL);
- irow = GPOINTER_TO_INT (g_hash_table_lookup (imodel->priv->sh->index, GINT_TO_POINTER (int_row + 1)));
- if (irow > 0)
- prow = g_array_index (imodel->priv->sh->rows, GdaRow *, irow - 1);
+ gint *ptr;
+ irow = int_row;
+ ptr = g_hash_table_lookup (imodel->priv->sh->index, &irow);
+ if (ptr)
+ prow = g_array_index (imodel->priv->sh->rows, GdaRow *, *ptr);
else if (!CLASS (model)->fetch_next (imodel, &prow, int_row, NULL)) {
/* an error occurred */
g_object_set (G_OBJECT (iter), "current-row", target_iter_row, NULL);
@@ -1981,10 +1989,12 @@ gda_data_select_iter_prev (GdaDataModel *model, GdaDataModelIter *iter)
else
target_iter_row = imodel->priv->sh->iter_row - 1;
+ gint *ptr;
int_row = external_to_internal_row (imodel, target_iter_row, NULL);
- irow = GPOINTER_TO_INT (g_hash_table_lookup (imodel->priv->sh->index, GINT_TO_POINTER (int_row + 1)));
- if (irow > 0)
- prow = g_array_index (imodel->priv->sh->rows, GdaRow *, irow - 1);
+ irow = int_row;
+ ptr = g_hash_table_lookup (imodel->priv->sh->index, &irow);
+ if (ptr)
+ prow = g_array_index (imodel->priv->sh->rows, GdaRow *, *ptr);
else if (!CLASS (model)->fetch_prev (imodel, &prow, int_row, NULL)) {
/* an error occurred */
g_object_set (G_OBJECT (iter), "current-row", target_iter_row, NULL);
@@ -2007,7 +2017,7 @@ gda_data_select_iter_at_row (GdaDataModel *model, GdaDataModelIter *iter, gint r
{
GdaDataSelect *imodel;
GdaRow *prow = NULL;
- gint irow, int_row;
+ gint irow, int_row, *ptr;
imodel = (GdaDataSelect *) model;
g_return_val_if_fail (imodel->priv, FALSE);
@@ -2019,10 +2029,10 @@ gda_data_select_iter_at_row (GdaDataModel *model, GdaDataModelIter *iter, gint r
g_return_val_if_fail (iter, FALSE);
g_return_val_if_fail (imodel->priv->iter == iter, FALSE);
- irow = GPOINTER_TO_INT (g_hash_table_lookup (imodel->priv->sh->index,
- GINT_TO_POINTER (int_row + 1)));
- if (irow > 0)
- prow = g_array_index (imodel->priv->sh->rows, GdaRow *, irow - 1);
+ irow = int_row;
+ ptr = g_hash_table_lookup (imodel->priv->sh->index, &irow);
+ if (ptr)
+ prow = g_array_index (imodel->priv->sh->rows, GdaRow *, *ptr);
if (CLASS (model)->fetch_at) {
if (!CLASS (model)->fetch_at (imodel, &prow, int_row, NULL)) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]