heads up: glib changes will break array code

I just commited a set of changes to glib.  There are big changes
to correct major problems with the GArray interface and a few name
changes for consistency while we're at it.  

I'm sorry it came to this, but people were using GArray code that
Peter originally stuck in glib before it was "ready".  As a result,
the length field of the GArray is in bytes, not elements.  This is
a major problem because the len field is tempting to use but yields
the wrong result, forcing the use of g_array_length(ARRAY,TYPE) which
is quite a lengthy expression for getting the array's length.  While
at it, I removed as much of the Type-name-as-an-argument-to-the-accessor
as possible, it only remains in g_array_index, where it casts to the
appropriate type.

Here's the Changelog:

Tue Sep  1 23:46:31 1998  Josh MacDonald  <jmacd@axis.hip.berkeley.edu>

	* testglib.c (main): Update the array tests.  Reduce the number of
	iterations for the prepend test from 10000 to 100 since it is
	O(n^2) and was taking longer than I would like to wait.

	* garray.c: I've worked on the GArray interface, mostly.  It was
 	seriously broken before and I hate to do it, but this is going to
 	break some code.  It is important to do this now, because more and
 	more people are starting to use glib and the interface was both
 	broken and inconsistent.  First, rename the _truncate functions of
 	both the GArray and GPtrArray classes to _set_size, since this
 	function can also be used to extend the arrays.  GArray now
 	accepts two more initialization arguments: clear and element_size.
  	Instead of providing the type to each access function, the array
 	now stores the element size.  Clear, if set, causes the library to
 	zero element's memory as the array expands.  The major broken-ness
 	here was that array->len was in bytes, not elements.  Now, since
 	the array knows its element size, array->len is correct and I have
 	removed the g_array_length macro.  The only macro which now
 	accepts the type as an argument is g_array_index, which casts the
 	element to the right type--this interface does not change.  The
 	append and prepend functions simply need the types removed.
  	g_ptr_array_remove_index now returns the removed element.

	* gprimes.c (g_spaced_primes_closest): Move this function out of
 	ghash.c and rename it from g_hash_closest_prime.  Fix the primes
 	so that they are actually prime (they weren't all -- isn't that

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