Don't export the consistency check function

svn path=/trunk/; revision=5422
This commit is contained in:
Matthias Clasen 2007-03-17 04:25:40 +00:00
parent 3dd8e2daa1
commit 45b2988d05
5 changed files with 88 additions and 68 deletions

View File

@ -1,3 +1,10 @@
2007-03-17 Matthias Clasen <mclasen@redhat.com>
* glib/gsequence.[hc]:
* glib/glib.symbols:
* tests/sequence-test.c: Move the consistency
checks to the test.
2007-03-16 Matthias Clasen <mclasen@redhat.com> 2007-03-16 Matthias Clasen <mclasen@redhat.com>
* configure.in: Bump version * configure.in: Bump version

View File

@ -963,7 +963,6 @@ g_sequence_iter_move
g_sequence_iter_get_sequence g_sequence_iter_get_sequence
g_sequence_iter_compare g_sequence_iter_compare
g_sequence_range_get_midpoint g_sequence_range_get_midpoint
g_sequence_self_test_internal_to_glib_dont_use
#endif #endif
#endif #endif

View File

@ -1735,61 +1735,6 @@ node_insert_sorted (GSequenceNode *node,
node_insert_before (closest, new); node_insert_before (closest, new);
} }
/* Self-test function */
static int
count_nodes (GSequenceNode *node)
{
if (!node)
return 0;
return count_nodes (node->left) + count_nodes (node->right) + 1;
}
static void
check_node (GSequenceNode *node)
{
if (node)
{
g_assert (node->parent != node);
if (node->parent)
g_assert (node->parent->left == node || node->parent->right == node);
g_assert (node->n_nodes == count_nodes (node));
if (node->left)
g_assert (get_priority (node) >= get_priority (node->left));
if (node->right)
g_assert (get_priority (node) >= get_priority (node->right));
check_node (node->left);
check_node (node->right);
}
}
static gint
compute_height (GSequenceNode *node)
{
int left, right;
if (!node)
return 0;
left = compute_height (node->left);
right = compute_height (node->right);
return MAX (left, right) + 1;
}
void
g_sequence_self_test_internal_to_glib_dont_use (GSequence *seq)
{
GSequenceNode *node = find_root (seq->end_node);
check_node (node);
node = node_get_last (node);
g_assert (seq->end_node == node);
g_assert (node->data == seq);
}
#define __G_SEQUENCE_C__ #define __G_SEQUENCE_C__
#include "galiasdef.c" #include "galiasdef.c"

View File

@ -118,7 +118,4 @@ GSequenceIter *g_sequence_range_get_midpoint (GSequenceIter *begin,
GSequenceIter *end); GSequenceIter *end);
/* Private */
void g_sequence_self_test_internal_to_glib_dont_use (GSequence *seq);
#endif /* __G_SEQUENCE_H__ */ #endif /* __G_SEQUENCE_H__ */

View File

