static void nm_cmd_line_destroy (NMCmdLine *cmd) { g_ptr_array_free (cmd->array, TRUE); g_string_chunk_free (cmd->chunk); g_slice_free (NMCmdLine, cmd); }
GStringChunk * free_GStringChunk(GStringChunk * gs) { assert(gs); g_string_chunk_free(gs); return NULL; }
void lr_packagetarget_free(LrPackageTarget *target) { if (!target) return; g_string_chunk_free(target->chunk); g_free(target); }
void free_pip_db(pip_db_t *db) { /* free states */ g_hash_table_destroy(db->hash); g_string_chunk_free(db->chunk); g_free(db->state_array); g_free(db->pip_array); g_free(db); }
static void lr_yum_repomdrecord_free(LrYumRepoMdRecord *rec) { if (!rec) return; g_string_chunk_free(rec->chunk); lr_free(rec); }
static void core_finalize (GObject * o) { TrCore * core = TR_CORE (o); g_string_chunk_free (core->priv->string_chunk); G_OBJECT_CLASS (tr_core_parent_class)->finalize (o); }
void cr_repomd_record_free(cr_RepomdRecord *md) { if (!md) return; g_string_chunk_free(md->chunk); g_free(md); }
void free_wiredb(wire_db_t *wires) { GStringChunk *wirenames = wires->wirenames; if (wirenames) g_string_chunk_free(wirenames); g_free((void *)wires->details); g_free(wires->names); empty_db(wires, wires->dblen); g_free((void *)wires->wires); g_free(wires); }
/** * ide_debugger_address_map_free: * @self: a #IdeDebuggerAddressMap * * Frees all memory associated with @self. * * Since: 3.32 */ void ide_debugger_address_map_free (IdeDebuggerAddressMap *self) { if (self != NULL) { g_sequence_free (self->seq); g_string_chunk_free (self->chunk); g_slice_free (IdeDebuggerAddressMap, self); } }
void lr_downloadtarget_free(LrDownloadTarget *target) { if (!target) return; g_slist_free_full(target->checksums, (GDestroyNotify) lr_downloadtargetchecksum_free); g_string_chunk_free(target->chunk); lr_free(target); }
void cr_repomd_free(cr_Repomd *repomd) { if (!repomd) return; cr_slist_free_full(repomd->records, (GDestroyNotify) cr_repomd_record_free ); g_slist_free(repomd->repo_tags); cr_slist_free_full(repomd->distro_tags, (GDestroyNotify) g_free); g_slist_free(repomd->content_tags); g_string_chunk_free(repomd->chunk); g_free(repomd); }
void lr_yum_repomd_free(LrYumRepoMd *repomd) { if (!repomd) return; g_slist_free_full(repomd->records, (GDestroyNotify) lr_yum_repomdrecord_free); g_slist_free(repomd->repo_tags); g_slist_free(repomd->content_tags); g_slist_free_full(repomd->distro_tags, (GDestroyNotify) g_free); g_string_chunk_free(repomd->chunk); g_free(repomd); }
/* free playlist info (table + strings) */ void irmpc_playlist_free () { if (playlist_table != NULL) { g_tree_foreach (playlist_table, irmpc_playlist_entry_free, NULL); g_tree_destroy (playlist_table); playlist_table = NULL; } if (playlist_name_storage != NULL) { g_string_chunk_free (playlist_name_storage); playlist_name_storage = NULL; } }
void cr_metadata_free(cr_Metadata *md) { if (!md) return; cr_destroy_metadata_hashtable(md->ht); if (md->chunk) g_string_chunk_free(md->chunk); if (md->pkglist_ht) g_hash_table_destroy(md->pkglist_ht); g_free(md); }
/* Reset expert stats */ static void expert_stat_reset(void *tapdata) { gint n; expert_tapdata_t *etd = (expert_tapdata_t *)tapdata; /* Free & reallocate chunk of strings */ g_string_chunk_free(etd->text); etd->text = g_string_chunk_new(100); /* Empty each of the arrays */ for (n=0; n < max_level; n++) { g_array_set_size(etd->ei_array[n], 0); } }
void _const_free_data (s4_const_data_t *data) { g_hash_table_destroy (data->coll_table); g_hash_table_destroy (data->case_table); g_hash_table_destroy (data->strings_table); g_hash_table_destroy (data->int_table); g_string_chunk_free (data->strings); g_mutex_clear (&data->strings_lock); g_mutex_clear (&data->case_lock); g_mutex_clear (&data->coll_lock); g_mutex_clear (&data->int_lock); free (data); }
/* lock must be held */ static void __cookie_cache_check_swap(struct cookie_cache *c) { if (poller_now - c->swap_time >= 30) { g_hash_table_remove_all(c->old.cookies); #if GLIB_CHECK_VERSION(2,14,0) g_string_chunk_clear(c->old.chunks); swap_ptrs(&c->old.chunks, &c->current.chunks); #else g_string_chunk_free(c->old.chunks); c->old.chunks = c->current.chunks; c->current.chunks = g_string_chunk_new(4 * 1024); #endif swap_ptrs(&c->old.cookies, &c->current.cookies); c->swap_time = poller_now; } }
/* complete reset, e.g. capture file closed */ void expert_dlg_reset(void *tapdata) { expert_tapdata_t * etd = tapdata; etd->chat_events = 0; etd->note_events = 0; etd->warn_events = 0; etd->error_events = 0; etd->last = 0; etd->first = 0; /* g_string_chunk_clear() is introduced in glib 2.14 */ g_string_chunk_free(etd->text); etd->text = g_string_chunk_new(100); g_array_set_size(etd->ei_array, 0); expert_dlg_display_reset(etd); }
void _xfce_rc_simple_close (XfceRc *rc) { XfceRcSimple *simple = XFCE_RC_SIMPLE (rc); Group *group_next; Group *group; /* release all memory allocated to the groups */ for (group = simple->gfirst; group != NULL; group = group_next) { /* determine the next group */ group_next = group->next; /* release this group */ simple_group_free (group); } /* release the string chunk */ if (!simple->shared_chunks) g_string_chunk_free (simple->string_chunk); }
int main (int argc, char *argv[]) { GStringChunk *string_chunk; gchar *tmp_string = NULL, *tmp_string_2; gint i; GString *string1, *string2; string_chunk = g_string_chunk_new (1024); for (i = 0; i < 100000; i ++) { tmp_string = g_string_chunk_insert (string_chunk, "hi pete"); if (strcmp ("hi pete", tmp_string) != 0) g_error ("string chunks are broken.\n"); } tmp_string_2 = g_string_chunk_insert_const (string_chunk, tmp_string); g_assert (tmp_string_2 != tmp_string && strcmp(tmp_string_2, tmp_string) == 0); tmp_string = g_string_chunk_insert_const (string_chunk, tmp_string); g_assert (tmp_string_2 == tmp_string); g_string_chunk_free (string_chunk); string1 = g_string_new ("hi pete!"); string2 = g_string_new (""); g_assert (string1 != NULL); g_assert (string2 != NULL); g_assert (strlen (string1->str) == string1->len); g_assert (strlen (string2->str) == string2->len); g_assert (string2->len == 0); g_assert (strcmp ("hi pete!", string1->str) == 0); g_assert (strcmp ("", string2->str) == 0); for (i = 0; i < 10000; i++) g_string_append_c (string1, 'a'+(i%26)); g_assert((strlen("hi pete!") + 10000) == string1->len); g_assert((strlen("hi pete!") + 10000) == strlen(string1->str)); #ifndef G_OS_WIN32 /* MSVC and mingw32 use the same run-time C library, which doesn't like the %10000.10000f format... */ g_string_sprintf (string2, "%s|%0100d|%s|%s|%0*d|%*.*f|%10000.10000f", "this pete guy sure is a wuss, like he's the number ", 1, " wuss. everyone agrees.\n", string1->str, 10, 666, 15, 15, 666.666666666, 666.666666666); #else g_string_sprintf (string2, "%s|%0100d|%s|%s|%0*d|%*.*f|%100.100f", "this pete guy sure is a wuss, like he's the number ", 1, " wuss. everyone agrees.\n", string1->str, 10, 666, 15, 15, 666.666666666, 666.666666666); #endif g_string_free (string1, TRUE); g_string_free (string2, TRUE); /* append */ string1 = g_string_new ("firsthalf"); g_string_append (string1, "lasthalf"); g_assert (strcmp (string1->str, "firsthalflasthalf") == 0); g_string_free (string1, TRUE); /* append_len */ string1 = g_string_new ("firsthalf"); g_string_append_len (string1, "lasthalfjunkjunk", strlen ("lasthalf")); g_assert (strcmp (string1->str, "firsthalflasthalf") == 0); g_string_free (string1, TRUE); /* prepend */ string1 = g_string_new ("lasthalf"); g_string_prepend (string1, "firsthalf"); g_assert (strcmp (string1->str, "firsthalflasthalf") == 0); g_string_free (string1, TRUE); /* prepend_len */ string1 = g_string_new ("lasthalf"); g_string_prepend_len (string1, "firsthalfjunkjunk", strlen ("firsthalf")); g_assert (strcmp (string1->str, "firsthalflasthalf") == 0); g_string_free (string1, TRUE); /* insert */ string1 = g_string_new ("firstlast"); g_string_insert (string1, 5, "middle"); g_assert (strcmp (string1->str, "firstmiddlelast") == 0); g_string_free (string1, TRUE); /* insert with pos == end of the string */ string1 = g_string_new ("firstmiddle"); g_string_insert (string1, strlen ("firstmiddle"), "last"); g_assert (strcmp (string1->str, "firstmiddlelast") == 0); g_string_free (string1, TRUE); /* insert_len */ string1 = g_string_new ("firstlast"); g_string_insert_len (string1, 5, "middlejunkjunk", strlen ("middle")); g_assert (strcmp (string1->str, "firstmiddlelast") == 0); g_string_free (string1, TRUE); /* insert_len with magic -1 pos for append */ string1 = g_string_new ("first"); g_string_insert_len (string1, -1, "lastjunkjunk", strlen ("last")); g_assert (strcmp (string1->str, "firstlast") == 0); g_string_free (string1, TRUE); /* insert_len with magic -1 len for strlen-the-string */ string1 = g_string_new ("first"); g_string_insert_len (string1, 5, "last", -1); g_assert (strcmp (string1->str, "firstlast") == 0); g_string_free (string1, TRUE); /* g_string_equal */ string1 = g_string_new ("test"); string2 = g_string_new ("te"); g_assert (! g_string_equal(string1, string2)); g_string_append (string2, "st"); g_assert (g_string_equal(string1, string2)); g_string_free (string1, TRUE); g_string_free (string2, TRUE); /* Check handling of embedded ASCII 0 (NUL) characters in GString. */ string1 = g_string_new ("fiddle"); string2 = g_string_new ("fiddle"); g_assert (g_string_equal(string1, string2)); g_string_append_c(string1, '\0'); g_assert (! g_string_equal(string1, string2)); g_string_append_c(string2, '\0'); g_assert (g_string_equal(string1, string2)); g_string_append_c(string1, 'x'); g_string_append_c(string2, 'y'); g_assert (! g_string_equal(string1, string2)); g_assert (string1->len == 8); g_string_append(string1, "yzzy"); g_assert (string1->len == 12); g_assert ( memcmp(string1->str, "fiddle\0xyzzy", 13) == 0); g_string_insert(string1, 1, "QED"); g_assert ( memcmp(string1->str, "fQEDiddle\0xyzzy", 16) == 0); g_string_free (string1, TRUE); g_string_free (string2, TRUE); return 0; }
void rm_trie_destroy(RmTrie *self) { rm_trie_iter(self, NULL, false, true, rm_trie_destroy_callback, NULL); g_string_chunk_free(self->chunks); g_mutex_clear(&self->lock); }
/** * Free dynamically-allocated storage within check result struct. * * @param pResult pointer to check result struct */ void free_check_result(oi_check_result *pResult) { g_string_chunk_free(pResult->chunk); }
void sdp_chopper_destroy(struct sdp_chopper *chop) { g_string_chunk_free(chop->chunk); g_array_free(chop->iov, 1); g_slice_free1(sizeof(*chop), chop); }
void stf_preview_set_lines (RenderData_t *renderdata, GStringChunk *lines_chunk, GPtrArray *lines) { unsigned int i; int colcount = 1; GnumericLazyList *ll; gboolean hidden; g_return_if_fail (renderdata != NULL); /* Empty the table. */ gtk_tree_view_set_model (renderdata->tree_view, NULL); if (renderdata->lines != lines) { if (renderdata->lines) stf_parse_general_free (renderdata->lines); renderdata->lines = lines; } if (renderdata->lines_chunk != lines_chunk) { if (renderdata->lines_chunk) g_string_chunk_free (renderdata->lines_chunk); renderdata->lines_chunk = lines_chunk; } if (lines == NULL) return; for (i = 0; i < lines->len; i++) { GPtrArray *line = g_ptr_array_index (lines, i); colcount = MAX (colcount, (int)line->len); } /* * If we are making large changes we need to hide the treeview * because performance otherwise suffers a lot. */ hidden = gtk_widget_get_visible (GTK_WIDGET (renderdata->tree_view)) && (colcount < renderdata->colcount - 1 || colcount > renderdata->colcount + 10); if (hidden) gtk_widget_hide (GTK_WIDGET (renderdata->tree_view)); while (renderdata->colcount > colcount) gtk_tree_view_remove_column (renderdata->tree_view, gtk_tree_view_get_column (renderdata->tree_view, --(renderdata->colcount))); while (renderdata->colcount < colcount) { char *text = g_strdup_printf (_(COLUMN_CAPTION), renderdata->colcount + 1); GtkCellRenderer *cell = gtk_cell_renderer_text_new (); GtkTreeViewColumn *column = gtk_tree_view_column_new_with_attributes (text, cell, "text", renderdata->colcount, NULL); g_object_set (cell, "single_paragraph_mode", TRUE, NULL); gtk_tree_view_append_column (renderdata->tree_view, column); g_free (text); renderdata->colcount++; } ll = gnumeric_lazy_list_new (render_get_value, renderdata, MIN (lines->len, LINE_DISPLAY_LIMIT), 0); gnumeric_lazy_list_add_column (ll, colcount, G_TYPE_STRING); gtk_tree_view_set_model (renderdata->tree_view, GTK_TREE_MODEL (ll)); g_object_unref (ll); if (hidden) gtk_widget_show (GTK_WIDGET (renderdata->tree_view)); }
int main (int argc, char *argv[]) { GList *list, *t; GSList *slist, *st; GHashTable *hash_table; GMemChunk *mem_chunk; GStringChunk *string_chunk; GTimer *timer; gint nums[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; gint morenums[10] = { 8, 9, 7, 0, 3, 2, 5, 1, 4, 6}; gchar *string; gchar *mem[10000], *tmp_string = NULL, *tmp_string_2; gint i, j; GArray *garray; GPtrArray *gparray; GByteArray *gbarray; GString *string1, *string2; GTree *tree; char chars[62]; GRelation *relation; GTuples *tuples; gint data [1024]; struct { gchar *filename; gchar *dirname; } dirname_checks[] = { #ifndef NATIVE_WIN32 { "/", "/" }, { "////", "/" }, { ".////", "." }, { ".", "." }, { "..", "." }, { "../", ".." }, { "..////", ".." }, { "", "." }, { "a/b", "a" }, { "a/b/", "a/b" }, { "c///", "c" }, #else { "\\", "\\" }, { ".\\\\\\\\", "." }, { ".", "." }, { "..", "." }, { "..\\", ".." }, { "..\\\\\\\\", ".." }, { "", "." }, { "a\\b", "a" }, { "a\\b\\", "a\\b" }, { "c\\\\\\", "c" }, #endif }; guint n_dirname_checks = sizeof (dirname_checks) / sizeof (dirname_checks[0]); guint16 gu16t1 = 0x44afU, gu16t2 = 0xaf44U; guint32 gu32t1 = 0x02a7f109U, gu32t2 = 0x09f1a702U; #ifdef G_HAVE_GINT64 guint64 gu64t1 = G_GINT64_CONSTANT(0x1d636b02300a7aa7U), gu64t2 = G_GINT64_CONSTANT(0xa77a0a30026b631dU); #endif g_print ("TestGLib v%u.%u.%u (i:%u b:%u)\n", glib_major_version, glib_minor_version, glib_micro_version, glib_interface_age, glib_binary_age); string = g_get_current_dir (); g_print ("cwd: %s\n", string); g_free (string); g_print ("user: %s\n", g_get_user_name ()); g_print ("real: %s\n", g_get_real_name ()); g_print ("home: %s\n", g_get_home_dir ()); g_print ("tmp-dir: %s\n", g_get_tmp_dir ()); /* type sizes */ g_print ("checking size of gint8: %d", (int)sizeof (gint8)); TEST (NULL, sizeof (gint8) == 1); g_print ("\nchecking size of gint16: %d", (int)sizeof (gint16)); TEST (NULL, sizeof (gint16) == 2); g_print ("\nchecking size of gint32: %d", (int)sizeof (gint32)); TEST (NULL, sizeof (gint32) == 4); #ifdef G_HAVE_GINT64 g_print ("\nchecking size of gint64: %d", (int)sizeof (gint64)); TEST (NULL, sizeof (gint64) == 8); #endif /* G_HAVE_GINT64 */ g_print ("\n"); g_print ("checking g_dirname()..."); for (i = 0; i < n_dirname_checks; i++) { gchar *dirname; dirname = g_dirname (dirname_checks[i].filename); if (strcmp (dirname, dirname_checks[i].dirname) != 0) { g_print ("\nfailed for \"%s\"==\"%s\" (returned: \"%s\")\n", dirname_checks[i].filename, dirname_checks[i].dirname, dirname); n_dirname_checks = 0; } g_free (dirname); } if (n_dirname_checks) g_print ("ok\n"); g_print ("checking doubly linked lists..."); list = NULL; for (i = 0; i < 10; i++) list = g_list_append (list, &nums[i]); list = g_list_reverse (list); for (i = 0; i < 10; i++) { t = g_list_nth (list, i); if (*((gint*) t->data) != (9 - i)) g_error ("Regular insert failed"); } for (i = 0; i < 10; i++) if(g_list_position(list, g_list_nth (list, i)) != i) g_error("g_list_position does not seem to be the inverse of g_list_nth\n"); g_list_free (list); list = NULL; for (i = 0; i < 10; i++) list = g_list_insert_sorted (list, &morenums[i], my_list_compare_one); /* g_print("\n"); g_list_foreach (list, my_list_print, NULL); */ for (i = 0; i < 10; i++) { t = g_list_nth (list, i); if (*((gint*) t->data) != i) g_error ("Sorted insert failed"); } g_list_free (list); list = NULL; for (i = 0; i < 10; i++) list = g_list_insert_sorted (list, &morenums[i], my_list_compare_two); /* g_print("\n"); g_list_foreach (list, my_list_print, NULL); */ for (i = 0; i < 10; i++) { t = g_list_nth (list, i); if (*((gint*) t->data) != (9 - i)) g_error ("Sorted insert failed"); } g_list_free (list); list = NULL; for (i = 0; i < 10; i++) list = g_list_prepend (list, &morenums[i]); list = g_list_sort (list, my_list_compare_two); /* g_print("\n"); g_list_foreach (list, my_list_print, NULL); */ for (i = 0; i < 10; i++) { t = g_list_nth (list, i); if (*((gint*) t->data) != (9 - i)) g_error ("Merge sort failed"); } g_list_free (list); g_print ("ok\n"); g_print ("checking singly linked lists..."); slist = NULL; for (i = 0; i < 10; i++) slist = g_slist_append (slist, &nums[i]); slist = g_slist_reverse (slist); for (i = 0; i < 10; i++) { st = g_slist_nth (slist, i); if (*((gint*) st->data) != (9 - i)) g_error ("failed"); } g_slist_free (slist); slist = NULL; for (i = 0; i < 10; i++) slist = g_slist_insert_sorted (slist, &morenums[i], my_list_compare_one); /* g_print("\n"); g_slist_foreach (slist, my_list_print, NULL); */ for (i = 0; i < 10; i++) { st = g_slist_nth (slist, i); if (*((gint*) st->data) != i) g_error ("Sorted insert failed"); } g_slist_free(slist); slist = NULL; for (i = 0; i < 10; i++) slist = g_slist_insert_sorted (slist, &morenums[i], my_list_compare_two); /* g_print("\n"); g_slist_foreach (slist, my_list_print, NULL); */ for (i = 0; i < 10; i++) { st = g_slist_nth (slist, i); if (*((gint*) st->data) != (9 - i)) g_error("Sorted insert failed"); } g_slist_free(slist); slist = NULL; for (i = 0; i < 10; i++) slist = g_slist_prepend (slist, &morenums[i]); slist = g_slist_sort (slist, my_list_compare_two); /* g_print("\n"); g_slist_foreach (slist, my_list_print, NULL); */ for (i = 0; i < 10; i++) { st = g_slist_nth (slist, i); if (*((gint*) st->data) != (9 - i)) g_error("Sorted insert failed"); } g_slist_free(slist); g_print ("ok\n"); g_print ("checking binary trees...\n"); tree = g_tree_new (my_compare); i = 0; for (j = 0; j < 10; j++, i++) { chars[i] = '0' + j; g_tree_insert (tree, &chars[i], &chars[i]); } for (j = 0; j < 26; j++, i++) { chars[i] = 'A' + j; g_tree_insert (tree, &chars[i], &chars[i]); } for (j = 0; j < 26; j++, i++) { chars[i] = 'a' + j; g_tree_insert (tree, &chars[i], &chars[i]); } g_print ("tree height: %d\n", g_tree_height (tree)); g_print ("tree nnodes: %d\n", g_tree_nnodes (tree)); g_print ("tree: "); g_tree_traverse (tree, my_traverse, G_IN_ORDER, NULL); g_print ("\n"); for (i = 0; i < 10; i++) g_tree_remove (tree, &chars[i]); g_print ("tree height: %d\n", g_tree_height (tree)); g_print ("tree nnodes: %d\n", g_tree_nnodes (tree)); g_print ("tree: "); g_tree_traverse (tree, my_traverse, G_IN_ORDER, NULL); g_print ("\n"); g_print ("ok\n"); /* check n-way trees */ g_node_test (); g_print ("checking mem chunks..."); mem_chunk = g_mem_chunk_new ("test mem chunk", 50, 100, G_ALLOC_AND_FREE); for (i = 0; i < 10000; i++) { mem[i] = g_chunk_new (gchar, mem_chunk); for (j = 0; j < 50; j++) mem[i][j] = i * j; } for (i = 0; i < 10000; i++) { g_mem_chunk_free (mem_chunk, mem[i]); } g_print ("ok\n"); g_print ("checking hash tables..."); hash_table = g_hash_table_new (my_hash, my_hash_compare); for (i = 0; i < 10000; i++) { array[i] = i; g_hash_table_insert (hash_table, &array[i], &array[i]); } g_hash_table_foreach (hash_table, my_hash_callback, NULL); for (i = 0; i < 10000; i++) if (array[i] == 0) g_print ("%d\n", i); for (i = 0; i < 10000; i++) g_hash_table_remove (hash_table, &array[i]); for (i = 0; i < 10000; i++) { array[i] = i; g_hash_table_insert (hash_table, &array[i], &array[i]); } if (g_hash_table_foreach_remove (hash_table, my_hash_callback_remove, NULL) != 5000 || g_hash_table_size (hash_table) != 5000) g_print ("bad!\n"); g_hash_table_foreach (hash_table, my_hash_callback_remove_test, NULL); g_hash_table_destroy (hash_table); g_print ("ok\n"); g_print ("checking string chunks..."); string_chunk = g_string_chunk_new (1024); for (i = 0; i < 100000; i ++) { tmp_string = g_string_chunk_insert (string_chunk, "hi pete"); if (strcmp ("hi pete", tmp_string) != 0) g_error ("string chunks are broken.\n"); } tmp_string_2 = g_string_chunk_insert_const (string_chunk, tmp_string); g_assert (tmp_string_2 != tmp_string && strcmp(tmp_string_2, tmp_string) == 0); tmp_string = g_string_chunk_insert_const (string_chunk, tmp_string); g_assert (tmp_string_2 == tmp_string); g_string_chunk_free (string_chunk); g_print ("ok\n"); g_print ("checking arrays..."); garray = g_array_new (FALSE, FALSE, sizeof (gint)); for (i = 0; i < 10000; i++) g_array_append_val (garray, i); for (i = 0; i < 10000; i++) if (g_array_index (garray, gint, i) != i) g_print ("uh oh: %d ( %d )\n", g_array_index (garray, gint, i), i); g_array_free (garray, TRUE); garray = g_array_new (FALSE, FALSE, sizeof (gint)); for (i = 0; i < 100; i++) g_array_prepend_val (garray, i); for (i = 0; i < 100; i++) if (g_array_index (garray, gint, i) != (100 - i - 1)) g_print ("uh oh: %d ( %d )\n", g_array_index (garray, gint, i), 100 - i - 1); g_array_free (garray, TRUE); g_print ("ok\n"); g_print ("checking strings..."); string1 = g_string_new ("hi pete!"); string2 = g_string_new (""); g_assert (strcmp ("hi pete!", string1->str) == 0); for (i = 0; i < 10000; i++) g_string_append_c (string1, 'a'+(i%26)); #if !(defined (_MSC_VER) || defined (__LCC__)) /* MSVC and LCC use the same run-time C library, which doesn't like the %10000.10000f format... */ g_string_sprintf (string2, "%s|%0100d|%s|%s|%0*d|%*.*f|%10000.10000f", "this pete guy sure is a wuss, like he's the number ", 1, " wuss. everyone agrees.\n", string1->str, 10, 666, 15, 15, 666.666666666, 666.666666666); #else g_string_sprintf (string2, "%s|%0100d|%s|%s|%0*d|%*.*f|%100.100f", "this pete guy sure is a wuss, like he's the number ", 1, " wuss. everyone agrees.\n", string1->str, 10, 666, 15, 15, 666.666666666, 666.666666666); #endif g_print ("string2 length = %d...\n", string2->len); string2->str[70] = '\0'; g_print ("first 70 chars:\n%s\n", string2->str); string2->str[141] = '\0'; g_print ("next 70 chars:\n%s\n", string2->str+71); string2->str[212] = '\0'; g_print ("and next 70:\n%s\n", string2->str+142); g_print ("last 70 chars:\n%s\n", string2->str+string2->len - 70); g_print ("ok\n"); g_print ("checking timers...\n"); timer = g_timer_new (); g_print (" spinning for 3 seconds...\n"); g_timer_start (timer); while (g_timer_elapsed (timer, NULL) < 3) ; g_timer_stop (timer); g_timer_destroy (timer); g_print ("ok\n"); g_print ("checking g_strcasecmp..."); g_assert (g_strcasecmp ("FroboZZ", "frobozz") == 0); g_assert (g_strcasecmp ("frobozz", "frobozz") == 0); g_assert (g_strcasecmp ("frobozz", "FROBOZZ") == 0); g_assert (g_strcasecmp ("FROBOZZ", "froboz") != 0); g_assert (g_strcasecmp ("", "") == 0); g_assert (g_strcasecmp ("!#%&/()", "!#%&/()") == 0); g_assert (g_strcasecmp ("a", "b") < 0); g_assert (g_strcasecmp ("a", "B") < 0); g_assert (g_strcasecmp ("A", "b") < 0); g_assert (g_strcasecmp ("A", "B") < 0); g_assert (g_strcasecmp ("b", "a") > 0); g_assert (g_strcasecmp ("b", "A") > 0); g_assert (g_strcasecmp ("B", "a") > 0); g_assert (g_strcasecmp ("B", "A") > 0); g_print ("ok\n"); g_print ("checking g_strdup..."); g_assert(g_strdup(NULL) == NULL); string = g_strdup(GLIB_TEST_STRING); g_assert(string != NULL); g_assert(strcmp(string, GLIB_TEST_STRING) == 0); g_free(string); g_print ("ok\n"); g_print ("checking g_strconcat..."); string = g_strconcat(GLIB_TEST_STRING, NULL); g_assert(string != NULL); g_assert(strcmp(string, GLIB_TEST_STRING) == 0); g_free(string); string = g_strconcat(GLIB_TEST_STRING, GLIB_TEST_STRING, GLIB_TEST_STRING, NULL); g_assert(string != NULL); g_assert(strcmp(string, GLIB_TEST_STRING GLIB_TEST_STRING GLIB_TEST_STRING) == 0); g_free(string); g_print ("ok\n"); g_print ("checking g_strdup_printf..."); string = g_strdup_printf ("%05d %-5s", 21, "test"); g_assert (string != NULL); g_assert (strcmp(string, "00021 test ") == 0); g_free (string); g_print ("ok\n"); /* g_debug (argv[0]); */ /* Relation tests */ g_print ("checking relations..."); relation = g_relation_new (2); g_relation_index (relation, 0, g_int_hash, g_int_equal); g_relation_index (relation, 1, g_int_hash, g_int_equal); for (i = 0; i < 1024; i += 1) data[i] = i; for (i = 1; i < 1023; i += 1) { g_relation_insert (relation, data + i, data + i + 1); g_relation_insert (relation, data + i, data + i - 1); } for (i = 2; i < 1022; i += 1) { g_assert (! g_relation_exists (relation, data + i, data + i)); g_assert (! g_relation_exists (relation, data + i, data + i + 2)); g_assert (! g_relation_exists (relation, data + i, data + i - 2)); } for (i = 1; i < 1023; i += 1) { g_assert (g_relation_exists (relation, data + i, data + i + 1)); g_assert (g_relation_exists (relation, data + i, data + i - 1)); } for (i = 2; i < 1022; i += 1) { g_assert (g_relation_count (relation, data + i, 0) == 2); g_assert (g_relation_count (relation, data + i, 1) == 2); } g_assert (g_relation_count (relation, data, 0) == 0); g_assert (g_relation_count (relation, data + 42, 0) == 2); g_assert (g_relation_count (relation, data + 43, 1) == 2); g_assert (g_relation_count (relation, data + 41, 1) == 2); g_relation_delete (relation, data + 42, 0); g_assert (g_relation_count (relation, data + 42, 0) == 0); g_assert (g_relation_count (relation, data + 43, 1) == 1); g_assert (g_relation_count (relation, data + 41, 1) == 1); tuples = g_relation_select (relation, data + 200, 0); g_assert (tuples->len == 2); #if 0 for (i = 0; i < tuples->len; i += 1) { printf ("%d %d\n", *(gint*) g_tuples_index (tuples, i, 0), *(gint*) g_tuples_index (tuples, i, 1)); } #endif g_assert (g_relation_exists (relation, data + 300, data + 301)); g_relation_delete (relation, data + 300, 0); g_assert (!g_relation_exists (relation, data + 300, data + 301)); g_tuples_destroy (tuples); g_relation_destroy (relation); relation = NULL; g_print ("ok\n"); g_print ("checking pointer arrays..."); gparray = g_ptr_array_new (); for (i = 0; i < 10000; i++) g_ptr_array_add (gparray, GINT_TO_POINTER (i)); for (i = 0; i < 10000; i++) if (g_ptr_array_index (gparray, i) != GINT_TO_POINTER (i)) g_print ("array fails: %p ( %p )\n", g_ptr_array_index (gparray, i), GINT_TO_POINTER (i)); g_ptr_array_free (gparray, TRUE); g_print ("ok\n"); g_print ("checking byte arrays..."); gbarray = g_byte_array_new (); for (i = 0; i < 10000; i++) g_byte_array_append (gbarray, (guint8*) "abcd", 4); for (i = 0; i < 10000; i++) { g_assert (gbarray->data[4*i] == 'a'); g_assert (gbarray->data[4*i+1] == 'b'); g_assert (gbarray->data[4*i+2] == 'c'); g_assert (gbarray->data[4*i+3] == 'd'); } g_byte_array_free (gbarray, TRUE); g_print ("ok\n"); g_printerr ("g_log tests:"); g_warning ("harmless warning with parameters: %d %s %#x", 42, "Boo", 12345); g_message ("the next warning is a test:"); string = NULL; g_print (string); g_print ("checking endian macros (host is "); #if G_BYTE_ORDER == G_BIG_ENDIAN g_print ("big endian)..."); #else g_print ("little endian)..."); #endif g_assert (GUINT16_SWAP_LE_BE (gu16t1) == gu16t2); g_assert (GUINT32_SWAP_LE_BE (gu32t1) == gu32t2); #ifdef G_HAVE_GINT64 g_assert (GUINT64_SWAP_LE_BE (gu64t1) == gu64t2); #endif g_print ("ok\n"); return 0; }
void cr_package_free(cr_Package *package) { if (!package) return; if (package->chunk && !(package->loadingflags & CR_PACKAGE_SINGLE_CHUNK)) g_string_chunk_free (package->chunk); /* Note: Since glib 2.28 * g_slist_foreach && g_slist_free could be replaced with one function: * g_slist_free_full() */ if (package->requires) { g_slist_foreach (package->requires, (GFunc) g_free, NULL); g_slist_free (package->requires); } if (package->provides) { g_slist_foreach (package->provides, (GFunc) g_free, NULL); g_slist_free (package->provides); } if (package->conflicts) { g_slist_foreach (package->conflicts, (GFunc) g_free, NULL); g_slist_free (package->conflicts); } if (package->obsoletes) { g_slist_foreach (package->obsoletes, (GFunc) g_free, NULL); g_slist_free (package->obsoletes); } if (package->suggests) { g_slist_foreach (package->suggests, (GFunc) g_free, NULL); g_slist_free (package->suggests); } if (package->enhances) { g_slist_foreach (package->enhances, (GFunc) g_free, NULL); g_slist_free (package->enhances); } if (package->recommends) { g_slist_foreach (package->recommends, (GFunc) g_free, NULL); g_slist_free (package->recommends); } if (package->supplements) { g_slist_foreach (package->supplements, (GFunc) g_free, NULL); g_slist_free (package->supplements); } if (package->files) { g_slist_foreach (package->files, (GFunc) g_free, NULL); g_slist_free (package->files); } if (package->changelogs) { g_slist_foreach (package->changelogs, (GFunc) g_free, NULL); g_slist_free (package->changelogs); } g_free(package->siggpg); g_free(package->sigpgp); g_free (package); }
/* * stf_read_workbook_auto_csvtab: * @fo: file opener * @enc: optional encoding * @context: command context * @book: workbook * @input: file to read from+convert * * Attempt to auto-detect CSV or tab-delimited file */ static void stf_read_workbook_auto_csvtab (G_GNUC_UNUSED GOFileOpener const *fo, gchar const *enc, GOIOContext *context, GoView *view, GsfInput *input) { Sheet *sheet; Workbook *book; char *name; char *data; GString *utf8data; size_t data_len; StfParseOptions_t *po; const char *gsfname; int cols, rows, i; GStringChunk *lines_chunk; GPtrArray *lines; WorkbookView *wbv = GNM_WORKBOOK_VIEW (view); g_return_if_fail (context != NULL); g_return_if_fail (wbv != NULL); book = wb_view_get_workbook (wbv); data = stf_preparse (context, input, &data_len); if (!data) return; enc = go_guess_encoding (data, data_len, enc, &utf8data, NULL); g_free (data); if (!enc) { go_cmd_context_error_import (GO_CMD_CONTEXT (context), _("That file is not in the given encoding.")); return; } clear_stray_NULs (context, utf8data); /* * Try to get the filename we're reading from. This is not a * great way. */ gsfname = gsf_input_name (input); { const char *ext = gsf_extension_pointer (gsfname); gboolean iscsv = ext && strcasecmp (ext, "csv") == 0; if (iscsv) po = stf_parse_options_guess_csv (utf8data->str); else po = stf_parse_options_guess (utf8data->str); } lines_chunk = g_string_chunk_new (100 * 1024); lines = stf_parse_general (po, lines_chunk, utf8data->str, utf8data->str + utf8data->len); rows = lines->len; cols = 0; for (i = 0; i < rows; i++) { GPtrArray *line = g_ptr_array_index (lines, i); cols = MAX (cols, (int)line->len); } gnm_sheet_suggest_size (&cols, &rows); stf_parse_general_free (lines); g_string_chunk_free (lines_chunk); name = g_path_get_basename (gsfname); sheet = sheet_new (book, name, cols, rows); g_free (name); workbook_sheet_attach (book, sheet); if (stf_parse_sheet (po, utf8data->str, NULL, sheet, 0, 0)) { gboolean is_csv; workbook_recalc_all (book); resize_columns (sheet); if (po->cols_exceeded || po->rows_exceeded) { stf_warning (context, _("Some data did not fit on the " "sheet and was dropped.")); } is_csv = po->sep.chr && po->sep.chr[0] == ','; workbook_set_saveinfo (book, GO_FILE_FL_WRITE_ONLY, go_file_saver_for_id (is_csv ? "Gnumeric_stf:stf_csv" : "Gnumeric_stf:stf_assistant")); } else { workbook_sheet_delete (sheet); go_cmd_context_error_import (GO_CMD_CONTEXT (context), _("Parse error while trying to parse data into sheet")); } stf_parse_options_free (po); g_string_free (utf8data, TRUE); }