Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
September 26, 2012 [Issue 8730] New: writeln stops on a nul character, even if passed a D string | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=8730 Summary: writeln stops on a nul character, even if passed a D string Product: D Version: D2 Platform: All OS/Version: All Status: NEW Severity: minor Priority: P2 Component: Phobos AssignedTo: nobody@puremagic.com ReportedBy: destructionator@gmail.com --- Comment #0 from Adam D. Ruppe <destructionator@gmail.com> 2012-09-26 13:12:00 PDT --- import std.stdio; void main() { writeln("test\0gone"); } only prints "test". writefln("%s") prints the whole thing. $ ./test | xxd 0000000: 7465 7374 0a as you can see the data is indeed not being printed; it isn't just invisible on my screen. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
October 05, 2012 [Issue 8730] writeln stops on a nul character, even if passed a D string | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | http://d.puremagic.com/issues/show_bug.cgi?id=8730 Andrej Mitrovic <andrej.mitrovich@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |andrej.mitrovich@gmail.com --- Comment #1 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-10-04 17:11:33 PDT --- I'm just guessing, but: void writeln(T...)(T args) { static if (T.length == 0) { enforce(fputc('\n', .stdout.p.handle) == '\n'); } else static if (T.length == 1 && is(typeof(args[0]) : const(char)[]) && !is(typeof(args[0]) == enum) && !is(typeof(args[0]) == typeof(null)) && !isAggregateType!(typeof(args[0]))) { // Specialization for strings - a very frequent case enforce(fprintf(.stdout.p.handle, "%.*s\n", cast(int) args[0].length, args[0].ptr) >= 0); } else { // Most general instance stdout.write(args, '\n'); } } The specialization is probably to blame. I think 'args[0].length' probably sets the max limit rather than min, but I don't know enough about fprintf internals. :) -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
October 10, 2012 [Issue 8730] writeln stops on a nul character, even if passed a D string | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | http://d.puremagic.com/issues/show_bug.cgi?id=8730 --- Comment #2 from Adam D. Ruppe <destructionator@gmail.com> 2012-10-09 19:24:49 PDT --- (In reply to comment #1) > The specialization is probably to blame. I think 'args[0].length' probably sets the max limit rather than min, but I don't know enough about fprintf internals. :) Yeah, you're right. The man page for printf says "the maximum number of characters to be printed from a string for s and S conversions." I'm not sure what is best here. I really think it should work, but the specialization has got to be there for a reason too. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
October 10, 2012 [Issue 8730] writeln stops on a nul character, even if passed a D string | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | http://d.puremagic.com/issues/show_bug.cgi?id=8730 --- Comment #3 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-10-09 19:38:15 PDT --- (In reply to comment #2) > (In reply to comment #1) > > The specialization is probably to blame. I think 'args[0].length' probably sets the max limit rather than min, but I don't know enough about fprintf internals. :) > > > Yeah, you're right. The man page for printf says "the maximum number of > characters to be printed from a string for s and S conversions." > > > I'm not sure what is best here. I really think it should work, but the specialization has got to be there for a reason too. It could me off guard just recently. E.g. git uses two strings separated by nul in it's object format, and when I've tried to print out the contents as a char[] using writeln it would only print out a small portion of it, even though printing it as a byte[] would print much more. Anyway this *is* a bug. We can't have it both ways: writeln("bla\0bla"); // bla writefln("%s", "bla\0bla"); // bla[NUL]bla -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
October 10, 2012 [Issue 8730] writeln stops on a nul character, even if passed a D string | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | http://d.puremagic.com/issues/show_bug.cgi?id=8730 Brad Roberts <braddr@puremagic.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |braddr@puremagic.com --- Comment #4 from Brad Roberts <braddr@puremagic.com> 2012-10-09 20:33:42 PDT --- Shouldn't this be trivial to fix: Replace: fprintf(.stdout.p.handle, "%.*s\n", cast(int) args[0].length, args[0].ptr) with: fwrite(args[0].ptr, 1, args[0].length, .stdout.p.handle) -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
October 10, 2012 [Issue 8730] writeln stops on a nul character, even if passed a D string | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | http://d.puremagic.com/issues/show_bug.cgi?id=8730 --- Comment #5 from Brad Roberts <braddr@puremagic.com> 2012-10-09 20:36:53 PDT --- oops, followed by the same code as in the length == 0 code to get the \n. At which point it's questionable that specialization is all that special. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation