diff options
author | Christian Persch <chpe@gnome.org> | 2012-02-15 18:37:06 +0100 |
---|---|---|
committer | Christian Persch <chpe@gnome.org> | 2012-02-15 18:44:24 +0100 |
commit | 6c7d121caf0fc19804670b8e98ae5e1c9abf6a76 (patch) | |
tree | 707c7e1c12abd41f68d542f9f49bbc9e2e312167 | |
parent | 4471d09cd4628eacd46d5bd299a4c7aa8e8fec77 (diff) | |
download | glib-wip/mapped-bytes.tar.gz |
gbytes: Replace GMappedFile with GBytes in glibwip/mapped-bytes
Don't use deprecated APIs inside glib!
-rw-r--r-- | gio/gvdb/gvdb-reader.c | 10 | ||||
-rw-r--r-- | glib/gtimezone.c | 11 | ||||
-rw-r--r-- | glib/gvariant.c | 2 | ||||
-rw-r--r-- | glib/tests/mappedfile.c | 35 | ||||
-rw-r--r-- | glib/tests/strfuncs.c | 13 | ||||
-rw-r--r-- | tests/mapping-test.c | 32 |
6 files changed, 50 insertions, 53 deletions
diff --git a/gio/gvdb/gvdb-reader.c b/gio/gvdb/gvdb-reader.c index 5c3343403..47f85bd3d 100644 --- a/gio/gvdb/gvdb-reader.c +++ b/gio/gvdb/gvdb-reader.c @@ -207,17 +207,17 @@ gvdb_table_new (const gchar *filename, gboolean trusted, GError **error) { - GMappedFile *mapped; + GBytes *mapped; if ((mapped = g_mapped_file_new (filename, FALSE, error)) == NULL) return NULL; - return new_from_data (g_mapped_file_get_contents (mapped), - g_mapped_file_get_length (mapped), + return new_from_data (g_bytes_get_data (mapped, NULL), + g_bytes_get_size (mapped), trusted, mapped, - (GvdbRefFunc)g_mapped_file_ref, - (GDestroyNotify)g_mapped_file_unref, + (GvdbRefFunc)g_bytes_ref, + (GDestroyNotify)g_bytes_unref, filename, error); } diff --git a/glib/gtimezone.c b/glib/gtimezone.c index 8195106e0..493d6734f 100644 --- a/glib/gtimezone.c +++ b/glib/gtimezone.c @@ -345,7 +345,6 @@ GTimeZone * g_time_zone_new (const gchar *identifier) { GTimeZone *tz; - GMappedFile *file; G_LOCK (time_zones); if (time_zones == NULL) @@ -391,15 +390,7 @@ g_time_zone_new (const gchar *identifier) else filename = g_strdup ("/etc/localtime"); - file = g_mapped_file_new (filename, FALSE, NULL); - if (file != NULL) - { - tz->zoneinfo = g_bytes_new_with_free_func (g_mapped_file_get_contents (file), - g_mapped_file_get_length (file), - (GDestroyNotify)g_mapped_file_unref, - g_mapped_file_ref (file)); - g_mapped_file_unref (file); - } + tz->zoneinfo = g_mapped_file_new (filename, FALSE, NULL); g_free (filename); } diff --git a/glib/gvariant.c b/glib/gvariant.c index 22341ff62..943169da3 100644 --- a/glib/gvariant.c +++ b/glib/gvariant.c @@ -238,7 +238,7 @@ * that it uses. The buffer is responsible for ensuring that the * correct call is made when the data is no longer in use by * #GVariant. This may involve a g_free() or a g_slice_free() or - * even g_mapped_file_unref(). + * even g_bytes_unref(). * </para> * <para> * One buffer management structure is used for each chunk of diff --git a/glib/tests/mappedfile.c b/glib/tests/mappedfile.c index 5387a643f..1c979c3fb 100644 --- a/glib/tests/mappedfile.c +++ b/glib/tests/mappedfile.c @@ -13,30 +13,30 @@ static void test_basic (void) { - GMappedFile *file; + GBytes *file; GError *error; error = NULL; file = g_mapped_file_new (SRCDIR "/empty", FALSE, &error); g_assert_no_error (error); - g_mapped_file_ref (file); - g_mapped_file_unref (file); + g_bytes_ref (file); + g_bytes_unref (file); - g_mapped_file_unref (file); + g_bytes_unref (file); } static void test_empty (void) { - GMappedFile *file; + GBytes *file; GError *error; error = NULL; file = g_mapped_file_new (SRCDIR "/empty", FALSE, &error); g_assert_no_error (error); - g_assert (g_mapped_file_get_contents (file) == NULL); + g_assert (g_bytes_get_data (file, NULL) == NULL); g_mapped_file_free (file); } @@ -45,7 +45,7 @@ static void test_device (void) { GError *error = NULL; - GMappedFile *file; + GBytes *file; file = g_mapped_file_new ("/dev/null", FALSE, &error); g_assert_error (error, G_FILE_ERROR, G_FILE_ERROR_INVAL); @@ -56,7 +56,7 @@ test_device (void) static void test_nonexisting (void) { - GMappedFile *file; + GBytes *file; GError *error; error = NULL; @@ -69,9 +69,10 @@ test_nonexisting (void) static void test_writable (void) { - GMappedFile *file; + GBytes *file; GError *error; gchar *contents; + gsize size; const gchar *old = "MMMMMMMMMMMMMMMMMMMMMMMMM"; const gchar *new = "abcdefghijklmnopqrstuvxyz"; @@ -85,7 +86,8 @@ test_writable (void) file = g_mapped_file_new (SRCDIR "/4096-random-bytes", TRUE, &error); g_assert_no_error (error); - contents = g_mapped_file_get_contents (file); + contents = (gchar *) g_bytes_get_data (file, &size); + g_assert_cmpint (size, ==, 4096); g_assert (strncmp (contents, old, strlen (old)) == 0); memcpy (contents, new, strlen (new)); @@ -97,7 +99,8 @@ test_writable (void) file = g_mapped_file_new (SRCDIR "/4096-random-bytes", TRUE, &error); g_assert_no_error (error); - contents = g_mapped_file_get_contents (file); + contents = (gchar *) g_bytes_get_data (file, &size); + g_assert_cmpint (size, ==, 4096); g_assert (strncmp (contents, old, strlen (old)) == 0); g_mapped_file_free (file); @@ -106,9 +109,10 @@ test_writable (void) static void test_writable_fd (void) { - GMappedFile *file; + GBytes *file; GError *error; gchar *contents; + gsize size; const gchar *old = "MMMMMMMMMMMMMMMMMMMMMMMMM"; const gchar *new = "abcdefghijklmnopqrstuvxyz"; int fd; @@ -125,7 +129,8 @@ test_writable_fd (void) file = g_mapped_file_new_from_fd (fd, TRUE, &error); g_assert_no_error (error); - contents = g_mapped_file_get_contents (file); + contents = (gchar *) g_bytes_get_data (file, &size); + g_assert_cmpint (size, ==, 4096); g_assert (strncmp (contents, old, strlen (old)) == 0); memcpy (contents, new, strlen (new)); @@ -140,11 +145,11 @@ test_writable_fd (void) file = g_mapped_file_new_from_fd (fd, TRUE, &error); g_assert_no_error (error); - contents = g_mapped_file_get_contents (file); + contents = (gchar *) g_bytes_get_data (file, &size); + g_assert_cmpint (size, ==, 4096); g_assert (strncmp (contents, old, strlen (old)) == 0); g_mapped_file_free (file); - } int diff --git a/glib/tests/strfuncs.c b/glib/tests/strfuncs.c index 358bc58d5..e83f9c3d7 100644 --- a/glib/tests/strfuncs.c +++ b/glib/tests/strfuncs.c @@ -1074,11 +1074,12 @@ test_strtoll (void) static void test_bounds (void) { - GMappedFile *file, *before, *after; + GBytes *file, *before, *after; char buffer[4097]; char *tmp, *tmp2; char **array; char *string; + gsize size; /* if we allocate the file between two others and then free those * other two, then hopefully we end up with unmapped memory on either @@ -1092,12 +1093,12 @@ test_bounds (void) file = g_mapped_file_new ("4096-random-bytes", TRUE, NULL); after = g_mapped_file_new ("4096-random-bytes", TRUE, NULL); - g_mapped_file_unref (before); - g_mapped_file_unref (after); + g_bytes_unref (before); + g_bytes_unref (after); g_assert (file != NULL); - g_assert_cmpint (g_mapped_file_get_length (file), ==, 4096); - string = g_mapped_file_get_contents (file); + string = (char *) g_bytes_get_data (file, &size); + g_assert_cmpint (size, ==, 4096); /* ensure they're all non-nul */ g_assert (memchr (string, '\0', 4096) == NULL); @@ -1227,7 +1228,7 @@ test_bounds (void) g_free (tmp2); g_free (tmp); - g_mapped_file_unref (file); + g_bytes_unref (file); } static void diff --git a/tests/mapping-test.c b/tests/mapping-test.c index 1a10b190b..8d4c55510 100644 --- a/tests/mapping-test.c +++ b/tests/mapping-test.c @@ -75,12 +75,12 @@ write_or_die (const gchar *filename, } } -static GMappedFile * +static GBytes * map_or_die (const gchar *filename, gboolean writable) { GError *error = NULL; - GMappedFile *map; + GBytes *map; gchar *displayname; map = g_mapped_file_new (filename, writable, &error); @@ -98,7 +98,7 @@ map_or_die (const gchar *filename, static int child_main (int argc, char *argv[]) { - GMappedFile *map; + GBytes *map; GMainLoop *loop; map = map_or_die (filename, FALSE); @@ -112,8 +112,8 @@ child_main (int argc, char *argv[]) g_main_loop_run (loop); write_or_die (childname, - g_mapped_file_get_contents (map), - g_mapped_file_get_length (map)); + g_bytes_get_data (map, NULL), + g_bytes_get_size (map)); return 0; } @@ -121,35 +121,35 @@ child_main (int argc, char *argv[]) static void test_mapping (void) { - GMappedFile *map; + GBytes *map; write_or_die (filename, "ABC", -1); map = map_or_die (filename, FALSE); - g_assert (g_mapped_file_get_length (map) == 3); - g_mapped_file_free (map); + g_assert_cmpint (g_bytes_get_size (map), ==, 3); + g_bytes_unref (map); map = map_or_die (filename, TRUE); - g_assert (g_mapped_file_get_length (map) == 3); - g_mapped_file_free (map); + g_assert_cmpint (g_bytes_get_size (map), ==, 3); + g_bytes_unref (map); } static void test_private (void) { GError *error = NULL; - GMappedFile *map; + GBytes *map; gchar *buffer; gsize len; write_or_die (filename, "ABC", -1); map = map_or_die (filename, TRUE); - buffer = (gchar *)g_mapped_file_get_contents (map); + buffer = (gchar *)g_bytes_get_data (map, NULL); buffer[0] = '1'; buffer[1] = '2'; buffer[2] = '3'; - g_mapped_file_free (map); + g_bytes_unref (map); if (!g_file_get_contents (filename, &buffer, &len, &error)) { @@ -168,7 +168,7 @@ static void test_child_private (gchar *argv0) { GError *error = NULL; - GMappedFile *map; + GBytes *map; gchar *buffer; gsize len; gchar *child_argv[3]; @@ -196,11 +196,11 @@ test_child_private (gchar *argv0) /* give the child some time to set up its mapping */ g_usleep (2000000); - buffer = (gchar *)g_mapped_file_get_contents (map); + buffer = (gchar *)g_bytes_get_data (map, NULL); buffer[0] = '1'; buffer[1] = '2'; buffer[2] = '3'; - g_mapped_file_free (map); + g_bytes_unref (map); #ifndef G_OS_WIN32 kill (child_pid, SIGUSR1); |