Commit Graph

76 Commits

Author SHA1 Message Date
Matthias Clasen
c575d24dfb Docs: Don't use the note tag
More markup avoidance.
2014-01-31 18:20:06 -05:00
Daniel Mustieles
078dbda148 Updated FSF's address 2014-01-31 14:31:55 +01:00
Matthias Clasen
3d42934b71 Docs: don't use the structname tag
Just avoid explicit docbook markup.
2014-01-31 00:29:14 -05:00
Tristan Van Berkom
9ed0d0c509 GPtrArray: Added g_ptr_array_insert()
Speaks for itself, I've found myself on numerous occasions
writing my own version of this, or using a GArray of pointers.

https://bugzilla.gnome.org/show_bug.cgi?id=719395
2013-12-14 23:41:44 -05:00
Matthias Clasen
616af3b80e Avoid a compiler warning 2013-11-24 00:59:35 -05:00
Matthias Clasen
dedc990e28 Fix array API inconsistency
g_array_remove_range and g_byte_array_remove_range return
a pointer to the array, g_ptr_array_remove_range returns
void. Since it is pretty harmless, make it return the array
too.

https://bugzilla.gnome.org/show_bug.cgi?id=159528
2013-11-23 21:10:06 -05:00
Dan Winship
6e4a7fca43 Require C90 compliance
Assume all supported platforms implement C90, and therefore they
(correctly) implement atexit(), memmove(), setlocale(), strerror(),
and vprintf(), and have <float.h> and <limits.h>.

