crc-turbo 0.2-x86-mingw32 → 0.3-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 019207cb17862096bb83b5ab102ca7fc5ac1d372
4
- data.tar.gz: 025ab1256a46655f1ed2cc75b4d44b868474aafc
3
+ metadata.gz: e3f7657cd03168447650953f2f45a192ca524a2f
4
+ data.tar.gz: 7fb40a997e3044b4b8d4111346b4bff5baf7e935
5
5
  SHA512:
6
- metadata.gz: 9213fc2651da32478981d4bac664e13b6810bd5375aec627027bcb50b5b769da27d8dbd0a89e4f4eb3fedf9522d6519d603b61a9c9d2af3f4e7570f72c512012
7
- data.tar.gz: 882bd8bca35dbcdde5f2f50bd4616a9d2b1f192d183483bb8609154f12b16f64d8346da34871e38b919cb978fe2d101642a514bbe82d7706f873e1d6ec3d67a5
6
+ metadata.gz: 758b38d47f51aad43ebee00049730d1f1afdd567822fc71ac2f36f5b63ee7af1a04b6bf96f20850fc1c56bb9fc13f18871c1ccbf8491c64f538cab933e1bea58
7
+ data.tar.gz: 0d432aeb70d85bcab2f285d8b81510670ace05e1c2829df21fe9152c26ed264021405bb1ef175dfd1ce5ee1acb327c6d4ef8bdd25d0970ed85023862a0954d5b
data/HISTORY.ja.md CHANGED
@@ -2,6 +2,10 @@ This document is written in Japanese.
2
2
 
3
3
  # crc-turbo for ruby の更新履歴
4
4
 
5
+ ## crc-0.3
6
+
7
+ * crc-0.3 に追従して、CRC::BasicCRC と CRC::Generator を CRC に統合
8
+
5
9
  ## crc-0.2 (平成28年5月15日 (日))
6
10
 
7
11
  * \[FIX\] CRC::Generator#polynomial メソッドが間違った値を返していた問題を修正
data/README.md CHANGED
@@ -12,12 +12,12 @@ Just install this, and to do "require 'crc'" only. Additional other work is not
12
12
  * author: dearblue (mailto:dearblue@users.osdn.me)
13
13
  * report issue to: <https://osdn.jp/projects/rutsubo/ticket/>
14
14
  * how to install: ``gem install crc-turbo``
15
- * version: 0.2
15
+ * version: 0.3
16
16
  * release quality: thechnical preview
17
17
  * licensing: BSD-2-Clause<br>any parts are under Creative Commons License Zero (CC0 / Public Domain).
