hirlite 0.0.2 → 0.0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/ext/hirlite_ext/extconf.rb +2 -2
  3. data/lib/hirlite/version.rb +1 -1
  4. data/vendor/rlite/deps/lua/Makefile +128 -0
  5. data/vendor/rlite/deps/lua/src/fpconv.c +205 -0
  6. data/vendor/rlite/deps/lua/src/fpconv.h +22 -0
  7. data/vendor/rlite/deps/lua/src/lapi.c +1087 -0
  8. data/vendor/rlite/deps/lua/src/lapi.h +16 -0
  9. data/vendor/rlite/deps/lua/src/lauxlib.c +652 -0
  10. data/vendor/rlite/deps/lua/src/lauxlib.h +174 -0
  11. data/vendor/rlite/deps/lua/src/lbaselib.c +653 -0
  12. data/vendor/rlite/deps/lua/src/lcode.c +831 -0
  13. data/vendor/rlite/deps/lua/src/lcode.h +76 -0
  14. data/vendor/rlite/deps/lua/src/ldblib.c +398 -0
  15. data/vendor/rlite/deps/lua/src/ldebug.c +638 -0
  16. data/vendor/rlite/deps/lua/src/ldebug.h +33 -0
  17. data/vendor/rlite/deps/lua/src/ldo.c +519 -0
  18. data/vendor/rlite/deps/lua/src/ldo.h +57 -0
  19. data/vendor/rlite/deps/lua/src/ldump.c +164 -0
  20. data/vendor/rlite/deps/lua/src/lfunc.c +174 -0
  21. data/vendor/rlite/deps/lua/src/lfunc.h +34 -0
  22. data/vendor/rlite/deps/lua/src/lgc.c +710 -0
  23. data/vendor/rlite/deps/lua/src/lgc.h +110 -0
  24. data/vendor/rlite/deps/lua/src/linit.c +38 -0
  25. data/vendor/rlite/deps/lua/src/liolib.c +556 -0
  26. data/vendor/rlite/deps/lua/src/llex.c +463 -0
  27. data/vendor/rlite/deps/lua/src/llex.h +81 -0
  28. data/vendor/rlite/deps/lua/src/llimits.h +128 -0
  29. data/vendor/rlite/deps/lua/src/lmathlib.c +263 -0
  30. data/vendor/rlite/deps/lua/src/lmem.c +86 -0
  31. data/vendor/rlite/deps/lua/src/lmem.h +49 -0
  32. data/vendor/rlite/deps/lua/src/loadlib.c +666 -0
  33. data/vendor/rlite/deps/lua/src/lobject.c +214 -0
  34. data/vendor/rlite/deps/lua/src/lobject.h +381 -0
  35. data/vendor/rlite/deps/lua/src/lopcodes.c +102 -0
  36. data/vendor/rlite/deps/lua/src/lopcodes.h +268 -0
  37. data/vendor/rlite/deps/lua/src/loslib.c +243 -0
  38. data/vendor/rlite/deps/lua/src/lparser.c +1339 -0
  39. data/vendor/rlite/deps/lua/src/lparser.h +82 -0
  40. data/vendor/rlite/deps/lua/src/lstate.c +214 -0
  41. data/vendor/rlite/deps/lua/src/lstate.h +169 -0
  42. data/vendor/rlite/deps/lua/src/lstring.c +111 -0
  43. data/vendor/rlite/deps/lua/src/lstring.h +31 -0
  44. data/vendor/rlite/deps/lua/src/lstrlib.c +871 -0
  45. data/vendor/rlite/deps/lua/src/ltable.c +588 -0
  46. data/vendor/rlite/deps/lua/src/ltable.h +40 -0
  47. data/vendor/rlite/deps/lua/src/ltablib.c +287 -0
  48. data/vendor/rlite/deps/lua/src/ltm.c +75 -0
  49. data/vendor/rlite/deps/lua/src/ltm.h +54 -0
  50. data/vendor/rlite/deps/lua/src/lua.c +392 -0
  51. data/vendor/rlite/deps/lua/src/lua.h +388 -0
  52. data/vendor/rlite/deps/lua/src/lua_bit.c +189 -0
  53. data/vendor/rlite/deps/lua/src/lua_cjson.c +1427 -0
  54. data/vendor/rlite/deps/lua/src/lua_cmsgpack.c +957 -0
  55. data/vendor/rlite/deps/lua/src/lua_struct.c +421 -0
  56. data/vendor/rlite/deps/lua/src/luac.c +200 -0
  57. data/vendor/rlite/deps/lua/src/luaconf.h +763 -0
  58. data/vendor/rlite/deps/lua/src/lualib.h +53 -0
  59. data/vendor/rlite/deps/lua/src/lundump.c +227 -0
  60. data/vendor/rlite/deps/lua/src/lundump.h +36 -0
  61. data/vendor/rlite/deps/lua/src/lvm.c +767 -0
  62. data/vendor/rlite/deps/lua/src/lvm.h +36 -0
  63. data/vendor/rlite/deps/lua/src/lzio.c +82 -0
  64. data/vendor/rlite/deps/lua/src/lzio.h +67 -0
  65. data/vendor/rlite/deps/lua/src/print.c +227 -0
  66. data/vendor/rlite/deps/lua/src/strbuf.c +251 -0
  67. data/vendor/rlite/deps/lua/src/strbuf.h +154 -0
  68. data/vendor/rlite/src/Makefile +97 -25
  69. data/vendor/rlite/{deps → src}/crc64.c +0 -0
  70. data/vendor/rlite/{deps → src}/crc64.h +0 -0
  71. data/vendor/rlite/src/dump.c +2 -2
  72. data/vendor/rlite/{deps → src}/endianconv.h +0 -0
  73. data/vendor/rlite/src/hirlite.c +134 -90
  74. data/vendor/rlite/src/hirlite.h +34 -1
  75. data/vendor/rlite/{deps → src}/hyperloglog.c +0 -0
  76. data/vendor/rlite/{deps → src}/hyperloglog.h +0 -0
  77. data/vendor/rlite/{deps → src}/lzf.h +0 -0
  78. data/vendor/rlite/{deps → src}/lzfP.h +0 -0
  79. data/vendor/rlite/{deps → src}/lzf_c.c +0 -0
  80. data/vendor/rlite/{deps → src}/lzf_d.c +0 -0
  81. data/vendor/rlite/src/page_btree.c +10 -10
  82. data/vendor/rlite/src/page_btree.h +2 -2
  83. data/vendor/rlite/src/page_list.c +3 -3
  84. data/vendor/rlite/src/page_list.h +1 -1
  85. data/vendor/rlite/src/page_multi_string.c +1 -1
  86. data/vendor/rlite/src/page_skiplist.c +1 -1
  87. data/vendor/rlite/src/page_skiplist.h +1 -1
  88. data/vendor/rlite/src/rand.c +93 -0
  89. data/vendor/rlite/src/rand.h +38 -0
  90. data/vendor/rlite/src/restore.c +286 -155
  91. data/vendor/rlite/src/restore.h +6 -0
  92. data/vendor/rlite/src/rlite.c +30 -30
  93. data/vendor/rlite/src/rlite.h +1 -1
  94. data/vendor/rlite/src/scripting.c +1138 -0
  95. data/vendor/rlite/src/scripting.h +10 -0
  96. data/vendor/rlite/{deps → src}/sha1.c +0 -0
  97. data/vendor/rlite/{deps → src}/sha1.h +0 -0
  98. data/vendor/rlite/src/solarisfixes.h +54 -0
  99. data/vendor/rlite/src/sort.c +4 -2
  100. data/vendor/rlite/src/sort.h +1 -1
  101. data/vendor/rlite/src/type_string.c +1 -1
  102. data/vendor/rlite/src/util.c +4 -4
  103. data/vendor/rlite/src/util.h +3 -3
  104. data/vendor/rlite/{deps → src}/utilfromredis.c +0 -0
  105. data/vendor/rlite/{deps → src}/utilfromredis.h +0 -0
  106. metadata +84 -15