(Also remove the configure check testing that "do ... while (0)" works
correctly; the non-do/while-based version of G_STMT_START and
G_STMT_END was removed years ago, but the check remained. Also, remove
some checks that configure.ac claimed were needed for libcharset, but
aren't actually used.)

Note that removing the g_memmove() function is not an ABI break even
on systems where g_memmove() was previously not a macro, because it
was never marked GLIB_AVAILABLE_IN_ALL or listed in glib.symbols, so
it would have been glib-internal since 2004.

https://bugzilla.gnome.org/show_bug.cgi?id=710519
2013-11-20 09:16:16 -05:00
Philip Withnall
4af135ce49 garray: Note lack of bounds checking in g_ptr_array_index() documentation 2013-11-05 16:43:26 +00:00
Martin Pitt
a07a5f82aa GByteArray: Add missing transfer annotations
Make g_byte_array_new() and g_byte_array_new_take() introspectable by adding
missing transfer annotations to return value.

Covered by tests in PyGObject.
2012-11-09 09:32:03 +01:00
Robert Ancell
59a24ab5a3 Use "Returns:" instead of the invalid "@returns" for annotating return values.
https://bugzilla.gnome.org/show_bug.cgi?id=673229
2012-11-01 14:47:25 +13:00
Matthias Clasen
6270b3f384 Fix g_ptr_array_ref_docs
https://bugzilla.gnome.org/show_bug.cgi?id=676034
2012-09-23 11:16:26 -04:00
Robert Ancell
4143842eb4 Add missing allow-none annotations for function parameters.
Found using:
find . -name '*.c' | xargs grep 'or %NULL' | grep ' \* @' | grep -v '@error' | grep -v allow-none
2012-03-31 20:34:28 +11:00
Alexander Larsson
a43dd7435a Make g_array_sort* methods use a stable sort
Also, remove previous comments about sort stability in g_array_sort docs,
as the method that was explained does not work. Adds a new comment
about this.

https://bugzilla.gnome.org/show_bug.cgi?id=672095
2012-03-16 16:04:36 +01:00
Guillaume Desmottes
ca949756de GArray: initialize the clear_func pointer
https://bugzilla.gnome.org/show_bug.cgi?id=668650
2012-01-25 12:04:12 +01:00
Emmanuele Bassi
c602a5f887 array: Add a clear function
Like GPtrArray has a "free function" that can be used to free memory
associated to each pointer in the array, GArray would benefit from
having a "clear function" that can be used to clear the content of
each element of the array when it's removed, or when the entire array
is freed.

https://bugzilla.gnome.org/show_bug.cgi?id=667243
2012-01-24 23:25:38 -05:00
Benjamin Otte
a6e149e41f array: return_if_fail() if element size is 0
This is particular useful for:
  g_array_new (sizeof (MyStruct), FALSE, FALSE);
because the correct incantation is
  g_array_new (FALSE, FALSE, sizeof (MyStruct));
and these warnings will trigger in the first situation.
2012-01-14 01:15:16 +01:00
Simon McVittie
e129deb017 g_array_free, g_ptr_array_free: decrement refcount if not the last ref
foo_free is conceptually "worth" one unref; not decrementing the
refcount here means the GArray or GPtrArray wrapper (but not its
contents) would leak in the following call sequence:

    p = g_ptr_array_new ();
    g_ptr_array_ref (p);
    g_ptr_array_free (p, TRUE);
    g_ptr_array_unref (p);

Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=666113
Reviewed-by: Emmanuele Bassi <ebassi@linux.intel.com>
2011-12-14 18:10:31 +00:00
Simon McVittie
df9d9cc72f GArray, GPtrArray: factor out the actual freeing
Depending how the array is freed, we may want to free the underlying
array (the "segment"), the struct wrapper or both.

Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=666113
Reviewed-by: Emmanuele Bassi <ebassi@linux.intel.com>
2011-12-14 18:10:25 +00:00
Stef Walter
7e92997539 documentation fixes
Fixes for gtk-doc warnings.

http://bugzilla.gnome.org/show_bug.cgi?id=66469

https://bugzilla.gnome.org/show_bug.cgi?id=664699
2011-12-13 23:01:51 -05:00
Stef Walter
fcc69fd318 GBytes: A new type for an immutable set of bytes.
* Represents an immutable reference counted block of memory.
 * This is basically the internal glib GBuffer structure exposed,
   renamed, and with some additional capabilities.
 * The GBytes name comes from python3's immutable 'bytes' type
 * GBytes can be safely used as keys in hash tables, and have
   functions for doing so: g_bytes_hash, g_bytes_equal
 * GByteArray is a mutable form of GBytes, and vice versa. There
   are functions for converting from one to the other efficiently:
   g_bytes_unref_to_array() and g_byte_array_free_to_bytes()
 * Adds g_byte_array_new_take() to support above functions

https://bugzilla.gnome.org/show_bug.cgi?id=663291
2011-11-24 08:58:38 +01:00
Ryan Lortie
37c740d509 Don't #include <glib/gslice.h> from gmem.h
It looks like this was done just to help people port from gmem to
gslice, but nothing in this header actually requires gslice.h to be
included.
2011-09-18 22:07:18 -04:00
Xavier Claessens
eec69a75ee Add g_ptr_array_new_full
Fixes bug #654450
2011-07-22 10:19:48 +02:00
Matthias Clasen
75f7eef9cd Fix doc typos
Now with fewer broken links...
2011-06-04 14:43:52 -04:00
Matthias Clasen
666adc2dc0 Volatile not necessary after all
I was temporarily confused.
2011-05-28 22:33:37 -04:00
Matthias Clasen
edc7fde495 GArray: Avoid unncessary atomic accesses to refcounts
Not really necessary to double-check the ref-count.
2011-05-28 21:41:08 -04:00
Philip Withnall
2122191595 docs: Improve punctuation in some of the GArray method documentation 2011-05-15 15:31:16 +01:00
Benjamin Otte
cb7a5a8e94 docs: Add the cute trick comment to all sort functions
Thanks to Sebastian Dröge for pointing out there's more than
g_array_sort() and I hadn't in fact added the comment to g_array_sort()
in 80928ea403
2011-05-15 16:16:30 +02:00
Benjamin Otte
80928ea403 docs: Add a cute trick for achieving a stable sort
This trick is inspired by
http://www.gnu.org/s/hello/manual/libc/Array-Sort-Function.html
http://jeffreystedfast.blogspot.com/2011/04/optimizing-merge-sort.html
2011-05-15 16:13:55 +02:00
Johan Dahlin
fdaaa22b58 Correct gtk-doc SECTION: syntax
g-ir-scanner does not allow a space between the : and the
section name.
2011-02-01 16:18:02 -02:00
Matthias Clasen
de3c6efa22 Remove two redundant comments 2010-08-08 23:55:11 -04:00
Ryan Lortie
2e53e50244 glib/: fully remove galias hacks 2010-07-07 19:34:35 -04:00
Matthias Clasen
5fffa39b6a Fix a memory leak in g_ptr_array_remove_index_fast
We need to call the element_free_func even if we remove the
last element. Bug #618866.
2010-06-20 00:15:31 -04:00
Krzesimir Nowak
33b011ce7d Add checks for NULL pointer in arrays.
Fixes: Bug 599197 -  array ref and unref functions crash on NULL
array.

* garray.c: Added safety guards to all public functions, which did
not have them earlier. Now when NULL is passed to them, they will
issue a warning and return, instead of segfaulting.
2010-02-03 21:48:39 +01:00
Ryan Lortie
3443f47ddf G{Byte,Ptr,}Array: move docs from tmpl to .c 2010-02-01 12:39:29 -05:00
Sven Herzberg
7448eb71c3 properly abort instead of looping infinitely
Fixes: Bug 568760 - nautilus freezes due to a bug in garray.c:322

* glib/garray.c: increase the size of potential return values by
  using an unsigned result; properly check if we still handle valid size
  proposals, return the original request if there's no usable size left
* tests/array-test.c: reproduce the error condition of the bug report
2010-01-13 15:01:00 +01:00
Dan Winship
bc1dd5cf11 Call element_free_func when shrinking array with g_ptr_array_set_size 2009-09-07 12:35:51 -04:00
Dan Winship
92ac8d165e Misc warning fixes
glib/pcre/pcre_ucp_search_funcs.c, glib/pcre/pcre_valid_utf8.c: add
back missing config.h includes, and this time add them to the copies
in glib/update-pcre/ too so they don't get lost again on the next PCRE
update.

glib/garray.c, glib/gbase64.c: fix signed/unsigned pointer casts

gio/xdgmime/xdgmimeglob.c: remove unused variable

gio/tests/live-g-file.c: fix printf args on x86_64

tests/Makefile.am, tests/regex-test.c: remove redundant -DENABLE_REGEX
2009-05-01 10:37:45 -04:00
David Zeuthen
402847c887 Bug 580450 – Reference counting and boxed types for arrays
Add reference counting and boxed types for GArray, GByteArray and GPtrArray.

Signed-off-by: Matthias Clasen <mclasen@redhat.com>
2009-04-29 11:17:23 -04:00
Matthias Clasen
0f6b25ca96 Fix some compiler warnings
svn path=/trunk/; revision=7755
2008-12-31 05:51:47 +00:00
Tim Janik
eda944bca5 honour g_mem_gc_friendly settings when freeing slices, make sure
Wed Jan 25 16:39:18 2006  Tim Janik  <timj@imendio.com>

        * glib/gslice.c: honour g_mem_gc_friendly settings when freeing
        slices, make sure g_mem_gc_friendly is properly initialized.

        * gmem.[hc]: ensure g_mem_gc_friendly is initialized from G_DEBUG upon
        the first allocation. applied some branching optimizations.

        * docs/macros.txt: reflected --enable-gc-friendly change and
        described ENABLE_GC_FRIENDLY_DEFAULT as well as G_DEBUG=gc-friendly.

        * configure.in: changed --enable-gc-friendly=yes to define
        ENABLE_GC_FRIENDLY_DEFAULT.

        * glib/garray.c: changed ENABLE_GC_FRIENDLY macro #ifdef-s to
        if (G_UNLIKELY (g_mem_gc_friendly)).

        * glib/gtree.c:
        * glib/ghash.c: removed ENABLE_GC_FRIENDLY code which is now taken
        care of by g_slice_free1().

        * tests/slice-test.c: fixed leaks, reported by Kjartan Maraas.
2006-01-25 15:51:43 +00:00
Tim Janik
0cba1b531d prepared deprecation of GMemChunk and GAllocator. added g_slice_*() API to
Tue Nov  1 16:24:20 2005  Tim Janik  <timj@imendio.com>

        * glib/gmem.[hc]: prepared deprecation of GMemChunk and GAllocator.
        added g_slice_*() API to allocate and cache small bits of memory.
        an actuall allocator implementation for g_slice_*() is still pending.

        * glib/gthread.[hc]: changes from a patch by Matthias Clasen.
        changed GRealThread list to use in-structure *next; fields instead
        of GSList, in order for thread iteration to not depenend on g_slice_*()
        indirectly.
        _g_thread_mem_private_get():
        _g_thread_mem_private_set(): added accessors for private memory,
        needed because the ordinary GPrivate implementation relies on GArray
        and GSList and therefore indirectly on working g_slice_*() allocations.

        * glib/gthread.[hc]:
        g_thread_foreach(): new public API function to loop over all existing threads.

        * glib/gdataset.c:
        * glib/gstring.c:
        * glib/gcache.c:
        * glib/garray.c:
        * glib/gqueue.c:
        * glib/gslist.c:
        * glib/glist.c:
        * glib/ghash.c:
        * glib/gtree.c:
        * glib/ghook.c:
        * glib/gmain.c:
        * glib/gnode.c:
        removed GAllocator and free list usages and accompanying locks.
        use g_slice_*() API to allocate and cache small bits of memory.

        * glib/ghook.h: removed GMemChunk field from public API.

        * glib/gslist.h:
        * glib/glist.h: deprecate allocator API, provide _free1() for consistency.

        * glib/gnode.h: deprecate allocator API.

        * glib/gmain.c: reordered GPollRec fields so g_slice_free_chain() can
        be used for poll rec lists.

        * glib/grel.c: removed mem chunk usage, and allocated tuples via g_slice_*().
        g_relation_destroy(): free all tuples from the all_tuples hash table,
        this effectively maintains the life time track keeping of tuples.
        g_relation_delete_tuple(): free tuples which are removed from the
        all_tuples hash table. this fixes a temporary leak that was present
        in the memchunk code until the destruction of the relation.
2005-11-01 18:10:31 +00:00
Matthias Clasen
608a31b98e Make PLT-reduction work with gcc4, and don't include everything in
2005-03-13  Matthias Clasen  <mclasen@redhat.com>

	Make PLT-reduction work with gcc4, and don't include
	everything in galias.h:

	* glib/glib.symbols: Group symbols by header and source file.
	* glib/makegalias.pl: Protect definitions by the same
	preprocessor symbols used to guard the headers. Move
	the alias declarations to a separate file which is
	produced when calling makegalias.pl -def
	* glib/Makefile.am (galiasdef.c): Add a rule to generate this
	file.
	* glib/*.c: Include galias.h after the other GLib headers,
	include galiasdef.c at the bottom.
2005-03-14 04:26:57 +00:00
Matthias Clasen
dafdffd751 Implement the same PLT reduction technique used in GTK+:
Thu Sep 16 02:03:15 2004  Matthias Clasen  <maclas@gmx.de>

	Implement the same PLT reduction technique used in GTK+:
2004-09-16 06:05:53 +00:00
Matthias Clasen
884d7c76ab Don't return FALSE from a pointer function. (#131472, Morten Welinder)
Sat Jan 31 03:13:56 2004  Matthias Clasen  <maclas@gmx.de>

	* glib/garray.c (g_byte_array_remove_range): Don't return FALSE
	from a pointer function.  (#131472, Morten Welinder)
2004-01-31 02:12:06 +00:00
Matthias Clasen
e09de99eb5 New function to call a function for each element of a GPtrArray. (#114790)
Fri Dec 26 02:03:58 2003  Matthias Clasen  <maclas@gmx.de>

	* glib/garray.[hc] (g_ptr_array_foreach): New function to
	call a function for each element of a GPtrArray.  (#114790)

	* tests/array-test.c (main): Add a test for g_ptr_array_foreach().
2003-12-26 01:04:12 +00:00
Morten Welinder
36715ffb1e Make it compile. (#119337, self.)
2003-11-05  Morten Welinder  <terra@gnome.org>

	* glib/garray.c (g_ptr_array_remove_range): Make it compile.
	(#119337, self.)
2003-11-05 17:15:24 +00:00
Soeren Sandmann
8b75e12b13 make the argument const to get rid of warning
Tue Sep 30 15:31:16 2003  Soeren Sandmann  <sandmann@daimi.au.dk>

	* glib/guniprop.c (has_more_above): make the argument const to
	get rid of warning

	* glib/garray.c (g_byte_array_remove_range): insert cast to get
	rid of warning
2003-09-30 13:36:25 +00:00
Matthias Clasen
971af34af9 New functions to remove a range of elements from an array. (#94879, Nalin
2003-07-26  Matthias Clasen  <maclas@gmx.de>

	* glib/garray.h:
	* glib/garray.c (g_{,byte,pointer}_remove_range): New functions to remove a range of elements
	from an array.  (#94879, Nalin Dahyabhai)
2003-07-26 08:03:16 +00:00
Owen Taylor
bbbd329ff5 Patch from Sven Neumann to make the include order consistent. (#71704)
Tue Dec  3 20:22:27 2002  Owen Taylor  <otaylor@redhat.com>

        * glib/*.c: Patch from Sven Neumann to make the
        include order consistent. (#71704)
2002-12-04 01:27:44 +00:00
Owen Taylor
053a1ce434 Fixes for #79347, Ron Arts.
Tue May  7 11:24:22 2002  Owen Taylor  <otaylor@redhat.com>

        Fixes for #79347, Ron Arts.

        * glib/gqsort.c (g_qsort_with_data): Handle 0 elements,
        don't g_return_if_fail().

        * tests/qsort-test.c (main): Add a 0 element test.

        * glib/garray.c (g_[ptr_]array_sort_with[_data]):
        Remove invalid assertions that array->pdata != NULL ..
        it's NULL for 0 elements which is a valid case.
2002-05-07 15:32:08 +00:00