diff --git a/cgi.d b/cgi.d index ebb7e9e..9dcbf7e 100644 --- a/cgi.d +++ b/cgi.d @@ -163,6 +163,8 @@ +/ module arsd.cgi; +static import std.file; + version(embedded_httpd) { version(linux) version=embedded_httpd_processes; @@ -291,7 +293,7 @@ private struct stdin { } } - import std.c.windows.windows; + import core.sys.windows.windows; static: static this() { diff --git a/eventloop.d b/eventloop.d index 0e5b581..7a7ab5b 100644 --- a/eventloop.d +++ b/eventloop.d @@ -1,6 +1,8 @@ /// crappy event loop for linux module arsd.eventloop; +version(linux): + /* **** */ // Loop implementation // FIXME: much of this is posix or even linux specific, but we ideally want the same interface across all operating systems, though not necessarily even a remotely similar implementation diff --git a/html.d b/html.d index 614fd0e..e828614 100644 --- a/html.d +++ b/html.d @@ -11,6 +11,7 @@ module arsd.html; public import arsd.dom; import arsd.color; +static import std.uri; import std.array; import std.string; import std.variant; diff --git a/jsvar.d b/jsvar.d index 7d8e0a0..493f60a 100644 --- a/jsvar.d +++ b/jsvar.d @@ -61,6 +61,7 @@ module arsd.jsvar; version=new_std_json; import std.stdio; +static import std.array; import std.traits; import std.conv; import std.json; diff --git a/minigui.d b/minigui.d index bd4c4f2..cf6ed96 100644 --- a/minigui.d +++ b/minigui.d @@ -988,7 +988,7 @@ class Window : Widget { auto b = SelectObject(painter.impl.hdc, GetSysColorBrush(COLOR_3DFACE)); auto p = SelectObject(painter.impl.hdc, GetStockObject(NULL_PEN)); // since the pen is null, to fill the whole space, we need the +1 on both. - Rectangle(painter.impl.hdc, 0, 0, this.width + 1, this.height + 1); + gdi.Rectangle(painter.impl.hdc, 0, 0, this.width + 1, this.height + 1); SelectObject(painter.impl.hdc, p); SelectObject(painter.impl.hdc, b); }; @@ -1341,7 +1341,7 @@ class MenuBar : Widget { this.addChild(item); items ~= item; version(win32_widgets) { - AppendMenu(handle, MF_STRING, item.action is null ? 9000 : item.action.id, toStringzInternal(item.label)); + AppendMenuA(handle, MF_STRING, item.action is null ? 9000 : item.action.id, toStringzInternal(item.label)); // XXX } return item; } @@ -1353,7 +1353,7 @@ class MenuBar : Widget { items ~= mbItem; version(win32_widgets) { - AppendMenu(handle, MF_STRING | MF_POPUP, cast(UINT) item.handle, toStringzInternal(item.label)); + AppendMenuA(handle, MF_STRING | MF_POPUP, cast(UINT) item.handle, toStringzInternal(item.label)); // XXX } else { mbItem.defaultEventHandlers["click"] = (Widget e, Event ev) { item.parentWindow = e.parentWindow; @@ -1695,7 +1695,7 @@ class Menu : Widget { addChild(item); items ~= item; version(win32_widgets) { - AppendMenu(handle, MF_STRING, item.action is null ? 9000 : item.action.id, toStringzInternal(item.label)); + AppendMenuA(handle, MF_STRING, item.action is null ? 9000 : item.action.id, toStringzInternal(item.label)); // XXX } return item; } @@ -2506,7 +2506,8 @@ extern(Windows): } version(win32_widgets) { - import std.c.windows.windows; + import core.sys.windows.windows; + import gdi = core.sys.windows.wingdi; // import win32.commctrl; // import win32.winuser; @@ -2531,8 +2532,6 @@ extern(Windows): HMENU CreateMenu(); bool SetMenu(HWND, HMENU); HMENU CreatePopupMenu(); - BOOL AppendMenuA(HMENU, uint, UINT_PTR, LPCTSTR); - alias AppendMenuA AppendMenu; enum MF_POPUP = 0x10; enum MF_STRING = 0; diff --git a/simpledisplay.d b/simpledisplay.d index 89ba918..81fae74 100644 --- a/simpledisplay.d +++ b/simpledisplay.d @@ -1063,7 +1063,7 @@ class SimpleWindow : CapableOfHandlingNativeEvent { version(X11) { return (glXMakeCurrent(display, impl.window, impl.glc) != 0); } else version(Windows) { - return wglMakeCurrent(ghDC, ghRC); + return wglMakeCurrent(ghDC, ghRC) ? true : false; } } @@ -1074,7 +1074,7 @@ class SimpleWindow : CapableOfHandlingNativeEvent { version(X11) { return (glXMakeCurrent(display, 0, null) != 0); } else version(Windows) { - return wglMakeCurrent(ghDC, null); + return wglMakeCurrent(ghDC, null) ? true : false; } } @@ -1337,23 +1337,7 @@ class Timer { } else version(linux) { static import ep = core.sys.linux.epoll; - // static import tfd = core.sys.linux.timerfd; - - static struct tfd { - static: - import core.sys.posix.time; - extern(C): - pragma(mangle, "timerfd_create") - int timerfd_create(int, int); - pragma(mangle, "timerfd_settime") - int timerfd_settime(int, int, const itimerspec*, itimerspec*); - pragma(mangle, "timerfd_gettime") - int timerfd_gettime(int, itimerspec*); - enum TFD_TIMER_ABSTIME = 1 << 0; - enum TFD_CLOEXEC = 0x80000; - enum TFD_NONBLOCK = 0x800; - } - + static import tfd = core.sys.linux.timerfd; fd = tfd.timerfd_create(tfd.CLOCK_MONOTONIC, 0); if(fd == -1) @@ -1437,9 +1421,11 @@ class Timer { version(Windows) extern(Windows) - static void timerCallback(HWND, UINT, UINT_PTR timer, DWORD dwTime) { + static void timerCallback(HWND, UINT, UINT_PTR timer, DWORD dwTime) nothrow { if(Timer* t = timer in mapping) { + try (*t).trigger(); + catch(Exception e) { throw new Error(e.msg, e.file, e.line); } } } @@ -1856,6 +1842,14 @@ enum RasterOp { // being phobos-free keeps the size WAY down private const(char)* toStringz(string s) { return (s ~ '\0').ptr; } +private const(wchar)* toWStringz(wstring s) { return (s ~ '\0').ptr; } +private const(wchar)* toWStringz(string s) { + wstring r; + foreach(dchar c; s) + r ~= c; + r ~= '\0'; + return r.ptr; +} private string[] split(in void[] a, char c) { string[] ret; size_t previous = 0; @@ -3474,14 +3468,14 @@ version(Windows) { Size textSize(string text) { RECT rect; - DrawText(hdc, text.ptr, cast(int) text.length, &rect, DT_CALCRECT); + DrawTextA(hdc, text.ptr, cast(int) text.length, &rect, DT_CALCRECT); /// XXX return Size(rect.right, rect.bottom); } void drawText(int x, int y, int x2, int y2, string text, uint alignment) { // FIXME: use the unicode function if(x2 == 0 && y2 == 0) - TextOut(hdc, x, y, text.ptr, cast(int) text.length); + TextOutA(hdc, x, y, text.ptr, cast(int) text.length); // XXX else { RECT rect; rect.left = x; @@ -3499,7 +3493,7 @@ version(Windows) { if(alignment & TextAlignment.VerticalCenter) mode |= DT_VCENTER | DT_SINGLELINE; - DrawText(hdc, text.ptr, cast(int) text.length, &rect, mode); + DrawTextA(hdc, text.ptr, cast(int) text.length, &rect, mode); // XXX } /* @@ -3533,7 +3527,7 @@ version(Windows) { } void drawRectangle(int x, int y, int width, int height) { - Rectangle(hdc, x, y, x + width, y + height); + gdi.Rectangle(hdc, x, y, x + width, y + height); } /// Arguments are the points of the bounding rectangle @@ -3589,7 +3583,7 @@ version(Windows) { } void createWindow(int width, int height, string title, OpenGlOptions opengl, SimpleWindow parent) { - const char* cn = "DSimpleWindow"; + wstring cn = "DSimpleWindow"w; HINSTANCE hInstance = cast(HINSTANCE) GetModuleHandle(null); @@ -3599,13 +3593,13 @@ version(Windows) { wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hbrBackground = cast(HBRUSH) (COLOR_WINDOW+1); // GetStockObject(WHITE_BRUSH); - wc.hCursor = LoadCursor(null, IDC_ARROW); + wc.hCursor = LoadCursorW(null, IDC_ARROW); wc.hIcon = LoadIcon(hInstance, null); wc.hInstance = hInstance; wc.lpfnWndProc = &WndProc; - wc.lpszClassName = cn; + wc.lpszClassName = cn.ptr; wc.style = CS_HREDRAW | CS_VREDRAW; - if(!RegisterClass(&wc)) + if(!RegisterClassW(&wc)) throw new Exception("RegisterClass"); classRegistered = true; } @@ -3622,7 +3616,7 @@ version(Windows) { break; } - hwnd = CreateWindow(cn, toStringz(title), style, + hwnd = CreateWindow(cn.ptr, toWStringz(title), style, CW_USEDEFAULT, CW_USEDEFAULT, width, height, parent is null ? null : parent.impl.hwnd, null, hInstance, null); @@ -3668,7 +3662,7 @@ version(Windows) { auto oldBmp = SelectObject(hdcBmp, buffer); auto oldBrush = SelectObject(hdcBmp, GetStockObject(WHITE_BRUSH)); auto oldPen = SelectObject(hdcBmp, GetStockObject(WHITE_PEN)); - Rectangle(hdcBmp, 0, 0, width, height); + gdi.Rectangle(hdcBmp, 0, 0, width, height); SelectObject(hdcBmp, oldBmp); SelectObject(hdcBmp, oldBrush); SelectObject(hdcBmp, oldPen); @@ -4950,25 +4944,7 @@ version(X11) { static import unix = core.sys.posix.unistd; static import err = core.stdc.errno; - // until this is reliably in druntime i'll use my own - // so probably like next year i'll switch this over! - // static import tfd = core.sys.linux.timerfd; - - static struct tfd { - static: - import core.sys.posix.time; - extern(C): - pragma(mangle, "timerfd_create") - int timerfd_create(int, int); - pragma(mangle, "timerfd_settime") - int timerfd_settime(int, int, const itimerspec*, itimerspec*); - pragma(mangle, "timerfd_gettime") - int timerfd_gettime(int, itimerspec*); - enum TFD_TIMER_ABSTIME = 1 << 0; - enum TFD_CLOEXEC = 0x80000; - enum TFD_NONBLOCK = 0x800; - } - + static import tfd = core.sys.linux.timerfd; prepareEventLoop(); ep.epoll_event[16] events = void; @@ -5474,9 +5450,13 @@ version(X11) { version(Windows) { import core.sys.windows.windows; + static import gdi = core.sys.windows.wingdi; pragma(lib, "gdi32"); pragma(lib, "user32"); +} else + +version(none) { extern(Windows) { HWND GetConsoleWindow(); diff --git a/sqlite.d b/sqlite.d index 0f4d50b..90fad9e 100644 --- a/sqlite.d +++ b/sqlite.d @@ -18,7 +18,7 @@ import std.exception; import std.string; -import std.c.stdlib; +import core.stdc.stdlib; import core.exception; import core.memory; import std.file; @@ -558,7 +558,7 @@ template extract(A, T, R...){ { void* p; - p = std.c.stdlib.malloc(sz); + p = core.stdc.stdlib.malloc(sz); if (!p) throw new OutOfMemoryError(__FILE__, __LINE__); GC.addRange(p, sz); @@ -569,7 +569,7 @@ template extract(A, T, R...){ { if (p) { GC.removeRange(p); - std.c.stdlib.free(p); + core.stdc.stdlib.free(p); } } diff --git a/sslsocket.d b/sslsocket.d index cdc84b9..166f107 100644 --- a/sslsocket.d +++ b/sslsocket.d @@ -41,6 +41,7 @@ version(use_openssl) { SSL_CTX* SSL_CTX_new(const SSL_METHOD* method); SSL* SSL_new(SSL_CTX*); + int SSL_pending(SSL*); int SSL_set_fd(SSL*, int); int SSL_connect(SSL*); int SSL_write(SSL*, const void*, int); diff --git a/web.d b/web.d index ccc25fa..f65c980 100644 --- a/web.d +++ b/web.d @@ -174,6 +174,7 @@ struct IfInputContentType { */ import std.exception; +static import std.uri; public import arsd.dom; public import arsd.cgi; // you have to import this in the actual usage file or else it won't link; surely a compiler bug import arsd.sha; @@ -2946,7 +2947,8 @@ deprecated string getSessionId(Cgi cgi) { } version(Posix) { - static import linux = std.c.linux.linux; + static import linux = core.sys.linux.unistd; + static import sys_stat = core.sys.posix.sys.stat; } /// This is cookie parameters for the Session class. The default initializers provide some simple default @@ -3433,7 +3435,7 @@ class Session { // users on the operating system for each user, it's still possible // for them to access this file and hijack your session! version(linux) - enforce(linux.chmod(toStringz(getFilePath()), octal!600) == 0, "chmod failed"); + enforce(sys_stat.chmod(toStringz(getFilePath()), octal!600) == 0, "chmod failed"); // FIXME: ensure the file's read permissions are locked down // on Windows too. }