Commit 45fb7194 authored by Tim Janik's avatar Tim Janik Committed by Tim Janik

removed archaic gpointer derived_data; relict and added a GData member

Wed Mar 14 18:46:54 2001  Tim Janik  <timj@gtk.org>

        * gscanner.[hc]: removed archaic gpointer derived_data; relict and
        added a GData member instead.

        * glist.[hc]: added g_list_remove_all().

        * gslist.[hc]: added g_slist_remove_all().

Sat Mar 17 23:18:36 2001  Tim Janik  <timj@gtk.org>

        * gobject.c (g_object_get_property): minor bug-fix.

        * gbsearcharray.[hc]: provide a macro for static initialization and
        functions g_bsearch_array_new() and g_bsearch_array_destroy() for
        dynamic allocations.

        * gboxed.c: introduce G_TYPE_GSTRING, boxed type for GString.

        * gclosure.[hc]: naming corrections.

Fri Mar  9 16:42:08 2001  Tim Janik  <timj@gtk.org>

        * gvaluetypes.[hc]: moved g_strdup_value_contents() into this file as
        a public function (was static in gobject.c before). it's a bit odd
        to have that function here, especially since it requires extra includes,
        but then it doesn't very well fit somewhere else either.

        * gparamspecs.c: added default/max/min checks to param spec creation
        functions.
