Skip to content

Commit

Permalink
Added nothrow attribute for each callback methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
shoo committed May 27, 2012
1 parent fdb8875 commit acce05b
Show file tree
Hide file tree
Showing 11 changed files with 164 additions and 82 deletions.
100 changes: 56 additions & 44 deletions win32/dfl/application.d
Expand Up @@ -117,7 +117,7 @@ class ApplicationContext // docmain
}


private extern(Windows)
private extern(Windows) nothrow
{
alias UINT function(LPCWSTR lpPathName, LPCWSTR lpPrefixString, UINT uUnique,
LPWSTR lpTempFileName) GetTempFileNameWProc;
Expand Down Expand Up @@ -871,53 +871,59 @@ final class Application // docmain


///
void onThreadException(DThrowable e)
void onThreadException(DThrowable e) nothrow
{
static bool except = false;

version(WINDOWS_HUNG_WORKAROUND)
try
{
version(WINDOWS_HUNG_WORKAROUND_NO_IGNORE)
static bool except = false;

version(WINDOWS_HUNG_WORKAROUND)
{
version(WINDOWS_HUNG_WORKAROUND_NO_IGNORE)
{
}
else
{
if(cast(WindowsHungDflException)e)
return;
}
}
else

if(except)
{
if(cast(WindowsHungDflException)e)
return;
cprintf("Error: %.*s\n", cast(int)getObjectString(e).length, getObjectString(e).ptr);

abort();
return;
}
}

if(except)
{
cprintf("Error: %.*s\n", cast(int)getObjectString(e).length, getObjectString(e).ptr);

abort();
return;
}

except = true;
//if(threadException.handlers.length)
if(threadException.hasHandlers)
{
threadException(typeid(Application), new ThreadExceptionEventArgs(e));
except = false;
return;
}
else
{
// No thread exception handlers, display a dialog.
if(showDefaultExceptionDialog(e))
except = true;
//if(threadException.handlers.length)
if(threadException.hasHandlers)
{
threadException(typeid(Application), new ThreadExceptionEventArgs(e));
except = false;
return;
}
else
{
// No thread exception handlers, display a dialog.
if(showDefaultExceptionDialog(e))
{
except = false;
return;
}
}
//except = false;

//throw e;
cprintf("Error: %.*s\n", cast(int)getObjectString(e).length, getObjectString(e).ptr);
//exitThread();
Environment.exit(EXIT_FAILURE);
}
catch (DThrowable e)
{
}
//except = false;

//throw e;
cprintf("Error: %.*s\n", cast(int)getObjectString(e).length, getObjectString(e).ptr);
//exitThread();
Environment.exit(EXIT_FAILURE);
}


Expand Down Expand Up @@ -1079,7 +1085,7 @@ final class Application // docmain
}

// Returns null if not found.
package Control lookupHwnd(HWND hwnd)
package Control lookupHwnd(HWND hwnd) nothrow
{
//if(hwnd in controls)
// return controls[hwnd];
Expand Down Expand Up @@ -1286,7 +1292,7 @@ final class Application // docmain
}


package void creatingControl(Control ctrl)
package void creatingControl(Control ctrl) nothrow
{
TlsSetValue(tlsControl, cast(Control*)ctrl);
}
Expand Down Expand Up @@ -1575,7 +1581,7 @@ final class Application // docmain
}


Control getCreatingControl()
Control getCreatingControl() nothrow
{
return cast(Control)cast(Control*)TlsGetValue(tlsControl);
}
Expand Down Expand Up @@ -1668,7 +1674,7 @@ final class Application // docmain
package:


extern(Windows) void _gcTimeout(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime)
extern(Windows) void _gcTimeout(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime) nothrow
{
KillTimer(hwnd, Application.gctimer);
Application.gctimer = 0;
Expand Down Expand Up @@ -1857,7 +1863,7 @@ debug(SHOW_MESSAGE_INFO)
}


