Problem with release build.

sanjayss via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Feb 8 21:17:20 PST 2016


Ignore this -- this is probably due to how I am doing the 
assert(). In the release build, it is getting compiled out and in 
the process compiling out the tcgetattr and the tcsetattr.....



On Tuesday, 9 February 2016 at 05:08:20 UTC, sanjayss wrote:
> In the following sample program (which tries to set terminal to 
> raw mode and check for key presses), compiling as usual (dmd 
> t.d), the program works, but compiling in release mode (dmd 
> -release t.d) and the raw mode doesn't seem to work. Where do I 
> start looking to figure this out or if it is obvious, what am I 
> doing wrong? (In the release mode output, notice the character 
> getting echo-ed before the "Got").
>
> MacBook-Pro:$ dmd --version
> DMD64 D Compiler v2.069.2
> Copyright (c) 1999-2015 by Digital Mars written by Walter Bright
> MacBook-Pro:$ dmd t.d
> MacBook-Pro:$ ./t
> Got: a
> Got: b
> Got: c
> Got: d
> Got: q
> MacBook-Pro:$ dmd -release t.d
> MacBook-Pro:$ ./t
> aGot: a
> bGot: b
> cGot: c
> dGot: d
> eGot: e
> qGot: q
> MacBook-Pro:$ cat t.d
> import core.thread;
> import core.stdc.stdio;
> import core.sys.posix.fcntl;
> import core.sys.posix.termios;
> import std.stdio : writeln;
>
> int oldf;
> termios oldt;
>
> void
> makeraw()
> {
>     termios newt;
>
>     assert(tcgetattr(0, &oldt) == 0);
>     newt = oldt;
>
>     newt.c_lflag &= ~(ICANON | ECHO | ECHONL | ISIG | IEXTEN);
>     newt.c_iflag &= ~(IGNBRK | BRKINT | ISTRIP | INLCR | ICRNL 
> | IGNCR | IXON | IXOFF);
>     newt.c_cc[VMIN] = 1;
>     assert(tcsetattr(0, TCSANOW, &newt) == 0);
>
>     oldf = fcntl(0, F_GETFL, 0);
>     fcntl(0, F_SETFL, oldf | O_NONBLOCK);
> }
>
> void
> makecooked()
> {
>     fcntl(0, F_SETFL, oldf);
>     assert(tcsetattr(0, TCSANOW, &oldt) == 0);
> }
>
> void
> main(string[] args)
> {
>     int ch;
>
>     makeraw();
>     scope(exit) makecooked();
>
>     do
>     {
>         while ((ch = fgetc(stdin)) == EOF)
>         {
>             Thread.sleep(dur!("seconds")(1));
>         }
>         writeln("Got: ", cast(dchar)ch);
>     } while (ch != 'q');
> }




More information about the Digitalmars-d-learn mailing list