[vte] [ring] Use gulong instead of guint for row/col indices



commit 723aec79c9aa7c05b86278d0f304d0640ba9ee5e
Author: Behdad Esfahbod <behdad behdad org>
Date:   Fri Oct 23 18:19:40 2009 -0400

    [ring] Use gulong instead of guint for row/col indices
    
    Bug 599444 - Scrollback index type mess

 src/buffer.h      |    2 +-
 src/ring.c        |   68 ++++++++++++++++++++++++++--------------------------
 src/ring.h        |   34 +++++++++++++-------------
 src/vte-private.h |    4 +-
 src/vte.c         |   10 ++++---
 src/vterowdata.c  |   20 +++++++-------
 src/vterowdata.h  |   12 ++++----
 7 files changed, 76 insertions(+), 74 deletions(-)
---
diff --git a/src/buffer.h b/src/buffer.h
index 58b396a..987a6a8 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -36,7 +36,7 @@ typedef GByteArray VteBuffer;
 #define _vte_buffer_length(B)			((B)->len)
 #define _vte_buffer_consume(B, length)		g_byte_array_remove_range (B, 0, length)
 #define _vte_buffer_clear(B)			g_byte_array_set_size (B, 0)
-#define _vte_buffer_set_minimum_size(B, length)	g_byte_array_set_size (B, MAX ((length), (B)->len))
+#define _vte_buffer_set_minimum_size(B, length)	g_byte_array_set_size (B, (guint) MAX ((gint) (length), (gint) (B)->len))
 
 G_END_DECLS
 
diff --git a/src/ring.c b/src/ring.c
index 908acd6..3c0a0bb 100644
--- a/src/ring.c
+++ b/src/ring.c
@@ -51,7 +51,7 @@ _vte_ring_validate (VteRing * ring)
 
 
 void
-_vte_ring_init (VteRing *ring, guint max_rows)
+_vte_ring_init (VteRing *ring, gulong max_rows)
 {
 	_vte_debug_print(VTE_DEBUG_RING, "New ring %p.\n", ring);
 
@@ -71,7 +71,7 @@ _vte_ring_init (VteRing *ring, guint max_rows)
 	ring->utf8_buffer = g_string_sized_new (128);
 
 	_vte_row_data_init (&ring->cached_row);
-	ring->cached_row_num = (guint) -1;
+	ring->cached_row_num = (gulong) -1;
 
 	_vte_ring_validate(ring);
 }