extern(Windows) LRESULT dflWndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
extern(Windows) LRESULT dflWndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) nothrow
{
//cprintf("HWND %p; WM %d(0x%X); WPARAM %d(0x%X); LPARAM %d(0x%X);\n", hwnd, msg, msg, wparam, wparam, lparam, lparam);

Expand Down Expand Up @@ -1990,9 +1996,15 @@ extern(Windows) LRESULT dflWndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lp
if(ctrl)
{
do_msg:
ctrl.mustWndProc(dm);
if(!ctrl.preProcessMessage(dm))
ctrl._wndProc(dm);
try
{
ctrl.mustWndProc(dm);
if(!ctrl.preProcessMessage(dm))
ctrl._wndProc(dm);
}
catch (DThrowable e)
{
}
}
return dm.result;
}
Expand Down
16 changes: 7 additions & 9 deletions win32/dfl/base.d
Expand Up @@ -328,15 +328,13 @@ struct Message // docmain


/// Construct a Message struct.
static Message opCall(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
Message m;
m.hWnd = hWnd;
m.msg = msg;
m.wParam = wParam;
m.lParam = lParam;
m.result = 0;
return m;
this(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) nothrow
{
hWnd = hWnd;
msg = msg;
wParam = wParam;
lParam = lParam;
result = 0;
}
}

Expand Down
84 changes: 67 additions & 17 deletions win32/dfl/control.d
Expand Up @@ -581,46 +581,75 @@ version(_DFL_WINDOWS_HUNG_WORKAROUND)
}
}


package alias BOOL delegate(HWND) EnumWindowsCallback;
alias BOOL delegate(HWND) EnumWindowsCallback;
package struct EnumWindowsCallbackData
{
EnumWindowsCallback callback;
DThrowable exception;
}


// Callback for EnumWindows() and EnumChildWindows().
private extern(Windows) BOOL enumingWindows(HWND hwnd, LPARAM lparam)
private extern(Windows) BOOL enumingWindows(HWND hwnd, LPARAM lparam) nothrow
{
EnumWindowsCallback dg = *(cast(EnumWindowsCallback*)lparam);
return dg(hwnd);
auto cbd = *(cast(EnumWindowsCallbackData*)lparam);
try
{
return cbd.callback(hwnd);
}
catch (DThrowable e)
{
cbd.exception = e;
return FALSE;
}
assert(0);
}


private struct Efi
{
HWND hwParent;
EnumWindowsCallback dg;
EnumWindowsCallbackData cbd;
}


// Callback for EnumChildWindows(). -lparam- = pointer to Efi;
private extern(Windows) BOOL enumingFirstWindows(HWND hwnd, LPARAM lparam)
private extern(Windows) BOOL enumingFirstWindows(HWND hwnd, LPARAM lparam) nothrow
{
Efi* efi = cast(Efi*)lparam;
auto efi = cast(Efi*)lparam;
if(efi.hwParent == GetParent(hwnd))
return efi.dg(hwnd);
return true;
{
try
{
return efi.cbd.callback(hwnd);
}
catch (DThrowable e)
{
efi.cbd.exception = e;
return FALSE;
}
}
return TRUE;
}


package BOOL enumWindows(EnumWindowsCallback dg)
{
static assert((&dg).sizeof <= LPARAM.sizeof);
return EnumWindows(&enumingWindows, cast(LPARAM)&dg);
EnumWindowsCallbackData cbd;
cbd.callback = dg;
scope (exit) if (cbd.exception) throw cbd.exception;
static assert((&cbd).sizeof <= LPARAM.sizeof);
return EnumWindows(&enumingWindows, cast(LPARAM)&cbd);
}


package BOOL enumChildWindows(HWND hwParent, EnumWindowsCallback dg)
{
static assert((&dg).sizeof <= LPARAM.sizeof);
return EnumChildWindows(hwParent, &enumingWindows, cast(LPARAM)&dg);
EnumWindowsCallbackData cbd;
cbd.callback = dg;
scope (exit) if (cbd.exception) throw cbd.exception;
static assert((&cbd).sizeof <= LPARAM.sizeof);
return EnumChildWindows(hwParent, &enumingWindows, cast(LPARAM)&cbd);
}


