gcc-segfault-issue.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. Copyright (C) 2016 Francesc Alted
  3. http://blosc.org
  4. License: MIT (see LICENSE.txt)
  5. Test program trying to replicate the python-blosc issue:
  6. https://github.com/Blosc/python-blosc/issues/110
  7. Apparently this only affects to blosc-powered Python extensions.
  8. To compile this program:
  9. $ gcc -O3 gcc-segfault-issue.c -o gcc-segfault-issue -lblosc
  10. To run:
  11. $ ./gcc-segfault-issue
  12. Blosc version info: 1.8.1.dev ($Date:: 2016-03-31 #$)
  13. Compression: 8000000 -> 73262 (109.2x)
  14. To check that everything goes well:
  15. $ time for i in {1..1000}; do ./gcc-segfault-issue > p ; done
  16. real 0m4.590s
  17. user 0m2.516s
  18. sys 0m1.884s
  19. If you don't see any "Segmentation fault (core dumped)", the
  20. C-Blosc library itself is probably not a victim of the infamous
  21. issue above that only seems to affect Python extensions.
  22. */
  23. #include <stdio.h>
  24. #include <blosc.h>
  25. #define SIZE 1000*1000
  26. int main(){
  27. static double data[SIZE];
  28. static double data_out[SIZE];
  29. static double data_dest[SIZE];
  30. int isize = SIZE*sizeof(double), osize = SIZE*sizeof(double);
  31. int dsize = SIZE*sizeof(double), csize;
  32. int i;
  33. for(i=0; i<SIZE; i++){
  34. data[i] = i;
  35. }
  36. /* Register the filter with the library */
  37. printf("Blosc version info: %s (%s)\n",
  38. BLOSC_VERSION_STRING, BLOSC_VERSION_DATE);
  39. /* Initialize the gobal Blosc context */
  40. blosc_init();
  41. /* Use multithreading */
  42. blosc_set_nthreads(3);
  43. /* Compress with clevel=9 and shuffle active */
  44. csize = blosc_compress(9, 1, sizeof(double), isize, data, data_out, osize);
  45. if (csize == 0) {
  46. printf("Buffer is uncompressible. Giving up.\n");
  47. return 1;
  48. }
  49. else if (csize < 0) {
  50. printf("Compression error. Error code: %d\n", csize);
  51. return csize;
  52. }
  53. printf("Compression: %d -> %d (%.1fx)\n", isize, csize, (1.*isize) / csize);
  54. /* Destroy the global Blosc context */
  55. blosc_destroy();
  56. return 0;
  57. }