cbor 0.5.10.3 → 0.6.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5c19c16a813216e3c903a39aa6f0ecda394583573c45838b7544ec2514541280
4
- data.tar.gz: d68cb04551414615326546e33603f86a6353e336b61ee3415ddfc173cb6bb798
3
+ metadata.gz: 81901bcce887dfccdd18d87f3f965a39fd227ae17efd65f8542ff00664e2d9db
4
+ data.tar.gz: b18c012f042203da87aa7a6cfc67162fab835fbb3fac175c6ca9c4b848955b35
5
5
  SHA512:
6
- metadata.gz: 17f03486f27be553722e1f5f737701b74be8bfbf824ee96da8bb42cb52aa182b9c9c717f5e63fcf705a7ffcd793207489755b3309ea8be727d4afb0752a42433
7
- data.tar.gz: 50da5b227f4a4247386f6ef72a958d50343e517ad25c2780d945a99c520506b80a51f19a98967600490a493fc88ef1fc41c778c4b350bb17b24a28ea45b1da22
6
+ metadata.gz: fba1eb8572bf19ea27ff9ca433161f53081f40a6fb283119a84741691439de10c390e030fe59f1038599f4299b2d958655a9b975d33346c09704d46d8c340d19
7
+ data.tar.gz: 97e16103db5fccb67c319541624ff4d7a6333b5d932baccea3a594d1e65e586e683e941dd0042fc58d1b4fb82e1934b655efc754f3489212af7e24195ab69607
@@ -38,9 +38,10 @@ static ID s_write;
38
38
  static ID s_append;
39
39
  static ID s_close;
40
40
 
41
+ static msgpack_buffer_t* Buffer_get(VALUE self);
42
+
41
43
  #define BUFFER(from, name) \
42
- msgpack_buffer_t *name = NULL; \
43
- Data_Get_Struct(from, msgpack_buffer_t, name); \
44
+ msgpack_buffer_t *name = Buffer_get(from); \
44
45
  if(name == NULL) { \
45
46
  rb_raise(rb_eArgError, "NULL found for " # name " when shouldn't be."); \
46
47
  }
@@ -51,22 +52,64 @@ static ID s_close;
51
52
  rb_raise(rb_eTypeError, "instance of String needed"); \
52
53
  }
53
54
 
55
+ static void Buffer_mark(void* data)
56
+ {
57
+ msgpack_buffer_t* b = data;
58
+ msgpack_buffer_mark(b);
59
+ }
60
+
54
61
  static void Buffer_free(void* data)
55
62
  {
56
63
  if(data == NULL) {
57
64
  return;
58
65
  }
59
- msgpack_buffer_t* b = (msgpack_buffer_t*) data;
66
+ msgpack_buffer_t* b = data;
60
67
  msgpack_buffer_destroy(b);
61
- xfree(b);
68
+ xfree(data);
69
+ }
70
+
71
+ #ifdef TypedData_Make_Struct
72
+ static size_t Buffer_memsize(const void* data)
73
+ {
74
+ return data == NULL ? 0 : sizeof(msgpack_buffer_t);
75
+ }
76
+
77
+ static const rb_data_type_t buffer_data_type = {
78
+ "CBOR::Buffer",
79
+ {Buffer_mark, Buffer_free, Buffer_memsize,},
80
+ NULL, NULL, 0
81
+ };
82
+
83
+ static const rb_data_type_t wrapped_buffer_data_type = {
84
+ "CBOR::WrappedBuffer",
85
+ {Buffer_mark, NULL, Buffer_memsize,},
86
+ &buffer_data_type, NULL, 0
87
+ };
88
+ #endif
89
+
90
+ static msgpack_buffer_t* Buffer_get(VALUE self)
91
+ {
92
+ msgpack_buffer_t* b = NULL;
93
+ #ifdef TypedData_Make_Struct
94
+ TypedData_Get_Struct(self, msgpack_buffer_t, &buffer_data_type, b);
95
+ #else
96
+ Data_Get_Struct(self, msgpack_buffer_t, b);
97
+ #endif
98
+ return b;
62
99
  }