Expand All @@ -629,7 +658,8 @@ package BOOL enumFirstChildWindows(HWND hwParent, EnumWindowsCallback dg)
{
Efi efi;
efi.hwParent = hwParent;
efi.dg = dg;
efi.cbd.callback = dg;
scope (exit) if (efi.cbd.exception) throw efi.cbd.exception;
return EnumChildWindows(hwParent, &enumingFirstWindows, cast(LPARAM)&efi);
}

Expand Down Expand Up @@ -2608,8 +2638,28 @@ class Control: DObject, IWindow // docmain
{
GetZIndex gzi;
gzi.find = this;
EnumChildWindows(parent.hwnd, &getZIndexCallback, cast(LPARAM)&gzi);
return gzi.index;
int index;
int tmp;

BOOL getZIndexCallback(HWND hWnd)
{
if(hWnd is hwnd)
{
index = tmp;
return FALSE; // Stop, found it.
}

auto ctrl = Control.fromHandle(hWnd);
if(ctrl && ctrl.parent is parent)
{
tmp++;
}

return TRUE; // Keep looking.
}

enumChildWindows(parent.hwnd, &getZIndexCallback);
return index;
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion win32/dfl/filedialog.d
Expand Up @@ -969,7 +969,7 @@ class SaveFileDialog: FileDialog // docmain
}


private extern(Windows) LRESULT ofnHookProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
private extern(Windows) LRESULT ofnHookProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) nothrow
{
alias dfl.internal.winapi.HANDLE HANDLE; // Otherwise, odd conflict with wine.

Expand Down
2 changes: 1 addition & 1 deletion win32/dfl/folderdialog.d
Expand Up @@ -321,7 +321,7 @@ class FolderBrowserDialog: CommonDialog // docmain

private:

private extern(Windows) int fbdHookProc(HWND hwnd, UINT msg, LPARAM lparam, LPARAM lpData)
private extern(Windows) int fbdHookProc(HWND hwnd, UINT msg, LPARAM lparam, LPARAM lpData) nothrow
{
FolderBrowserDialog fd;
int result = 0;
Expand Down
2 changes: 1 addition & 1 deletion win32/dfl/fontdialog.d
Expand Up @@ -418,7 +418,7 @@ class FontDialog: CommonDialog
// WM_CHOOSEFONT_SETFLAGS to update flags after dialog creation ... ?


private extern(Windows) UINT fondHookProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
private extern(Windows) UINT fondHookProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) nothrow
{
const Dstring PROP_STR = "DFL_FontDialog";
FontDialog fd;
Expand Down
10 changes: 8 additions & 2 deletions win32/dfl/internal/dlib.d
Expand Up @@ -414,9 +414,15 @@ else // Phobos
core.memory.GC.collect();
}

void gcFullCollect()
void gcFullCollect() nothrow
{
core.memory.GC.collect();
try
{
core.memory.GC.collect();
}
catch (Throwable e)
{
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion win32/dfl/internal/winapi.d
Expand Up @@ -65,7 +65,7 @@ else
//version = DFL_D1_AND_ABOVE;


extern(Windows):
extern(Windows) nothrow:

struct SIZE
{
Expand Down
4 changes: 2 additions & 2 deletions win32/dfl/richtextbox.d
Expand Up @@ -1019,7 +1019,7 @@ class RichTextBox: TextBoxBase // docmain
}


private extern(Windows) DWORD _streamingInStr(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG* pcb)
private extern(Windows) DWORD _streamingInStr(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG* pcb) nothrow
{
RichTextBox._StreamStr* si;
si = cast(typeof(si))dwCookie;
Expand All @@ -1046,7 +1046,7 @@ private extern(Windows) DWORD _streamingInStr(DWORD dwCookie, LPBYTE pbBuff, LON
}


private extern(Windows) DWORD _streamingOutStr(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG* pcb)
private extern(Windows) DWORD _streamingOutStr(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG* pcb) nothrow
{
RichTextBox._StreamStr* so;
so = cast(typeof(so))dwCookie;
Expand Down

0 comments on commit acce05b

Please sign in to comment.