This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project gfxprim.git.
The branch, master has been updated via 334730ba119db655383ca862373271fb11fd9d87 (commit) via ec22f36da6e391b7eeb08d02f860ae12371ef1a4 (commit) via 273279db3fb62bc3757a213b231a88b8e107383b (commit) from 25054131fde91ee366211edb541a0628ffa4b2e3 (commit)
Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below.
- Log ----------------------------------------------------------------- http://repo.or.cz/w/gfxprim.git/commit/334730ba119db655383ca862373271fb11fd9...
commit 334730ba119db655383ca862373271fb11fd9d87 Author: Cyril Hrubis metan@ucw.cz Date: Wed Jun 25 21:43:17 2014 +0200
loaders: IO; Fix IOMem and IOSubIO seeks
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/libs/loaders/GP_IO.c b/libs/loaders/GP_IO.c index c8dd9038..ae29eb93 100644 --- a/libs/loaders/GP_IO.c +++ b/libs/loaders/GP_IO.c @@ -65,7 +65,7 @@ static off_t file_seek(GP_IO *self, off_t off, enum GP_IOWhence whence) default: GP_WARN("Invalid whence"); errno = EINVAL; - return (off_t)-1; + return -1; }
return lseek(file_io->fd, off, whence); @@ -173,31 +173,32 @@ static off_t mem_seek(GP_IO *io, off_t off, enum GP_IOWhence whence)
switch (whence) { case GP_IO_SEEK_CUR: - if (off + mem_io->pos > mem_io->size) { + if (-off > (off_t)mem_io->pos || + off + mem_io->pos > mem_io->size) { errno = EINVAL; - return (off_t)-1; + return -1; }
mem_io->pos += off; break; case GP_IO_SEEK_SET: - if (off < 0 || off > (off_t)mem_io->pos) { + if (off < 0 || off > (off_t)mem_io->size) { errno = EINVAL; - return (off_t)-1; + return -1; } mem_io->pos = off; break; case GP_IO_SEEK_END: - if (off) { + if (off > 0 || off + (off_t)mem_io->size < 0) { errno = EINVAL; - return (off_t)-1; + return -1; } - mem_io->pos = mem_io->size; + mem_io->pos = mem_io->size + off; break; default: GP_WARN("Invalid whence"); errno = EINVAL; - return (off_t)-1; + return -1; }
return mem_io->pos; @@ -295,7 +296,7 @@ static off_t sub_seek(GP_IO *io, off_t off, enum GP_IOWhence whence)
if (poff < sub_io->start || poff > sub_io->end) { errno = EINVAL; - return (off_t)-1; + return -1; }
ret = GP_IOSeek(sub_io->io, off, whence); @@ -305,7 +306,7 @@ static off_t sub_seek(GP_IO *io, off_t off, enum GP_IOWhence whence)
if (off > io_size || off < 0) { errno = EINVAL; - return (off_t)-1; + return -1; }
ret = GP_IOSeek(sub_io->io, sub_io->start + off, whence); @@ -315,19 +316,19 @@ static off_t sub_seek(GP_IO *io, off_t off, enum GP_IOWhence whence)
if (off + io_size < 0 || off > 0) { errno = EINVAL; - return (off_t)-1; + return -1; }
- ret = GP_IOSeek(sub_io->io, sub_io->end + off, whence); + ret = GP_IOSeek(sub_io->io, sub_io->end + off, GP_IO_SEEK_SET); break; default: GP_WARN("Invalid whence"); errno = EINVAL; - return (off_t)-1; + return -1; }
- if (ret == (off_t)-1) - return (off_t)-1; + if (ret == -1) + return -1;
sub_io->cur = ret;
@@ -467,8 +468,8 @@ int GP_IOMark(GP_IO *self, enum GP_IOMarkTypes type) return -1; }
- if (ret == (off_t)-1) { - GP_WARN("Failed to lseek IO Stream"); + if (ret == -1) { + GP_WARN("Failed to seek I/O Stream"); return -1; }
@@ -483,12 +484,12 @@ off_t GP_IOSize(GP_IO *io)
ret = GP_IOSeek(io, 0, GP_IO_SEEK_END);
- if (ret == (off_t)-1) + if (ret == -1) return ret;
GP_IOSeek(io, cur, GP_IO_SEEK_SET);
- GP_DEBUG(2, "IO Size = %lli", (long long)ret); + GP_DEBUG(2, "I/O Size = %lli", (long long)ret);
return ret; }
http://repo.or.cz/w/gfxprim.git/commit/ec22f36da6e391b7eeb08d02f860ae12371ef...
commit ec22f36da6e391b7eeb08d02f860ae12371ef1a4 Author: Cyril Hrubis metan@ucw.cz Date: Wed Jun 25 21:33:39 2014 +0200
tests: loaders: IO: Much more tests.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/tests/loaders/IO.c b/tests/loaders/IO.c index c193098d..2d08d831 100644 --- a/tests/loaders/IO.c +++ b/tests/loaders/IO.c @@ -28,20 +28,85 @@
#include "tst_test.h"
+static const char *whence_name(int whence) +{ + switch (whence) { + case GP_IO_SEEK_SET: + return "SEEK_SET"; + case GP_IO_SEEK_CUR: + return "SEEK_CUR"; + case GP_IO_SEEK_END: + return "SEEK_END"; + } + + return "INVALID"; +} + +static int seek_and_tell(GP_IO *io, off_t off, int whence, off_t exp_off) +{ + if (GP_IOSeek(io, off, whence) == -1) { + tst_msg("Failed to seek %zi %s", off, whence_name(whence)); + return 1; + } + + off = GP_IOTell(io); + + if (off != exp_off) { + tst_msg("Wrong offset %zi expected %zi", off, exp_off); + return 1; + } + + return 0; +} + +static int seek_fail(GP_IO *io, off_t off, int whence) +{ + off_t ret, start, end; + + start = GP_IOTell(io); + + ret = GP_IOSeek(io, off, whence); + + if (ret != -1) { + tst_msg("Seek succeded unexpectedly %zi %s", + off, whence_name(whence)); + return 1; + } + + end = GP_IOTell(io); + + if (start != end) { + tst_msg("Seek %zi %s failed but offset changed %zi -> %zi", + off, whence_name(whence), start, end); + return 1; + } + + return 0; +} + /* * Expects IO buffer filled with monotonically increasing bytes, i.e. * 0x00 0x01 0x02 ... */ -static int do_test(GP_IO *io) +static int do_test(GP_IO *io, off_t io_size, int is_file) { int ret; uint8_t buf[10]; unsigned int i; + off_t off; + int failed = 0; + + off = GP_IOTell(io); + + if (off != 0) { + tst_msg("Wrong offset before first read %zu", off); + return TST_FAILED; + }
ret = GP_IORead(io, buf, 10);
if (ret != 10) { - tst_msg("First IO read failed"); + tst_msg("First I/O read failed"); return TST_FAILED; }
@@ -52,10 +117,10 @@ static int do_test(GP_IO *io) } }
- ret = GP_IOTell(io); + off = GP_IOTell(io);
- if (ret != 10) { - tst_msg("Have wrong offset %u, after read 10", ret); + if (off != 10) { + tst_msg("Have wrong offset %zu, after read 10", off); return TST_FAILED; }
@@ -63,7 +128,7 @@ static int do_test(GP_IO *io) ret = GP_IORead(io, buf, 10);
if (ret != 10) { - tst_msg("Second IO read failed"); + tst_msg("Second I/O read failed"); return TST_FAILED; }
@@ -99,7 +164,7 @@ static int do_test(GP_IO *io) uint16_t val;
if (GP_IOReadF(io, header, &byte, &val) != 5) { - tst_msg("Failed to ReadF from Memory IO"); + tst_msg("Failed to ReadF from I/O"); return TST_FAILED; }
@@ -113,6 +178,49 @@ static int do_test(GP_IO *io) return TST_FAILED; }
+ /* Seek tests */ + if (seek_and_tell(io, 0, GP_IO_SEEK_END, io_size)) + failed++; + + if (seek_and_tell(io, -io_size, GP_IO_SEEK_END, 0)) + failed++; + + if (seek_and_tell(io, io_size, GP_IO_SEEK_SET, io_size)) + failed++; + + if (seek_and_tell(io, 0, GP_IO_SEEK_SET, 0)) + failed++; + + if (seek_and_tell(io, io_size, GP_IO_SEEK_CUR, io_size)) + failed++; + + if (seek_and_tell(io, -io_size, GP_IO_SEEK_CUR, 0)) + failed++; + + if (seek_fail(io, -1, GP_IO_SEEK_CUR)) + failed++; + + if (!is_file && seek_fail(io, io_size+1, GP_IO_SEEK_CUR)) + failed++; + + if (seek_fail(io, -1, GP_IO_SEEK_SET)) + failed++; + + if (!is_file && seek_fail(io, io_size + 1, GP_IO_SEEK_SET)) + failed++; + + if (!is_file && seek_fail(io, 1, GP_IO_SEEK_END)) + failed++; + + if (seek_fail(io, -io_size - 1, GP_IO_SEEK_END)) + failed++; + + if (seek_fail(io, 0, 100)) + failed++; + + if (failed) + return TST_FAILED; + return TST_SUCCESS; }
@@ -129,16 +237,18 @@ static int test_IOMem(void) io = GP_IOMem(buffer, sizeof(buffer), NULL);
if (!io) { - tst_msg("Failed to initialize memory IO"); + tst_msg("Failed to initialize memory I/O"); return TST_FAILED; }
- ret = do_test(io); - if (ret) + ret = do_test(io, sizeof(buffer), 0); + if (ret) { + GP_IOClose(io); return ret; + }
if (GP_IOClose(io)) { - tst_msg("Failed to close memory IO"); + tst_msg("Failed to close memory I/O"); return TST_FAILED; }
@@ -160,7 +270,7 @@ static int test_IOFile(void) io = GP_IOFile(TFILE, GP_IO_WRONLY);
if (!io) { - tst_msg("Failed to open file IO for writing: %s", + tst_msg("Failed to open file I/O for writing: %s", strerror(errno)); return TST_FAILED; } @@ -173,28 +283,101 @@ static int test_IOFile(void) }
if (GP_IOClose(io)) { - tst_msg("Failed to close file IO: %s", strerror(errno)); + tst_msg("Failed to close file I/O: %s", strerror(errno)); return TST_FAILED; }
io = GP_IOFile(TFILE, GP_IO_RDONLY);
if (!io) { - tst_msg("Failed to open file IO for reading: %s", + tst_msg("Failed to open file I/O for reading: %s", strerror(errno)); return TST_FAILED; }
- ret = do_test(io); - if (ret) + ret = do_test(io, sizeof(buffer), 1); + if (ret) { + GP_IOClose(io); + return ret; + } + + if (GP_IOClose(io)) { + tst_msg("Failed to close file I/O: %s", strerror(errno)); + return TST_FAILED; + } + + return TST_SUCCESS; +} + +static int test_IOSubIO(void) +{ + uint8_t buffer[128]; + unsigned int i; + GP_IO *io, *pio; + off_t off; + int ret; + + for (i = 0; i < sizeof(buffer); i++) + buffer[i] = i; + + pio = GP_IOMem(buffer, sizeof(buffer), NULL); + + if (!pio) { + tst_msg("Failed to initialize memory I/O"); + return TST_FAILED; + } + + io = GP_IOSubIO(pio, 100); + + if (!io) { + tst_msg("Failed to initialize sub I/O"); + GP_IOClose(io); + return TST_FAILED; + } + + ret = do_test(io, 100, 0); + if (ret) { + GP_IOClose(pio); + GP_IOClose(io); return ret; + } + + if (GP_IOSeek(io, 0, GP_IO_SEEK_END) == (off_t)-1) { + tst_msg("Failed to seek to the end of sub I/O: %s", + tst_strerr(errno)); + goto failed; + } + + ret = GP_IORead(io, buffer, sizeof(buffer)); + + if (ret != 0) { + tst_msg("Read at the end of sub I/O returned %i", ret); + goto failed; + } + + off = GP_IOTell(pio); + + if (off != 100) { + tst_msg("Wrong offset at the parent I/O: %zu", off); + goto failed; + }
if (GP_IOClose(io)) { - tst_msg("Failed to close file IO: %s", strerror(errno)); + tst_msg("Failed to close sub I/O"); + GP_IOClose(pio); + return TST_FAILED; + } + + if (GP_IOClose(pio)) { + tst_msg("Failed to close memory I/O"); return TST_FAILED; }
return TST_SUCCESS; +failed: + GP_IOClose(io); + GP_IOClose(pio); + return TST_FAILED; }
static ssize_t test_IOFill_read(GP_IO GP_UNUSED(*io), void *buf, size_t size) @@ -369,6 +552,10 @@ const struct tst_suite tst_suite = { .tst_fn = test_IOMem, .flags = TST_CHECK_MALLOC},
+ {.name = "IOSubIO", + .tst_fn = test_IOSubIO, + .flags = TST_CHECK_MALLOC}, + {.name = "IOFile", .tst_fn = test_IOFile, .flags = TST_CHECK_MALLOC | TST_TMPDIR},
http://repo.or.cz/w/gfxprim.git/commit/273279db3fb62bc3757a213b231a88b8e1073...
commit 273279db3fb62bc3757a213b231a88b8e107383b Author: Cyril Hrubis metan@ucw.cz Date: Wed Jun 25 20:50:07 2014 +0200
doc: loaders_io: Add GP_IOSubIO() documentation
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/doc/loaders_io.txt b/doc/loaders_io.txt index d3d00a7e..64656fd6 100644 --- a/doc/loaders_io.txt +++ b/doc/loaders_io.txt @@ -248,6 +248,32 @@ Creates an IO stream from a file. Returns a pointer to initialized I/O stream, or in case of failure NULL and errno is set.
+[source,c] +------------------------------------------------------------------------------- +#include <loaders/GP_IO.h> +/* or */ +#include <GP.h> + +GP_IO *GP_IOSubIO(GP_IO *pio, size_t size); +------------------------------------------------------------------------------- + +Creates an readable I/O on the top of an existing readable I/O. + +The stream position in the parent I/O is advanced when reading or seeking the +sub I/O. + +The sub I/O is limited to an interval starting at current position and can +advance size bytes at max; then it behaves like the stream has ended i.e. +'GP_IORead()' returns zero. + +You can seek in the resulting I/O if: + +* The parent I/O is seekable + +* The the combination of 'off' and 'whence' fits inside the sub I/O + +WARNING: If you combine reading or seeking in the parent I/O and sub I/O the + result is undefined.
[source,c] -------------------------------------------------------------------------------
-----------------------------------------------------------------------
Summary of changes: doc/loaders_io.txt | 26 ++++++ libs/loaders/GP_IO.c | 41 +++++----- tests/loaders/IO.c | 221 ++++++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 251 insertions(+), 37 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos@gmail.com if you want to unsubscribe, or site admin admin@repo.or.cz if you receive no reply.