63
100
 
64
101
  static VALUE Buffer_alloc(VALUE klass)
65
102
  {
66
- msgpack_buffer_t* b = ALLOC_N(msgpack_buffer_t, 1);
103
+ msgpack_buffer_t* b;
104
+ VALUE self;
105
+ #ifdef TypedData_Make_Struct
106
+ self = TypedData_Make_Struct(klass, msgpack_buffer_t, &buffer_data_type, b);
107
+ #else
108
+ self = Data_Make_Struct(klass, msgpack_buffer_t, Buffer_mark, Buffer_free, b);
109
+ #endif
67
110
  msgpack_buffer_init(b);
68
111
 
69
- return Data_Wrap_Struct(klass, msgpack_buffer_mark, Buffer_free, b);
112
+ return self;
70
113
  }
71
114
 
72
115
  static ID get_partial_read_method(VALUE io)
@@ -118,7 +161,11 @@ void MessagePack_Buffer_initialize(msgpack_buffer_t* b, VALUE io, VALUE options)
118
161
  VALUE MessagePack_Buffer_wrap(msgpack_buffer_t* b, VALUE owner)
119
162
  {
120
163
  b->owner = owner;
121
- return Data_Wrap_Struct(cMessagePack_Buffer, msgpack_buffer_mark, NULL, b);
164
+ #ifdef TypedData_Make_Struct
165
+ return TypedData_Wrap_Struct(cMessagePack_Buffer, &wrapped_buffer_data_type, b);
166
+ #else
167
+ return Data_Wrap_Struct(cMessagePack_Buffer, Buffer_mark, NULL, b);
168
+ #endif
122
169
  }
123
170
 
124
171
  static VALUE Buffer_initialize(int argc, VALUE* argv, VALUE self)
@@ -512,4 +559,3 @@ void MessagePack_Buffer_module_init(VALUE mMessagePack)
512
559
  rb_define_alias(cMessagePack_Buffer, "to_s", "to_str");
513
560
  rb_define_method(cMessagePack_Buffer, "to_a", Buffer_to_a, 0);
514
561
  }
515
-
data/ext/cbor/core_ext.c CHANGED
@@ -49,8 +49,7 @@ static inline VALUE delegete_to_pack(int argc, VALUE* argv, VALUE self)
49
49
  return delegete_to_pack(argc, argv, self); \
50
50
  } \
51
51
  VALUE packer = argv[0]; \
52
- msgpack_packer_t *pk; \
53
- Data_Get_Struct(packer, msgpack_packer_t, pk);
52
+ msgpack_packer_t *pk = MessagePack_Packer_get(packer);
54
53
 
55
54
  static VALUE NilClass_to_msgpack(int argc, VALUE* argv, VALUE self)
56
55
  {
@@ -198,4 +197,3 @@ void MessagePack_core_ext_module_init()
198
197
  rb_define_method(rb_cCBOR_Simple, "to_cbor", Simple_to_msgpack, -1);
199
198
  rb_define_method(rb_cCBOR_Tagged, "to_cbor", Tagged_to_msgpack, -1);
200
199
  }
201
-
@@ -39,15 +39,23 @@ static ID s_write;
39
39
  //static VALUE s_packer_value;
40
40
  //static msgpack_packer_t* s_packer;
41
41
 
42
+ static msgpack_packer_t* Packer_get(VALUE self);
43
+
42
44
  #define PACKER(from, name) \
