msgpack 1.4.0.pre1 → 1.4.3
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 +4 -4
- data/.github/workflows/ci.yaml +56 -0
- data/ChangeLog +22 -0
- data/README.md +242 -0
- data/Rakefile +2 -9
- data/doclib/msgpack/factory.rb +1 -0
- data/ext/java/org/msgpack/jruby/Buffer.java +17 -16
- data/ext/java/org/msgpack/jruby/Decoder.java +29 -10
- data/ext/java/org/msgpack/jruby/Encoder.java +22 -12
- data/ext/java/org/msgpack/jruby/ExtensionRegistry.java +9 -9
- data/ext/java/org/msgpack/jruby/ExtensionValue.java +5 -8
- data/ext/java/org/msgpack/jruby/Factory.java +7 -2
- data/ext/java/org/msgpack/jruby/Packer.java +11 -9
- data/ext/java/org/msgpack/jruby/Unpacker.java +39 -26
- data/ext/msgpack/buffer.c +4 -16
- data/ext/msgpack/buffer.h +46 -5
- data/ext/msgpack/compat.h +1 -12
- data/ext/msgpack/extconf.rb +27 -7
- data/ext/msgpack/factory_class.c +10 -5
- data/ext/msgpack/packer.c +18 -5
- data/ext/msgpack/packer.h +0 -16
- data/ext/msgpack/packer_class.c +0 -9
- data/ext/msgpack/packer_ext_registry.c +0 -22
- data/ext/msgpack/unpacker.c +39 -50
- data/ext/msgpack/unpacker.h +8 -0
- data/ext/msgpack/unpacker_class.c +10 -5
- data/lib/msgpack/symbol.rb +14 -4
- data/lib/msgpack/time.rb +1 -1
- data/lib/msgpack/version.rb +4 -8
- data/lib/msgpack.rb +1 -2
- data/msgpack.gemspec +3 -5
- data/spec/factory_spec.rb +17 -0
- data/spec/msgpack_spec.rb +1 -1
- data/spec/packer_spec.rb +18 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/timestamp_spec.rb +40 -0
- data/spec/unpacker_spec.rb +102 -1
- metadata +12 -26
- data/.travis.yml +0 -39
- data/README.rdoc +0 -225
@@ -37,7 +37,7 @@ public class ExtensionRegistry {
|
|
37
37
|
}
|
38
38
|
|
39
39
|
public IRubyObject toInternalPackerRegistry(ThreadContext ctx) {
|
40
|
-
RubyHash hash = RubyHash.newHash(ctx.
|
40
|
+
RubyHash hash = RubyHash.newHash(ctx.runtime);
|
41
41
|
for (RubyModule extensionModule : extensionsByModule.keySet()) {
|
42
42
|
ExtensionEntry entry = extensionsByModule.get(extensionModule);
|
43
43
|
if (entry.hasPacker()) {
|
@@ -48,11 +48,11 @@ public class ExtensionRegistry {
|
|
48
48
|
}
|
49
49
|
|
50
50
|
public IRubyObject toInternalUnpackerRegistry(ThreadContext ctx) {
|
51
|
-
RubyHash hash = RubyHash.newHash(ctx.
|
51
|
+
RubyHash hash = RubyHash.newHash(ctx.runtime);
|
52
52
|
for (int typeIdIndex = 0 ; typeIdIndex < 256 ; typeIdIndex++) {
|
53
53
|
ExtensionEntry entry = extensionsByTypeId[typeIdIndex];
|
54
54
|
if (entry != null && entry.hasUnpacker()) {
|
55
|
-
IRubyObject typeId = RubyFixnum.newFixnum(ctx.
|
55
|
+
IRubyObject typeId = RubyFixnum.newFixnum(ctx.runtime, typeIdIndex - 128);
|
56
56
|
hash.put(typeId, entry.toUnpackerTuple(ctx));
|
57
57
|
}
|
58
58
|
}
|
@@ -124,7 +124,7 @@ public class ExtensionRegistry {
|
|
124
124
|
private ExtensionEntry findEntryByModuleOrAncestor(final RubyModule mod) {
|
125
125
|
ThreadContext ctx = mod.getRuntime().getCurrentContext();
|
126
126
|
for (RubyModule extensionModule : extensionsByModule.keySet()) {
|
127
|
-
RubyArray ancestors = (RubyArray)
|
127
|
+
RubyArray<?> ancestors = (RubyArray)mod.callMethod(ctx, "ancestors");
|
128
128
|
if (ancestors.callMethod(ctx, "include?", extensionModule).isTrue()) {
|
129
129
|
return extensionsByModule.get(extensionModule);
|
130
130
|
}
|
@@ -173,16 +173,16 @@ public class ExtensionRegistry {
|
|
173
173
|
return unpackerProc;
|
174
174
|
}
|
175
175
|
|
176
|
-
public RubyArray toPackerTuple(ThreadContext ctx) {
|
177
|
-
return
|
176
|
+
public RubyArray<?> toPackerTuple(ThreadContext ctx) {
|
177
|
+
return ctx.runtime.newArray(new IRubyObject[] {ctx.runtime.newFixnum(typeId), packerProc, packerArg});
|
178
178
|
}
|
179
179
|
|
180
|
-
public RubyArray toUnpackerTuple(ThreadContext ctx) {
|
181
|
-
return
|
180
|
+
public RubyArray<?> toUnpackerTuple(ThreadContext ctx) {
|
181
|
+
return ctx.runtime.newArray(new IRubyObject[] {mod, unpackerProc, unpackerArg});
|
182
182
|
}
|
183
183
|
|
184
184
|
public IRubyObject[] toPackerProcTypeIdPair(ThreadContext ctx) {
|
185
|
-
return new IRubyObject[] {packerProc,
|
185
|
+
return new IRubyObject[] {packerProc, ctx.runtime.newFixnum(typeId)};
|
186
186
|
}
|
187
187
|
}
|
188
188
|
}
|
@@ -25,6 +25,7 @@ import static org.msgpack.jruby.Types.*;
|
|
25
25
|
|
26
26
|
@JRubyClass(name="MessagePack::ExtensionValue")
|
27
27
|
public class ExtensionValue extends RubyObject {
|
28
|
+
private static final long serialVersionUID = 8451274621449322492L;
|
28
29
|
private final Encoding binaryEncoding;
|
29
30
|
|
30
31
|
private RubyFixnum type;
|
@@ -77,12 +78,10 @@ public class ExtensionValue extends RubyObject {
|
|
77
78
|
}
|
78
79
|
if (o instanceof ExtensionValue) {
|
79
80
|
ExtensionValue other = (ExtensionValue) o;
|
80
|
-
if (!this.type.eql_p(other.type).isTrue())
|
81
|
+
if (!this.type.eql_p(other.type).isTrue()) {
|
81
82
|
return runtime.getFalse();
|
82
|
-
if (runtime.is1_8()) {
|
83
|
-
return this.payload.str_eql_p(ctx, other.payload);
|
84
83
|
} else {
|
85
|
-
return this.payload.
|
84
|
+
return this.payload.str_eql_p(ctx, other.payload);
|
86
85
|
}
|
87
86
|
}
|
88
87
|
return runtime.getFalse();
|
@@ -96,12 +95,10 @@ public class ExtensionValue extends RubyObject {
|
|
96
95
|
}
|
97
96
|
if (o instanceof ExtensionValue) {
|
98
97
|
ExtensionValue other = (ExtensionValue) o;
|
99
|
-
if (!this.type.op_equal(ctx, other.type).isTrue())
|
98
|
+
if (!this.type.op_equal(ctx, other.type).isTrue()) {
|
100
99
|
return runtime.getFalse();
|
101
|
-
if (runtime.is1_8()) {
|
102
|
-
return this.payload.op_equal(ctx, other.payload);
|
103
100
|
} else {
|
104
|
-
return this.payload.
|
101
|
+
return this.payload.op_equal(ctx, other.payload);
|
105
102
|
}
|
106
103
|
}
|
107
104
|
return runtime.getFalse();
|
@@ -23,6 +23,7 @@ import static org.jruby.runtime.Visibility.PRIVATE;
|
|
23
23
|
|
24
24
|
@JRubyClass(name="MessagePack::Factory")
|
25
25
|
public class Factory extends RubyObject {
|
26
|
+
private static final long serialVersionUID = 8441284623445322492L;
|
26
27
|
private final Ruby runtime;
|
27
28
|
private final ExtensionRegistry extensionRegistry;
|
28
29
|
private boolean hasSymbolExtType;
|
@@ -61,7 +62,7 @@ public class Factory extends RubyObject {
|
|
61
62
|
|
62
63
|
@JRubyMethod(name = "registered_types_internal", visibility = PRIVATE)
|
63
64
|
public IRubyObject registeredTypesInternal(ThreadContext ctx) {
|
64
|
-
return RubyArray.newArray(ctx.
|
65
|
+
return RubyArray.newArray(ctx.runtime, new IRubyObject[] {
|
65
66
|
extensionRegistry.toInternalPackerRegistry(ctx),
|
66
67
|
extensionRegistry.toInternalUnpackerRegistry(ctx)
|
67
68
|
});
|
@@ -69,7 +70,7 @@ public class Factory extends RubyObject {
|
|
69
70
|
|
70
71
|
@JRubyMethod(name = "register_type", required = 2, optional = 1)
|
71
72
|
public IRubyObject registerType(ThreadContext ctx, IRubyObject[] args) {
|
72
|
-
Ruby runtime = ctx.
|
73
|
+
Ruby runtime = ctx.runtime;
|
73
74
|
IRubyObject type = args[0];
|
74
75
|
IRubyObject mod = args[1];
|
75
76
|
|
@@ -88,6 +89,10 @@ public class Factory extends RubyObject {
|
|
88
89
|
RubyHash options = (RubyHash) args[args.length - 1];
|
89
90
|
packerArg = options.fastARef(runtime.newSymbol("packer"));
|
90
91
|
unpackerArg = options.fastARef(runtime.newSymbol("unpacker"));
|
92
|
+
IRubyObject optimizedSymbolsParsingArg = options.fastARef(runtime.newSymbol("optimized_symbols_parsing"));
|
93
|
+
if (optimizedSymbolsParsingArg != null && optimizedSymbolsParsingArg.isTrue()) {
|
94
|
+
throw runtime.newArgumentError("JRuby implementation does not support the optimized_symbols_parsing option");
|
95
|
+
}
|
91
96
|
} else {
|
92
97
|
throw runtime.newArgumentError(String.format("expected Hash but found %s.", args[args.length - 1].getType().getName()));
|
93
98
|
}
|
@@ -27,6 +27,7 @@ import static org.jruby.runtime.Visibility.PRIVATE;
|
|
27
27
|
|
28
28
|
@JRubyClass(name="MessagePack::Packer")
|
29
29
|
public class Packer extends RubyObject {
|
30
|
+
private static final long serialVersionUID = 8451274621499362492L;
|
30
31
|
public ExtensionRegistry registry;
|
31
32
|
private Buffer buffer;
|
32
33
|
private Encoder encoder;
|
@@ -48,9 +49,10 @@ public class Packer extends RubyObject {
|
|
48
49
|
@JRubyMethod(name = "initialize", optional = 2)
|
49
50
|
public IRubyObject initialize(ThreadContext ctx, IRubyObject[] args) {
|
50
51
|
boolean compatibilityMode = false;
|
52
|
+
Ruby runtime = ctx.runtime;
|
51
53
|
if (args.length > 0 && args[args.length - 1] instanceof RubyHash) {
|
52
54
|
RubyHash options = (RubyHash) args[args.length - 1];
|
53
|
-
IRubyObject mode = options.fastARef(
|
55
|
+
IRubyObject mode = options.fastARef(runtime.newSymbol("compatibility_mode"));
|
54
56
|
compatibilityMode = (mode != null) && mode.isTrue();
|
55
57
|
}
|
56
58
|
if (registry == null) {
|
@@ -58,22 +60,22 @@ public class Packer extends RubyObject {
|
|
58
60
|
// registry is already initialized (and somthing might be registered) when newPacker from Factory
|
59
61
|
this.registry = new ExtensionRegistry();
|
60
62
|
}
|
61
|
-
this.encoder = new Encoder(
|
62
|
-
this.buffer = new Buffer(
|
63
|
+
this.encoder = new Encoder(runtime, compatibilityMode, registry, hasSymbolExtType);
|
64
|
+
this.buffer = new Buffer(runtime, runtime.getModule("MessagePack").getClass("Buffer"));
|
63
65
|
this.buffer.initialize(ctx, args);
|
64
|
-
this.binaryEncoding =
|
66
|
+
this.binaryEncoding = runtime.getEncodingService().getAscii8bitEncoding();
|
65
67
|
return this;
|
66
68
|
}
|
67
69
|
|
68
70
|
public static Packer newPacker(ThreadContext ctx, ExtensionRegistry extRegistry, boolean hasSymbolExtType, IRubyObject[] args) {
|
69
|
-
Packer packer = new Packer(ctx.
|
71
|
+
Packer packer = new Packer(ctx.runtime, ctx.runtime.getModule("MessagePack").getClass("Packer"), extRegistry, hasSymbolExtType);
|
70
72
|
packer.initialize(ctx, args);
|
71
73
|
return packer;
|
72
74
|
}
|
73
75
|
|
74
76
|
@JRubyMethod(name = "compatibility_mode?")
|
75
77
|
public IRubyObject isCompatibilityMode(ThreadContext ctx) {
|
76
|
-
return encoder.isCompatibilityMode() ? ctx.
|
78
|
+
return encoder.isCompatibilityMode() ? ctx.runtime.getTrue() : ctx.runtime.getFalse();
|
77
79
|
}
|
78
80
|
|
79
81
|
@JRubyMethod(name = "registered_types_internal", visibility = PRIVATE)
|
@@ -83,7 +85,7 @@ public class Packer extends RubyObject {
|
|
83
85
|
|
84
86
|
@JRubyMethod(name = "register_type", required = 2, optional = 1)
|
85
87
|
public IRubyObject registerType(ThreadContext ctx, IRubyObject[] args, final Block block) {
|
86
|
-
Ruby runtime = ctx.
|
88
|
+
Ruby runtime = ctx.runtime;
|
87
89
|
IRubyObject type = args[0];
|
88
90
|
IRubyObject mod = args[1];
|
89
91
|
|
@@ -182,12 +184,12 @@ public class Packer extends RubyObject {
|
|
182
184
|
|
183
185
|
@JRubyMethod(name = "write_true")
|
184
186
|
public IRubyObject writeTrue(ThreadContext ctx) {
|
185
|
-
return write(ctx, ctx.
|
187
|
+
return write(ctx, ctx.runtime.getTrue());
|
186
188
|
}
|
187
189
|
|
188
190
|
@JRubyMethod(name = "write_false")
|
189
191
|
public IRubyObject writeFalse(ThreadContext ctx) {
|
190
|
-
return write(ctx, ctx.
|
192
|
+
return write(ctx, ctx.runtime.getFalse());
|
191
193
|
}
|
192
194
|
|
193
195
|
@JRubyMethod(name = "write_nil")
|
@@ -27,6 +27,7 @@ import static org.jruby.runtime.Visibility.PRIVATE;
|
|
27
27
|
|
28
28
|
@JRubyClass(name="MessagePack::Unpacker")
|
29
29
|
public class Unpacker extends RubyObject {
|
30
|
+
private static final long serialVersionUID = 8451264671199362492L;
|
30
31
|
private final ExtensionRegistry registry;
|
31
32
|
|
32
33
|
private IRubyObject stream;
|
@@ -34,6 +35,7 @@ public class Unpacker extends RubyObject {
|
|
34
35
|
private Decoder decoder;
|
35
36
|
private final RubyClass underflowErrorClass;
|
36
37
|
private boolean symbolizeKeys;
|
38
|
+
private boolean freeze;
|
37
39
|
private boolean allowUnknownExt;
|
38
40
|
|
39
41
|
public Unpacker(Ruby runtime, RubyClass type) {
|
@@ -56,19 +58,25 @@ public class Unpacker extends RubyObject {
|
|
56
58
|
public IRubyObject initialize(ThreadContext ctx, IRubyObject[] args) {
|
57
59
|
symbolizeKeys = false;
|
58
60
|
allowUnknownExt = false;
|
61
|
+
freeze = false;
|
59
62
|
if (args.length > 0) {
|
63
|
+
Ruby runtime = ctx.runtime;
|
60
64
|
if (args[args.length - 1] instanceof RubyHash) {
|
61
65
|
RubyHash options = (RubyHash) args[args.length - 1];
|
62
|
-
IRubyObject sk = options.fastARef(
|
66
|
+
IRubyObject sk = options.fastARef(runtime.newSymbol("symbolize_keys"));
|
63
67
|
if (sk != null) {
|
64
68
|
symbolizeKeys = sk.isTrue();
|
65
69
|
}
|
66
|
-
IRubyObject
|
70
|
+
IRubyObject f = options.fastARef(runtime.newSymbol("freeze"));
|
71
|
+
if (f != null) {
|
72
|
+
freeze = f.isTrue();
|
73
|
+
}
|
74
|
+
IRubyObject au = options.fastARef(runtime.newSymbol("allow_unknown_ext"));
|
67
75
|
if (au != null) {
|
68
76
|
allowUnknownExt = au.isTrue();
|
69
77
|
}
|
70
78
|
}
|
71
|
-
if (args[0] !=
|
79
|
+
if (args[0] != runtime.getNil() && !(args[0] instanceof RubyHash)) {
|
72
80
|
setStream(ctx, args[0]);
|
73
81
|
}
|
74
82
|
}
|
@@ -76,19 +84,24 @@ public class Unpacker extends RubyObject {
|
|
76
84
|
}
|
77
85
|
|
78
86
|
public static Unpacker newUnpacker(ThreadContext ctx, ExtensionRegistry extRegistry, IRubyObject[] args) {
|
79
|
-
Unpacker unpacker = new Unpacker(ctx.
|
87
|
+
Unpacker unpacker = new Unpacker(ctx.runtime, ctx.runtime.getModule("MessagePack").getClass("Unpacker"), extRegistry);
|
80
88
|
unpacker.initialize(ctx, args);
|
81
89
|
return unpacker;
|
82
90
|
}
|
83
91
|
|
84
92
|
@JRubyMethod(name = "symbolize_keys?")
|
85
93
|
public IRubyObject isSymbolizeKeys(ThreadContext ctx) {
|
86
|
-
return symbolizeKeys ? ctx.
|
94
|
+
return symbolizeKeys ? ctx.runtime.getTrue() : ctx.runtime.getFalse();
|
95
|
+
}
|
96
|
+
|
97
|
+
@JRubyMethod(name = "freeze?")
|
98
|
+
public IRubyObject isFreeze(ThreadContext ctx) {
|
99
|
+
return freeze ? ctx.runtime.getTrue() : ctx.runtime.getFalse();
|
87
100
|
}
|
88
101
|
|
89
102
|
@JRubyMethod(name = "allow_unknown_ext?")
|
90
103
|
public IRubyObject isAllowUnknownExt(ThreadContext ctx) {
|
91
|
-
return allowUnknownExt ? ctx.
|
104
|
+
return allowUnknownExt ? ctx.runtime.getTrue() : ctx.runtime.getFalse();
|
92
105
|
}
|
93
106
|
|
94
107
|
@JRubyMethod(name = "registered_types_internal", visibility = PRIVATE)
|
@@ -98,7 +111,7 @@ public class Unpacker extends RubyObject {
|
|
98
111
|
|
99
112
|
@JRubyMethod(name = "register_type", required = 1, optional = 2)
|
100
113
|
public IRubyObject registerType(ThreadContext ctx, IRubyObject[] args, final Block block) {
|
101
|
-
Ruby runtime = ctx.
|
114
|
+
Ruby runtime = ctx.runtime;
|
102
115
|
IRubyObject type = args[0];
|
103
116
|
|
104
117
|
RubyModule extModule;
|
@@ -144,7 +157,7 @@ public class Unpacker extends RubyObject {
|
|
144
157
|
if (limit == -1) {
|
145
158
|
limit = byteList.length() - offset;
|
146
159
|
}
|
147
|
-
Decoder decoder = new Decoder(ctx.
|
160
|
+
Decoder decoder = new Decoder(ctx.runtime, registry, byteList.unsafeBytes(), byteList.begin() + offset, limit, symbolizeKeys, freeze, allowUnknownExt);
|
148
161
|
try {
|
149
162
|
data = null;
|
150
163
|
data = decoder.next();
|
@@ -153,13 +166,13 @@ public class Unpacker extends RubyObject {
|
|
153
166
|
throw re;
|
154
167
|
}
|
155
168
|
}
|
156
|
-
return ctx.
|
169
|
+
return ctx.runtime.newFixnum(decoder.offset());
|
157
170
|
}
|
158
171
|
|
159
172
|
@JRubyMethod(name = "data")
|
160
173
|
public IRubyObject getData(ThreadContext ctx) {
|
161
174
|
if (data == null) {
|
162
|
-
return ctx.
|
175
|
+
return ctx.runtime.getNil();
|
163
176
|
} else {
|
164
177
|
return data;
|
165
178
|
}
|
@@ -167,14 +180,14 @@ public class Unpacker extends RubyObject {
|
|
167
180
|
|
168
181
|
@JRubyMethod(name = "finished?")
|
169
182
|
public IRubyObject finished_p(ThreadContext ctx) {
|
170
|
-
return data == null ? ctx.
|
183
|
+
return data == null ? ctx.runtime.getFalse() : ctx.runtime.getTrue();
|
171
184
|
}
|
172
185
|
|
173
186
|
@JRubyMethod(required = 1, name = "feed", alias = { "feed_reference" })
|
174
187
|
public IRubyObject feed(ThreadContext ctx, IRubyObject data) {
|
175
188
|
ByteList byteList = data.asString().getByteList();
|
176
189
|
if (decoder == null) {
|
177
|
-
decoder = new Decoder(ctx.
|
190
|
+
decoder = new Decoder(ctx.runtime, registry, byteList.unsafeBytes(), byteList.begin(), byteList.length(), symbolizeKeys, freeze, allowUnknownExt);
|
178
191
|
} else {
|
179
192
|
decoder.feed(byteList.unsafeBytes(), byteList.begin(), byteList.length());
|
180
193
|
}
|
@@ -191,7 +204,7 @@ public class Unpacker extends RubyObject {
|
|
191
204
|
feed(ctx, data);
|
192
205
|
if (block.isGiven()) {
|
193
206
|
each(ctx, block);
|
194
|
-
return ctx.
|
207
|
+
return ctx.runtime.getNil();
|
195
208
|
} else {
|
196
209
|
return callMethod(ctx, "to_enum");
|
197
210
|
}
|
@@ -219,7 +232,7 @@ public class Unpacker extends RubyObject {
|
|
219
232
|
|
220
233
|
@JRubyMethod
|
221
234
|
public IRubyObject fill(ThreadContext ctx) {
|
222
|
-
return ctx.
|
235
|
+
return ctx.runtime.getNil();
|
223
236
|
}
|
224
237
|
|
225
238
|
@JRubyMethod
|
@@ -227,13 +240,13 @@ public class Unpacker extends RubyObject {
|
|
227
240
|
if (decoder != null) {
|
228
241
|
decoder.reset();
|
229
242
|
}
|
230
|
-
return ctx.
|
243
|
+
return ctx.runtime.getNil();
|
231
244
|
}
|
232
245
|
|
233
246
|
@JRubyMethod(name = "read", alias = { "unpack" })
|
234
247
|
public IRubyObject read(ThreadContext ctx) {
|
235
248
|
if (decoder == null) {
|
236
|
-
throw ctx.
|
249
|
+
throw ctx.runtime.newEOFError();
|
237
250
|
}
|
238
251
|
try {
|
239
252
|
return decoder.next();
|
@@ -241,19 +254,19 @@ public class Unpacker extends RubyObject {
|
|
241
254
|
if (re.getException().getType() != underflowErrorClass) {
|
242
255
|
throw re;
|
243
256
|
} else {
|
244
|
-
throw ctx.
|
257
|
+
throw ctx.runtime.newEOFError();
|
245
258
|
}
|
246
259
|
}
|
247
260
|
}
|
248
261
|
|
249
262
|
@JRubyMethod(name = "skip")
|
250
263
|
public IRubyObject skip(ThreadContext ctx) {
|
251
|
-
throw ctx.
|
264
|
+
throw ctx.runtime.newNotImplementedError("Not supported yet in JRuby implementation");
|
252
265
|
}
|
253
266
|
|
254
267
|
@JRubyMethod(name = "skip_nil")
|
255
268
|
public IRubyObject skipNil(ThreadContext ctx) {
|
256
|
-
throw ctx.
|
269
|
+
throw ctx.runtime.newNotImplementedError("Not supported yet in JRuby implementation");
|
257
270
|
}
|
258
271
|
|
259
272
|
@JRubyMethod
|
@@ -265,11 +278,11 @@ public class Unpacker extends RubyObject {
|
|
265
278
|
if (re.getException().getType() != underflowErrorClass) {
|
266
279
|
throw re;
|
267
280
|
} else {
|
268
|
-
throw ctx.
|
281
|
+
throw ctx.runtime.newEOFError();
|
269
282
|
}
|
270
283
|
}
|
271
284
|
}
|
272
|
-
return ctx.
|
285
|
+
return ctx.runtime.getNil();
|
273
286
|
}
|
274
287
|
|
275
288
|
@JRubyMethod
|
@@ -281,17 +294,17 @@ public class Unpacker extends RubyObject {
|
|
281
294
|
if (re.getException().getType() != underflowErrorClass) {
|
282
295
|
throw re;
|
283
296
|
} else {
|
284
|
-
throw ctx.
|
297
|
+
throw ctx.runtime.newEOFError();
|
285
298
|
}
|
286
299
|
}
|
287
300
|
}
|
288
|
-
return ctx.
|
301
|
+
return ctx.runtime.getNil();
|
289
302
|
}
|
290
303
|
|
291
304
|
@JRubyMethod(name = "stream")
|
292
305
|
public IRubyObject getStream(ThreadContext ctx) {
|
293
306
|
if (stream == null) {
|
294
|
-
return ctx.
|
307
|
+
return ctx.runtime.getNil();
|
295
308
|
} else {
|
296
309
|
return stream;
|
297
310
|
}
|
@@ -307,12 +320,12 @@ public class Unpacker extends RubyObject {
|
|
307
320
|
} else if (stream.respondsTo("read")) {
|
308
321
|
str = stream.callMethod(ctx, "read").asString();
|
309
322
|
} else {
|
310
|
-
throw ctx.
|
323
|
+
throw ctx.runtime.newTypeError(stream, "IO");
|
311
324
|
}
|
312
325
|
ByteList byteList = str.getByteList();
|
313
326
|
this.stream = stream;
|
314
327
|
this.decoder = null;
|
315
|
-
this.decoder = new Decoder(ctx.
|
328
|
+
this.decoder = new Decoder(ctx.runtime, registry, byteList.unsafeBytes(), byteList.begin(), byteList.length(), symbolizeKeys, freeze, allowUnknownExt);
|
316
329
|
return getStream(ctx);
|
317
330
|
}
|
318
331
|
}
|
data/ext/msgpack/buffer.c
CHANGED
@@ -23,11 +23,11 @@
|
|
23
23
|
static ID s_replace;
|
24
24
|
#endif
|
25
25
|
|
26
|
-
#ifdef COMPAT_HAVE_ENCODING /* see compat.h*/
|
27
26
|
int msgpack_rb_encindex_utf8;
|
28
27
|
int msgpack_rb_encindex_usascii;
|
29
28
|
int msgpack_rb_encindex_ascii8bit;
|
30
|
-
|
29
|
+
|
30
|
+
ID s_uminus;
|
31
31
|
|
32
32
|
#ifndef DISABLE_RMEM
|
33
33
|
static msgpack_rmem_t s_rmem;
|
@@ -35,11 +35,11 @@ static msgpack_rmem_t s_rmem;
|
|
35
35
|
|
36
36
|
void msgpack_buffer_static_init()
|
37
37
|
{
|
38
|
-
|
38
|
+
s_uminus = rb_intern("-@");
|
39
|
+
|
39
40
|
msgpack_rb_encindex_utf8 = rb_utf8_encindex();
|
40
41
|
msgpack_rb_encindex_usascii = rb_usascii_encindex();
|
41
42
|
msgpack_rb_encindex_ascii8bit = rb_ascii8bit_encindex();
|
42
|
-
#endif
|
43
43
|
|
44
44
|
#ifndef DISABLE_RMEM
|
45
45
|
msgpack_rmem_init(&s_rmem);
|
@@ -164,12 +164,7 @@ size_t msgpack_buffer_read_to_string_nonblock(msgpack_buffer_t* b, VALUE string,
|
|
164
164
|
b->head->mapped_string != NO_MAPPED_STRING &&
|
165
165
|
length >= b->read_reference_threshold) {
|
166
166
|
VALUE s = _msgpack_buffer_refer_head_mapped_string(b, length);
|
167
|
-
#ifndef HAVE_RB_STR_REPLACE
|
168
|
-
/* TODO MRI 1.8 */
|
169
|
-
rb_funcall(string, s_replace, 1, s);
|
170
|
-
#else
|
171
167
|
rb_str_replace(string, s);
|
172
|
-
#endif
|
173
168
|
/* here doesn't have to call ENCODING_SET because
|
174
169
|
* encoding of s is always ASCII-8BIT */
|
175
170
|
_msgpack_buffer_consumed(b, length);
|
@@ -308,9 +303,7 @@ static inline void _msgpack_buffer_add_new_chunk(msgpack_buffer_t* b)
|
|
308
303
|
static inline void _msgpack_buffer_append_reference(msgpack_buffer_t* b, VALUE string)
|
309
304
|
{
|
310
305
|
VALUE mapped_string = rb_str_dup(string);
|
311
|
-
#ifdef COMPAT_HAVE_ENCODING
|
312
306
|
ENCODING_SET(mapped_string, msgpack_rb_encindex_ascii8bit);
|
313
|
-
#endif
|
314
307
|
|
315
308
|
_msgpack_buffer_add_new_chunk(b);
|
316
309
|
|
@@ -337,7 +330,6 @@ void _msgpack_buffer_append_long_string(msgpack_buffer_t* b, VALUE string)
|
|
337
330
|
|
338
331
|
if(b->io != Qnil) {
|
339
332
|
msgpack_buffer_flush(b);
|
340
|
-
#ifdef COMPAT_HAVE_ENCODING
|
341
333
|
if (ENCODING_GET(string) == msgpack_rb_encindex_ascii8bit) {
|
342
334
|
rb_funcall(b->io, b->io_write_all_method, 1, string);
|
343
335
|
} else if(!STR_DUP_LIKELY_DOES_COPY(string)) {
|
@@ -347,10 +339,6 @@ void _msgpack_buffer_append_long_string(msgpack_buffer_t* b, VALUE string)
|
|
347
339
|
} else {
|
348
340
|
msgpack_buffer_append(b, RSTRING_PTR(string), length);
|
349
341
|
}
|
350
|
-
#else
|
351
|
-
rb_funcall(b->io, b->io_write_all_method, 1, string);
|
352
|
-
#endif
|
353
|
-
|
354
342
|
} else if(!STR_DUP_LIKELY_DOES_COPY(string)) {
|
355
343
|
_msgpack_buffer_append_reference(b, string);
|
356
344
|
|
data/ext/msgpack/buffer.h
CHANGED
@@ -49,11 +49,11 @@
|
|
49
49
|
|
50
50
|
#define NO_MAPPED_STRING ((VALUE)0)
|
51
51
|
|
52
|
-
#ifdef COMPAT_HAVE_ENCODING /* see compat.h*/
|
53
52
|
extern int msgpack_rb_encindex_utf8;
|
54
53
|
extern int msgpack_rb_encindex_usascii;
|
55
54
|
extern int msgpack_rb_encindex_ascii8bit;
|
56
|
-
|
55
|
+
|
56
|
+
extern ID s_uminus;
|
57
57
|
|
58
58
|
struct msgpack_buffer_chunk_t;
|
59
59
|
typedef struct msgpack_buffer_chunk_t msgpack_buffer_chunk_t;
|
@@ -438,7 +438,7 @@ static inline VALUE _msgpack_buffer_refer_head_mapped_string(msgpack_buffer_t* b
|
|
438
438
|
return rb_str_substr(b->head->mapped_string, offset, length);
|
439
439
|
}
|
440
440
|
|
441
|
-
static inline VALUE msgpack_buffer_read_top_as_string(msgpack_buffer_t* b, size_t length, bool will_be_frozen)
|
441
|
+
static inline VALUE msgpack_buffer_read_top_as_string(msgpack_buffer_t* b, size_t length, bool will_be_frozen, bool utf8)
|
442
442
|
{
|
443
443
|
#ifndef DISABLE_BUFFER_READ_REFERENCE_OPTIMIZE
|
444
444
|
/* optimize */
|
@@ -446,16 +446,57 @@ static inline VALUE msgpack_buffer_read_top_as_string(msgpack_buffer_t* b, size_
|
|
446
446
|
b->head->mapped_string != NO_MAPPED_STRING &&
|
447
447
|
length >= b->read_reference_threshold) {
|
448
448
|
VALUE result = _msgpack_buffer_refer_head_mapped_string(b, length);
|
449
|
+
if (utf8) ENCODING_SET(result, msgpack_rb_encindex_utf8);
|
449
450
|
_msgpack_buffer_consumed(b, length);
|
450
451
|
return result;
|
451
452
|
}
|
452
453
|
#endif
|
453
454
|
|
454
|
-
VALUE result
|
455
|
+
VALUE result;
|
456
|
+
|
457
|
+
#ifdef HAVE_RB_ENC_INTERNED_STR
|
458
|
+
if (will_be_frozen) {
|
459
|
+
result = rb_enc_interned_str(b->read_buffer, length, utf8 ? rb_utf8_encoding() : rb_ascii8bit_encoding());
|
460
|
+
} else {
|
461
|
+
if (utf8) {
|
462
|
+
result = rb_utf8_str_new(b->read_buffer, length);
|
463
|
+
} else {
|
464
|
+
result = rb_str_new(b->read_buffer, length);
|
465
|
+
}
|
466
|
+
}
|
467
|
+
_msgpack_buffer_consumed(b, length);
|
468
|
+
return result;
|
469
|
+
|
470
|
+
#else
|
471
|
+
|
472
|
+
if (utf8) {
|
473
|
+
result = rb_utf8_str_new(b->read_buffer, length);
|
474
|
+
} else {
|
475
|
+
result = rb_str_new(b->read_buffer, length);
|
476
|
+
}
|
477
|
+
|
478
|
+
#if STR_UMINUS_DEDUPE
|
479
|
+
if (will_be_frozen) {
|
480
|
+
#if STR_UMINUS_DEDUPE_FROZEN
|
481
|
+
// Starting from MRI 2.8 it is preferable to freeze the string
|
482
|
+
// before deduplication so that it can be interned directly
|
483
|
+
// otherwise it would be duplicated first which is wasteful.
|
484
|
+
rb_str_freeze(result);
|
485
|
+
#endif //STR_UMINUS_DEDUPE_FROZEN
|
486
|
+
// MRI 2.5 and older do not deduplicate strings that are already
|
487
|
+
// frozen.
|
488
|
+
result = rb_funcall(result, s_uminus, 0);
|
489
|
+
}
|
490
|
+
#endif // STR_UMINUS_DEDUPE
|
455
491
|
_msgpack_buffer_consumed(b, length);
|
456
492
|
return result;
|
493
|
+
|
494
|
+
#endif // HAVE_RB_ENC_INTERNED_STR
|
457
495
|
}
|
458
496
|
|
497
|
+
static inline VALUE msgpack_buffer_read_top_as_symbol(msgpack_buffer_t* b, size_t length)
|
498
|
+
{
|
499
|
+
return rb_str_intern(msgpack_buffer_read_top_as_string(b, length, true, false));
|
500
|
+
}
|
459
501
|
|
460
502
|
#endif
|
461
|
-
|
data/ext/msgpack/compat.h
CHANGED
@@ -20,6 +20,7 @@
|
|
20
20
|
|
21
21
|
#include <stdbool.h>
|
22
22
|
#include "ruby.h"
|
23
|
+
#include "ruby/encoding.h"
|
23
24
|
|
24
25
|
#if defined(HAVE_RUBY_ST_H)
|
25
26
|
# include "ruby/st.h" /* ruby hash on Ruby 1.9 */
|
@@ -38,18 +39,6 @@
|
|
38
39
|
# define ZALLOC_N(type,n) RB_ZALLOC_N(type,n)
|
39
40
|
#endif
|
40
41
|
|
41
|
-
/*
|
42
|
-
* COMPAT_HAVE_ENCODING
|
43
|
-
*/
|
44
|
-
#ifdef HAVE_RUBY_ENCODING_H
|
45
|
-
# include "ruby/encoding.h"
|
46
|
-
# define COMPAT_HAVE_ENCODING
|
47
|
-
#endif
|
48
|
-
|
49
|
-
#if defined(__MACRUBY__) /* MacRuby */
|
50
|
-
# undef COMPAT_HAVE_ENCODING
|
51
|
-
#endif
|
52
|
-
|
53
42
|
|
54
43
|
/*
|
55
44
|
* define STR_DUP_LIKELY_DOES_COPY
|
data/ext/msgpack/extconf.rb
CHANGED
@@ -2,13 +2,7 @@ require 'mkmf'
|
|
2
2
|
|
3
3
|
have_header("ruby/st.h")
|
4
4
|
have_header("st.h")
|
5
|
-
have_func("
|
6
|
-
have_func("rb_intern_str", ["ruby.h"])
|
7
|
-
have_func("rb_sym2str", ["ruby.h"])
|
8
|
-
have_func("rb_str_intern", ["ruby.h"])
|
9
|
-
have_func("rb_block_lambda", ["ruby.h"])
|
10
|
-
have_func("rb_hash_dup", ["ruby.h"])
|
11
|
-
have_func("rb_hash_clear", ["ruby.h"])
|
5
|
+
have_func("rb_enc_interned_str", "ruby.h")
|
12
6
|
|
13
7
|
unless RUBY_PLATFORM.include? 'mswin'
|
14
8
|
$CFLAGS << %[ -I.. -Wall -O3 -g -std=gnu99]
|
@@ -37,6 +31,32 @@ else
|
|
37
31
|
$CFLAGS << ' -DHASH_ASET_DEDUPE=0 '
|
38
32
|
end
|
39
33
|
|
34
|
+
|
35
|
+
# checking if String#-@ (str_uminus) dedupes... '
|
36
|
+
begin
|
37
|
+
a = -(%w(t e s t).join)
|
38
|
+
b = -(%w(t e s t).join)
|
39
|
+
if a.equal?(b)
|
40
|
+
$CFLAGS << ' -DSTR_UMINUS_DEDUPE=1 '
|
41
|
+
else
|
42
|
+
$CFLAGS += ' -DSTR_UMINUS_DEDUPE=0 '
|
43
|
+
end
|
44
|
+
rescue NoMethodError
|
45
|
+
$CFLAGS << ' -DSTR_UMINUS_DEDUPE=0 '
|
46
|
+
end
|
47
|
+
|
48
|
+
# checking if String#-@ (str_uminus) directly interns frozen strings... '
|
49
|
+
begin
|
50
|
+
s = rand.to_s.freeze
|
51
|
+
if (-s).equal?(s) && (-s.dup).equal?(s)
|
52
|
+
$CFLAGS << ' -DSTR_UMINUS_DEDUPE_FROZEN=1 '
|
53
|
+
else
|
54
|
+
$CFLAGS << ' -DSTR_UMINUS_DEDUPE_FROZEN=0 '
|
55
|
+
end
|
56
|
+
rescue NoMethodError
|
57
|
+
$CFLAGS << ' -DSTR_UMINUS_DEDUPE_FROZEN=0 '
|
58
|
+
end
|
59
|
+
|
40
60
|
if warnflags = CONFIG['warnflags']
|
41
61
|
warnflags.slice!(/ -Wdeclaration-after-statement/)
|
42
62
|
end
|