18
- * dependency gems: crc-0.2 (<https://rubygems/gems/crc>)
19
- * dependency external c libraries: none
20
- * bundled external c libraries: none
18
+ * dependency gems: crc-0.3 (<https://rubygems/gems/crc>)
19
+ * dependency external C libraries: none
20
+ * bundled external C libraries: none
21
21
 
22
22
 
23
23
  ## How to usage
@@ -26,8 +26,6 @@ First, install on your system.
26
26
 
27
27
  ``` shell:shell
28
28
  # gem install crc-turbo
29
- .....
30
- #
31
29
  ```
32
30
 
33
31
  And, to do ``require "crc"``.
data/ext/crc/crc_imps.h CHANGED
@@ -4,7 +4,7 @@
4
4
  *
5
5
  * This is a general CRC generator.
6
6
  *
7
- * It's used slice-by-16 algorithm with byte-order free and byte-alignment free.
7
+ * It's used slice-by-16 algorithm with byte-order free.
8
8
  * This is based on the Intel's slice-by-eight algorithm.
9
9
  *
10
10
  * Worst point is need more memory!
data/ext/crc/crcturbo.c CHANGED
@@ -16,15 +16,16 @@ enum {
16
16
  TABLE_NOTREADY = 0x1000,
17
17
  };
18
18
 
19
- #define SWITCH_BY_TYPE(FLAGS, STMT_U8, STMT_U16, STMT_U32, STMT_U64, STMT_U128) \
20
- switch ((FLAGS) & TYPE_MASK) { \
21
- case TYPE_UINT8_T: { STMT_U8; break; } \
22
- case TYPE_UINT16_T: { STMT_U16; break; } \
23
- case TYPE_UINT32_T: { STMT_U32; break; } \
24
- case TYPE_UINT64_T: { STMT_U64; break; } \
25
- /* case TYPE_UINT128_T: { STMT_U128; break; } */ \
26
- default: { rb_bug(" [INVALID TYPE FLAGS: 0x%02X] ", (FLAGS) & TYPE_MASK); } \
27
- } \
19
+ //#define SNNIPET(BITSIZE, AS, TYPE, TOUINT, CONVUINT)
20
+ #define SWITCH_BY_TYPE(TYPE, SNNIPET) \
21
+ switch ((TYPE)) { \
22
+ case TYPE_UINT8_T: { SNNIPET( 8, as8, uint8_t, to_uint8, conv_uint8); break; } \
23
+ case TYPE_UINT16_T: { SNNIPET( 16, as16, uint16_t, to_uint16, conv_uint16); break; } \
24
+ case TYPE_UINT32_T: { SNNIPET( 32, as32, uint32_t, to_uint32, conv_uint32); break; } \
25
+ case TYPE_UINT64_T: { SNNIPET( 64, as64, uint64_t, to_uint64, conv_uint64); break; } \
26
+ /* case TYPE_UINT128_T: { SNNIPET(128, as128, uint128_t, to_uint128, conv_uint128); break; } */ \
27
+ default: { rb_bug(" [INVALID TYPE FLAGS: 0x%02X] ", (TYPE)); } \
28
+ } \
28
29
 
29
30
  static inline uint8_t
30
31
  to_uint8(VALUE num)
@@ -321,52 +322,50 @@ typedef struct anyuint_t
321
322
  };
322
323
  } anyuint_t;
323
324
 
324
- struct generator
325
+ struct crc_module
325
326
  {
326
- int bitsize;
327
- int flags; /* int type, refin, refout */
327
+ uint32_t bitsize:10;
328
+ uint32_t type:10;
329
+ uint32_t reflect_input:1;
330
+ uint32_t reflect_output:1;
331
+
328
332
  anyuint_t bitmask, polynomial, initial, xorout;
329
333
  const void *table; /* entity is String buffer as instance variable */
330
334
  };
331
335
 
332
- static VALUE mCRC; /* module CRC */
336
+ static VALUE cCRC; /* class CRC */
333
337
  static VALUE mUtils; /* module CRC::Utils */
334
- static VALUE cGenerator; /* class CRC::Generator */
335
- static ID generator_iv_name;
336
- static ID generator_iv_table_buffer;
338
+ static ID ext_iv_name;
339
+ static ID ext_iv_module;
340
+ static ID ext_iv_table_buffer;
337
341
 