@@ -79,7 +79,7 @@ _vte_ring_init (VteRing *ring, guint max_rows)
 void
 _vte_ring_fini (VteRing *ring)
 {
-	guint i;
+	gulong i;
 
 	for (i = 0; i <= ring->mask; i++)
 		_vte_row_data_fini (&ring->array[i]);
@@ -101,19 +101,19 @@ typedef struct _VteRowRecord {
 } VteRowRecord;
 
 static gboolean
-_vte_ring_read_row_record (VteRing *ring, VteRowRecord *record, guint position)
+_vte_ring_read_row_record (VteRing *ring, VteRowRecord *record, gulong position)
 {
 	return _vte_stream_read (ring->row_stream, position * sizeof (*record), (char *) record, sizeof (*record));
 }
 
 static void
-_vte_ring_append_row_record (VteRing *ring, const VteRowRecord *record, guint position)
+_vte_ring_append_row_record (VteRing *ring, const VteRowRecord *record, gulong position)
 {
 	_vte_stream_append (ring->row_stream, (const char *) record, sizeof (*record));
 }
 
 static void
-_vte_ring_freeze_row (VteRing *ring, guint position, const VteRowData *row)
+_vte_ring_freeze_row (VteRing *ring, gulong position, const VteRowData *row)
 {
 	VteRowRecord record;
 	VteCell *cell;
@@ -121,7 +121,7 @@ _vte_ring_freeze_row (VteRing *ring, guint position, const VteRowData *row)
 	guint32 basic_attr = basic_cell.i.attr;
 	int i;
 
-	_vte_debug_print (VTE_DEBUG_RING, "Freezing row %d.\n", position);
+	_vte_debug_print (VTE_DEBUG_RING, "Freezing row %lu.\n", position);
 
 	record.text_offset = _vte_stream_head (ring->text_stream);
 	record.attr_offset = _vte_stream_head (ring->attr_stream);
@@ -177,7 +177,7 @@ _vte_ring_freeze_row (VteRing *ring, guint position, const VteRowData *row)
 }
 
 static void
-_vte_ring_thaw_row (VteRing *ring, guint position, VteRowData *row, gboolean truncate)
+_vte_ring_thaw_row (VteRing *ring, gulong position, VteRowData *row, gboolean truncate)
 {
 	VteRowRecord records[2], record;
 	VteIntCellAttr attr;
@@ -187,7 +187,7 @@ _vte_ring_thaw_row (VteRing *ring, guint position, VteRowData *row, gboolean tru
 	GString *buffer = ring->utf8_buffer;
 	guint32 basic_attr = basic_cell.i.attr;
 
-	_vte_debug_print (VTE_DEBUG_RING, "Thawing row %d.\n", position);
+	_vte_debug_print (VTE_DEBUG_RING, "Thawing row %lu.\n", position);
 
 	_vte_row_data_clear (row);
 
@@ -265,9 +265,9 @@ _vte_ring_thaw_row (VteRing *ring, guint position, VteRowData *row, gboolean tru
 }
 
 static void
-_vte_ring_reset_streams (VteRing *ring, guint position)
+_vte_ring_reset_streams (VteRing *ring, gulong position)
 {
-	_vte_debug_print (VTE_DEBUG_RING, "Reseting streams to %d.\n", position);
+	_vte_debug_print (VTE_DEBUG_RING, "Reseting streams to %lu.\n", position);
 
 	_vte_stream_reset (ring->row_stream, position * sizeof (VteRowRecord));
 	_vte_stream_reset (ring->text_stream, 0);
@@ -282,7 +282,7 @@ _vte_ring_reset_streams (VteRing *ring, guint position)
 static void
 _vte_ring_new_page (VteRing *ring)
 {
-	_vte_debug_print (VTE_DEBUG_RING, "Starting new stream page at %d.\n", ring->writable);
+	_vte_debug_print (VTE_DEBUG_RING, "Starting new stream page at %lu.\n", ring->writable);
 
 	_vte_stream_new_page (ring->attr_stream);
 	_vte_stream_new_page (ring->text_stream);
@@ -294,19 +294,19 @@ _vte_ring_new_page (VteRing *ring)
 
 
 static inline VteRowData *
-_vte_ring_writable_index (VteRing *ring, guint position)
+_vte_ring_writable_index (VteRing *ring, gulong position)
 {
 	return &ring->array[position & ring->mask];
 }
 
 const VteRowData *
-_vte_ring_index (VteRing *ring, guint position)
+_vte_ring_index (VteRing *ring, gulong position)
 {
 	if (G_LIKELY (position >= ring->writable))
 		return _vte_ring_writable_index (ring, position);
 
 	if (ring->cached_row_num != position) {
-		_vte_debug_print(VTE_DEBUG_RING, "Caching row %d.\n", position);
+		_vte_debug_print(VTE_DEBUG_RING, "Caching row %lu.\n", position);
 		_vte_ring_thaw_row (ring, position, &ring->cached_row, FALSE);
 		ring->cached_row_num = position;
 	}
@@ -314,11 +314,11 @@ _vte_ring_index (VteRing *ring, guint position)
 	return &ring->cached_row;
 }
 
-static void _vte_ring_ensure_writable (VteRing *ring, guint position);
+static void _vte_ring_ensure_writable (VteRing *ring, gulong position);
 static void _vte_ring_ensure_writable_room (VteRing *ring);
 
 VteRowData *
-_vte_ring_index_writable (VteRing *ring, guint position)
+_vte_ring_index_writable (VteRing *ring, gulong position)
 {
 	_vte_ring_ensure_writable (ring, position);
 	return _vte_ring_writable_index (ring, position);
@@ -353,7 +353,7 @@ _vte_ring_thaw_one_row (VteRing *ring)
 	ring->writable--;
 
 	if (ring->writable == ring->cached_row_num)
-		ring->cached_row_num = (guint) -1; /* Invalidate cached row */
+		ring->cached_row_num = (gulong) -1; /* Invalidate cached row */
 
 	row = _vte_ring_writable_index (ring, ring->writable);
 
@@ -381,14 +381,14 @@ _vte_ring_maybe_freeze_one_row (VteRing *ring)
 static void
 _vte_ring_maybe_discard_one_row (VteRing *ring)
 {
-	if (_vte_ring_length (ring) == ring->max)
+	if ((gulong) _vte_ring_length (ring) == ring->max)
 		_vte_ring_discard_one_row (ring);
 }
 
 static void
 _vte_ring_ensure_writable_room (VteRing *ring)
 {
-	guint new_mask, old_mask, i, end;
+	gulong new_mask, old_mask, i, end;
 	VteRowData *old_array, *new_array;;
 
 	if (G_LIKELY (ring->writable + ring->mask > ring->end))
@@ -413,12 +413,12 @@ _vte_ring_ensure_writable_room (VteRing *ring)
 }
 
 static void
-_vte_ring_ensure_writable (VteRing *ring, guint position)
+_vte_ring_ensure_writable (VteRing *ring, gulong position)
 {
 	if (G_LIKELY (position >= ring->writable))
 		return;
 
-	_vte_debug_print(VTE_DEBUG_RING, "Ensure writable %d.\n", position);
+	_vte_debug_print(VTE_DEBUG_RING, "Ensure writable %lu.\n", position);
 
 	while (position < ring->writable)
 		_vte_ring_thaw_one_row (ring);
@@ -432,13 +432,13 @@ _vte_ring_ensure_writable (VteRing *ring, guint position)
  * Changes the number of lines the ring can contain.
  */
 void
-_vte_ring_resize (VteRing *ring, guint max_rows)
+_vte_ring_resize (VteRing *ring, gulong max_rows)
 {
-	_vte_debug_print(VTE_DEBUG_RING, "Resizing to %d.\n", max_rows);
+	_vte_debug_print(VTE_DEBUG_RING, "Resizing to %lu.\n", max_rows);
 	_vte_ring_validate(ring);
 
 	/* Adjust the start of tail chunk now */
-	if (_vte_ring_length (ring) > max_rows) {
+	if ((gulong) _vte_ring_length (ring) > max_rows) {
 		ring->start = ring->end - max_rows;
 		if (ring->start >= ring->writable) {
 			_vte_ring_reset_streams (ring, 0);
@@ -450,12 +450,12 @@ _vte_ring_resize (VteRing *ring, guint max_rows)
 }
 
 void
-_vte_ring_shrink (VteRing *ring, guint max_len)
+_vte_ring_shrink (VteRing *ring, gulong max_len)
 {
-	if (_vte_ring_length (ring) <= max_len)
+	if ((gulong) _vte_ring_length (ring) <= max_len)
 		return;
 
-	_vte_debug_print(VTE_DEBUG_RING, "Shrinking to %d.\n", max_len);
+	_vte_debug_print(VTE_DEBUG_RING, "Shrinking to %lu.\n", max_len);
 	_vte_ring_validate(ring);
 
 	if (ring->writable - ring->start <= max_len)
@@ -483,12 +483,12 @@ _vte_ring_shrink (VteRing *ring, guint max_len)
  * Return: the newly added row.
  */
 VteRowData *
-_vte_ring_insert (VteRing *ring, guint position)
+_vte_ring_insert (VteRing *ring, gulong position)
 {
-	guint i;
+	gulong i;
 	VteRowData *row, tmp;
 
-	_vte_debug_print(VTE_DEBUG_RING, "Inserting at position %u.\n", position);
+	_vte_debug_print(VTE_DEBUG_RING, "Inserting at position %lu.\n", position);
 	_vte_ring_validate(ring);
 
 	_vte_ring_maybe_discard_one_row (ring);
@@ -521,12 +521,12 @@ _vte_ring_insert (VteRing *ring, guint position)
  * Removes the @position'th item from @ring.
  */
 void
-_vte_ring_remove (VteRing * ring, guint position)
+_vte_ring_remove (VteRing * ring, gulong position)
 {
-	guint i;
+	gulong i;
 	VteRowData tmp;
 
-	_vte_debug_print(VTE_DEBUG_RING, "Removing item at position %u.\n", position);
+	_vte_debug_print(VTE_DEBUG_RING, "Removing item at position %lu.\n", position);
 	_vte_ring_validate(ring);
 
 	g_assert (_vte_ring_contains (ring, position));
diff --git a/src/ring.h b/src/ring.h
index 9019664..5bc2534 100644
--- a/src/ring.h
+++ b/src/ring.h
@@ -39,42 +39,42 @@ typedef struct _VteCellAttrChange {
 
 typedef struct _VteRing VteRing;
 struct _VteRing {
-	guint max;
+	gulong max;
 
-	guint start, end;
+	gulong start, end;
 
 	/* Writable */
-	guint writable, mask;
+	gulong writable, mask;
 	VteRowData *array;
 
 	/* Storage */
-	guint last_page;
+	gulong last_page;
 	VteStream *attr_stream, *text_stream, *row_stream;
 	VteCellAttrChange last_attr;
 	GString *utf8_buffer;
 
 	VteRowData cached_row;
-	guint cached_row_num;
+	gulong cached_row_num;
 
 };
 
 #define _vte_ring_contains(__ring, __position) \
-	(((__position) >= (__ring)->start) && \
-	 ((__position) < (__ring)->end))
-#define _vte_ring_delta(__ring) ((__ring)->start + 0)
-#define _vte_ring_length(__ring) ((__ring)->end - (__ring)->start)
-#define _vte_ring_next(__ring) ((__ring)->end + 0)
+	(((gulong) (__position) >= (__ring)->start) && \
+	 ((gulong) (__position) < (__ring)->end))
+#define _vte_ring_delta(__ring) ((glong) (__ring)->start)
+#define _vte_ring_length(__ring) ((glong) ((__ring)->end - (__ring)->start))
+#define _vte_ring_next(__ring) ((glong) (__ring)->end)
 
-const VteRowData *_vte_ring_index (VteRing *ring, guint position);
-VteRowData *_vte_ring_index_writable (VteRing *ring, guint position);
+const VteRowData *_vte_ring_index (VteRing *ring, gulong position);
+VteRowData *_vte_ring_index_writable (VteRing *ring, gulong position);
 
-void _vte_ring_init (VteRing *ring, guint max_rows);
+void _vte_ring_init (VteRing *ring, gulong max_rows);
 void _vte_ring_fini (VteRing *ring);
-void _vte_ring_resize (VteRing *ring, guint max_rows);
-void _vte_ring_shrink (VteRing *ring, guint max_len);
-VteRowData *_vte_ring_insert (VteRing *ring, guint position);
+void _vte_ring_resize (VteRing *ring, gulong max_rows);
+void _vte_ring_shrink (VteRing *ring, gulong max_len);
+VteRowData *_vte_ring_insert (VteRing *ring, gulong position);
 VteRowData *_vte_ring_append (VteRing *ring);
-void _vte_ring_remove (VteRing *ring, guint position);
+void _vte_ring_remove (VteRing *ring, gulong position);
 
 G_END_DECLS
 
diff --git a/src/vte-private.h b/src/vte-private.h
index e7ae90b..7513d12 100644
--- a/src/vte-private.h
+++ b/src/vte-private.h
@@ -416,9 +416,9 @@ void _vte_terminal_beep(VteTerminal *terminal);
 
 void _vte_terminal_inline_error_message(VteTerminal *terminal, const char *format, ...) G_GNUC_PRINTF(2,3);
 
-VteRowData *_vte_terminal_ring_insert (VteTerminal *terminal, guint position, gboolean fill);
+VteRowData *_vte_terminal_ring_insert (VteTerminal *terminal, glong position, gboolean fill);
 VteRowData *_vte_terminal_ring_append (VteTerminal *terminal, gboolean fill);
-void _vte_terminal_ring_remove (VteTerminal *terminal, guint position);
+void _vte_terminal_ring_remove (VteTerminal *terminal, glong position);
 
 /* vteseq.c: */
 void _vte_terminal_handle_sequence(VteTerminal *terminal,
diff --git a/src/vte.c b/src/vte.c
index bc9c181..f8eb3ad 100644
--- a/src/vte.c
+++ b/src/vte.c
@@ -286,7 +286,7 @@ vte_g_array_fill(GArray *array, gconstpointer item, guint final_size)
 
 
 VteRowData *
-_vte_terminal_ring_insert (VteTerminal *terminal, guint position, gboolean fill)
+_vte_terminal_ring_insert (VteTerminal *terminal, glong position, gboolean fill)
 {
 	VteRowData *row;
 	VteRing *ring = terminal->pvt->screen->row_data;
@@ -307,7 +307,7 @@ _vte_terminal_ring_append (VteTerminal *terminal, gboolean fill)
 }
 
 void
-_vte_terminal_ring_remove (VteTerminal *terminal, guint position)
+_vte_terminal_ring_remove (VteTerminal *terminal, glong position)
 {
 	_vte_ring_remove (terminal->pvt->screen->row_data, position);
 }
@@ -8073,13 +8073,15 @@ vte_terminal_size_allocate(GtkWidget *widget, GtkAllocation *allocation)
 
 	if (width != terminal->column_count
 			|| height != terminal->row_count
-			|| update_scrollback) {
+			|| update_scrollback)
+	{
+		VteScreen *screen = terminal->pvt->screen;
+
 		/* Set the size of the pseudo-terminal. */
 		vte_terminal_set_size(terminal, width, height);
 
 		/* Adjust scrolling area in case our boundaries have just been
 		 * redefined to be invalid. */
-		VteScreen *screen = terminal->pvt->screen;
 		if (screen->scrolling_restricted) {
 			screen->scrolling_region.start =
 				MIN(screen->scrolling_region.start,
diff --git a/src/vterowdata.c b/src/vterowdata.c
index fadd434..1a29523 100644
--- a/src/vterowdata.c
+++ b/src/vterowdata.c
@@ -46,9 +46,9 @@ _vte_cells_for_cell_array (VteCell *cells)
 }
 
 static VteCells *
-_vte_cells_realloc (VteCells *cells, guint len)
+_vte_cells_realloc (VteCells *cells, guint32 len)
 {
-	guint alloc_len = (1 << g_bit_storage (MAX (len, 80))) - 1;
+	guint32 alloc_len = (1 << g_bit_storage (MAX (len, 80))) - 1;
 
 	_vte_debug_print(VTE_DEBUG_RING, "Enlarging cell array of %d cells to %d cells\n", cells ? cells->alloc_len : 0, alloc_len);
 	cells = g_realloc (cells, G_STRUCT_OFFSET (VteCells, cells) + alloc_len * sizeof (cells->cells[0]));
@@ -92,7 +92,7 @@ _vte_row_data_fini (VteRowData *row)
 }
 
 static inline gboolean
-_vte_row_data_ensure (VteRowData *row, guint len)
+_vte_row_data_ensure (VteRowData *row, gulong len)
 {
 	VteCells *cells = _vte_cells_for_cell_array (row->cells);
 	if (G_LIKELY (cells && len <= cells->alloc_len))
@@ -107,9 +107,9 @@ _vte_row_data_ensure (VteRowData *row, guint len)
 }
 
 void
-_vte_row_data_insert (VteRowData *row, guint col, const VteCell *cell)
+_vte_row_data_insert (VteRowData *row, gulong col, const VteCell *cell)
 {
-	guint i;
+	gulong i;
 
 	if (G_UNLIKELY (!_vte_row_data_ensure (row, row->len + 1)))
 		return;
@@ -130,9 +130,9 @@ void _vte_row_data_append (VteRowData *row, const VteCell *cell)
 	row->len++;
 }
 
-void _vte_row_data_remove (VteRowData *row, guint col)
+void _vte_row_data_remove (VteRowData *row, gulong col)
 {
-	guint i;
+	gulong i;
 
 	for (i = col + 1; i < row->len; i++)
 		row->cells[i - 1] = row->cells[i];
@@ -141,10 +141,10 @@ void _vte_row_data_remove (VteRowData *row, guint col)
 		row->len--;
 }
 
-void _vte_row_data_fill (VteRowData *row, const VteCell *cell, guint len)
+void _vte_row_data_fill (VteRowData *row, const VteCell *cell, gulong len)
 {
 	if (row->len < len) {
-		guint i = len - row->len;
+		gulong i = len - row->len;
 
 		if (G_UNLIKELY (!_vte_row_data_ensure (row, len)))
 			return;
@@ -156,7 +156,7 @@ void _vte_row_data_fill (VteRowData *row, const VteCell *cell, guint len)
 	}
 }
 
-void _vte_row_data_shrink (VteRowData *row, guint max_len)
+void _vte_row_data_shrink (VteRowData *row, gulong max_len)
 {
 	if (max_len < row->len)
 		row->len = max_len;
diff --git a/src/vterowdata.h b/src/vterowdata.h
index 1ad4c70..769deec 100644
--- a/src/vterowdata.h
+++ b/src/vterowdata.h
@@ -142,7 +142,7 @@ typedef struct _VteRowData {
 #define _vte_row_data_length(__row)			((__row)->len + 0)
 
 static inline const VteCell *
-_vte_row_data_get (const VteRowData *row, guint col)
+_vte_row_data_get (const VteRowData *row, gulong col)
 {
 	if (G_UNLIKELY (row->len <= col))
 		return NULL;
@@ -151,7 +151,7 @@ _vte_row_data_get (const VteRowData *row, guint col)
 }
 
 static inline VteCell *
-_vte_row_data_get_writable (VteRowData *row, guint col)
+_vte_row_data_get_writable (VteRowData *row, gulong col)
 {
 	if (G_UNLIKELY (row->len <= col))
 		return NULL;
@@ -162,11 +162,11 @@ _vte_row_data_get_writable (VteRowData *row, guint col)
 void _vte_row_data_init (VteRowData *row);
 void _vte_row_data_clear (VteRowData *row);
 void _vte_row_data_fini (VteRowData *row);
-void _vte_row_data_insert (VteRowData *row, guint col, const VteCell *cell);
+void _vte_row_data_insert (VteRowData *row, gulong col, const VteCell *cell);
 void _vte_row_data_append (VteRowData *row, const VteCell *cell);
-void _vte_row_data_remove (VteRowData *row, guint col);
-void _vte_row_data_fill (VteRowData *row, const VteCell *cell, guint len);
-void _vte_row_data_shrink (VteRowData *row, guint max_len);
+void _vte_row_data_remove (VteRowData *row, gulong col);
+void _vte_row_data_fill (VteRowData *row, const VteCell *cell, gulong len);
+void _vte_row_data_shrink (VteRowData *row, gulong max_len);
 
 
 G_END_DECLS



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