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 5c9dc009be46441c7144aeed9461616baeb931a2 (commit) via cdfa30d0778d9c858b177df70de3eeda298d1614 (commit) via b3f1272a01421ef58f93055ef540b4da7f2e8a9b (commit) from 65def9162f29b2c9e8b4d49192289cc5fa95c3e1 (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/5c9dc009be46441c7144aeed9461616baeb93...
commit 5c9dc009be46441c7144aeed9461616baeb931a2 Author: Cyril Hrubis metan@ucw.cz Date: Thu Sep 26 23:15:29 2013 +0200
loaders: BMP, PNM, TIFF: Fix abort path.
* Unlink file if GP_Save{BMP, PNM, TIFF}() was aborted.
* Fix memleak if GP_SaveTIFF() was aborted.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/libs/loaders/GP_BMP.c b/libs/loaders/GP_BMP.c index 3a56413..d7ea61f 100644 --- a/libs/loaders/GP_BMP.c +++ b/libs/loaders/GP_BMP.c @@ -883,6 +883,7 @@ int GP_SaveBMP(const GP_Context *src, const char *dst_path, err1: fclose(f); err0: + unlink(dst_path); errno = err; return 1; } diff --git a/libs/loaders/GP_PNM.c b/libs/loaders/GP_PNM.c index 027dae2..09018fe 100644 --- a/libs/loaders/GP_PNM.c +++ b/libs/loaders/GP_PNM.c @@ -659,6 +659,7 @@ int GP_SavePBM(const GP_Context *src, const char *dst_path, GP_ProgressCallback *callback) { FILE *f; + int err;
GP_DEBUG(1, "Saving context %ux%u %s to '%s'", src->w, src->h, GP_PixelTypeName(src->pixel_type), dst_path); @@ -676,19 +677,22 @@ int GP_SavePBM(const GP_Context *src, const char *dst_path, return 1;
if (fprintf(f, "P1n%u %un", - (unsigned int) src->w, (unsigned int) src->h) < 0) - goto err; + (unsigned int) src->w, (unsigned int) src->h) < 0) { + err = EIO; + goto err0; + }
- if (save_ascii(f, src, callback, 1)) - goto err; + if ((err = save_ascii(f, src, callback, 1))) + goto err0;
if (fclose(f)) - return 1; + goto err0;
return 0; -err: +err0: fclose(f); - errno = EIO; + unlink(dst_path); + errno = err; return 1; }
@@ -866,6 +870,7 @@ int GP_SavePGM(const GP_Context *src, const char *dst_path, err1: fclose(f); err0: + unlink(dst_path); errno = err; return 1; } @@ -1048,9 +1053,8 @@ err1: fclose(f); err0: errno = err; + unlink(dst_path); return 1; - errno = ENOSYS; - return -1; }
GP_Context *GP_LoadPNM(const char *src_path, GP_ProgressCallback *callback) diff --git a/libs/loaders/GP_TIFF.c b/libs/loaders/GP_TIFF.c index 3a7b422..4443127 100644 --- a/libs/loaders/GP_TIFF.c +++ b/libs/loaders/GP_TIFF.c @@ -543,20 +543,15 @@ static int save_grayscale(TIFF *tiff, const GP_Context *src, if (ret == -1) { //TODO TIFF ERROR GP_DEBUG(1, "TIFFWriteEncodedStrip failed"); - errno = EIO; - return 1; + return EIO; }
if (GP_ProgressCallbackReport(callback, y, src->h, src->w)) { GP_DEBUG(1, "Operation aborted"); - errno = ECANCELED; - return 1; + return ECANCELED; } }
- TIFFClose(tiff); - - GP_ProgressCallbackDone(callback); return 0; }
@@ -598,14 +593,10 @@ static int save_rgb(TIFF *tiff, const GP_Context *src,
if (GP_ProgressCallbackReport(callback, y, src->h, src->w)) { GP_DEBUG(1, "Operation aborted"); - errno = ECANCELED; - return 1; + return ECANCELED; } }
- TIFFClose(tiff); - - GP_ProgressCallbackDone(callback); return 0; }
@@ -613,6 +604,7 @@ int GP_SaveTIFF(const GP_Context *src, const char *dst_path, GP_ProgressCallback *callback) { TIFF *tiff; + int err = 0;
if (GP_PixelHasFlags(src->pixel_type, GP_PIXEL_HAS_ALPHA)) { GP_DEBUG(1, "Alpha channel not supported yet"); @@ -642,6 +634,7 @@ int GP_SaveTIFF(const GP_Context *src, const char *dst_path,
if (tiff == NULL) { GP_DEBUG(1, "Failed to open tiff '%s'", dst_path); + //ERRNO? return 1; }
@@ -651,20 +644,32 @@ int GP_SaveTIFF(const GP_Context *src, const char *dst_path, TIFFSetField(tiff, TIFFTAG_ROWSPERSTRIP, 1); TIFFSetField(tiff, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
- /* Save grayscale */ - if (GP_PixelHasFlags(src->pixel_type, GP_PIXEL_IS_GRAYSCALE)) - return save_grayscale(tiff, src, callback); - switch (src->pixel_type) { case GP_PIXEL_RGB888: case GP_PIXEL_BGR888: case GP_PIXEL_xRGB8888: - return save_rgb(tiff, src, callback); + err = save_rgb(tiff, src, callback); + break; + case GP_PIXEL_G1: + case GP_PIXEL_G2: + case GP_PIXEL_G4: + case GP_PIXEL_G8: + err = save_grayscale(tiff, src, callback); + break; default: + GP_BUG("Wrong pixel type"); break; }
- GP_BUG("Should not be reached"); + if (err) { + TIFFClose(tiff); + unlink(dst_path); + errno = err; + return 1; + } + + TIFFClose(tiff); + GP_ProgressCallbackDone(callback); return 0; }
http://repo.or.cz/w/gfxprim.git/commit/cdfa30d0778d9c858b177df70de3eeda298d1...
commit cdfa30d0778d9c858b177df70de3eeda298d1614 Author: Cyril Hrubis metan@ucw.cz Date: Thu Sep 26 22:47:46 2013 +0200
tests: loaders: New SaveAbort test.
New test that aborts file saving and checks that file was removed and memory freed.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/tests/loaders/Makefile b/tests/loaders/Makefile index 24cd1e4..66edb90 100644 --- a/tests/loaders/Makefile +++ b/tests/loaders/Makefile @@ -2,9 +2,9 @@ TOPDIR=../.. include $(TOPDIR)/pre.mk
CSOURCES=loaders_suite.c PNG.c PBM.c PGM.c PPM.c -GENSOURCES=SaveLoad.gen.c +GENSOURCES=SaveLoad.gen.c SaveAbort.gen.c
-APPS=loaders_suite PNG PBM PGM PPM SaveLoad.gen +APPS=loaders_suite PNG PBM PGM PPM SaveLoad.gen SaveAbort.gen
include ../tests.mk
diff --git a/tests/loaders/SaveLoad.gen.c.t b/tests/loaders/SaveAbort.gen.c.t similarity index 73% copy from tests/loaders/SaveLoad.gen.c.t copy to tests/loaders/SaveAbort.gen.c.t index df2767f..eb0796c 100644 --- a/tests/loaders/SaveLoad.gen.c.t +++ b/tests/loaders/SaveAbort.gen.c.t @@ -23,7 +23,7 @@ %% extends "base.test.c.t"
%% block descr -Iterate over all pixel types, try to save and load back context. +Iterate over all pixel types, try to save context but abort it from callback. %% endblock descr
%% block body @@ -33,21 +33,24 @@ Iterate over all pixel types, try to save and load back context. #include <stdlib.h>
#include <core/GP_Context.h> -#include <core/GP_GetPutPixel.h> #include <loaders/GP_Loaders.h>
#include "tst_test.h"
-%% set fmts = ['PNG', 'JPG', 'TIFF', 'BMP', 'PBM', 'PGM', 'PPM', 'PNM'] +%% import "savers.t" as savers
typedef int (*Save)(const GP_Context *src, const char *path, GP_ProgressCallback *callback); -typedef GP_Context *(*Load)(const char *path, GP_ProgressCallback *callback);
-static int test(Save Saver, Load Loader, GP_PixelType pixel_type) +static int progress_callback(GP_ProgressCallback *self) +{ + (void) self; + return 1; +} + +static int test(Save Saver, GP_PixelType pixel_type) { GP_Context *src; - GP_Context *res; - unsigned int x, y; + GP_ProgressCallback callback ={.callback = progress_callback}; int ret = TST_SUCCESS;
src = GP_ContextAlloc(100, 100, pixel_type); @@ -57,11 +60,7 @@ static int test(Save Saver, Load Loader, GP_PixelType pixel_type) return TST_UNTESTED; }
- for (x = 0; x < src->w; x++) - for (y = 0; y < src->w; y++) - GP_PutPixel(src, x, y, 0); - - if (Saver(src, "testfile", NULL)) { + if (Saver(src, "testfile", &callback)) { if (errno == ENOSYS) { tst_msg("Unimplemented pixel value"); ret = TST_SKIPPED; @@ -74,43 +73,35 @@ static int test(Save Saver, Load Loader, GP_PixelType pixel_type) goto err; }
- tst_msg("Saver failed with %s", strerror(errno)); - ret = TST_FAILED; - goto err; - } - - res = Loader("testfile", NULL); + if (errno == ECANCELED) { + if (access("testfile", F_OK) == 0) { + tst_msg("Operation canceled but file exists"); + ret = TST_FAILED; + goto err; + } else { + goto err; + } + }
- if (!res) { - tst_msg("Failed to load saved image"); + tst_msg("Saver failed with %s", strerror(errno)); ret = TST_FAILED; goto err; - } - - tst_msg("Loaded back as %s", GP_PixelTypeName(res->pixel_type)); - - if (res->w != src->w || res->h != src->h) { - tst_msg("Invalid loaded image size %ux%u", res->w, res->h); - ret = TST_FAILED; - } - - if (GP_GetPixel(res, 0, 0) != 0) { - tst_msg("Pixel value is wrong %x", GP_GetPixel(res, 0, 0)); + } else { + tst_msg("Succedded unexpectedly"); ret = TST_FAILED; }
- GP_ContextFree(res); err: GP_ContextFree(src); return ret; }
-%% for fmt in fmts +%% for fmt in savers.fmts %% for pt in pixeltypes %% if not pt.is_unknown() static int test_{{ fmt }}_{{ pt.name }}(void) { - return test(GP_Save{{ fmt }}, GP_Load{{ fmt }}, GP_PIXEL_{{ pt.name }}); + return test(GP_Save{{ fmt }}, GP_PIXEL_{{ pt.name }}); }
%% endif @@ -118,9 +109,9 @@ static int test_{{ fmt }}_{{ pt.name }}(void) %% endfor
const struct tst_suite tst_suite = { - .suite_name = "SaveLoad", + .suite_name = "SaveAbort", .tests = { -%% for fmt in fmts +%% for fmt in savers.fmts %% for pt in pixeltypes %% if not pt.is_unknown() {.name = "{{ fmt }} {{ pt.name }}", diff --git a/tests/loaders/SaveLoad.gen.c.t b/tests/loaders/SaveLoad.gen.c.t index df2767f..81478c0 100644 --- a/tests/loaders/SaveLoad.gen.c.t +++ b/tests/loaders/SaveLoad.gen.c.t @@ -38,7 +38,7 @@ Iterate over all pixel types, try to save and load back context.
#include "tst_test.h"
-%% set fmts = ['PNG', 'JPG', 'TIFF', 'BMP', 'PBM', 'PGM', 'PPM', 'PNM'] +%% import "savers.t" as savers
typedef int (*Save)(const GP_Context *src, const char *path, GP_ProgressCallback *callback); typedef GP_Context *(*Load)(const char *path, GP_ProgressCallback *callback); @@ -105,7 +105,7 @@ err: return ret; }
-%% for fmt in fmts +%% for fmt in savers.fmts %% for pt in pixeltypes %% if not pt.is_unknown() static int test_{{ fmt }}_{{ pt.name }}(void) @@ -120,7 +120,7 @@ static int test_{{ fmt }}_{{ pt.name }}(void) const struct tst_suite tst_suite = { .suite_name = "SaveLoad", .tests = { -%% for fmt in fmts +%% for fmt in savers.fmts %% for pt in pixeltypes %% if not pt.is_unknown() {.name = "{{ fmt }} {{ pt.name }}", diff --git a/tests/loaders/savers.t b/tests/loaders/savers.t new file mode 100644 index 0000000..2403cfe --- /dev/null +++ b/tests/loaders/savers.t @@ -0,0 +1,2 @@ +{# Formats for which save is implemented #} +%% set fmts = ['PNG', 'JPG', 'TIFF', 'BMP', 'PBM', 'PGM', 'PPM', 'PNM'] diff --git a/tests/loaders/test_list.txt b/tests/loaders/test_list.txt index e9fdf3d..162943e 100644 --- a/tests/loaders/test_list.txt +++ b/tests/loaders/test_list.txt @@ -5,3 +5,4 @@ PBM PGM PPM SaveLoad.gen +SaveAbort.gen
http://repo.or.cz/w/gfxprim.git/commit/b3f1272a01421ef58f93055ef540b4da7f2e8...
commit b3f1272a01421ef58f93055ef540b4da7f2e8a9b Author: Cyril Hrubis metan@ucw.cz Date: Thu Sep 26 22:35:15 2013 +0200
render_utils.py: Add ./ to jinja2 template paths.
This allows us to import and include files located in current directory.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/pylib/gp_codegen/render_utils.py b/pylib/gp_codegen/render_utils.py index c5433ea..c0177db 100644 --- a/pylib/gp_codegen/render_utils.py +++ b/pylib/gp_codegen/render_utils.py @@ -40,7 +40,7 @@ def create_environment(config, template_dir): env = jinja2.Environment( line_statement_prefix = "%%", undefined = jinja2.StrictUndefined, - loader = jinja2.FileSystemLoader(template_dir)) + loader = jinja2.FileSystemLoader([template_dir,"./"])) env.globals['undefined'] = jinja2.StrictUndefined() env.globals['pixelsizes'] = config.pixelsizes env.globals['pixelsizes_by_bpp'] = config.pixelsizes_by_bpp
-----------------------------------------------------------------------
Summary of changes: libs/loaders/GP_BMP.c | 1 + libs/loaders/GP_PNM.c | 22 ++++--- libs/loaders/GP_TIFF.c | 41 +++++++------ pylib/gp_codegen/render_utils.py | 2 +- tests/loaders/Makefile | 4 +- .../{SaveLoad.gen.c.t => SaveAbort.gen.c.t} | 63 ++++++++----------- tests/loaders/SaveLoad.gen.c.t | 6 +- tests/loaders/savers.t | 2 + tests/loaders/test_list.txt | 1 + 9 files changed, 73 insertions(+), 69 deletions(-) copy tests/loaders/{SaveLoad.gen.c.t => SaveAbort.gen.c.t} (73%) create mode 100644 tests/loaders/savers.t
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.