@ -2,6 +2,78 @@
#include <glib.h> #include <glib.h>
#include <stdlib.h> #include <stdlib.h>
/* Keep this in sync with gsequence.c !!! */
typedef struct _GSequenceNode GSequenceNode;
struct _GSequence
{
GSequenceNode * end_node;
GDestroyNotify data_destroy_notify;
gboolean access_prohibited;
GSequence * real_sequence;
};
struct _GSequenceNode
{
gint n_nodes;
GSequenceNode * parent;
GSequenceNode * left;
GSequenceNode * right;
gpointer data;
};
static guint
get_priority (GSequenceNode *node)
{
guint key = GPOINTER_TO_UINT (node);
key = (key << 15) - key - 1;
key = key ^ (key >> 12);
key = key + (key << 2);
key = key ^ (key >> 4);
key = key + (key << 3) + (key << 11);
key = key ^ (key >> 16);
return key? key : 1;
}
static void
check_node (GSequenceNode *node)
{
if (node)
{
g_assert (node->parent != node);
if (node->parent)
g_assert (node->parent->left == node || node->parent->right == node);
g_assert (node->n_nodes == 1 + (node->left ? node->left->n_nodes : 0) + (node->right ? node->right->n_nodes : 0));
if (node->left)
g_assert (get_priority (node) >= get_priority (node->left));
if (node->right)
g_assert (get_priority (node) >= get_priority (node->right));
check_node (node->left);
check_node (node->right);
}
}
void
g_sequence_check (GSequence *seq)
{
GSequenceNode *node = seq->end_node;
while (node->parent)
node = node->parent;
check_node (node);
while (node->right)
node = node->right;
g_assert (seq->end_node == node);
g_assert (node->data == seq);
}
enum { enum {
NEW, FREE, GET_LENGTH, FOREACH, FOREACH_RANGE, SORT, SORT_ITER, NEW, FREE, GET_LENGTH, FOREACH, FOREACH_RANGE, SORT, SORT_ITER,
@ -35,7 +107,7 @@ typedef struct
int number; int number;
} Item; } Item;
void g_sequence_self_test_internal_to_glib_dont_use (GSequence *sequence); void g_sequence_check (GSequence *sequence);
static Item * static Item *
fix_pointer (gconstpointer data) fix_pointer (gconstpointer data)
@ -56,7 +128,7 @@ check_integrity (SequenceInfo *info)
GSequenceIter *iter; GSequenceIter *iter;
int i; int i;
g_sequence_self_test_internal_to_glib_dont_use (info->sequence); g_sequence_check (info->sequence);
if (g_sequence_get_length (info->sequence) != info->n_items) if (g_sequence_get_length (info->sequence) != info->n_items)
g_print ("%d %d\n", g_print ("%d %d\n",
@ -1148,7 +1220,7 @@ test_insert_sorted_non_pointer (void)
compare_iter, NULL); compare_iter, NULL);
} }
g_sequence_self_test_internal_to_glib_dont_use (seq); g_sequence_check (seq);
g_sequence_free (seq); g_sequence_free (seq);
} }
@ -1168,21 +1240,21 @@ test_stable_sort (void)
for (i = 0; i < N_ITEMS; ++i) for (i = 0; i < N_ITEMS; ++i)
{ {
iters[i] = g_sequence_append (seq, GINT_TO_POINTER (3000)); iters[i] = g_sequence_append (seq, GINT_TO_POINTER (3000));
g_sequence_self_test_internal_to_glib_dont_use (seq); g_sequence_check (seq);
g_assert (g_sequence_iter_get_sequence (iters[i]) == seq); g_assert (g_sequence_iter_get_sequence (iters[i]) == seq);
} }
i = 0; i = 0;
iter = g_sequence_get_begin_iter (seq); iter = g_sequence_get_begin_iter (seq);
g_assert (g_sequence_iter_get_sequence (iter) == seq); g_assert (g_sequence_iter_get_sequence (iter) == seq);
g_sequence_self_test_internal_to_glib_dont_use (seq); g_sequence_check (seq);
while (!g_sequence_iter_is_end (iter)) while (!g_sequence_iter_is_end (iter))
{ {
g_assert (g_sequence_iter_get_sequence (iters[i]) == seq); g_assert (g_sequence_iter_get_sequence (iters[i]) == seq);
g_assert (iters[i++] == iter); g_assert (iters[i++] == iter);
iter = g_sequence_iter_next (iter); iter = g_sequence_iter_next (iter);
g_sequence_self_test_internal_to_glib_dont_use (seq); g_sequence_check (seq);
} }
g_sequence_sort (seq, compare, NULL); g_sequence_sort (seq, compare, NULL);
@ -1195,14 +1267,14 @@ test_stable_sort (void)
g_assert (iters[i] == iter); g_assert (iters[i] == iter);
iter = g_sequence_iter_next (iter); iter = g_sequence_iter_next (iter);
g_sequence_self_test_internal_to_glib_dont_use (seq); g_sequence_check (seq);
i++; i++;
} }
for (i = N_ITEMS - 1; i >= 0; --i) for (i = N_ITEMS - 1; i >= 0; --i)
{ {
g_sequence_self_test_internal_to_glib_dont_use (seq); g_sequence_check (seq);
g_assert (g_sequence_iter_get_sequence (iters[i]) == seq); g_assert (g_sequence_iter_get_sequence (iters[i]) == seq);
g_assert (g_sequence_get_end_iter (seq) != iters[i]); g_assert (g_sequence_get_end_iter (seq) != iters[i]);
g_sequence_sort_changed (iters[i], compare, NULL); g_sequence_sort_changed (iters[i], compare, NULL);
@ -1215,7 +1287,7 @@ test_stable_sort (void)
g_assert (iters[i++] == iter); g_assert (iters[i++] == iter);
iter = g_sequence_iter_next (iter); iter = g_sequence_iter_next (iter);
g_sequence_self_test_internal_to_glib_dont_use (seq); g_sequence_check (seq);
} }
} }