parent 1d5b01bb
Wed Mar 14 18:46:54 2001 Tim Janik <timj@gtk.org>
* gscanner.[hc]: removed archaic gpointer derived_data; relict and
added a GData member instead.
* glist.[hc]: added g_list_remove_all().
* gslist.[hc]: added g_slist_remove_all().
Sat Mar 17 19:54:51 2001 Owen Taylor <otaylor@redhat.com>
* timeloop.c: Reorder headers to make FreeBSD happy.
......
Wed Mar 14 18:46:54 2001 Tim Janik <timj@gtk.org>
* gscanner.[hc]: removed archaic gpointer derived_data; relict and
added a GData member instead.
* glist.[hc]: added g_list_remove_all().
* gslist.[hc]: added g_slist_remove_all().
Sat Mar 17 19:54:51 2001 Owen Taylor <otaylor@redhat.com>
* timeloop.c: Reorder headers to make FreeBSD happy.
......
Wed Mar 14 18:46:54 2001 Tim Janik <timj@gtk.org>
* gscanner.[hc]: removed archaic gpointer derived_data; relict and
added a GData member instead.
* glist.[hc]: added g_list_remove_all().
* gslist.[hc]: added g_slist_remove_all().
Sat Mar 17 19:54:51 2001 Owen Taylor <otaylor@redhat.com>
* timeloop.c: Reorder headers to make FreeBSD happy.
......
Wed Mar 14 18:46:54 2001 Tim Janik <timj@gtk.org>
* gscanner.[hc]: removed archaic gpointer derived_data; relict and
added a GData member instead.
* glist.[hc]: added g_list_remove_all().
* gslist.[hc]: added g_slist_remove_all().
Sat Mar 17 19:54:51 2001 Owen Taylor <otaylor@redhat.com>
* timeloop.c: Reorder headers to make FreeBSD happy.
......
Wed Mar 14 18:46:54 2001 Tim Janik <timj@gtk.org>
* gscanner.[hc]: removed archaic gpointer derived_data; relict and
added a GData member instead.
* glist.[hc]: added g_list_remove_all().
* gslist.[hc]: added g_slist_remove_all().
Sat Mar 17 19:54:51 2001 Owen Taylor <otaylor@redhat.com>
* timeloop.c: Reorder headers to make FreeBSD happy.
......
Wed Mar 14 18:46:54 2001 Tim Janik <timj@gtk.org>
* gscanner.[hc]: removed archaic gpointer derived_data; relict and
added a GData member instead.
* glist.[hc]: added g_list_remove_all().
* gslist.[hc]: added g_slist_remove_all().
Sat Mar 17 19:54:51 2001 Owen Taylor <otaylor@redhat.com>
* timeloop.c: Reorder headers to make FreeBSD happy.
......
Wed Mar 14 18:46:54 2001 Tim Janik <timj@gtk.org>
* gscanner.[hc]: removed archaic gpointer derived_data; relict and
added a GData member instead.
* glist.[hc]: added g_list_remove_all().
* gslist.[hc]: added g_slist_remove_all().
Sat Mar 17 19:54:51 2001 Owen Taylor <otaylor@redhat.com>
* timeloop.c: Reorder headers to make FreeBSD happy.
......
Wed Mar 14 18:46:54 2001 Tim Janik <timj@gtk.org>
* gscanner.[hc]: removed archaic gpointer derived_data; relict and
added a GData member instead.
* glist.[hc]: added g_list_remove_all().
* gslist.[hc]: added g_slist_remove_all().
Sat Mar 17 19:54:51 2001 Owen Taylor <otaylor@redhat.com>
* timeloop.c: Reorder headers to make FreeBSD happy.
......
......@@ -66,6 +66,7 @@ only one statement is expected by the compiler.
Portable way to copy <type>va_list</type> variables.
</para>
<!-- # Unused Parameters # -->
@ap1: the <type>va_list</type> variable to place a copy of @ap2 in.
@ap2: a <type>va_list</type>.
......
......@@ -43,7 +43,7 @@ handler function is declared by #GScannerMsgFunc.
@max_parse_errors:
@parse_errors:
@input_name:
@derived_data:
@qdata:
@config:
@token:
@value:
......
......@@ -178,46 +178,6 @@ Closures
@closure:
<!-- ##### FUNCTION g_closure_add_fnotify ##### -->
<para>
</para>
@closure:
@notify_data:
@notify_func:
<!-- ##### FUNCTION g_closure_remove_fnotify ##### -->
<para>
</para>
@closure:
@notify_data:
@notify_func:
<!-- ##### FUNCTION g_closure_add_inotify ##### -->
<para>
</para>
@closure:
@notify_data:
@notify_func:
<!-- ##### FUNCTION g_closure_remove_inotify ##### -->
<para>
</para>
@closure:
@notify_data:
@notify_func:
<!-- ##### FUNCTION g_closure_new_simple ##### -->
<para>
......
<!-- ##### FUNCTION g_closure_add_fnotify ##### -->
<para>
</para>
@closure:
@notify_data:
@notify_func:
<!-- ##### FUNCTION g_closure_add_inotify ##### -->
<para>
</para>
@closure:
@notify_data:
@notify_func:
<!-- ##### FUNCTION g_closure_remove_fnotify ##### -->
<para>
</para>
@closure:
@notify_data:
@notify_func:
<!-- ##### FUNCTION g_closure_remove_inotify ##### -->
<para>
</para>
@closure:
@notify_data:
@notify_func:
<!-- ##### FUNCTION g_param_spec_string_c ##### -->
<para>
......
......@@ -203,6 +203,7 @@ The predefined identifiers of the reserved fundamental types.
@G_TYPE_CLOSURE:
@G_TYPE_VALUE:
@G_TYPE_VALUE_ARRAY:
@G_TYPE_GSTRING:
@G_TYPE_PARAM_CHAR: Identifier for the "#GParamSpecChar" type.
@G_TYPE_PARAM_UCHAR: Identifier for the "#GParamSpecUChar" type.
@G_TYPE_PARAM_BOOLEAN: Identifier for the "#GParamSpecBoolean" type.
......
......@@ -24,6 +24,41 @@
/* --- structures --- */
GBSearchArray*
g_bsearch_array_new (guint16 sizeof_node,
GBSearchCompareFunc node_cmp_func,
GBSearchArrayFlags flags)
{
GBSearchArray *barray;
g_return_val_if_fail (sizeof_node > 0, NULL);
g_return_val_if_fail (node_cmp_func != NULL, NULL);
barray = g_new0 (GBSearchArray, 1);
barray->sizeof_node = sizeof_node;
barray->cmp_nodes = node_cmp_func;
barray->flags = flags;
return barray;
}
void
g_bsearch_array_destroy (GBSearchArray *barray)
{
g_return_if_fail (barray != NULL);
#if 0
if (barray->destroy_node)
while (barray->n_nodes)
{
barray->destroy_node (((guint8*) barray->nodes) + (barray->n_nodes - 1) * barray->sizeof_node);
barray->n_nodes--;
}
#endif
g_free (barray->nodes);
g_free (barray);
}
static inline guint
upper_power2 (guint number)
{
......@@ -47,16 +82,15 @@ bsearch_array_insert (GBSearchArray *barray,
{
guint new_size = barray->sizeof_node;
if (barray->flags & G_BSEARCH_ALIGN_POWER2)
if (barray->flags & G_BSEARCH_ARRAY_ALIGN_POWER2)
new_size = upper_power2 (new_size);
barray->nodes = g_realloc (barray->nodes, new_size);
barray->n_nodes = 1;
check = barray->nodes;
replace = TRUE;
}
else
{
GBSearchCompareFunc cmp_func = barray->cmp_func;
GBSearchCompareFunc cmp_nodes = barray->cmp_nodes;
guint n_nodes = barray->n_nodes;
guint8 *nodes = barray->nodes;
gint cmp;
......@@ -67,7 +101,7 @@ bsearch_array_insert (GBSearchArray *barray,
{
i = (n_nodes + 1) >> 1;
check = nodes + i * sizeof_node;
cmp = cmp_func (key_node, check);
cmp = cmp_nodes (key_node, check);
if (cmp > 0)
{
n_nodes -= i;
......@@ -76,7 +110,17 @@ bsearch_array_insert (GBSearchArray *barray,
else if (cmp < 0)
n_nodes = i - 1;
else /* if (cmp == 0) */
goto SKIP_GROW;
{
if (replace)
{
#if 0
if (barray->destroy_node)
barray->destroy_node (check);
#endif
memcpy (check, key_node, sizeof_node);
}
return check;
}
}
while (n_nodes);
/* grow */
......@@ -84,7 +128,7 @@ bsearch_array_insert (GBSearchArray *barray,
check += sizeof_node;
i = (check - ((guint8*) barray->nodes)) / sizeof_node;
n_nodes = barray->n_nodes++;
if (barray->flags & G_BSEARCH_ALIGN_POWER2)
if (barray->flags & G_BSEARCH_ARRAY_ALIGN_POWER2)
{
guint new_size = upper_power2 (barray->n_nodes * sizeof_node);
guint old_size = upper_power2 (n_nodes * sizeof_node);
......@@ -96,12 +140,8 @@ bsearch_array_insert (GBSearchArray *barray,
barray->nodes = g_realloc (barray->nodes, barray->n_nodes * sizeof_node);
check = ((guint8*) barray->nodes) + i * sizeof_node;
g_memmove (check + sizeof_node, check, (n_nodes - i) * sizeof_node);
replace = TRUE;
SKIP_GROW:
;
}
if (replace)
memcpy (check, key_node, sizeof_node);
memcpy (check, key_node, sizeof_node);
return check;
}
......@@ -132,16 +172,20 @@ g_bsearch_array_remove_node (GBSearchArray *barray,
bound = nodes + old_size;
g_return_if_fail (node_in_array >= nodes && node_in_array < bound);
#if 0
if (barray->destroy_node)
barray->destroy_node (node_in_array);
#endif
bound -= barray->sizeof_node;
barray->n_nodes -= 1;
g_memmove (node_in_array, node_in_array + barray->sizeof_node, (bound - node_in_array) / barray->sizeof_node);
if ((barray->flags & G_BSEARCH_DEFER_SHRINK) == 0)
if ((barray->flags & G_BSEARCH_ARRAY_DEFER_SHRINK) == 0)
{
guint new_size = bound - nodes; /* old_size - barray->sizeof_node */
if (barray->flags & G_BSEARCH_ALIGN_POWER2)
if (barray->flags & G_BSEARCH_ARRAY_ALIGN_POWER2)
{
new_size = upper_power2 (new_size);
old_size = upper_power2 (old_size);
......
......@@ -35,23 +35,27 @@ typedef gint (*GBSearchCompareFunc) (gconstpointer bsearch_node1,
gconstpointer bsearch_node2);
typedef enum
{
G_BSEARCH_ALIGN_POWER2 = 1 << 0,
G_BSEARCH_DEFER_SHRINK = 1 << 1
} GBSearchFlags;
G_BSEARCH_ARRAY_ALIGN_POWER2 = 1 << 0,
G_BSEARCH_ARRAY_DEFER_SHRINK = 1 << 1
} GBSearchArrayFlags;
/* --- structures --- */
struct _GBSearchArray
{
GBSearchCompareFunc cmp_func;
guint16 sizeof_node;
GBSearchCompareFunc cmp_nodes;
guint16 flags;
guint16 sizeof_node;
guint n_nodes;
gpointer nodes;
};
/* --- prototypes --- */
GBSearchArray* g_bsearch_array_new (guint16 sizeof_node,
GBSearchCompareFunc node_cmp_func,
GBSearchArrayFlags flags);
void g_bsearch_array_destroy (GBSearchArray *barray);
gpointer g_bsearch_array_insert (GBSearchArray *barray,
gconstpointer key_node,
gboolean replace_existing);
......@@ -70,6 +74,11 @@ guint g_bsearch_array_get_index (GBSearchArray *barray,
gpointer node_in_array);
/* initialization of static arrays */
#define G_STATIC_BSEARCH_ARRAY_INIT(sizeof_node, cmp_nodes, flags) \
{ (cmp_nodes), (flags), (sizeof_node), 0, NULL }
/* --- implementation details --- */
#if defined (G_CAN_INLINE) || defined (__G_BSEARCHARRAY_C__)
G_INLINE_FUNC gpointer
......@@ -78,7 +87,7 @@ g_bsearch_array_lookup (GBSearchArray *barray,
{
if (barray->n_nodes > 0)
{
GBSearchCompareFunc cmp_func = barray->cmp_func;
GBSearchCompareFunc cmp_nodes = barray->cmp_nodes;
gint sizeof_node = barray->sizeof_node;
guint n_nodes = barray->n_nodes;
guint8 *nodes = (guint8 *) barray->nodes;
......@@ -92,7 +101,7 @@ g_bsearch_array_lookup (GBSearchArray *barray,
i = (n_nodes + 1) >> 1;
check = nodes + i * sizeof_node;
cmp = cmp_func (key_node, check);
cmp = cmp_nodes (key_node, check);
if (cmp == 0)
return check;
else if (cmp > 0)
......
......@@ -364,6 +364,34 @@ g_list_remove (GList *list,
return list;
}
GList*
g_list_remove_all (GList *list,
gconstpointer data)
{
GList *tmp = list;
while (tmp)
{
if (tmp->data != data)
tmp = tmp->next;
else
{
GList *next = tmp->next;
if (tmp->prev)
tmp->prev->next = next;
else
list = next;
if (next)
next->prev = tmp->prev;
_g_list_free_1 (tmp);
tmp = next;
}
}
return list;
}
static inline GList*
_g_list_remove_link (GList *list,
GList *link)
......
......@@ -61,6 +61,8 @@ GList* g_list_concat (GList *list1,
GList *list2);
GList* g_list_remove (GList *list,
gconstpointer data);
GList* g_list_remove_all (GList *list,
gconstpointer data);
GList* g_list_remove_link (GList *list,
GList *llink);
GList* g_list_delete_link (GList *list,
......
......@@ -184,7 +184,7 @@ g_scanner_new (const GScannerConfig *config_templ)
scanner->max_parse_errors = 0;
scanner->parse_errors = 0;
scanner->input_name = NULL;
scanner->derived_data = NULL;
g_datalist_init (&scanner->qdata);
scanner->config = g_new0 (GScannerConfig, 1);
......@@ -275,6 +275,7 @@ g_scanner_destroy (GScanner *scanner)
{
g_return_if_fail (scanner != NULL);
g_datalist_clear (&scanner->qdata);
g_hash_table_foreach (scanner->symbol_table,
g_scanner_destroy_symbol_table_entry, NULL);
g_hash_table_destroy (scanner->symbol_table);
......
......@@ -168,8 +168,8 @@ struct _GScanner
/* name of input stream, featured by the default message handler */
const gchar *input_name;
/* data pointer for derived structures */
gpointer derived_data;
/* quarked data */
GData *qdata;
/* link into the scanner configuration */
GScannerConfig *config;
......
......@@ -325,29 +325,54 @@ GSList*
g_slist_remove (GSList *list,
gconstpointer data)
{
GSList *tmp;
GSList *prev;
GSList *tmp, *prev = NULL;
prev = NULL;
tmp = list;
while (tmp)
{
if (tmp->data == data)
{
if (prev)
prev->next = tmp->next;
if (list == tmp)
list = list->next;
tmp->next = NULL;
g_slist_free (tmp);
else
list = tmp->next;
g_slist_free_1 (tmp);
break;
}
prev = tmp;
tmp = tmp->next;
tmp = prev->next;
}
return list;
}
GSList*
g_slist_remove_all (GSList *list,
gconstpointer data)
{
GSList *tmp, *prev = NULL;
tmp = list;
while (tmp)
{
if (tmp->data == data)
{
GSList *next = tmp->next;
if (prev)
prev->next = next;
else
list = next;
g_slist_free_1 (tmp);
tmp = next;
}
else
{
prev = tmp;
tmp = prev->next;
}
}
return list;
......
......@@ -63,6 +63,8 @@ GSList* g_slist_concat (GSList *list1,
GSList *list2);
GSList* g_slist_remove (GSList *list,
gconstpointer data);
GSList* g_slist_remove_all (GSList *list,
gconstpointer data);
GSList* g_slist_remove_link (GSList *list,
GSList *link);
GSList* g_slist_delete_link (GSList *list,
......
......@@ -43,7 +43,6 @@ typedef short gshort;
typedef long glong;
typedef int gint;
typedef gint gboolean;
typedef gchar* gstring;
typedef unsigned char guchar;
typedef unsigned short gushort;
......
......@@ -364,6 +364,34 @@ g_list_remove (GList *list,
return list;
}
GList*
g_list_remove_all (GList *list,
gconstpointer data)
{
GList *tmp = list;
while (tmp)
{
if (tmp->data != data)
tmp = tmp->next;
else
{
GList *next = tmp->next;
if (tmp->prev)
tmp->prev->next = next;
else
list = next;
if (next)
next->prev = tmp->prev;
_g_list_free_1 (tmp);
tmp = next;
}
}
return list;
}
static inline GList*
_g_list_remove_link (GList *list,
GList *link)
......
......@@ -61,6 +61,8 @@ GList* g_list_concat (GList *list1,
GList *list2);
GList* g_list_remove (GList *list,
gconstpointer data);
GList* g_list_remove_all (GList *list,
gconstpointer data);
GList* g_list_remove_link (GList *list,
GList *llink);
GList* g_list_delete_link (GList *list,
......
Sat Mar 17 23:18:36 2001 Tim Janik <timj@gtk.org>
* gobject.c (g_object_get_property): minor bug-fix.
* gbsearcharray.[hc]: provide a macro for static initialization and
functions g_bsearch_array_new() and g_bsearch_array_destroy() for
dynamic allocations.
* gboxed.c: introduce G_TYPE_GSTRING, boxed type for GString.
* gclosure.[hc]: naming corrections.
Fri Mar 9 16:42:08 2001 Tim Janik <timj@gtk.org>
* gvaluetypes.[hc]: moved g_strdup_value_contents() into this file as
......
......@@ -43,7 +43,7 @@ static gint boxed_nodes_cmp (gconstpointer p1,
/* --- variables --- */
static GBSearchArray boxed_bsa = { boxed_nodes_cmp, sizeof (BoxedNode), 0, 0, NULL };
static GBSearchArray boxed_bsa = G_STATIC_BSEARCH_ARRAY_INIT (sizeof (BoxedNode), boxed_nodes_cmp, 0);
/* --- functions --- */
......@@ -94,6 +94,28 @@ value_array_init (void)
return g_value_array_new (0);
}
static gpointer
gstring_init (void)
{
return g_string_new ("");
}
static gpointer
gstring_copy (gpointer boxed)
{
const GString *src_gstring = boxed;
return g_string_new_len (src_gstring->str, src_gstring->len);
}
static void
gstring_free (gpointer boxed)
{
GString *gstring = boxed;
g_string_free (gstring, TRUE);
}
void
g_boxed_type_init (void) /* sync with gtype.c */
{
......@@ -144,6 +166,16 @@ g_boxed_type_init (void) /* sync with gtype.c */
(GBoxedFreeFunc) g_value_array_free,
FALSE);
g_assert (type == G_TYPE_VALUE_ARRAY);
/* boxed: G_TYPE_GSTRING
* yes, the naming is a bit odd, but GString is obviously not G_TYPE_STRING
*/
type = g_boxed_type_register_static ("GString",
gstring_init, /* don't allow NULL values */
gstring_copy,
gstring_free,
FALSE);
g_assert (type == G_TYPE_GSTRING);
}
static void
......
......@@ -24,6 +24,41 @@
/* --- structures --- */
GBSearchArray*
g_bsearch_array_new (guint16 sizeof_node,
GBSearchCompareFunc node_cmp_func,
GBSearchArrayFlags flags)
{
GBSearchArray *barray;
g_return_val_if_fail (sizeof_node > 0, NULL);
g_return_val_if_fail (node_cmp_func != NULL, NULL);
barray = g_new0 (GBSearchArray, 1);
barray->sizeof_node = sizeof_node;
barray->cmp_nodes = node_cmp_func;
barray->flags = flags;
return barray;
}
void
g_bsearch_array_destroy (GBSearchArray *barray)
{
g_return_if_fail (barray != NULL);
#if 0
if (barray->destroy_node)
while (barray->n_nodes)
{
barray->destroy_node (((guint8*) barray->nodes) + (barray->n_nodes - 1) * barray->sizeof_node);
barray->n_nodes--;
}
#endif
g_free (barray->nodes);
g_free (barray);
}
static inline guint
upper_power2 (guint number)
{
......@@ -47,16 +82,15 @@ bsearch_array_insert (GBSearchArray *barray,
{
guint new_size = barray->sizeof_node;
if (barray->flags & G_BSEARCH_ALIGN_POWER2)
if (barray->flags & G_BSEARCH_ARRAY_ALIGN_POWER2)
new_size = upper_power2 (new_size);
barray->nodes = g_realloc (barray->nodes, new_size);
barray->n_nodes = 1;
check = barray->nodes;
replace = TRUE;
}
else
{