www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Possible codegen bug when using Tcl/Tk (related to DMC and DMD)

I was first reducing a strange behavior bug in D, but then realized
the behavior can be recreated with a C code sample built with DMC as
well. I cannot reproduce it when using GCC, so I'm left to believe it
could be a codegen bug.

I'm on Windows 7, 64bit, and I'm using Tcl's Tk library, v8.6 (x86).
First, here is the C code:

-----
#include <windows.h>

#include "tcl.h"

typedef Tcl_Interp* (* Tcl_CreateInterp_Type)(void);
typedef int (* Tcl_Init_Type)(Tcl_Interp*);
typedef int (* Tk_Init_Type)(Tcl_Interp*);
typedef int (* Tcl_Eval_Type)(Tcl_Interp*, const char *);
typedef void (* Tk_MainLoop_Type)(void);

int main()
{
    HMODULE hTcl = LoadLibraryA("tcl86.dll");
    HMODULE hTk = LoadLibraryA("tk86.dll");

    Tcl_CreateInterp_Type Tcl_CreateInterp;
    Tcl_CreateInterp = (Tcl_CreateInterp_Type)GetProcAddress(hTcl,
"Tcl_CreateInterp");

    Tcl_Init_Type Tcl_Init;
    Tcl_Init = (Tcl_Init_Type)GetProcAddress(hTcl, "Tcl_Init");

    Tk_Init_Type Tk_Init;
    Tk_Init = (Tk_Init_Type)GetProcAddress(hTk, "Tk_Init");

    Tcl_Eval_Type Tcl_Eval;
    Tcl_Eval = (Tcl_Eval_Type)GetProcAddress(hTcl, "Tcl_Eval");

    Tk_MainLoop_Type Tk_MainLoop;
    Tk_MainLoop = (Tk_MainLoop_Type)GetProcAddress(hTk, "Tk_MainLoop");

    Tcl_Interp* _interp = Tcl_CreateInterp();
    Tcl_Init(_interp);
    Tk_Init(_interp);

    Tcl_Eval(_interp, "tkwait visibility .");
    Tcl_Eval(_interp, "tk::toplevel .mywin");
    Tcl_Eval(_interp, "wm resizable .mywin false false");

    Tk_MainLoop();

    return 0;
}
-----

Then, the dependency is Tcl v8.6 x86, grab it from here:

http://www.activestate.com/activetcl/downloads/thank-you?dl=http://downloads.activestate.com/ActiveTcl/releases/8.6.0.0/ActiveTcl8.6.0.0.296563-win32-ix86-threaded.exe

To compile with both DMC and GCC I use this build.bat script:

-----
 echo off
set include_dir=C:\Tcl\include
dmc test_tk.c -I%include_dir% -otest_dmc.exe
g++ test_tk.c -m32 -I%include_dir% -o test_gcc.exe
-----

You can run the build script now (but make sure the include dir is set
to wherever you've installed Tcl)

Since the sample app loads the Tcl and Tk DLLs, you need to have them
in your PATH variable. You can do this through command-line and try
out the built apps:

-----
set PATH=C:\Tcl\bin;%PATH%
test_gcc.exe
test_dmc.exe
-----

Here's the behavior problem:

When running test_gcc.exe, when I try to move the window labeled
"mywin" with the mouse, the window is moved normally and there's
nothing problematic.

But when doing the same when running test_dmc.exe, the window starts
shrinking in size horizontally until it reaches some minimal width.

I'm using DMC v8.42n, and GCC v4.8.0.

Initially this was D code and I thought I had a bug in my D code, but
now I've ported this sample into C and it seems like it could be a
backend-related bug (since DMD and DMC share the same backend).

Anyway I'm not an ASM expert so I'm hoping to get some more people who
can reproduce this and possibly know what's going on.
Aug 17 2013