43
- msgpack_packer_t* name; \
44
- Data_Get_Struct(from, msgpack_packer_t, name); \
45
+ msgpack_packer_t* name = Packer_get(from); \
45
46
  if(name == NULL) { \
46
47
  rb_raise(rb_eArgError, "NULL found for " # name " when shouldn't be."); \
47
48
  }
48
49
 
49
- static void Packer_free(msgpack_packer_t* pk)
50
+ static void Packer_mark(void* data)
50
51
  {
52
+ msgpack_packer_t* pk = data;
53
+ msgpack_packer_mark(pk);
54
+ }
55
+
56
+ static void Packer_free(void* data)
57
+ {
58
+ msgpack_packer_t* pk = data;
51
59
  if(pk == NULL) {
52
60
  return;
53
61
  }
@@ -55,13 +63,47 @@ static void Packer_free(msgpack_packer_t* pk)
55
63
  xfree(pk);
56
64
  }
57
65
 
66
+ #ifdef TypedData_Make_Struct
67
+ static size_t Packer_memsize(const void* data)
68
+ {
69
+ return data == NULL ? 0 : sizeof(msgpack_packer_t);
70
+ }
71
+
72
+ static const rb_data_type_t packer_data_type = {
73
+ "CBOR::Packer",
74
+ {Packer_mark, Packer_free, Packer_memsize,},
75
+ NULL, NULL, 0
76
+ };
77
+ #endif
78
+
79
+ static msgpack_packer_t* Packer_get(VALUE self)
80
+ {
81
+ msgpack_packer_t* pk = NULL;
82
+ #ifdef TypedData_Make_Struct
83
+ TypedData_Get_Struct(self, msgpack_packer_t, &packer_data_type, pk);
84
+ #else
85
+ Data_Get_Struct(self, msgpack_packer_t, pk);
86
+ #endif
87
+ return pk;
88
+ }
89
+
90
+ msgpack_packer_t* MessagePack_Packer_get(VALUE self)
91
+ {
92
+ PACKER(self, pk);
93
+ return pk;
94
+ }
95
+
58
96
  static VALUE Packer_alloc(VALUE klass)
59
97
  {
60
- msgpack_packer_t* pk = ALLOC_N(msgpack_packer_t, 1);
98
+ msgpack_packer_t* pk;
99
+ VALUE self;
100
+ #ifdef TypedData_Make_Struct
101
+ self = TypedData_Make_Struct(klass, msgpack_packer_t, &packer_data_type, pk);
102
+ #else
103
+ self = Data_Make_Struct(klass, msgpack_packer_t, Packer_mark, Packer_free, pk);
104
+ #endif
61
105
  msgpack_packer_init(pk);
62
106
 
63
- VALUE self = Data_Wrap_Struct(klass, msgpack_packer_mark, Packer_free, pk);
64
-
65
107
  msgpack_packer_set_to_msgpack_method(pk, s_to_msgpack, self);
66
108
  pk->buffer_ref = MessagePack_Buffer_wrap(PACKER_BUFFER_(pk), self);
67
109
 
@@ -301,4 +343,3 @@ void MessagePack_Packer_module_init(VALUE mMessagePack)
301
343
  rb_define_module_function(mMessagePack, "encode", MessagePack_pack_module_method, -1);
302
344
  rb_define_module_function(mMessagePack, "dump", MessagePack_dump_module_method, -1);
303
345
  }
304
-
@@ -31,9 +31,10 @@
31
31
 
32
32
  extern VALUE cMessagePack_Packer;
33
33
 
34
+ msgpack_packer_t* MessagePack_Packer_get(VALUE self);
35
+
34
36
  void MessagePack_Packer_module_init(VALUE mMessagePack);
35
37
 
36
38
  VALUE MessagePack_pack(int argc, VALUE* argv);
37
39
 
38
40
  #endif
39
-
data/ext/cbor/unpacker.c CHANGED
@@ -30,10 +30,10 @@
30
30
  #include <math.h> /* for ldexp */
31
31
 
32
32
  /* work around https://bugs.ruby-lang.org/issues/15779 for now
33
- * by limiting preallocation to about a half a Mebibyte
34
- * limit is 2**n-1 (n==16) items so we can avoid a conditional
33
+ * by limiting preallocation to about a Tebibyte
34
+ * limit is 2**n-1 (n==28) so we can avoid a conditional
35
35
  */
36
- #define SANE_PREALLOCATION_MAX 0xFFFFUL
36
+ #define SANE_PREALLOCATION_MAX 0xFFFFFFFUL
37
37
  #define SANE_PREALLOCATE(n) (n & SANE_PREALLOCATION_MAX)
38
38
 
39
39
  #if !defined(DISABLE_RMEM) && !defined(DISABLE_UNPACKER_STACK_RMEM) && \
@@ -39,15 +39,23 @@ static VALUE eMalformedFormatError;
39
39
  static VALUE eStackError;
40
40
  static VALUE eTypeError;
41
41
 
42
+ static msgpack_unpacker_t* Unpacker_get(VALUE self);
43
+
42
44
  #define UNPACKER(from, name) \
43
- msgpack_unpacker_t *name = NULL; \
44
- Data_Get_Struct(from, msgpack_unpacker_t, name); \
45
+ msgpack_unpacker_t *name = Unpacker_get(from); \
45
46
  if(name == NULL) { \
46
47
  rb_raise(rb_eArgError, "NULL found for " # name " when shouldn't be."); \
47
48
  }
48
49
 
49
- static void Unpacker_free(msgpack_unpacker_t* uk)
50
+ static void Unpacker_mark(void* data)
51
+ {
52
+ msgpack_unpacker_t* uk = data;
53
+ msgpack_unpacker_mark(uk);
54
+ }
55
+
56
+ static void Unpacker_free(void* data)
50
57
  {
58
+ msgpack_unpacker_t* uk = data;
51
59
  if(uk == NULL) {
52
60
  return;
53
61
  }
@@ -55,13 +63,41 @@ static void Unpacker_free(msgpack_unpacker_t* uk)
55
63
  xfree(uk);
56
64
  }
57
65
 
66
+ #ifdef TypedData_Make_Struct
67
+ static size_t Unpacker_memsize(const void* data)
68
+ {
69
+ return data == NULL ? 0 : sizeof(msgpack_unpacker_t);
70
+ }
71
+
72
+ static const rb_data_type_t unpacker_data_type = {
73
+ "CBOR::Unpacker",
74
+ {Unpacker_mark, Unpacker_free, Unpacker_memsize,},
75
+ NULL, NULL, 0
76
+ };
77
+ #endif
78
+
79
+ static msgpack_unpacker_t* Unpacker_get(VALUE self)
80
+ {
81
+ msgpack_unpacker_t* uk = NULL;
82
+ #ifdef TypedData_Make_Struct
83
+ TypedData_Get_Struct(self, msgpack_unpacker_t, &unpacker_data_type, uk);
84
+ #else
85
+ Data_Get_Struct(self, msgpack_unpacker_t, uk);
86
+ #endif
87
+ return uk;
88
+ }
89
+
58
90
  static VALUE Unpacker_alloc(VALUE klass)
59
91
  {
60
- msgpack_unpacker_t* uk = ALLOC_N(msgpack_unpacker_t, 1);
92
+ msgpack_unpacker_t* uk;
93
+ VALUE self;
94
+ #ifdef TypedData_Make_Struct
95
+ self = TypedData_Make_Struct(klass, msgpack_unpacker_t, &unpacker_data_type, uk);
96
+ #else
97
+ self = Data_Make_Struct(klass, msgpack_unpacker_t, Unpacker_mark, Unpacker_free, uk);
98
+ #endif
61
99
  msgpack_unpacker_init(uk);
62
100
 
63
- VALUE self = Data_Wrap_Struct(klass, msgpack_unpacker_mark, Unpacker_free, uk);
64
-
65
101
  uk->buffer_ref = MessagePack_Buffer_wrap(UNPACKER_BUFFER_(uk), self);
66
102
 
67
103
  return self;
@@ -426,4 +462,3 @@ void MessagePack_Unpacker_module_init(VALUE mMessagePack)
426
462
  rb_define_module_function(mMessagePack, "unpack", MessagePack_unpack_module_method, -1);
427
463
  rb_define_module_function(mMessagePack, "decode", MessagePack_unpack_module_method, -1);
428
464
  }
429
-
data/lib/cbor/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module CBOR
2
- VERSION = "0.5.10.3"
2
+ VERSION = "0.6.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cbor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.10.3
4
+ version: 0.6.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carsten Bormann, standing on the tall shoulders of Sadayuki Furuhashi