@@ -14,8 +14,8 @@
14
14
  #include "type_hash.h"
15
15
  #include "rlite.h"
16
16
  #include "util.h"
17
- #include "../deps/sha1.h"
18
- #ifdef DEBUG
17
+ #include "sha1.h"
18
+ #ifdef RL_DEBUG
19
19
  #include <valgrind/valgrind.h>
20
20
  #endif
21
21
 
@@ -203,7 +203,7 @@ int rl_header_serialize(struct rlite *db, void *UNUSED(obj), unsigned char *data
203
203
  put_4bytes(&data[identifier_len + 8], db->number_of_pages);
204
204
  put_4bytes(&data[identifier_len + 12], db->number_of_databases);
205
205
  long i, pos = identifier_len + 16;
206
- for (i = 0; i < db->number_of_databases; i++) {
206
+ for (i = 0; i < db->number_of_databases + 1; i++) {
207
207
  put_4bytes(&data[pos], db->databases[i]);
208
208
  pos += 4;
209
209
  }
@@ -224,11 +224,11 @@ int rl_header_deserialize(struct rlite *db, void **UNUSED(obj), void *UNUSED(con
224
224
  db->number_of_pages = get_4bytes(&data[identifier_len + 8]);
225
225
  db->initial_number_of_databases =
226
226
  db->number_of_databases = get_4bytes(&data[identifier_len + 12]);
227
- RL_MALLOC(db->databases, sizeof(long) * db->number_of_databases);
228
- RL_MALLOC(db->initial_databases, sizeof(long) * db->number_of_databases);
227
+ RL_MALLOC(db->databases, sizeof(long) * (db->number_of_databases + 1));
228
+ RL_MALLOC(db->initial_databases, sizeof(long) * (db->number_of_databases + 1));
229
229
 
230
230
  long i, pos = identifier_len + 16;
231
- for (i = 0; i < db->number_of_databases; i++) {
231
+ for (i = 0; i < db->number_of_databases + 1; i++) {
232
232
  db->initial_databases[i] =
233
233
  db->databases[i] = get_4bytes(&data[pos]);
234
234
  pos += 4;
@@ -377,9 +377,9 @@ int rl_create_db(rlite *db)
377
377
  db->selected_database = 0;
378
378
  db->initial_number_of_databases =
379
379
  db->number_of_databases = 16;
380
- RL_MALLOC(db->databases, sizeof(long) * db->number_of_databases);
381
- RL_MALLOC(db->initial_databases, sizeof(long) * db->number_of_databases);
382
- for (i = 0; i < db->number_of_databases; i++) {
380
+ RL_MALLOC(db->databases, sizeof(long) * (db->number_of_databases + 1));
381
+ RL_MALLOC(db->initial_databases, sizeof(long) * (db->number_of_databases + 1));
382
+ for (i = 0; i < db->number_of_databases + 1; i++) {
383
383
  db->initial_databases[i] =
384
384
  db->databases[i] = 0;
385
385
  }
@@ -431,7 +431,7 @@ cleanup:
431
431
  return retval;
432
432
  }
433
433
 
434
- #ifdef DEBUG
434
+ #ifdef RL_DEBUG
435
435
  void print_cache(rlite *db)
436
436
  {
437
437
  printf("Cache read pages:");
@@ -450,7 +450,7 @@ void print_cache(rlite *db)
450
450
  }
451
451
  #endif
452
452
 
453
- #ifdef DEBUG
453
+ #ifdef RL_DEBUG
454
454
  static int rl_search_cache(rlite *db, rl_data_type *type, long page_number, void **obj, long *position, rl_page **pages, long page_len)
455
455
  #else
456
456
  static int rl_search_cache(rlite *UNUSED(db), rl_data_type *UNUSED(type), long page_number, void **obj, long *position, rl_page **pages, long page_len)
@@ -463,7 +463,7 @@ static int rl_search_cache(rlite *UNUSED(db), rl_data_type *UNUSED(type), long p
463
463
  pos = min + (max - min) / 2;
464
464
  page = pages[pos];
465
465
  if (page->page_number == page_number) {
466
- #ifdef DEBUG
466
+ #ifdef RL_DEBUG
467
467
  if (page->type != &rl_data_type_long && type != &rl_data_type_long && type != NULL && page->type != type) {
468
468
  fprintf(stderr, "Type of page in cache (%s) doesn't match the asked one (%s)\n", page->type->name, type->name);
469
469
  return RL_UNEXPECTED;
@@ -492,7 +492,7 @@ static int rl_search_cache(rlite *UNUSED(db), rl_data_type *UNUSED(type), long p
492
492
  if (pages[pos]->page_number < page_number && pos < page_len) {
493
493
  pos++;
494
494
  }
495
- #ifdef DEBUG
495
+ #ifdef RL_DEBUG
496
496
  long i, prev;
497
497
  rl_page *p;
498
498
  for (i = 0; i < db->read_pages_len; i++) {
@@ -541,7 +541,7 @@ int rl_read_from_cache(rlite *db, rl_data_type *type, long page_number, void **o
541
541
  int rl_read(rlite *db, rl_data_type *type, long page, void *context, void **obj, int cache)
542
542
  {
543
543
  // fprintf(stderr, "r %ld %s\n", page, type->name);
544
- #ifdef DEBUG
544
+ #ifdef RL_DEBUG
545
545
  int keep = 0;
546
546
  long initial_page_size = db->page_size;
547
547
  if (page == 0 && type != &rl_data_type_header) {
@@ -578,7 +578,7 @@ int rl_read(rlite *db, rl_data_type *type, long page, void *context, void **obj,
578
578
  size_t read = fread(data, sizeof(unsigned char), db->page_size, driver->fp);
579
579
  if (read != (size_t)db->page_size) {
580
580
  if (page > 0) {
581
- #ifdef DEBUG
581
+ #ifdef RL_DEBUG
582
582
  print_cache(db);
583
583
  #endif
584
584
  fprintf(stderr, "Unable to read page %ld on line %d\n", page, __LINE__);
@@ -633,7 +633,7 @@ int rl_read(rlite *db, rl_data_type *type, long page, void *context, void **obj,
633
633
  page_obj->page_number = page;
634
634
  page_obj->type = type;
635
635
  page_obj->obj = obj ? *obj : NULL;
636
- #ifdef DEBUG
636
+ #ifdef RL_DEBUG
637
637
  keep = 1;
638
638
  if (initial_page_size != db->page_size) {
639
639
  page_obj->serialized_data = realloc(data, db->page_size * sizeof(unsigned char));
@@ -677,12 +677,12 @@ int rl_read(rlite *db, rl_data_type *type, long page, void *context, void **obj,
677
677
  retval = RL_FOUND;
678
678
  }
679
679
  cleanup:
680
- #ifdef DEBUG
680
+ #ifdef RL_DEBUG
681
681
  if (!keep) {
682
682
  rl_free(data);
683
683
  }
684
684
  #endif
685
- #ifndef DEBUG
685
+ #ifndef RL_DEBUG
686
686
  rl_free(data);
687
687
  #endif
688
688
  return retval;
@@ -735,7 +735,7 @@ int rl_write(struct rlite *db, rl_data_type *type, long page_number, void *obj)
735
735
  else if (retval == RL_NOT_FOUND) {
736
736
  rl_ensure_pages(db);
737
737
  RL_MALLOC(page, sizeof(*page));
738
- #ifdef DEBUG
738
+ #ifdef RL_DEBUG
739
739
  page->serialized_data = NULL;
740
740
  #endif
741
741
  page->page_number = page_number;
@@ -749,7 +749,7 @@ int rl_write(struct rlite *db, rl_data_type *type, long page_number, void *obj)
749
749
 
750
750
  retval = rl_search_cache(db, type, page_number, NULL, &pos, db->read_pages, db->read_pages_len);
751
751
  if (retval == RL_FOUND) {
752
- #ifdef DEBUG
752
+ #ifdef RL_DEBUG
753
753
  rl_free(db->read_pages[pos]->serialized_data);
754
754
  #endif
755
755
  if (db->read_pages[pos]->obj != obj) {
@@ -853,7 +853,7 @@ int rl_commit(struct rlite *db)
853
853
  size_t written;
854
854
  unsigned char *data;
855
855
  RL_MALLOC(data, db->page_size * sizeof(unsigned char));
856
- #ifdef DEBUG
856
+ #ifdef RL_DEBUG
857
857
  for (i = 0; i < db->read_pages_len; i++) {
858
858
  page = db->read_pages[i];
859
859
  memset(data, 0, db->page_size);
@@ -896,7 +896,7 @@ int rl_commit(struct rlite *db)
896
896
  fseek(driver->fp, page_number * db->page_size, SEEK_SET);
897
897
  written = fwrite(data, sizeof(unsigned char), db->page_size, driver->fp);
898
898
  if ((size_t)db->page_size != written) {
899
- #ifdef DEBUG
899
+ #ifdef RL_DEBUG
900
900
  print_cache(db);
901
901
  #endif
902
902
  retval = RL_UNEXPECTED;
@@ -931,8 +931,8 @@ int rl_commit(struct rlite *db)
931
931
  db->initial_number_of_pages = db->number_of_pages;
932
932
  db->initial_number_of_databases = db->number_of_databases;
933
933
  rl_free(db->initial_databases);
934
- RL_MALLOC(db->initial_databases, sizeof(long) * db->number_of_databases);
935
- memcpy(db->initial_databases, db->databases, sizeof(long) * db->number_of_databases);
934
+ RL_MALLOC(db->initial_databases, sizeof(long) * (db->number_of_databases + 1));
935
+ memcpy(db->initial_databases, db->databases, sizeof(long) * (db->number_of_databases + 1));
936
936
  rl_discard(db);
937
937
  rl_free(data);
938
938
  cleanup:
@@ -948,15 +948,15 @@ int rl_discard(struct rlite *db)
948
948
  db->number_of_pages = db->initial_number_of_pages;
949
949
  db->number_of_databases = db->initial_number_of_databases;
950
950
  rl_free(db->databases);
951
- RL_MALLOC(db->databases, sizeof(long) * db->number_of_databases);
952
- memcpy(db->databases, db->initial_databases, sizeof(long) * db->number_of_databases);
951
+ RL_MALLOC(db->databases, sizeof(long) * (db->number_of_databases + 1));
952
+ memcpy(db->databases, db->initial_databases, sizeof(long) * (db->number_of_databases + 1));
953
953
  rl_page *page;
954
954
  for (i = 0; i < db->read_pages_len; i++) {
955
955
  page = db->read_pages[i];
956
956
  if (page->type->destroy && page->obj) {
957
957
  page->type->destroy(db, page->obj);
958
958
  }
959
- #ifdef DEBUG
959
+ #ifdef RL_DEBUG
960
960
  rl_free(page->serialized_data);
961
961
  #endif
962
962
  rl_free(page);
@@ -966,7 +966,7 @@ int rl_discard(struct rlite *db)
966
966
  if (page->type && page->type->destroy && page->obj) {
967
967
  page->type->destroy(db, page->obj);
968
968
  }
969
- #ifdef DEBUG
969
+ #ifdef RL_DEBUG
970
970
  rl_free(page->serialized_data);
971
971
  #endif
972
972
  rl_free(page);
@@ -1075,7 +1075,7 @@ int rl_is_balanced(rlite *db)
1075
1075
  pages[i] = 0;
1076
1076
  }
1077
1077
 
1078
- for (i = 0; i < db->number_of_databases; i++) {
1078
+ for (i = 0; i < db->number_of_databases + 1; i++) {
1079
1079
  if (db->databases[i] == 0) {
1080
1080
  continue;
1081
1081
  }
@@ -1299,7 +1299,7 @@ int rl_flushall(struct rlite *db)
1299
1299
  int retval, i;
1300
1300
  int selected_database = db->selected_database;
1301
1301
 
1302
- for (i = 0; i < db->number_of_databases; i++) {
1302
+ for (i = 0; i < db->number_of_databases + 1; i++) {
1303
1303
  db->selected_database = i;
1304
1304
  RL_CALL(rl_flushdb, RL_OK, db);
1305
1305
  }
@@ -75,7 +75,7 @@ typedef struct {
75
75
  long page_number;
76
76
  rl_data_type *type;
77
77
  void *obj;
78
- #ifdef DEBUG
78
+ #ifdef RL_DEBUG
79
79
  unsigned char *serialized_data;
80
80
  #endif
81
81
  } rl_page;