338
- static const rb_data_type_t generator_type = {
339
- .wrap_struct_name = "crc-turbo.CRC::Generator",
342
+ static const rb_data_type_t ext_type = {
343
+ .wrap_struct_name = "crc-turbo.CRC.module",
340
344
  .function.dmark = NULL,
341
345
  .function.dsize = NULL,
342
346
  .function.dfree = (void *)-1,
343
347
  };
344
348
 
345
- static void
346
- check_generator_notinit(VALUE obj)
347
- {
348
- struct generator *p;
349
- TypedData_Get_Struct(obj, struct generator, &generator_type, p);
350
- if (p) { rb_raise(rb_eArgError, "already initialized object - #<%s:0x%p>", rb_obj_classname(obj), (void *)obj); }
351
- }
352
-
353
- static struct generator *
354
- get_generator(VALUE obj)
349
+ static struct crc_module *
350
+ get_modulep(VALUE obj)
355
351
  {
356
- struct generator *p;
357
- TypedData_Get_Struct(obj, struct generator, &generator_type, p);
358
- if (!p) { rb_raise(rb_eArgError, "wrong initialized object - #<%s:0x%p>", rb_obj_classname(obj), (void *)obj); }
352
+ struct crc_module *p;
353
+ obj = rb_ivar_get(obj, ext_iv_module);
354
+ if (NIL_P(obj)) { return NULL; }
355
+ TypedData_Get_Struct(obj, struct crc_module, &ext_type, p);
359
356
  return p;
360
357
  }
361
358
 
362
- static VALUE
363
- generator_alloc(VALUE mod)
359
+ static struct crc_module *
360
+ get_module(VALUE obj)
364
361
  {
365
- return TypedData_Wrap_Struct(mod, &generator_type, NULL);
362
+ struct crc_module *p = get_modulep(obj);
363
+ if (!p) { rb_raise(rb_eTypeError, "wrong initialized object - #<%s:0x%p>", rb_obj_classname(obj), (void *)obj); }
364
+ return p;
366
365
  }
367
366
 
368
367
  static void
369
- generator_init_args(int argc, VALUE argv[], int *flags, int *bitsize, VALUE *poly, VALUE *init, VALUE *xorout, VALUE *name)
368
+ ext_init_args(int argc, VALUE argv[], int *flags, int *bitsize, VALUE *poly, VALUE *init, VALUE *xorout, VALUE *name)
370
369
  {
371
370
  rb_check_arity(argc, 2, 7);
372
371
  *bitsize = NUM2INT(argv[0]);
@@ -390,191 +389,180 @@ generator_init_args(int argc, VALUE argv[], int *flags, int *bitsize, VALUE *pol
390
389
  *name = (argc > 6 && !NIL_P(argv[6])) ? rb_String(argv[6]) : Qnil;
391
390
  }
392
391
 
393
- /*
394
- * call-seq:
395
- * initialize(bitsize, polynomial, initial_state = 0, reflect_input = true, reflect_output = true, xor_output = ~0, name = nil)
396
- */
397
392
  static VALUE
398
- generator_init(int argc, VALUE argv[], VALUE obj)
393
+ ext_s_new(int argc, VALUE argv[], VALUE crc)
399
394
  {
400
- int flags, bitsize;
401
- VALUE poly, init, xorout, name;
402
- check_generator_notinit(obj);
403
- generator_init_args(argc, argv, &flags, &bitsize, &poly, &init, &xorout, &name);
404
-
405
- struct generator *p;
406
- size_t allocsize = sizeof(struct generator);
407
- RTYPEDDATA_DATA(obj) = p = (struct generator *)ALLOC_N(char, allocsize);
408
- p->bitsize = bitsize;
409
- p->flags = flags;
410
- p->table = NULL;
411
-
412
- /*
413
- * bitmask の代入でわざわざ1ビット分を後から行う理由は、
414
- * 例えば uint8_t に対して << 8 をすると何もしないため、
415
- * これへの対処を目的とする。
416
- */
417
- #define INIT_GENERATOR(TYPE, AS, TO_UINT, CONV_UINT, P, BITSIZE, POLY, INIT, XOROUT) \
418
- P->bitmask.AS = ~(~(TYPE)0 << 1 << (BITSIZE - 1)); \
419
- P->polynomial.AS = P->bitmask.AS & TO_UINT(POLY); \
420
- P->initial.AS = P->bitmask.AS & TO_UINT(INIT); \
421
- P->xorout.AS = P->bitmask.AS & TO_UINT(XOROUT); \
422
-
423
- SWITCH_BY_TYPE(flags,
424
- INIT_GENERATOR(uint8_t, as8, to_uint8, conv_uint8, p, bitsize, poly, init, xorout),
425
- INIT_GENERATOR(uint16_t, as16, to_uint16, conv_uint16, p, bitsize, poly, init, xorout),
426
- INIT_GENERATOR(uint32_t, as32, to_uint32, conv_uint32, p, bitsize, poly, init, xorout),
427
- INIT_GENERATOR(uint64_t, as64, to_uint64, conv_uint64, p, bitsize, poly, init, xorout),
428
- INIT_GENERATOR(uint128_t, as128, to_uint128, conv_uint128, p, bitsize, poly, init, xorout));
429
-
430
- #undef INIT_GENERATOR
431
-
432
- rb_ivar_set(obj, generator_iv_name, name);
433
-
434
- return obj;
395
+ if (get_modulep(crc)) {
396
+ return rb_call_super(argc, argv);
397
+ } else {
398
+ int flags, bitsize;
399
+ VALUE poly, init, xorout, name;
400
+ ext_init_args(argc, argv, &flags, &bitsize, &poly, &init, &xorout, &name);
401
+
402
+ struct crc_module *p;
403
+ VALUE crcmod = TypedData_Make_Struct(crc, struct crc_module, &ext_type, p);
404
+
405
+ p->bitsize = bitsize;
406
+ p->type = flags & TYPE_MASK;
407
+ p->reflect_input = ((flags & REFLECT_INPUT) != 0) ? 1 : 0;
408
+ p->reflect_output = ((flags & REFLECT_OUTPUT) != 0) ? 1 : 0;
409
+ p->table = NULL;
410
+
411
+ /*
412
+ * bitmask の代入でわざわざ1ビット分を後から行う理由は、
413
+ * 例えば uint8_t に対して << 8 をすると何もしないため、
414
+ * これへの対処を目的とする。
415
+ */
416
+ #define SNNIPET_INIT_MOD(BITSIZE, AS, TYPE, TOUINT, CONVUINT) \
417
+ p->bitmask.AS = ~(~(TYPE)0 << 1 << (bitsize - 1)); \
418
+ p->polynomial.AS = p->bitmask.AS & TOUINT(poly); \
419
+ p->initial.AS = p->bitmask.AS & TOUINT(init); \
420
+ p->xorout.AS = p->bitmask.AS & TOUINT(xorout); \
421
+
422
+ SWITCH_BY_TYPE(p->type, SNNIPET_INIT_MOD);
423
+
424
+ VALUE newcrc = rb_define_class_id(0, crc);
425
+ rb_ivar_set(newcrc, ext_iv_module, crcmod);
426
+ rb_ivar_set(newcrc, ext_iv_name, name);
427
+
428
+ rb_extend_object(newcrc, rb_const_get(cCRC, rb_intern("ModuleClass")));
429
+ rb_define_alias(rb_singleton_class(newcrc), "[]", "new");
430
+
431
+ return newcrc;
432
+ }
435
433
  }
436
434
 
437
435
  static VALUE
438
- generator_bitsize(VALUE t)
436
+ ext_bitsize(VALUE t)
439
437
  {
440
- return INT2FIX(get_generator(t)->bitsize);
438
+ return INT2FIX(get_module(t)->bitsize);
441
439
  }
442
440
 
443
441
  static VALUE
444
- generator_bitmask(VALUE t)
442
+ ext_bitmask(VALUE t)
445
443
  {
446
- struct generator *p = get_generator(t);
447
- SWITCH_BY_TYPE(p->flags,
448
- return conv_uint8(p->bitmask.as8),
449
- return conv_uint16(p->bitmask.as16),
450
- return conv_uint32(p->bitmask.as32),
451
- return conv_uint64(p->bitmask.as64),
452
- return conv_uint128(p->bitmask.as128));
444
+ struct crc_module *p = get_module(t);
445
+
446
+ #define SNNIPET_BITMASK(BITSIZE, AS, TYPE, TOUINT, CONVUINT) \
447
+ return CONVUINT(p->bitmask.AS); \
448
+
449
+ SWITCH_BY_TYPE(p->type, SNNIPET_BITMASK);
453
450
  }
454
451
 
455
452
  static VALUE
456
- generator_polynomial(VALUE t)
453
+ ext_polynomial(VALUE t)
457
454
  {
458
- struct generator *p = get_generator(t);
459
- SWITCH_BY_TYPE(p->flags,
460
- return conv_uint8(p->polynomial.as8),
461
- return conv_uint16(p->polynomial.as16),
462
- return conv_uint32(p->polynomial.as32),
463
- return conv_uint64(p->polynomial.as64),
464
- return conv_uint128(p->polynomial.as128));
455
+ struct crc_module *p = get_module(t);
456
+
457
+ #define SNNIPET_POLYNOMIAL(BITSIZE, AS, TYPE, TOUINT, CONVUINT) \
458
+ return CONVUINT(p->polynomial.AS); \
459
+
460
+ SWITCH_BY_TYPE(p->type, SNNIPET_POLYNOMIAL);
465
461
  }
466
462
 
467
463
  static VALUE
468
- generator_initial_state(VALUE t)
464
+ ext_initial_crc(VALUE t)
469
465
  {
470
- struct generator *p = get_generator(t);
471
- SWITCH_BY_TYPE(p->flags,
472
- return conv_uint8(p->initial.as8),
473
- return conv_uint16(p->initial.as16),
474
- return conv_uint32(p->initial.as32),
475
- return conv_uint64(p->initial.as64),
476
- return conv_uint128(p->initial.as128));
466
+ struct crc_module *p = get_module(t);
467
+
468
+ #define SNNIPET_INITIAL_CRC(BITSIZE, AS, TYPE, TOUINT, CONVUINT) \
469
+ return CONVUINT(p->initial.AS); \
470
+
471
+ SWITCH_BY_TYPE(p->type, SNNIPET_INITIAL_CRC);
477
472
  }
478
473
 
479
474
  static VALUE
480
- generator_table(VALUE t)
475
+ ext_table(VALUE t)
481
476
  {
482
- struct generator *p = get_generator(t);
477
+ struct crc_module *p = get_module(t);
483
478
  rb_raise(rb_eNotImpError, "");
484
479
  }
485
480
 
486
481
  static VALUE
487
- generator_reflect_input(VALUE t)
482
+ ext_reflect_input(VALUE t)
488
483
  {
489
- struct generator *p = get_generator(t);
490
- return (p->flags & REFLECT_INPUT) ? Qtrue : Qfalse;
484
+ struct crc_module *p = get_module(t);
485
+ return (p->reflect_input != 0) ? Qtrue : Qfalse;
491
486
  }
492
487
 
493
488
  static VALUE
494
- generator_reflect_output(VALUE t)
489
+ ext_reflect_output(VALUE t)
495
490
  {
496
- struct generator *p = get_generator(t);
497
- return (p->flags & REFLECT_OUTPUT) ? Qtrue : Qfalse;
491
+ struct crc_module *p = get_module(t);
492
+ return (p->reflect_output != 0) ? Qtrue : Qfalse;
498
493
  }
499
494
 
500
495
  static VALUE
501
- generator_xor_output(VALUE t)
496
+ ext_xor_output(VALUE t)
502
497
  {
503
- struct generator *p = get_generator(t);
504
- SWITCH_BY_TYPE(p->flags,
505
- return conv_uint8(p->xorout.as8),
506
- return conv_uint16(p->xorout.as16),
507
- return conv_uint32(p->xorout.as32),
508
- return conv_uint64(p->xorout.as64),
509
- return conv_uint128(p->xorout.as128));
498
+ struct crc_module *p = get_module(t);
499
+
500
+ #define SNNIPET_XOR_OUTPUT(BITSIZE, AS, TYPE, TOUINT, CONVUINT) \
501
+ return CONVUINT(p->xorout.AS); \
502
+
503
+ SWITCH_BY_TYPE(p->type, SNNIPET_XOR_OUTPUT);
510
504
  }
511
505
 
512
506
  static VALUE
513
- generator_name(VALUE t)
507
+ ext_name(VALUE t)
514
508
  {
515
- // get_generator で初期化の確認
516
- get_generator(t);
509
+ // get_module で初期化の確認
510
+ get_module(t);
517
511
 
518
- return rb_ivar_get(t, generator_iv_name);
512
+ return rb_ivar_get(t, ext_iv_name);
519
513
  }
520
514
 
521
515
  static VALUE
522
- generator_set_name(VALUE t, VALUE name)
516
+ ext_set_name(VALUE t, VALUE name)
523
517
  {
524
- // get_generator で初期化の確認
525
- get_generator(t);
518
+ // get_module で初期化の確認
519
+ get_module(t);
526
520
 
527
- rb_ivar_set(t, generator_iv_name, rb_String(name));
521
+ rb_ivar_set(t, ext_iv_name, rb_String(name));
528
522
  return name;
529
523
  }
530
524
 
531
525
  static VALUE
532
- generator_update(VALUE t, VALUE seq, VALUE state)
526
+ ext_update(VALUE t, VALUE seq, VALUE state)
533
527
  {
534
- struct generator *p = get_generator(t);
528
+ struct crc_module *p = get_module(t);
535
529
  rb_check_type(seq, RUBY_T_STRING);
536
530
  const char *q = RSTRING_PTR(seq);
537
531
  const char *qq = q + RSTRING_LEN(seq);
538
532
 
539
533
  if (!p->table) {
540
- size_t tablebytes = (p->flags & TYPE_MASK) * 16 * 256;
534
+ size_t tablebytes = (p->type) * 16 * 256;
541
535
  VALUE tablebuf = rb_str_buf_new(tablebytes);
542
536
  rb_str_set_len(tablebuf, tablebytes);
543
537
  void *table = RSTRING_PTR(tablebuf);
544
- if (p->flags & REFLECT_INPUT) {
545
- SWITCH_BY_TYPE(p->flags,
546
- crc_build_reflect_tables_u8(p->bitsize, table, p->polynomial.as8, 16),
547
- crc_build_reflect_tables_u16(p->bitsize, table, p->polynomial.as16, 16),
548
- crc_build_reflect_tables_u32(p->bitsize, table, p->polynomial.as32, 16),
549
- crc_build_reflect_tables_u64(p->bitsize, table, p->polynomial.as64, 16),
550
- crc_build_reflect_tables_u128(p->bitsize, table, p->polynomial.as128, 16));
538
+ if (p->reflect_input) {
539
+ #define SNNIPET_BUILD_REFTABLE(BITSIZE, AS, TYPE, TOUINT, CONVUINT) \
540
+ crc_build_reflect_tables_u##BITSIZE(p->bitsize, table, p->polynomial.AS, 16); \
541
+
542
+ SWITCH_BY_TYPE(p->type, SNNIPET_BUILD_REFTABLE);
551
543
  } else {
552
- SWITCH_BY_TYPE(p->flags,
553
- crc_build_tables_u8(p->bitsize, table, p->polynomial.as8, 16),
554
- crc_build_tables_u16(p->bitsize, table, p->polynomial.as16, 16),
555
- crc_build_tables_u32(p->bitsize, table, p->polynomial.as32, 16),
556
- crc_build_tables_u64(p->bitsize, table, p->polynomial.as64, 16),
557
- crc_build_tables_u128(p->bitsize, table, p->polynomial.as128, 16));
544
+ #define SNNIPET_BUILD_TABLE(BITSIZE, AS, TYPE, TOUINT, CONVUINT) \
545
+ crc_build_tables_u##BITSIZE(p->bitsize, table, p->polynomial.AS, 16); \
546
+
547
+ SWITCH_BY_TYPE(p->type, SNNIPET_BUILD_TABLE);
558
548
  }
559
- rb_ivar_set(t, generator_iv_table_buffer, tablebuf);
549
+ rb_ivar_set(t, ext_iv_table_buffer, tablebuf);
560
550
  rb_obj_freeze(tablebuf);
561
551
  p->table = table;
562
552
  }
563
553
 
564
- if (p->flags & REFLECT_INPUT) {
565
- SWITCH_BY_TYPE(p->flags,
566
- return conv_uint8(crc_reflect_update_u8(p->bitsize, p->table, q, qq, to_uint8(state))),
567
- return conv_uint16(crc_reflect_update_u16(p->bitsize, p->table, q, qq, to_uint16(state))),
568
- return conv_uint32(crc_reflect_update_u32(p->bitsize, p->table, q, qq, to_uint32(state))),
569
- return conv_uint64(crc_reflect_update_u64(p->bitsize, p->table, q, qq, to_uint64(state))),
570
- return conv_uint128(crc_reflect_update_u128(p->bitsize, p->table, q, qq, to_uint128(state))));
554
+ if (p->reflect_input) {
555
+ #define SNNIPET_REFUPDATE(BITSIZE, AS, TYPE, TOUINT, CONVUINT) \
556
+ return CONVUINT(crc_reflect_update_u##BITSIZE( \
557
+ p->bitsize, p->table, q, qq, TOUINT(state))); \
558
+
559
+ SWITCH_BY_TYPE(p->type, SNNIPET_REFUPDATE);
571
560
  } else {
572
- SWITCH_BY_TYPE(p->flags,
573
- return conv_uint8(crc_update_u8(p->bitsize, p->table, q, qq, to_uint8(state))),
574
- return conv_uint16(crc_update_u16(p->bitsize, p->table, q, qq, to_uint16(state))),
575
- return conv_uint32(crc_update_u32(p->bitsize, p->table, q, qq, to_uint32(state))),
576
- return conv_uint64(crc_update_u64(p->bitsize, p->table, q, qq, to_uint64(state))),
577
- return conv_uint128(crc_update_u128(p->bitsize, p->table, q, qq, to_uint128(state))));
561
+ #define SNNIPET_UPDATE(BITSIZE, AS, TYPE, TOUINT, CONVUINT) \
562
+ return CONVUINT(crc_update_u##BITSIZE( \
563
+ p->bitsize, p->table, q, qq, TOUINT(state))); \
564
+
565
+ SWITCH_BY_TYPE(p->type, SNNIPET_UPDATE);
578
566
  }
579
567
  }
580
568
 
@@ -639,30 +627,28 @@ utils_s_bitref128(VALUE mod, VALUE num)
639
627
  void
640
628
  Init__turbo(void)
641
629
  {
642
- generator_iv_name = rb_intern("crc-turbo.CRC::Generator.name");
643
- generator_iv_table_buffer = rb_intern("crc-turbo.CRC::Generator.table-buffer");
644
-
645
- mCRC = rb_define_module("CRC");
646
-
647
- mUtils = rb_define_module_under(mCRC, "Utils");
630
+ ext_iv_name = rb_intern("crc-turbo.CRC.name");
631
+ ext_iv_module = rb_intern("crc-turbo.CRC.module");
632
+ ext_iv_table_buffer = rb_intern("crc-turbo.CRC.table-buffer");
633
+
634
+ cCRC = rb_define_class("CRC", rb_cObject);
635
+ rb_define_singleton_method(cCRC, "new", ext_s_new, -1);
636
+ rb_define_singleton_method(cCRC, "bitsize", ext_bitsize, 0);
637
+ rb_define_singleton_method(cCRC, "bitmask", ext_bitmask, 0);
638
+ rb_define_singleton_method(cCRC, "polynomial", ext_polynomial, 0);
639
+ rb_define_singleton_method(cCRC, "initial_crc", ext_initial_crc, 0);
640
+ rb_define_singleton_method(cCRC, "table", ext_table, 0);
641
+ rb_define_singleton_method(cCRC, "reflect_input?", ext_reflect_input, 0);
642
+ rb_define_singleton_method(cCRC, "reflect_output?", ext_reflect_output, 0);
643
+ rb_define_singleton_method(cCRC, "xor_output", ext_xor_output, 0);
644
+ rb_define_singleton_method(cCRC, "name", ext_name, 0);
645
+ rb_define_singleton_method(cCRC, "name=", ext_set_name, 1);
646
+ rb_define_singleton_method(cCRC, "update", ext_update, 2);
647
+
648
+ mUtils = rb_define_module_under(cCRC, "Utils");
648
649
  rb_define_method(mUtils, "bitreflect8", utils_s_bitref8, 1);
649
650
  rb_define_method(mUtils, "bitreflect16", utils_s_bitref16, 1);
650
651
  rb_define_method(mUtils, "bitreflect32", utils_s_bitref32, 1);
651
652
  rb_define_method(mUtils, "bitreflect64", utils_s_bitref64, 1);
652
653
  rb_define_method(mUtils, "bitreflect128", utils_s_bitref128, 1);
653
-
654
- cGenerator = rb_define_class_under(mCRC, "Generator", rb_cObject);
655
- rb_define_alloc_func(cGenerator, generator_alloc);
656
- rb_define_method(cGenerator, "initialize", generator_init, -1);
657
- rb_define_method(cGenerator, "bitsize", generator_bitsize, 0);
658
- rb_define_method(cGenerator, "bitmask", generator_bitmask, 0);
659
- rb_define_method(cGenerator, "polynomial", generator_polynomial, 0);
660
- rb_define_method(cGenerator, "initial_state", generator_initial_state, 0);
661
- rb_define_method(cGenerator, "table", generator_table, 0);
662
- rb_define_method(cGenerator, "reflect_input", generator_reflect_input, 0);
663
- rb_define_method(cGenerator, "reflect_output", generator_reflect_output, 0);
664
- rb_define_method(cGenerator, "xor_output", generator_xor_output, 0);
665
- rb_define_method(cGenerator, "name", generator_name, 0);
666
- rb_define_method(cGenerator, "name=", generator_set_name, 1);
667
- rb_define_method(cGenerator, "update", generator_update, 2);
668
654
  }
data/gemstub.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  GEMSTUB = Gem::Specification.new do |s|
2
2
  s.name = "crc-turbo"
3
- s.version = "0.2"
3
+ s.version = "0.3"
4
4
  s.summary = "general CRC generator"
5
5
  s.description = <<EOS
6
6
  This is a C extention for "crc" gem library.
@@ -12,8 +12,8 @@ EOS
12
12
  s.email = "dearblue@users.osdn.me"
13
13
 
14
14
  s.required_ruby_version = ">= 2.0"
15
- s.add_development_dependency "rake", "~> 11.0"
16
- s.add_runtime_dependency "crc", "~> 0.2"
15
+ s.add_development_dependency "rake"
16
+ s.add_runtime_dependency "crc", "~> 0.3"
17
17
  end
18
18
 
19
19
  EXTMAP["crc"] = "crc/_turbo"
Binary file
Binary file
Binary file
Binary file
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crc-turbo
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: '0.3'
5
5
  platform: x86-mingw32
6
6
  authors:
7
7
  - dearblue
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-15 00:00:00.000000000 Z
11
+ date: 2016-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '11.0'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '11.0'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: crc
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.2'
33
+ version: '0.3'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.2'
40
+ version: '0.3'
41
41
  description: |
42
42
  This is a C extention for "crc" gem library.
43
43
  Just install this, and to do "require 'crc'" only. Additional other work is not required.
@@ -93,4 +93,3 @@ signing_key:
93
93
  specification_version: 4
94
94
  summary: general CRC generator
95
95
  test_files: []
96
- has_rdoc: