This is an automated email from the git hooks/post-receive script. gert-guest pushed a commit to branch master in repository libvistaio.
commit 3abacb66596ca9bb85361fb1a6a2586e779521da Author: Gert Wollny <[email protected]> Date: Tue Nov 24 16:10:05 2015 +0100 Imported Upstream version 1.2.19 --- .gitignore | 1 + .travis.yml | 29 +++++++ CMakeLists.txt | 15 ++-- ChangeLog | 10 +++ README => README.md | 56 ++++++++---- vistaio/CMakeLists.txt | 5 +- vistaio/alloc.c | 3 +- vistaio/edgesType.c | 12 ++- vistaio/fileio.c | 37 +++++--- vistaio/graphType.c | 9 +- vistaio/imageType.c | 2 +- vistaio/option.c | 5 +- vistaio/{2dfield.c => test_2dfield.c} | 0 vistaio/{2dspline.c => test_2dspline.c} | 0 vistaio/{3dfield.c => test_3dfield.c} | 0 vistaio/test_attributes.c | 133 ++++++++++++++++++++++++++++ vistaio/test_images.c | 148 ++++++++++++++++++++++++++++++++ vistaio/vcplist.c | 1 + vistaio/vfield2d.c | 3 + vistaio/vfield3d.c | 3 + vistaio/volumes.c | 4 +- vistaio/volumesType.c | 24 ++++-- vistaio/vspline2d.c | 3 +- vistaio_change_names.py | 76 ++++++++++++++++ 24 files changed, 522 insertions(+), 57 deletions(-) diff --git a/.gitignore b/.gitignore index 96e8239..a0887d3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ build *~ +build-* diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..62f84dd --- /dev/null +++ b/.travis.yml @@ -0,0 +1,29 @@ +sudo: required +dist: trusty +before_script: +- mkdir build +- cd build +- cmake .. +script: +- make -j2 +after_success: +- make test + +env: + global: + secure: Swxl0u3vHytVnzKcv2QWDpjjOObA2H9QkUv9vtD6kEQsknVw2P9HYlhZgVGOLiH31SXNw2YN5qlZrPgDR96GwTtjmoWRKf7kNgM0SFtWYU1h4JbKfX/csLk6r3Vr/MAf7hPp4RPhmnzRU8wKNfWkUSIXYZ98oDqDdoD81prSDSlKKdm92EeOQ4PAimswWywzQJbBdSv49gT3tdQoure+1S+tbYcr7uUJVcOyFcDrO3sfgpdem+OTbVyP4BMdy3Q+ZsAvwwMMPFWnc67uMRzjxkEB6sU5L27Uu15IYMpYXmwdNYvsS+KdIEqOzYv+TD/GF8h4+JKaURPt1nuzPDKVrWqU+pdEGak625x1JMFqRl3x5/9cy1jIeRrpBjrq3B+V1JuB3t3iI9N3Ob7+ZRJLgwcQ02ikqtUbGY0Qiggi86GWGiOgHEpMfQ9e0gZ0DwBnRFwbd3hIssSBZKBxDDbaX73DBHEXGX6H [...] + + +addons: + coverity_scan: + + project: + name: vistaio + version: 1.2.19 + description: VistaIO library + + notification_email: [email protected] + + build_command: make + + branch_pattern: coverity_scan diff --git a/CMakeLists.txt b/CMakeLists.txt index 3ead488..aa057d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,16 +25,15 @@ SET(VENDOR "Gert Wollny") SET(PACKAGE_NAME "vistaio") SET(MAJOR_VERSION 1) SET(MINOR_VERSION 2) -SET(MICRO_VERSION 18) -SET(INTERFACE_AGE 1) -SET(BINARY_AGE 4) +SET(MICRO_VERSION 19) INCLUDE(GNUInstallDirs) -MATH(EXPR VISTAIO_CURRENT "${MICRO_VERSION} - ${BINARY_AGE}") -MATH(EXPR VISTAIO_AGE "${BINARY_AGE} - ${INTERFACE_AGE}") - -SET(LIBRARY_VERSION_INFO "${VISTAIO_CURRENT}.${INTERFACE_AGE}.${VISTAIO_AGE}") +SET(VISTAIO_CURRENT 14) +SET(VISTAIO_AGE 1) +SET(VISTAIO_REVISION 4) + +SET(LIBRARY_VERSION_INFO "${VISTAIO_CURRENT}.${VISTAIO_AGE}.${VISTAIO_REVISION}") SET(PACKAGE_VERSION "${MAJOR_VERSION}.${MINOR_VERSION}.${MICRO_VERSION}") SET(VERSION "${MAJOR_VERSION}.${MINOR_VERSION}") @@ -51,7 +50,7 @@ ADD_SUBDIRECTORY(doc) CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/libvistaio.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/libvistaio.pc) -SET(DOC_FILES Authors COPYING) +SET(DOC_FILES Authors COPYING README.md) INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/libvistaio.pc DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}/pkgconfig) INSTALL(FILES ${DOC_FILES} DESTINATION ${CMAKE_INSTALL_PREFIX}/share/doc/${VISTAIO_NAME}) diff --git a/ChangeLog b/ChangeLog index cd48b87..f4919e7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2.1.19 + + * Add test for attribute IO + * Add test for basic image IO + * Add travis-ci build check + +2.1.18 + + * Correct code for problems discovered by Coverity + 2.1.17 * Add a function to chech whether a file is actually a vista file diff --git a/README b/README.md similarity index 70% rename from README rename to README.md index 1316ca2..e5d4e42 100644 --- a/README +++ b/README.md @@ -1,3 +1,5 @@ +# Resume + This library includes the IO and data type part of the vista library originaly implemented by @@ -9,6 +11,42 @@ and Heike Jähnike at the Max-Planck-Institute of Human Cognitive and Brain Sciences, Leipzig, Germany, and later by Gert Wollny at the ETSI Telecomunicacion, UPM, Madrid, Spain. + +# Installation + +## Pre-packaged + +* The library is available as libvistaio-dev/libvistaio14 from + the official Debian archives. +* Ebuild for Gentoo Linux are available from the overlay gentoo-imaging + (currently not availabe from _layman_) + + https://github.com/gerddie/gentoo-imaging + +## Compilation from source: + +Requirements: + + * cmake - http://www.cmake.org + * a POSIX compatible C compiler (GNU gcc will do just fine). + +Then after unpacking the software to + + vistaio-X.X.X one does: + cd vistaio-X.X.X + mkdir build + cd build + cmake .. -DCMAKE_INSTALL_PATH=<prefix> + make + make test + make install + +The "make install" command you may have to run as root. +The tests cover only the 2d/3dfield loading and storing, and +the attribute IO. + +# Function naming remark + In order to avoid naming conflicts with other libraries that build onm the same source code, all functions, types and macro names have been changed from the name V.* to VistaIO.*. A python script to @@ -31,24 +69,8 @@ stored using the original library. If data is saved to one of the original formats the original library should also be able to read the files properly. -To compile and install the library, you need - * cmake - http://www.cmahe.org -and a POSIX compatible C compiler (GNU gcc will do just fine). - -Then after unpacking the software to - vistaio-X.X.X one does: - cd vistaio-X.X.X - mkdir build - cd build - cmake .. -DCMAKE_INSTALL_PATH=<prefix> - make - make test - make install - -The "make install" command you may have to run as root. -The tests cover only the 2d/3dfield loading and storing. -Remark aboud endianess: +# About endianess: The vista file format was initially developed on a big-endian machine, as a result Arthur Pope decided it is best to store the data in big-endian diff --git a/vistaio/CMakeLists.txt b/vistaio/CMakeLists.txt index 4e6fb51..9bb60d6 100644 --- a/vistaio/CMakeLists.txt +++ b/vistaio/CMakeLists.txt @@ -57,15 +57,18 @@ SET_TARGET_PROPERTIES(vistaio PROPERTIES MACRO(ADD_SIMPLE_TEST name) - add_executable(test-${name} ${name}.c) + add_executable(test-${name} test_${name}.c) target_link_libraries(test-${name} vistaio) add_test(${name} test-${name}) ENDMACRO(ADD_SIMPLE_TEST) +ADD_SIMPLE_TEST(attributes) +ADD_SIMPLE_TEST(images) ADD_SIMPLE_TEST(3dfield) ADD_SIMPLE_TEST(2dfield) ADD_SIMPLE_TEST(2dspline) + CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/vconfig.h.in ${CMAKE_CURRENT_BINARY_DIR}/vconfig.h) INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/vconfig.h DESTINATION ${CMAKE_INSTALL_FULL_INCLUDEDIR}/${VISTAIO_NAME}/vistaio) diff --git a/vistaio/alloc.c b/vistaio/alloc.c index 580145e..3734058 100644 --- a/vistaio/alloc.c +++ b/vistaio/alloc.c @@ -31,7 +31,8 @@ VistaIOPointer VistaIOMalloc (size_t size) if (size == 0) return NULL; - if (!(p = (VistaIOPointer) malloc (size))) + p = (VistaIOPointer) malloc (size); + if (!p) VistaIOSystemError ("VistaIOMalloc: Memory allocation failure"); return p; } diff --git a/vistaio/edgesType.c b/vistaio/edgesType.c index cfe7f2f..076ae23 100644 --- a/vistaio/edgesType.c +++ b/vistaio/edgesType.c @@ -186,8 +186,10 @@ static VistaIOPointer VistaIOEdgesEncodeDataMethod (VistaIOPointer value, VistaI pcount = -pcount; len = length; if (!VistaIOPackData - (VistaIOFloatRepn, 1, &pcount, VistaIOMsbFirst, &len, &p, NULL)) + (VistaIOFloatRepn, 1, &pcount, VistaIOMsbFirst, &len, &p, NULL)) { + VistaIOFree(ptr); return NULL; + } p = (char *)p + len; length -= len; @@ -196,8 +198,10 @@ static VistaIOPointer VistaIOEdgesEncodeDataMethod (VistaIOPointer value, VistaI len = length; if (!VistaIOPackData (VistaIOFloatRepn, edges->nedge_fields, e->edge_fields, - VistaIOMsbFirst, &len, &p, NULL)) + VistaIOMsbFirst, &len, &p, NULL)) { + VistaIOFree(ptr); return NULL; + } p = (char *)p + len; length -= len; } @@ -205,8 +209,10 @@ static VistaIOPointer VistaIOEdgesEncodeDataMethod (VistaIOPointer value, VistaI /* Pack point fields: */ len = length; if (!VistaIOPackData (VistaIOFloatRepn, edges->npoint_fields * e->npoints, - e->point_index[0], VistaIOMsbFirst, &len, &p, NULL)) + e->point_index[0], VistaIOMsbFirst, &len, &p, NULL)) { + VistaIOFree(ptr); return NULL; + } p = (char *)p + len; length -= len; } diff --git a/vistaio/fileio.c b/vistaio/fileio.c index ec73747..e359fb3 100644 --- a/vistaio/fileio.c +++ b/vistaio/fileio.c @@ -308,6 +308,8 @@ static VistaIOAttrList ReadAttrList (FILE * f, ReadStringBuf *sbuf) /* For each attribute up to the next "}": */ while (fscanf (f, " %255[^}: \t\n]", name_buf) == 1) { name_size = strlen (name_buf); + /* Covertiy does not detect that strlen(name_buf) <= 255 */ + /* Read a : */ if (fscanf (f, " %1s", buf) != 1 || buf[0] != ':') { @@ -316,9 +318,15 @@ static VistaIOAttrList ReadAttrList (FILE * f, ReadStringBuf *sbuf) } do { - buf[0] = fgetc(f); - } while (buf[0] == ' '); + ch = fgetc(f); + } while (ch == ' '); + /* File terminated early? */ + if (ch == EOF) + goto Fail; + + buf[0] = (char)ch; + /* The first character of the value tells us whether its an attribute list, quoted string, or unquoted string: */ if (buf[0] == '{') { @@ -357,6 +365,7 @@ static VistaIOAttrList ReadAttrList (FILE * f, ReadStringBuf *sbuf) } else { /* ...otherwise store it as a simple string value: */ + /*coverity[INTEGER_OVERFLOW] name_size is at most 255 (line 309)*/ a = VistaIOMalloc (sizeof (VistaIOAttrRec) + name_size + strlen (str) + 1); a->repn = VistaIOStringRepn; @@ -387,7 +396,8 @@ static VistaIOAttrList ReadAttrList (FILE * f, ReadStringBuf *sbuf) /* Swallow the terminating "}": */ if (fscanf (f, " %1s", buf) != 1 || buf[0] != '}') { VistaIOWarning ("VistaIOReadFile: Missing }"); - Fail:VistaIODestroyAttrList (list); + Fail: + VistaIODestroyAttrList (list); return NULL; } return list; @@ -414,6 +424,7 @@ static char *ReadString (FILE * f, char ch, VistaIOStringConst name, ReadStringB VistaIOBoolean escaped = (ch == '"'); size_t len = 0; char *cp; + int in_char; if (!buf->buf) { buf->buf = VistaIOMalloc (StringAllocIncrement); @@ -425,28 +436,32 @@ static char *ReadString (FILE * f, char ch, VistaIOStringConst name, ReadStringB cp = buf->buf; while (1) { - ch = fgetc (f); + in_char = fgetc (f); /* Check for premature EOF: */ - if (ch == EOF) { + if (in_char == EOF) { VistaIOWarning ("VistaIOReadFile: EOF encountered in %s attribute", name); return NULL; } /* Check for closing " or escape sequence: */ if (escaped) { - if (ch == '"') + if (in_char == '"') break; - if (ch == '\\') - switch (ch = fgetc (f)) { + if (in_char == '\\') + switch (in_char = fgetc (f)) { case '\n': continue; case 'n': - ch = '\n'; + in_char = '\n'; + break; + case EOF: + VistaIOWarning ("VistaIOReadFile: EOF encountered in %s attribute", name); + return NULL; } - } else if (isspace (ch)) + } else if (isspace (in_char)) break; /* If the buffer in which we're accumulating the value is full, @@ -457,7 +472,7 @@ static char *ReadString (FILE * f, char ch, VistaIOStringConst name, ReadStringB } /* Store the character in the current buffer: */ - *cp++ = ch; + *cp++ = (char)in_char; } *cp = 0; diff --git a/vistaio/graphType.c b/vistaio/graphType.c index 6077cb0..60d1c82 100644 --- a/vistaio/graphType.c +++ b/vistaio/graphType.c @@ -227,8 +227,11 @@ static VistaIOPointer VistaIOGraphEncodeDataMethod (VistaIOPointer value, VistaI int i, nadj; #define pack(repn, cnt, dest) \ - if (! VistaIOPackData (repn, cnt, dest, VistaIOMsbFirst, &len, &p, NULL)) return NULL; \ - p = (char *) p + len; length -= len; len = length; + if (! VistaIOPackData (repn, cnt, dest, VistaIOMsbFirst, &len, &p, NULL)) { \ + VistaIOFree(ptr); \ + return NULL; \ + } \ + p = (char *) p + len; length -= len; len = length; /* Remove the attributes prepended by the VistaIOGraphEncodeAttrsMethod: */ for (VistaIOFirstAttr (list, &posn); @@ -242,7 +245,7 @@ static VistaIOPointer VistaIOGraphEncodeDataMethod (VistaIOPointer value, VistaI return value; /* we may return anything != 0 here */ }; - p = ptr = VistaIOMalloc (length); +p = ptr = VistaIOMalloc (length); len = length; /* Pack each node: */ diff --git a/vistaio/imageType.c b/vistaio/imageType.c index 3cda06a..b40b106 100644 --- a/vistaio/imageType.c +++ b/vistaio/imageType.c @@ -192,7 +192,7 @@ static VistaIOPointer VistaIOImageEncodeDataMethod (VistaIOPointer value, VistaI VistaIOImage image = value; VistaIOAttrListPosn posn; size_t len; - VistaIOPointer ptr; + VistaIOPointer ptr = NULL; /* Remove the attributes prepended by the VistaIOImageEncodeAttrsMethod: */ for (VistaIOFirstAttr (list, &posn); diff --git a/vistaio/option.c b/vistaio/option.c index 2dbe899..49da8cf 100644 --- a/vistaio/option.c +++ b/vistaio/option.c @@ -27,6 +27,8 @@ /* Later in this file: */ static int ParseArgValues (int *, int, char **, VistaIOOptionDescRec *); +/* from error.c */ +extern EXPORT_VISTA void VistaIOSetProgramName (VistaIOStringConst name); /* The following provide distinguished values for the found field of a VistaIOOptionDescRec: */ VistaIOBoolean VistaIO_RequiredOpt; @@ -227,6 +229,7 @@ VistaIOBoolean VistaIOParseCommand (int noptions, VistaIOOptionDescRec options[] /* If found, return FALSE to force printing of usage info: */ *argc = 1; + VistaIOFree ((VistaIOPointer) opts_seen); return FALSE; } @@ -460,7 +463,7 @@ void VistaIOParseFilterCmd (int noptions, VistaIOOptionDescRec opts[], VerboseDict, "Verbosity level"} }; int i, n; - VistaIOOptionDescRec options[100]; + VistaIOOptionDescRec options[101]; /* Check that number of options will not overflow the options array. */ if (noptions >= 98) { diff --git a/vistaio/2dfield.c b/vistaio/test_2dfield.c similarity index 100% rename from vistaio/2dfield.c rename to vistaio/test_2dfield.c diff --git a/vistaio/2dspline.c b/vistaio/test_2dspline.c similarity index 100% rename from vistaio/2dspline.c rename to vistaio/test_2dspline.c diff --git a/vistaio/3dfield.c b/vistaio/test_3dfield.c similarity index 100% rename from vistaio/3dfield.c rename to vistaio/test_3dfield.c diff --git a/vistaio/test_attributes.c b/vistaio/test_attributes.c new file mode 100644 index 0000000..9ceac95 --- /dev/null +++ b/vistaio/test_attributes.c @@ -0,0 +1,133 @@ +/* + * Copyright (c) Madrid 2015 + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appears in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation. The authors makes no representations about the suitability + * of this software for any purpose. It is provided "as is" without express or + * implied warranty. + * + * Author: Gert Wollny <[email protected]> + */ + +#include <vistaio/vistaio.h> +#include <stdio.h> + + + +int main(int UNUSED(argc), const char **UNUSED(args)) +{ + FILE *file; + + VistaIOAttrList test_list; + VistaIODouble test_double = -3.0; + VistaIOFloat test_float = 2.0; + VistaIOShort test_short = 3; + VistaIOLong test_long = 6; + VistaIOString test_string = "This is a test string \" ;}:"; + + + VistaIOAttrList read_list; + VistaIODouble read_double = 1.0; + VistaIOFloat read_float = 1.0; + VistaIOShort read_short = 0; + VistaIOLong read_long = 0; + VistaIOString read_string = NULL; + + int test_failed = FALSE; + + test_list = VistaIOCreateAttrList(); + + VistaIOSetAttr(test_list, "test-double", NULL, VistaIODoubleRepn, test_double); + VistaIOSetAttr(test_list, "test-float", NULL, VistaIOFloatRepn, test_float); + VistaIOSetAttr(test_list, "test-short", NULL, VistaIOShortRepn, test_short); + VistaIOSetAttr(test_list, "test-long", NULL, VistaIOLongRepn, test_long); + VistaIOSetAttr(test_list, "test-string", NULL, VistaIOStringRepn, test_string); + + + /* open file for saving */ + if ((file = fopen("test-attr.v","w"))==0) { + VistaIOError("Unable to open file 'test-attr.v' for writing"); + ++test_failed; + } + + VistaIOWriteFile(file,test_list); + fclose(file); + + + /* open file for reading */ + if ((file = fopen("test-attr.v","r")) == NULL) { + VistaIOError("Unable to open file test-attr.v for reading"); + ++test_failed; + } + + /* Read field from file */ + read_list = VistaIOReadFile(file, NULL); + + if (VistaIOAttrFound != + VistaIOGetAttr(test_list, "test-double", NULL, VistaIODoubleRepn, &read_double)) { + VistaIOWarning("Attribute test-double not found"); + ++test_failed; + } + + if (VistaIOAttrFound != + VistaIOGetAttr(test_list, "test-float", NULL, VistaIOFloatRepn, &read_float)) { + VistaIOWarning("Attribute test-float not found"); + ++test_failed; + } + + if (VistaIOAttrFound != + VistaIOGetAttr(test_list, "test-short", NULL, VistaIOShortRepn, &read_short)) { + ++test_failed; + VistaIOWarning("Attribute test-short not found"); + } + + if (VistaIOAttrFound != + VistaIOGetAttr(test_list, "test-long", NULL, VistaIOLongRepn, &read_long)) { + ++test_failed; + VistaIOWarning("Attribute test-short not found"); + } + + if (VistaIOAttrFound != + VistaIOGetAttr(test_list, "test-string", NULL, VistaIOStringRepn, &read_string)) { + VistaIOWarning("Attribute test-string not found"); + ++test_failed; + } + + if (test_double != read_double) { + VistaIOWarning("Attribute test-double: read %f, expected %f", read_double, test_double); + ++test_failed; + } + + if (test_float != read_float) { + VistaIOWarning("Attribute test-float: read %f, expected %f", read_float, test_float); + ++test_failed; + } + + if (test_short != read_short) { + VistaIOWarning("Attribute test-short: read %f, expected %f", read_short, test_short); + ++test_failed; + } + + if (test_long != read_long) { + VistaIOWarning("Attribute test-long: read %f, expected %f", read_long, test_long); + ++test_failed; + } + + if (strcmp(read_string, test_string)) { + VistaIOWarning("Attribute test-string: read '%s', expected '%s'", read_string, test_string); + ++test_failed; + } + + + VistaIODestroyAttrList(test_list); + VistaIODestroyAttrList(read_list); + + if (remove( "test-attr.v" ) != 0) { + VistaIOWarning("Unable to remove test file test-attr.v"); + } + + return test_failed; +} diff --git a/vistaio/test_images.c b/vistaio/test_images.c new file mode 100644 index 0000000..2eaacd8 --- /dev/null +++ b/vistaio/test_images.c @@ -0,0 +1,148 @@ +/* + * Copyright (c) Leipzig, Madrid 2004 - 2015 + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appears in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation. The authors makes no representations about the suitability + * of this software for any purpose. It is provided "as is" without express or + * implied warranty. + * + * Author: Gert Wollny <[email protected]> + * + */ + +#include <string.h> +#include <stdio.h> +#include <vistaio/vistaio.h> + + + +int nx = 7; +int ny = 8; +int nz = 9; + +float dx = 1.6; +float dy = 2.2; +float dz = 3.2; + + +#define VTYPE double +#define TYPEREPN VistaIODoubleRepn + +VistaIOBoolean RepnFilter(VistaIOBundle UNUSED(bundle), VistaIORepnKind repn) +{ + return repn == VistaIOImageRepn; +} + + +#define CHECK_EQUAL(A, B, ErrorMsg) \ + if (A != B) VWarning(ErrorMsg, A, B) + + +int main(int UNUSED(argc), const char **UNUSED(args)) +{ + VistaIOImage image1; + VistaIOImage image2; + VistaIOAttrList list; + VistaIOAttrList in_list; + int x,y,z; + float test_float,number; + FILE *file; + int tests_run = 0; + int tests_failed = 0; + + image2 = NULL; + test_float = 1.2; + + /* Create the image */ + image1 = VistaIOCreateImage(nz, ny, nx, VistaIOShortRepn); + + + /* put in some data */ + VistaIOShort *s = VistaIOPixelPtr(image1, 0, 0, 0); + for (z = 0; z < nz; z++) + for (y = 0; y < ny; y++) + for (x = 0; x < nx; x++){ + *s++ = x + 10 * y + 100 * z; + } + + /* add some attribute the the field */ + VistaIOSetAttr(VistaIOImageAttrList(image1),"test_attribute", NULL, VistaIOFloatRepn, test_float); + + + list = VistaIOCreateAttrList(); + VistaIOSetAttr(list, "test-image", NULL, VistaIOImageRepn, image1); + + /* open file for saving */ + if ((file = fopen("test-image.v","w"))==0) + VistaIOError("Unable to open file 'test-image.v' for writing"); + + VistaIOWriteFile(file, list); + fclose(file); + + if ((file = fopen("test-image.v","r")) == NULL) + VistaIOError("Unable to open file test-image.v for reading"); + + /* Read field from file */ + in_list = VistaIOReadFile(file, RepnFilter); + + ++tests_run; + if (VistaIOAttrFound != + VistaIOGetAttr(in_list, "test-image", NULL, VistaIOImageRepn, &image2)) { + VistaIOWarning("Attribute test-image not found"); + ++tests_failed; + } + + ++tests_run; + if (VistaIOAttrFound != + VistaIOGetAttr(VistaIOImageAttrList(image1),"test_attribute", NULL, VistaIOFloatRepn, &number)) { + VistaIOWarning("Attribute test_attribute not found"); + ++tests_failed; + } + + ++tests_run; + if ( number != test_float) { + VistaIOWarning("Attribute test_float: got %f, expect %f", number, test_float); + ++tests_failed; + } + + +#define CHECK_EQUAL_IMAGE_ATTRIBUTE(A, B, ATTR) \ + ++tests_run; \ + if (A -> ATTR != B -> ATTR) { \ + VistaIOWarning( "Image %s: got %d, expect %d", #ATTR, A -> ATTR, B -> ATTR); \ + ++tests_failed; \ + } + + + CHECK_EQUAL_IMAGE_ATTRIBUTE(image2, image1, nrows); + CHECK_EQUAL_IMAGE_ATTRIBUTE(image2, image1, nbands); + CHECK_EQUAL_IMAGE_ATTRIBUTE(image2, image1, ncolumns); + CHECK_EQUAL_IMAGE_ATTRIBUTE(image2, image1, nframes); + CHECK_EQUAL_IMAGE_ATTRIBUTE(image2, image1, pixel_repn); + CHECK_EQUAL_IMAGE_ATTRIBUTE(image2, image1, nviewpoints); + CHECK_EQUAL_IMAGE_ATTRIBUTE(image2, image1, ncolors); + CHECK_EQUAL_IMAGE_ATTRIBUTE(image2, image1, ncomponents); + + /* put in some data */ + VistaIOShort *t = VistaIOPixelPtr(image2, 0, 0, 0); + for (z = 0; z < nz; z++) + for (y = 0; y < ny; y++) + for (x = 0; x < nx; x++, ++t){ + ++tests_run; + if (*t != x + 10 * y + 100 * z) { + VistaIOWarning("Pixel value at (%d, %d, %d): got %hd, expect %d", + x,y,z,*t, x + 10 * y + 100 * z); + ++tests_failed; + } + } + + + remove( "test-image.v" ); + + fprintf(stderr,"%d out of %d tests failed\n", tests_failed, tests_run); + + return tests_failed != 0; +} diff --git a/vistaio/vcplist.c b/vistaio/vcplist.c index bafa35b..41a5bfb 100644 --- a/vistaio/vcplist.c +++ b/vistaio/vcplist.c @@ -59,6 +59,7 @@ VistaIOCPEList VistaIOCreateCPEList(VistaIOLong _n_element) result->data = malloc(result->nsize); if (!result->data) { VistaIOWarning("VistaIOCreateCPEList: Unable to allocate %d byte of memory",result->nsize); + free(result); return NULL; } memset(result->data,0,result->nsize); diff --git a/vistaio/vfield2d.c b/vistaio/vfield2d.c index ead249d..fa610af 100644 --- a/vistaio/vfield2d.c +++ b/vistaio/vfield2d.c @@ -67,6 +67,7 @@ EXPORT_VISTA VistaIOField2D VistaIOCreateField2DFrom(VistaIOLong x_dim, case VistaIODoubleRepn:result->nsize *= 8; break; default:VistaIOWarning("Requested wrong Repn type in VistaIOCreateField2D"); + free(result); return NULL; } @@ -105,6 +106,7 @@ EXPORT_VISTA VistaIOField2D VistaIOCreateField2D(VistaIOLong x_dim, case VistaIODoubleRepn:result->nsize *= 8; break; default:VistaIOWarning("Requested wrong Repn type in VistaIOCreateField2D"); + free(result); return NULL; } @@ -113,6 +115,7 @@ EXPORT_VISTA VistaIOField2D VistaIOCreateField2D(VistaIOLong x_dim, result->p.data = malloc(result->nsize); if (!result->p.data) { VistaIOWarning("VistaIOCreateField2D: Unable to allocate %d byte of memory",result->nsize); + free(result); return NULL; } memset(result->p.data,0,result->nsize); diff --git a/vistaio/vfield3d.c b/vistaio/vfield3d.c index ef8950f..220742f 100644 --- a/vistaio/vfield3d.c +++ b/vistaio/vfield3d.c @@ -76,6 +76,7 @@ EXPORT_VISTA VistaIOField3D VistaIOCreateField3DFrom(VistaIOLong x_dim, case VistaIODoubleRepn:result->nsize *= 8; break; default:VistaIOWarning("Requested wrong Repn type in VistaIOCreateField3D"); + free(result); return NULL; } @@ -116,6 +117,7 @@ EXPORT_VISTA VistaIOField3D VistaIOCreateField3D(VistaIOLong x_dim, case VistaIODoubleRepn:result->nsize *= 8; break; default:VistaIOWarning("Requested wrong Repn type in VistaIOCreateField3D"); + free(result); return NULL; } @@ -124,6 +126,7 @@ EXPORT_VISTA VistaIOField3D VistaIOCreateField3D(VistaIOLong x_dim, result->p.data = malloc(result->nsize); if (!result->p.data) { VistaIOWarning("VistaIOCreateField3D: Unable to allocate %d byte of memory",result->nsize); + free(result); return NULL; } memset(result->p.data,0,result->nsize); diff --git a/vistaio/volumes.c b/vistaio/volumes.c index c78868d..22da8c3 100644 --- a/vistaio/volumes.c +++ b/vistaio/volumes.c @@ -78,8 +78,10 @@ Volume VistaIOCreateVolume (short label, short nbands, short nrows, short ncolum else vol->nbuckets = (short)nbuckets; vol->bucket = (VistaIOBucket) VistaIOMalloc (sizeof (VistaIOBucketRec) * vol->nbuckets); - if (!vol->bucket) + if (!vol->bucket) { + VistaIOFree(vol); return NULL; + } for (i = 0; i < vol->nbuckets; i++) { vol->bucket[i].ntracks = 0; diff --git a/vistaio/volumesType.c b/vistaio/volumesType.c index 8e3c5f7..fe69f03 100644 --- a/vistaio/volumesType.c +++ b/vistaio/volumesType.c @@ -68,6 +68,7 @@ static VistaIOPointer VolumesDecodeMethod (VistaIOStringConst UNUSED(name), Vist short *p; VistaIOTrack t; VistaIOPointer data; + VistaIOPointer data_allocated_ptr; Volume vol; #define Extract(name, dict, locn, required) \ @@ -99,7 +100,7 @@ static VistaIOPointer VolumesDecodeMethod (VistaIOStringConst UNUSED(name), Vist length = nels * (VistaIORepnPrecision (VistaIOShortRepn) / 8); /* Allocate storage for the Volumes binary data: */ - data = VistaIOMalloc (nels * sizeof (VistaIOShort)); + data_allocated_ptr = data = VistaIOMalloc (nels * sizeof (VistaIOShort)); /* Unpack the binary data: */ if (!VistaIOUnpackData @@ -127,6 +128,7 @@ static VistaIOPointer VolumesDecodeMethod (VistaIOStringConst UNUSED(name), Vist } VistaIOAddVolume (volumes, vol); } + VistaIOFree(data_allocated_ptr); return volumes; #undef Extract @@ -229,7 +231,7 @@ VolumesEncodeDataMethod (VistaIOPointer value, VistaIOAttrList UNUSED(list), siz len = VistaIORepnPrecision (VistaIOShortRepn) / 8; if (!VistaIOPackData (VistaIOShortRepn, 1, &ntracks, VistaIOMsbFirst, &len, &p, NULL)) - return NULL; + goto Fail; p = (char *)p + len; length -= len; @@ -237,7 +239,7 @@ VolumesEncodeDataMethod (VistaIOPointer value, VistaIOAttrList UNUSED(list), siz len = VistaIORepnPrecision (VistaIOShortRepn) / 8; if (!VistaIOPackData (VistaIOShortRepn, 1, &ntracks, VistaIOMsbFirst, &len, &p, NULL)) - return NULL; + goto Fail; p = (char *)p + len; length -= len; @@ -246,7 +248,7 @@ VolumesEncodeDataMethod (VistaIOPointer value, VistaIOAttrList UNUSED(list), siz len = VistaIORepnPrecision (VistaIOShortRepn) / 8; if (!VistaIOPackData (VistaIOShortRepn, 1, &hashlen, VistaIOMsbFirst, &len, &p, NULL)) - return NULL; + goto Fail; p = (char *)p + len; length -= len; @@ -255,7 +257,7 @@ VolumesEncodeDataMethod (VistaIOPointer value, VistaIOAttrList UNUSED(list), siz len = VistaIORepnPrecision (VistaIOShortRepn) / 8; if (!VistaIOPackData (VistaIOShortRepn, 1, &nbands, VistaIOMsbFirst, &len, &p, NULL)) - return NULL; + goto Fail; p = (char *)p + len; length -= len; @@ -263,8 +265,9 @@ VolumesEncodeDataMethod (VistaIOPointer value, VistaIOAttrList UNUSED(list), siz label = (VistaIOShort) v->label; len = VistaIORepnPrecision (VistaIOShortRepn) / 8; if (!VistaIOPackData - (VistaIOShortRepn, 1, &label, VistaIOMsbFirst, &len, &p, NULL)) - return NULL; + (VistaIOShortRepn, 1, &label, VistaIOMsbFirst, &len, &p, NULL)) { + goto Fail; + } p = (char *)p + len; length -= len; @@ -277,8 +280,8 @@ VolumesEncodeDataMethod (VistaIOPointer value, VistaIOAttrList UNUSED(list), siz len = 4 * VistaIORepnPrecision (VistaIOShortRepn) / 8; if (!VistaIOPackData (VistaIOShortRepn, 4, &idata[0], VistaIOMsbFirst, - &len, &p, NULL)) - return NULL; + &len, &p, NULL)) + goto Fail; p = (char *)p + len; length -= len; } @@ -287,4 +290,7 @@ VolumesEncodeDataMethod (VistaIOPointer value, VistaIOAttrList UNUSED(list), siz *free_itp = TRUE; return ptr; +Fail: + VistaIOFree(ptr); + return NULL; } diff --git a/vistaio/vspline2d.c b/vistaio/vspline2d.c index 0d3340b..e29678c 100644 --- a/vistaio/vspline2d.c +++ b/vistaio/vspline2d.c @@ -84,7 +84,8 @@ EXPORT_VISTA VistaIOSpline2D VistaIOCreateSpline2D(VistaIOLong _x_dim, result->data = VistaIOCreateField2D(_x_dim, _y_dim, nsize_element, repn); result->x_range = _x_range; result->y_range = _y_range; - result->kernel_descr = kernel_descr; + result->kernel_descr = kernel_descr; + result->attr = NULL; return result; } diff --git a/vistaio_change_names.py b/vistaio_change_names.py new file mode 100644 index 0000000..2cd1d91 --- /dev/null +++ b/vistaio_change_names.py @@ -0,0 +1,76 @@ +#!/usr/bin/python +# +# Copyright (C) 2011-2015 Gert Wollny <[email protected]> +# +# Permission to use, copy, modify, distribute, and sell this software and its +# documentation for any purpose is hereby granted without fee, provided that +# the above copyright notice appears in all copies and that both that +# copyright notice and this permission notice appear in supporting +# documentation. The authors makes no representations about the suitability +# of this software for any purpose. It is provided "as is" without express or +# implied warranty. +# + +import sys +import re +from os import rename +import string +from fnmatch import fnmatch +from os.path import walk + + + +class CPatternCollector: + def __init__(self, pattern): + self.pattern = pattern + self.files=[] + + +def collect_files(arg, dirname, names): + for f in names: + for p in arg.pattern: + if fnmatch(f, p): + arg.files.append(dirname + "/" + f) + + + +def find_files(root, pattern): + arg = CPatternCollector(pattern) + walk(root, collect_files, arg) + return arg.files + + +root= sys.argv[1] +files = find_files(root, ["*.C", "*.H", "*.c", "*.h", "*.cc", "*.hh", "*.cpp", "*.hpp"]) + + +# read all files and extract comment blocks +for f in files: + + # ignore some emacs security copies + h = re.search("/\.#[-a-z0-9]*\.[ch]*", f) + if h: + continue + + + + infile = open(f, "r"); + lines = infile.readlines() + infile.close(), + + changed = False + out_lines = [] + for l in lines: + ol = re.sub("\\bV(_*[A-Z]*[a-z][a-zA-Z0-9_]*)\\b", "VistaIO\\1",l) + out_lines.append(ol) + changed = changed or (ol != l) + + if changed: + print f, " updated" + outfile = open(f, "w") + outfile.writelines(out_lines) + outfile.close(); + else: + print f, " unchanged" + + -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/libvistaio.git _______________________________________________ debian-med-commit mailing list [email protected] http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/debian-med-commit
