Changeset 147
- Timestamp:
- 06/07/10 14:21:35 (3 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 6 edited
-
RELEASE_NOTES.txt (modified) (1 diff)
-
bench/Makefile (added)
-
bench/bench.c (modified) (4 diffs)
-
src/blosc.c (modified) (18 diffs)
-
src/blosc.h (modified) (4 diffs)
-
tests/Makefile (modified) (1 diff)
-
tests/test_all.sh (added)
-
tests/test_api.c (modified) (3 diffs)
-
tests/test_basics.c (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/RELEASE_NOTES.txt
r146 r147 10 10 =========================== 11 11 12 - Supported a new parameter `maxbytes` for ``blosc_compress()``. It 13 represents a maximum of bytes for output. Tests unit added too. 14 12 15 - Added 3 new functions for querying different metadata on compressed 13 16 buffers. A test suite for testing the new API has been added too. 14 15 17 16 18 Changes from 0.9.3 to 0.9.4 -
trunk/bench/bench.c
r142 r147 143 143 144 144 145 do_bench(int nthreads, unsigned int size, int elsize, int rshift) {145 void do_bench(int nthreads, unsigned int size, int elsize, int rshift) { 146 146 void *src, *srccpy; 147 147 void **dest[NCHUNKS], *dest2; 148 int nbytes , cbytes;148 int nbytes = 0, cbytes = 0; 149 149 size_t i, j; 150 150 struct timeval last, current; … … 164 164 memcpy(srccpy, src, size); 165 165 for (j = 0; j < nchunks; j++) { 166 dest[j] = malloc(size); 166 /* 16 additional bytes should be enough for encoding everything */ 167 dest[j] = malloc(size+16); 167 168 } 168 169 … … 210 211 for (i = 0; i < niter; i++) { 211 212 for (j = 0; j < nchunks; j++) { 212 cbytes = blosc_compress(clevel, doshuffle, elsize, size, src, dest[j]); 213 cbytes = blosc_compress(clevel, doshuffle, elsize, size, src, 214 dest[j], size); 213 215 } 214 216 } … … 307 309 char *usage = "Usage: bench ['single' | 'suite' | 'hardsuite' | 'extremesuite' | 'debugsuite'] [nthreads [bufsize(bytes) [typesize [sbits ]]]]"; 308 310 311 312 if (argc == 1) { 313 printf("%s\n", usage); 314 exit(1); 315 } 309 316 310 317 if (strcmp(argv[1], "single") == 0) { -
trunk/src/blosc.c
r146 r147 87 87 int32_t ntbytes; 88 88 uint32_t nbytes; 89 uint32_t maxbytes; 89 90 uint32_t nblocks; 90 91 uint32_t leftover; … … 133 134 /* Shuffle & compress a single block */ 134 135 static int blosc_c(size_t blocksize, int32_t leftoverblock, 135 uint32_t ntbytes, uint32_t nbytes,136 uint32_t ntbytes, uint32_t maxbytes, 136 137 uint8_t *src, uint8_t *dest, uint8_t *tmp) 137 138 { … … 168 169 ctbytes += sizeof(int32_t); 169 170 maxout = neblock; 170 if (ntbytes+maxout > nbytes) {171 maxout = nbytes - ntbytes; /* avoid buffer overrun */171 if (ntbytes+maxout > maxbytes) { 172 maxout = maxbytes - ntbytes; /* avoid buffer overrun */ 172 173 if (maxout <= 0) { 173 174 return 0; /* non-compressible block */ … … 188 189 /* Before doing the copy, check that we are not running into a 189 190 buffer overflow. */ 190 if ((ntbytes+neblock) > nbytes) {191 if ((ntbytes+neblock) > maxbytes) { 191 192 return 0; /* Non-compressible data */ 192 193 } … … 279 280 size_t blocksize = params.blocksize; 280 281 int32_t ntbytes = params.ntbytes; 281 int32_t nbytes = params.nbytes;282 uint32_t maxbytes = params.maxbytes; 282 283 uint32_t nblocks = params.nblocks; 283 284 int32_t leftover = params.nbytes % params.blocksize; … … 299 300 } 300 301 if (compress) { 301 cbytes = blosc_c(bsize, leftoverblock, ntbytes, nbytes,302 cbytes = blosc_c(bsize, leftoverblock, ntbytes, maxbytes, 302 303 src+j*blocksize, dest+ntbytes, tmp); 303 304 if (cbytes == 0) { … … 311 312 } 312 313 if (cbytes < 0) { 313 ntbytes = cbytes; /* error in blosc_c /blosc_d */314 ntbytes = cbytes; /* error in blosc_c or blosc_d */ 314 315 break; 315 316 } … … 319 320 /* Final check for ntbytes (only in compression mode) */ 320 321 if (compress) { 321 if (ntbytes == nbytes) {322 if (ntbytes == maxbytes) { 322 323 ntbytes = 0; /* non-compressible data */ 323 324 } 324 else if (ntbytes > nbytes) {325 else if (ntbytes > maxbytes) { 325 326 fprintf(stderr, "The impossible happened: buffer overflow!\n"); 326 327 ntbytes = -5; /* too large buffer */ … … 520 521 521 522 523 /* The public routine for compression. See blosc.h for docstrings. */ 522 524 unsigned int blosc_compress(int clevel, int shuffle, size_t typesize, 523 size_t nbytes, const void *src, void *dest) 525 size_t nbytes, const void *src, void *dest, 526 size_t maxbytes) 524 527 { 525 528 uint8_t *_dest=NULL; /* current pos for destination buffer */ 526 uint8_t *flags; /* flags for header */ 529 uint8_t *flags; /* flags for header. Currently booked: 530 - 0: shuffled? 531 - 1: memcpy'ed? */ 527 532 uint32_t nblocks; /* number of total blocks in buffer */ 528 533 uint32_t leftover; /* extra bytes at end of buffer */ … … 543 548 } 544 549 else if (nbytes < MIN_BUFFERSIZE) { 545 /* Too little buffer. Just return without doing anything else. */550 /* Buffer too small. Just return without doing anything else. */ 546 551 return 0; 547 552 } … … 596 601 params.ntbytes = ntbytes; 597 602 params.nbytes = nbytes; 603 params.maxbytes = maxbytes; 598 604 params.nblocks = nblocks; 599 605 params.leftover = leftover; … … 604 610 /* Do the actual compression */ 605 611 ntbytes = do_job(); 612 613 /* Last chance for fitting `src` buffer in `dest` */ 614 if ((ntbytes == 0) && (nbytes+16 <= maxbytes)) { 615 /* Specify that this buffer is memcpy'ed (bit 2 set to 1 in flags) */ 616 _dest = (uint8_t *)(dest); 617 _dest[2] = 0x2; 618 memcpy(dest+16, src, nbytes); 619 ntbytes = nbytes+16; 620 } 621 606 622 /* Set the number of compressed bytes in header */ 607 623 *ntbytes_ = sw32(ntbytes); 608 624 609 assert((int32_t)ntbytes < (int32_t)nbytes);625 assert((int32_t)ntbytes <= (int32_t)maxbytes); 610 626 return ntbytes; 611 627 } 612 628 613 629 614 unsigned int blosc_decompress(const void *src, void *dest, size_t dest_size) 630 /* The public routine for decompression. See blosc.h for docstrings. */ 631 unsigned int blosc_decompress(const void *src, void *dest, size_t destsize) 615 632 { 616 633 uint8_t *_src=NULL; /* current pos for source buffer */ … … 637 654 blocksize = sw32(((uint32_t *)_src)[1]); /* block size */ 638 655 ctbytes = sw32(((uint32_t *)_src)[2]); /* compressed buffer size */ 656 657 /* Check whether this buffer is memcpy'ed */ 658 if (flags == 0x2) { 659 memcpy(dest, src+16, nbytes); 660 return nbytes; 661 } 662 639 663 _src += sizeof(int32_t)*3; 640 664 bstarts = (uint32_t *)_src; … … 647 671 648 672 /* Check zero typesizes. From Blosc version format 2 on, this value 649 has been reserved for future use (most probably to indicate 650 uncompressible buffers). */ 673 has been reserved for future use. */ 651 674 if ((version == 1) && (typesize == 0)) { 652 675 typesize = 256; /* 0 means 256 in format version 1 */ 653 676 } 654 677 655 if (nbytes > dest _size) {678 if (nbytes > destsize) { 656 679 /* This should never happen but just in case */ 657 680 return -1; … … 680 703 ntbytes = do_job(); 681 704 682 assert(ntbytes <= (int32_t)dest _size);705 assert(ntbytes <= (int32_t)destsize); 683 706 return ntbytes; 684 707 } … … 764 787 size_t ebsize; 765 788 int32_t compress; 766 uint32_t nbytes;789 uint32_t maxbytes; 767 790 uint32_t ntbytes; 768 791 uint32_t nblocks; … … 815 838 ebsize = blocksize + params.typesize*sizeof(int32_t); 816 839 compress = params.compress; 817 nbytes = params.nbytes;840 maxbytes = params.maxbytes; 818 841 nblocks = params.nblocks; 819 842 leftover = params.leftover; … … 887 910 ntdest = params.ntbytes; 888 911 bstarts[nblock_] = sw32(ntdest); /* update block start counter */ 889 if ( (cbytes == 0) || (ntdest+cbytes > (int32_t) nbytes) ) {912 if ( (cbytes == 0) || (ntdest+cbytes > (int32_t)maxbytes) ) { 890 913 giveup_code = 0; /* uncompressible buffer */ 891 914 pthread_mutex_unlock(&count_mutex); -
trunk/src/blosc.h
r146 r147 57 57 Only a typesize > 1 will allow the shuffle to work. 58 58 59 The `dest` buffer must have at least the size of the `src` buffer. 60 The `src` buffer and the `dest` buffer can not overlap. 59 The `dest` buffer must have at least the size of `maxbytes`. Blosc 60 guarantees that if you set `maxbytes` at least to `nbytes` + 16, the 61 compression will always succeed. The `src` buffer and the `dest` 62 buffer can not overlap. 61 63 62 If `src` buffer is not compressible (len(`dest`) >= len(`src`)), the63 return value is zero and you should discard the contents of the64 `dest`buffer.64 If `src` buffer cannot be compressed into `maxbytes`, the return 65 value is zero and you should discard the contents of the `dest` 66 buffer. 65 67 66 68 A negative return value means that an internal error happened. This … … 69 71 70 72 Compression is memory safe and guaranteed not to write the `dest` 71 buffer more than what is specified in ` nbytes`. However, it is not72 re-entrant and not thread-safe (despite the fact that it uses73 buffer more than what is specified in `maxbytes`. However, it is 74 not re-entrant and not thread-safe (despite the fact that it uses 73 75 threads internally ;-) 74 76 … … 76 78 77 79 unsigned int blosc_compress(int clevel, int doshuffle, size_t typesize, 78 size_t nbytes, const void *src, void *dest); 80 size_t nbytes, const void *src, void *dest, 81 size_t maxbytes); 79 82 80 83 … … 96 99 */ 97 100 98 unsigned int blosc_decompress(const void *src, void *dest, size_t dest _size);101 unsigned int blosc_decompress(const void *src, void *dest, size_t destsize); 99 102 100 103 -
trunk/tests/Makefile
r146 r147 2 2 CFLAGS=-O3 -msse2 -Wall 3 3 LDFLAGS=-lpthread 4 SOURCES=test_api.c ../src/blosc.c ../src/blosclz.c ../src/shuffle.c 5 EXECUTABLE=test_api 4 BLOSC_LIB= ../src/blosc.c ../src/blosclz.c ../src/shuffle.c 6 5 7 all: $(SOURCES) $(EXECUTABLE) 6 # The list of executables 7 # Generated PNG (intermediate) files 8 SOURCES := $(wildcard *.c) 9 EXECUTABLES := $(patsubst %.c, %.exe, $(SOURCES)) 8 10 9 $(EXECUTABLE): $(SOURCES) 10 $(CC) $(CFLAGS) $(LDFLAGS) $(SOURCES) -o $@ 11 .PHONY: all 12 all: test 13 14 test: $(EXECUTABLES) 15 16 %.exe: %.c $(BLOSC_LIB) 17 $(CC) $(CFLAGS) $(LDFLAGS) "$<" $(BLOSC_LIB) -o "$@" 11 18 12 19 clean: 13 rm -rf test_api20 rm -rf $(EXECUTABLES) -
trunk/tests/test_api.c
r146 r147 10 10 **********************************************************************/ 11 11 12 #include <stdlib.h> 13 #include <stdio.h> 14 #include <string.h> 15 #include <sys/types.h> 16 #include <sys/stat.h> 17 #include <fcntl.h> 18 #if defined(_WIN32) && !defined(__MINGW32__) 19 #include <time.h> 20 #else 21 #include <unistd.h> 22 #include <sys/time.h> 23 #endif 24 #include <math.h> 25 #include "../src/blosc.h" 26 27 28 /* This is MinUnit in action (http://www.jera.com/techinfo/jtns/jtn002.html) */ 29 #define mu_assert(message, test) do { if (!(test)) return message; } while (0) 30 #define mu_run_test(test) do \ 31 { char *message = test(); tests_run++; \ 32 if (message) { printf("%c", 'F'); return message;} \ 33 else printf("%c", '.'); } while (0) 12 #include "tests_blosc.h" 34 13 35 14 int tests_run = 0; 36 37 #define KB 102438 #define MB (1024*KB)39 #define GB (1024*MB)40 15 41 16 /* Global vars */ … … 101 76 102 77 /* Get a compressed buffer */ 103 cbytes = blosc_compress(clevel, doshuffle, typesize, size, src, dest );78 cbytes = blosc_compress(clevel, doshuffle, typesize, size, src, dest, size); 104 79 105 80 /* Get a decompressed buffer */ … … 112 87 } 113 88 else { 114 printf("\nALL TESTS PASSED \n");89 printf("\nALL TESTS PASSED for %s", argv[0]); 115 90 } 116 printf("\ nTests run: %d\n", tests_run);91 printf("\tTests run: %d\n", tests_run); 117 92 93 free(src); free(srccpy); free(dest); free(dest2); 118 94 return result != 0; 119 95 }
Note: See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/images/blosc-logo-small.png)