Bug 5236 – [patch] std.format.formattedRead/unformatValue does not support the raw reading of integer types

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2010-11-18T11:35:00Z
Last change time
2017-01-16T23:25:29Z
Keywords
bootcamp, patch
Assigned to
razvan.nitu1305
Creator
sandford

Comments

Comment #0 by sandford — 2010-11-18T11:35:40Z
The raw value reading code was never duplicated in the isIntegral version of unformatValue. Given the amount of code overlap for raw value reading, I'd recommend a re-factor of the unformatValue, but in the mean time, here is a patch and unit test. Unit test: union B { char[int.sizeof] untyped; int typed; }; B b; b.typed = 5; char[] input = b.untyped[]; int witness; formattedRead(input, "%r", &witness); assert(witness == b.typed); Patch: /** Reads an integral value and returns it. */ T unformatValue(T, Range, Char)(ref Range input, ref FormatSpec!Char spec) if (isIntegral!T && isInputRange!Range) { if (spec.spec == 'r') { // raw read //enforce(input.length >= T.sizeof); enforce(isSomeString!Range || ElementType!(Range).sizeof == 1); union X { ubyte[T.sizeof] raw; T typed; } X x; foreach (i; 0 .. T.sizeof) { static if (isSomeString!Range) { x.raw[i] = input[0]; input = input[1 .. $]; } else { // TODO: recheck this x.raw[i] = cast(ubyte) input.front; input.popFront(); } } return x.typed; } enforce(std.algorithm.find("cdosuxX", spec.spec).length, text("Wrong integral type specifier: `", spec.spec, "'")); if (std.algorithm.find("dsu", spec.spec).length) { return parse!T(input); } assert(0, "Parsing spec '"~spec.spec~"' not implemented."); }
Comment #1 by sandford — 2010-11-18T14:05:23Z
Also, the unformatValue routines need to wrap the parse statements in a traits compiles test, in order to support raw reading from byte streams. i.e. static if(__traits(compiles, parse!T(input) )) { return parse!T(input); }
Comment #2 by github-bugzilla — 2016-12-06T22:57:11Z
Commits pushed to master at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/17d13e20666d388aba04357d98f7ed092b58bccb Issue 5236 - [patch] std.format.formattedRead/unformatValue does not support the raw reading of integer types https://github.com/dlang/phobos/commit/26f4aec45c75e0b6831a1d77614bbca25b5c4068 Issue 5236 - [patch] std.format.formattedRead/unformatValue does not support the raw reading of integer types https://github.com/dlang/phobos/commit/73406665c11c102d4c52e1f12ef9caa1c9ce50ff Issue 5236 - [patch] std.format.formattedRead/unformatValue does not support the raw reading of integer types
Comment #3 by github-bugzilla — 2016-12-07T17:48:04Z
Commits pushed to master at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/6d13f6685556d633ed0801cd638bc5d96fa69a71 Issue 5236 - [patch] std.format.formattedRead/unformatValue does not support the raw reading of integer types https://github.com/dlang/phobos/commit/ddc63be000232977e4ba4c8a3e3e7b0066eb85ad Issue 5236 - [patch] std.format.formattedRead/unformatValue does not support the raw reading of integer types https://github.com/dlang/phobos/commit/3ab55e96e1691b1fa72e3695fcf71f7e393f62b1 Issue 5236 - [patch] std.format.formattedRead/unformatValue does not support the raw reading of integer types https://github.com/dlang/phobos/commit/58374ac540420f2d9af3a5f5def4dbc8374043cf Issue 5236 - [patch] std.format.formattedRead/unformatValue does not support the raw reading of integer types https://github.com/dlang/phobos/commit/f5bece91ab50edbee200368016908bbac8924e0d Issue 5236 - [patch] std.format.formattedRead/unformatValue does not support the raw reading of integer types https://github.com/dlang/phobos/commit/bacddb87ff2fa9db635562f0bf17c2ed10d3ab5d Issue 5236 - [patch] std.format.formattedRead/unformatValue does not support the raw reading of integer types https://github.com/dlang/phobos/commit/99398975d45e520c645f5ca8c1681b7dd93150c9 Merge pull request #4912 from RazvanN7/bootcamp_fixes Issue 5236 - raw reading for integers and a few refactorings
Comment #4 by github-bugzilla — 2017-01-07T03:02:52Z
Commits pushed to stable at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/6d13f6685556d633ed0801cd638bc5d96fa69a71 Issue 5236 - [patch] std.format.formattedRead/unformatValue does not support the raw reading of integer types https://github.com/dlang/phobos/commit/ddc63be000232977e4ba4c8a3e3e7b0066eb85ad Issue 5236 - [patch] std.format.formattedRead/unformatValue does not support the raw reading of integer types https://github.com/dlang/phobos/commit/3ab55e96e1691b1fa72e3695fcf71f7e393f62b1 Issue 5236 - [patch] std.format.formattedRead/unformatValue does not support the raw reading of integer types https://github.com/dlang/phobos/commit/58374ac540420f2d9af3a5f5def4dbc8374043cf Issue 5236 - [patch] std.format.formattedRead/unformatValue does not support the raw reading of integer types https://github.com/dlang/phobos/commit/f5bece91ab50edbee200368016908bbac8924e0d Issue 5236 - [patch] std.format.formattedRead/unformatValue does not support the raw reading of integer types https://github.com/dlang/phobos/commit/bacddb87ff2fa9db635562f0bf17c2ed10d3ab5d Issue 5236 - [patch] std.format.formattedRead/unformatValue does not support the raw reading of integer types https://github.com/dlang/phobos/commit/17d13e20666d388aba04357d98f7ed092b58bccb Issue 5236 - [patch] std.format.formattedRead/unformatValue does not support the raw reading of integer types https://github.com/dlang/phobos/commit/26f4aec45c75e0b6831a1d77614bbca25b5c4068 Issue 5236 - [patch] std.format.formattedRead/unformatValue does not support the raw reading of integer types https://github.com/dlang/phobos/commit/73406665c11c102d4c52e1f12ef9caa1c9ce50ff Issue 5236 - [patch] std.format.formattedRead/unformatValue does not support the raw reading of integer types https://github.com/dlang/phobos/commit/99398975d45e520c645f5ca8c1681b7dd93150c9 Merge pull request #4912 from RazvanN7/bootcamp_fixes
Comment #5 by github-bugzilla — 2017-01-16T23:25:29Z
Commits pushed to newCTFE at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/6d13f6685556d633ed0801cd638bc5d96fa69a71 Issue 5236 - [patch] std.format.formattedRead/unformatValue does not support the raw reading of integer types https://github.com/dlang/phobos/commit/ddc63be000232977e4ba4c8a3e3e7b0066eb85ad Issue 5236 - [patch] std.format.formattedRead/unformatValue does not support the raw reading of integer types https://github.com/dlang/phobos/commit/3ab55e96e1691b1fa72e3695fcf71f7e393f62b1 Issue 5236 - [patch] std.format.formattedRead/unformatValue does not support the raw reading of integer types https://github.com/dlang/phobos/commit/58374ac540420f2d9af3a5f5def4dbc8374043cf Issue 5236 - [patch] std.format.formattedRead/unformatValue does not support the raw reading of integer types https://github.com/dlang/phobos/commit/f5bece91ab50edbee200368016908bbac8924e0d Issue 5236 - [patch] std.format.formattedRead/unformatValue does not support the raw reading of integer types https://github.com/dlang/phobos/commit/bacddb87ff2fa9db635562f0bf17c2ed10d3ab5d Issue 5236 - [patch] std.format.formattedRead/unformatValue does not support the raw reading of integer types https://github.com/dlang/phobos/commit/17d13e20666d388aba04357d98f7ed092b58bccb Issue 5236 - [patch] std.format.formattedRead/unformatValue does not support the raw reading of integer types https://github.com/dlang/phobos/commit/26f4aec45c75e0b6831a1d77614bbca25b5c4068 Issue 5236 - [patch] std.format.formattedRead/unformatValue does not support the raw reading of integer types https://github.com/dlang/phobos/commit/73406665c11c102d4c52e1f12ef9caa1c9ce50ff Issue 5236 - [patch] std.format.formattedRead/unformatValue does not support the raw reading of integer types https://github.com/dlang/phobos/commit/99398975d45e520c645f5ca8c1681b7dd93150c9 Merge pull request #4912 from RazvanN7/bootcamp_fixes