Index: d/phobos/std/loader.d =================================================================== --- d/phobos/std/loader.d (Revision 199) +++ d/phobos/std/loader.d (Arbeitskopie) @@ -858,8 +858,16 @@ this(uint errcode) { + version (linux) + { + char[80] buf = void; + super(std.string.toString(strerror_r(errcode, buf.ptr, buf.length)).dup); + } + else + { super(std.string.toString(strerror(errcode)).dup); } + } } /// This class represents an executable image Index: d/phobos/std/process.d =================================================================== --- d/phobos/std/process.d (Revision 199) +++ d/phobos/std/process.d (Arbeitskopie) @@ -146,7 +146,11 @@ Lerror: retval = getErrno; - throw new Exception("Cannot spawn " ~ toString(pathname) ~ "; " ~ toString(strerror(retval)) ~ " [errno " ~ toString(retval) ~ "]"); + char[80] buf = void; + throw new Exception( + "Cannot spawn " ~ toString(pathname) ~ "; " + ~ toString(strerror_r(retval, buf.ptr, buf.length)) + ~ " [errno " ~ toString(retval) ~ "]"); } // _spawnvp private { Index: d/phobos/std/stdio.d =================================================================== --- d/phobos/std/stdio.d (Revision 199) +++ d/phobos/std/stdio.d (Arbeitskopie) @@ -104,7 +104,15 @@ } this(uint errno) - { char* s = strerror(errno); + { + version (linux) + { char[80] buf = void; + auto s = std.string.strerror_r(errno, buf.ptr, buf.length); + } + else + { + auto s = std.string.strerror(errno); + } super(std.string.toString(s).dup); } Index: d/phobos/std/system.d =================================================================== --- d/phobos/std/system.d (Revision 199) +++ d/phobos/std/system.d (Arbeitskopie) @@ -1,3 +1,4 @@ +// Written in the D programming language /** * Information about the target operating system, environment, and CPU @@ -63,7 +64,7 @@ RedHatLinux, } - /// Byte order endiannes + /// Byte order endianness enum Endian { @@ -73,7 +74,7 @@ version(LittleEndian) { - /// Native system endiannes + /// Native system endianness Endian endian = Endian.LittleEndian; } else Index: d/phobos/std/math.d =================================================================== --- d/phobos/std/math.d (Revision 199) +++ d/phobos/std/math.d (Arbeitskopie) @@ -83,7 +83,7 @@ { this(string msg) { - super(msg ~ "not implemented"); + super(msg ~ " not implemented"); } } @@ -372,18 +372,18 @@ /*************** * Calculates the arc tangent of y / x, - * returning a value ranging from -$(PI)/2 to $(PI)/2. + * returning a value ranging from -$(PI) to $(PI). * * $(TABLE_SV * $(TR $(TH y) $(TH x) $(TH atan(y, x))) * $(TR $(TD $(NAN)) $(TD anything) $(TD $(NAN)) ) * $(TR $(TD anything) $(TD $(NAN)) $(TD $(NAN)) ) * $(TR $(TD $(PLUSMN)0.0) $(TD $(GT)0.0) $(TD $(PLUSMN)0.0) ) - * $(TR $(TD $(PLUSMN)0.0) $(TD $(PLUSMN)0.0) $(TD $(PLUSMN)0.0) ) + * $(TR $(TD $(PLUSMN)0.0) $(TD +0.0) $(TD $(PLUSMN)0.0) ) * $(TR $(TD $(PLUSMN)0.0) $(TD $(LT)0.0) $(TD $(PLUSMN)$(PI))) * $(TR $(TD $(PLUSMN)0.0) $(TD -0.0) $(TD $(PLUSMN)$(PI))) * $(TR $(TD $(GT)0.0) $(TD $(PLUSMN)0.0) $(TD $(PI)/2) ) - * $(TR $(TD $(LT)0.0) $(TD $(PLUSMN)0.0) $(TD $(PI)/2)) + * $(TR $(TD $(LT)0.0) $(TD $(PLUSMN)0.0) $(TD -$(PI)/2) ) * $(TR $(TD $(GT)0.0) $(TD $(INFIN)) $(TD $(PLUSMN)0.0) ) * $(TR $(TD $(PLUSMN)$(INFIN)) $(TD anything) $(TD $(PLUSMN)$(PI)/2)) * $(TR $(TD $(GT)0.0) $(TD -$(INFIN)) $(TD $(PLUSMN)$(PI)) ) @@ -906,6 +906,8 @@ * $(TR $(TD $(PLUSMN)$(INFIN)) $(TD $(PLUSMN)$(INFIN)) ) * $(TR $(TD $(PLUSMN)0.0) $(TD $(PLUSMN)0.0) ) * ) + * + * Note: Not supported on windows */ real scalbn(real x, int n) { @@ -1181,6 +1183,8 @@ /*************************************** * Rounds x to the nearest integer value, using the current rounding * mode. + * + * Note: Not supported on windows */ long lrint(real x) { @@ -1234,6 +1238,8 @@ * * If the fractional part of x is exactly 0.5, the return value is rounded * away from zero. + * + * Note: Not supported on windows */ long lround(real x) { @@ -1287,6 +1293,8 @@ * $(TR $(TD anything) $(TD $(PLUSMN)0.0) $(TD $(NAN)) $(TD ?) $(TD yes)) * $(TR $(TD != $(PLUSMN)$(INFIN)) $(TD $(PLUSMN)$(INFIN)) $(TD x) $(TD ?) $(TD no)) * ) + * + * Note: remquo not supported on windows */ real remainder(real x, real y) { return std.c.math.remainderl(x, y); } @@ -1498,6 +1506,8 @@ * the function result is infinite. The FE_INEXACT and FE_UNDERFLOW * exceptions will be raised if the function value is subnormal, and x is * not equal to y. + * + * Note: real nextafter(real, real) not supported on windows */ real nextafter(real x, real y) { Index: d/phobos/std/stream.d =================================================================== --- d/phobos/std/stream.d (Revision 199) +++ d/phobos/std/stream.d (Arbeitskopie) @@ -2130,7 +2130,7 @@ } /// creates file in requested mode - void create(char[] filename, FileMode mode = FileMode.Out) { + void create(char[] filename, FileMode mode = FileMode.OutNew) { File sf = cast(File)s; sf.create(filename,mode); resetSource(); Index: d/phobos/std/c/string.d =================================================================== --- d/phobos/std/c/string.d (Revision 199) +++ d/phobos/std/c/string.d (Arbeitskopie) @@ -68,3 +68,9 @@ { int memicmp(char* s1, char* s2, size_t n); /// } + +version (linux) +{ + char* strerror_r(int errnum, char* buf, size_t buflen); /// +} + Index: d/phobos/std/c/windows/winsock.d =================================================================== --- d/phobos/std/c/windows/winsock.d (Revision 199) +++ d/phobos/std/c/windows/winsock.d (Arbeitskopie) @@ -381,6 +381,7 @@ MSG_OOB = 0x1, MSG_PEEK = 0x2, MSG_DONTROUTE = 0x4, + MSG_NOSIGNAL = 0x0, /// not supported on win32, would be 0x4000 if it was } Index: d/phobos/std/c/windows/windows.d =================================================================== --- d/phobos/std/c/windows/windows.d (Revision 199) +++ d/phobos/std/c/windows/windows.d (Arbeitskopie) @@ -250,8 +250,11 @@ FILE_VOLUME_IS_COMPRESSED = 0x00008000, } -const DWORD MAILSLOT_NO_MESSAGE = cast(DWORD)-1; -const DWORD MAILSLOT_WAIT_FOREVER = cast(DWORD)-1; +enum +{ + MAILSLOT_NO_MESSAGE = cast(DWORD)-1, + MAILSLOT_WAIT_FOREVER = cast(DWORD)-1, +} enum : uint { @@ -275,9 +278,13 @@ } const HANDLE INVALID_HANDLE_VALUE = cast(HANDLE)-1; -const DWORD INVALID_SET_FILE_POINTER = cast(DWORD)-1; -const DWORD INVALID_FILE_SIZE = cast(DWORD)0xFFFFFFFF; +enum : DWORD +{ + INVALID_SET_FILE_POINTER = cast(DWORD)-1, + INVALID_FILE_SIZE = cast(DWORD)0xFFFFFFFF, +} + struct OVERLAPPED { DWORD Internal; DWORD InternalHigh; @@ -326,6 +333,13 @@ wchar cAlternateFileName[ 14 ]; } +enum +{ + STD_INPUT_HANDLE = cast(DWORD)-10, + STD_OUTPUT_HANDLE = cast(DWORD)-11, + STD_ERROR_HANDLE = cast(DWORD)-12, +} + export { BOOL SetCurrentDirectoryA(LPCSTR lpPathName); @@ -428,8 +442,11 @@ // Key creation/open disposition // -const int REG_CREATED_NEW_KEY = 0x00000001; // New Registry Key created -const int REG_OPENED_EXISTING_KEY = 0x00000002; // Existing Key opened +enum : int +{ + REG_CREATED_NEW_KEY = 0x00000001, // New Registry Key created + REG_OPENED_EXISTING_KEY = 0x00000002, // Existing Key opened +} // @@ -1102,6 +1119,7 @@ export HANDLE GetCurrentThread(); export BOOL GetProcessTimes(HANDLE hProcess, LPFILETIME lpCreationTime, LPFILETIME lpExitTime, LPFILETIME lpKernelTime, LPFILETIME lpUserTime); export HANDLE GetCurrentProcess(); +export DWORD GetCurrentProcessId(); export BOOL DuplicateHandle (HANDLE sourceProcess, HANDLE sourceThread, HANDLE targetProcessHandle, HANDLE *targetHandle, DWORD access, BOOL inheritHandle, DWORD options); @@ -2083,11 +2101,15 @@ COLOR_BTNHILIGHT = COLOR_BTNHIGHLIGHT, } -const int CW_USEDEFAULT = cast(int)0x80000000; +enum : int +{ + CW_USEDEFAULT = cast(int)0x80000000 +} + /* * Special value for CreateWindow, et al. */ -const HWND HWND_DESKTOP = (cast(HWND)0); +const HWND HWND_DESKTOP = cast(HWND)0; export ATOM RegisterClassA(WNDCLASSA *lpWndClass); @@ -2713,10 +2735,328 @@ export int wsprintfA(LPSTR, LPCSTR, ...); export int wsprintfW(LPWSTR, LPCWSTR, ...); -const uint INFINITE = uint.max; -const uint WAIT_OBJECT_0 = 0; +enum : uint +{ + INFINITE = uint.max, + WAIT_OBJECT_0 = 0, +} export HANDLE CreateSemaphoreA(LPSECURITY_ATTRIBUTES lpSemaphoreAttributes, LONG lInitialCount, LONG lMaximumCount, LPCTSTR lpName); export HANDLE OpenSemaphoreA(DWORD dwDesiredAccess, BOOL bInheritHandle, LPCTSTR lpName); export BOOL ReleaseSemaphore(HANDLE hSemaphore, LONG lReleaseCount, LPLONG lpPreviousCount); + +struct COORD { + SHORT X; + SHORT Y; } +alias COORD *PCOORD; + +struct SMALL_RECT { + SHORT Left; + SHORT Top; + SHORT Right; + SHORT Bottom; +} +alias SMALL_RECT *PSMALL_RECT; + +struct KEY_EVENT_RECORD { + BOOL bKeyDown; + WORD wRepeatCount; + WORD wVirtualKeyCode; + WORD wVirtualScanCode; + union { + WCHAR UnicodeChar; + CHAR AsciiChar; + } + DWORD dwControlKeyState; +} +alias KEY_EVENT_RECORD *PKEY_EVENT_RECORD; + +// +// ControlKeyState flags +// + +enum +{ + RIGHT_ALT_PRESSED = 0x0001, // the right alt key is pressed. + LEFT_ALT_PRESSED = 0x0002, // the left alt key is pressed. + RIGHT_CTRL_PRESSED = 0x0004, // the right ctrl key is pressed. + LEFT_CTRL_PRESSED = 0x0008, // the left ctrl key is pressed. + SHIFT_PRESSED = 0x0010, // the shift key is pressed. + NUMLOCK_ON = 0x0020, // the numlock light is on. + SCROLLLOCK_ON = 0x0040, // the scrolllock light is on. + CAPSLOCK_ON = 0x0080, // the capslock light is on. + ENHANCED_KEY = 0x0100, // the key is enhanced. +} + +struct MOUSE_EVENT_RECORD { + COORD dwMousePosition; + DWORD dwButtonState; + DWORD dwControlKeyState; + DWORD dwEventFlags; +} +alias MOUSE_EVENT_RECORD *PMOUSE_EVENT_RECORD; + +// +// ButtonState flags +// +enum +{ + FROM_LEFT_1ST_BUTTON_PRESSED = 0x0001, + RIGHTMOST_BUTTON_PRESSED = 0x0002, + FROM_LEFT_2ND_BUTTON_PRESSED = 0x0004, + FROM_LEFT_3RD_BUTTON_PRESSED = 0x0008, + FROM_LEFT_4TH_BUTTON_PRESSED = 0x0010, +} + +// +// EventFlags +// + +enum +{ + MOUSE_MOVED = 0x0001, + DOUBLE_CLICK = 0x0002, +} + +struct WINDOW_BUFFER_SIZE_RECORD { + COORD dwSize; +} +alias WINDOW_BUFFER_SIZE_RECORD *PWINDOW_BUFFER_SIZE_RECORD; + +struct MENU_EVENT_RECORD { + UINT dwCommandId; +} +alias MENU_EVENT_RECORD *PMENU_EVENT_RECORD; + +struct FOCUS_EVENT_RECORD { + BOOL bSetFocus; +} +alias FOCUS_EVENT_RECORD *PFOCUS_EVENT_RECORD; + +struct INPUT_RECORD { + WORD EventType; + union { + KEY_EVENT_RECORD KeyEvent; + MOUSE_EVENT_RECORD MouseEvent; + WINDOW_BUFFER_SIZE_RECORD WindowBufferSizeEvent; + MENU_EVENT_RECORD MenuEvent; + FOCUS_EVENT_RECORD FocusEvent; + } +} +alias INPUT_RECORD *PINPUT_RECORD; + +// +// EventType flags: +// + +enum +{ + KEY_EVENT = 0x0001, // Event contains key event record + MOUSE_EVENT = 0x0002, // Event contains mouse event record + WINDOW_BUFFER_SIZE_EVENT = 0x0004, // Event contains window change event record + MENU_EVENT = 0x0008, // Event contains menu event record + FOCUS_EVENT = 0x0010, // event contains focus change +} + +struct CHAR_INFO { + union { + WCHAR UnicodeChar; + CHAR AsciiChar; + } + WORD Attributes; +} +alias CHAR_INFO *PCHAR_INFO; + +// +// Attributes flags: +// + +enum +{ + FOREGROUND_BLUE = 0x0001, // text color contains blue. + FOREGROUND_GREEN = 0x0002, // text color contains green. + FOREGROUND_RED = 0x0004, // text color contains red. + FOREGROUND_INTENSITY = 0x0008, // text color is intensified. + BACKGROUND_BLUE = 0x0010, // background color contains blue. + BACKGROUND_GREEN = 0x0020, // background color contains green. + BACKGROUND_RED = 0x0040, // background color contains red. + BACKGROUND_INTENSITY = 0x0080, // background color is intensified. +} + +struct CONSOLE_SCREEN_BUFFER_INFO { + COORD dwSize; + COORD dwCursorPosition; + WORD wAttributes; + SMALL_RECT srWindow; + COORD dwMaximumWindowSize; +} +alias CONSOLE_SCREEN_BUFFER_INFO *PCONSOLE_SCREEN_BUFFER_INFO; + +struct CONSOLE_CURSOR_INFO { + DWORD dwSize; + BOOL bVisible; +} +alias CONSOLE_CURSOR_INFO *PCONSOLE_CURSOR_INFO; + +enum +{ + ENABLE_PROCESSED_INPUT = 0x0001, + ENABLE_LINE_INPUT = 0x0002, + ENABLE_ECHO_INPUT = 0x0004, + ENABLE_WINDOW_INPUT = 0x0008, + ENABLE_MOUSE_INPUT = 0x0010, +} + +enum +{ + ENABLE_PROCESSED_OUTPUT = 0x0001, + ENABLE_WRAP_AT_EOL_OUTPUT = 0x0002, +} + +BOOL PeekConsoleInputA(HANDLE hConsoleInput, PINPUT_RECORD lpBuffer, DWORD nLength, LPDWORD lpNumberOfEventsRead); +BOOL PeekConsoleInputW(HANDLE hConsoleInput, PINPUT_RECORD lpBuffer, DWORD nLength, LPDWORD lpNumberOfEventsRead); +BOOL ReadConsoleInputA(HANDLE hConsoleInput, PINPUT_RECORD lpBuffer, DWORD nLength, LPDWORD lpNumberOfEventsRead); +BOOL ReadConsoleInputW(HANDLE hConsoleInput, PINPUT_RECORD lpBuffer, DWORD nLength, LPDWORD lpNumberOfEventsRead); +BOOL WriteConsoleInputA(HANDLE hConsoleInput, INPUT_RECORD *lpBuffer, DWORD nLength, LPDWORD lpNumberOfEventsWritten); +BOOL WriteConsoleInputW(HANDLE hConsoleInput, INPUT_RECORD *lpBuffer, DWORD nLength, LPDWORD lpNumberOfEventsWritten); +BOOL ReadConsoleOutputA(HANDLE hConsoleOutput, PCHAR_INFO lpBuffer, COORD dwBufferSize, COORD dwBufferCoord, PSMALL_RECT lpReadRegion); +BOOL ReadConsoleOutputW(HANDLE hConsoleOutput, PCHAR_INFO lpBuffer, COORD dwBufferSize, COORD dwBufferCoord, PSMALL_RECT lpReadRegion); +BOOL WriteConsoleOutputA(HANDLE hConsoleOutput, CHAR_INFO *lpBuffer, COORD dwBufferSize, COORD dwBufferCoord, PSMALL_RECT lpWriteRegion); +BOOL WriteConsoleOutputW(HANDLE hConsoleOutput, CHAR_INFO *lpBuffer, COORD dwBufferSize, COORD dwBufferCoord, PSMALL_RECT lpWriteRegion); +BOOL ReadConsoleOutputCharacterA(HANDLE hConsoleOutput, LPSTR lpCharacter, DWORD nLength, COORD dwReadCoord, LPDWORD lpNumberOfCharsRead); +BOOL ReadConsoleOutputCharacterW(HANDLE hConsoleOutput, LPWSTR lpCharacter, DWORD nLength, COORD dwReadCoord, LPDWORD lpNumberOfCharsRead); +BOOL ReadConsoleOutputAttribute(HANDLE hConsoleOutput, LPWORD lpAttribute, DWORD nLength, COORD dwReadCoord, LPDWORD lpNumberOfAttrsRead); +BOOL WriteConsoleOutputCharacterA(HANDLE hConsoleOutput, LPCSTR lpCharacter, DWORD nLength, COORD dwWriteCoord, LPDWORD lpNumberOfCharsWritten); +BOOL WriteConsoleOutputCharacterW(HANDLE hConsoleOutput, LPCWSTR lpCharacter, DWORD nLength, COORD dwWriteCoord, LPDWORD lpNumberOfCharsWritten); +BOOL WriteConsoleOutputAttribute(HANDLE hConsoleOutput, WORD *lpAttribute, DWORD nLength, COORD dwWriteCoord, LPDWORD lpNumberOfAttrsWritten); +BOOL FillConsoleOutputCharacterA(HANDLE hConsoleOutput, CHAR cCharacter, DWORD nLength, COORD dwWriteCoord, LPDWORD lpNumberOfCharsWritten); +BOOL FillConsoleOutputCharacterW(HANDLE hConsoleOutput, WCHAR cCharacter, DWORD nLength, COORD dwWriteCoord, LPDWORD lpNumberOfCharsWritten); +BOOL FillConsoleOutputAttribute(HANDLE hConsoleOutput, WORD wAttribute, DWORD nLength, COORD dwWriteCoord, LPDWORD lpNumberOfAttrsWritten); +BOOL GetConsoleMode(HANDLE hConsoleHandle, LPDWORD lpMode); +BOOL GetNumberOfConsoleInputEvents(HANDLE hConsoleInput, LPDWORD lpNumberOfEvents); +BOOL GetConsoleScreenBufferInfo(HANDLE hConsoleOutput, PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo); +COORD GetLargestConsoleWindowSize( HANDLE hConsoleOutput); +BOOL GetConsoleCursorInfo(HANDLE hConsoleOutput, PCONSOLE_CURSOR_INFO lpConsoleCursorInfo); +BOOL GetNumberOfConsoleMouseButtons( LPDWORD lpNumberOfMouseButtons); +BOOL SetConsoleMode(HANDLE hConsoleHandle, DWORD dwMode); +BOOL SetConsoleActiveScreenBuffer(HANDLE hConsoleOutput); +BOOL FlushConsoleInputBuffer(HANDLE hConsoleInput); +BOOL SetConsoleScreenBufferSize(HANDLE hConsoleOutput, COORD dwSize); +BOOL SetConsoleCursorPosition(HANDLE hConsoleOutput, COORD dwCursorPosition); +BOOL SetConsoleCursorInfo(HANDLE hConsoleOutput, CONSOLE_CURSOR_INFO *lpConsoleCursorInfo); +BOOL ScrollConsoleScreenBufferA(HANDLE hConsoleOutput, SMALL_RECT *lpScrollRectangle, SMALL_RECT *lpClipRectangle, COORD dwDestinationOrigin, CHAR_INFO *lpFill); +BOOL ScrollConsoleScreenBufferW(HANDLE hConsoleOutput, SMALL_RECT *lpScrollRectangle, SMALL_RECT *lpClipRectangle, COORD dwDestinationOrigin, CHAR_INFO *lpFill); +BOOL SetConsoleWindowInfo(HANDLE hConsoleOutput, BOOL bAbsolute, SMALL_RECT *lpConsoleWindow); +BOOL SetConsoleTextAttribute(HANDLE hConsoleOutput, WORD wAttributes); +alias BOOL(*PHANDLER_ROUTINE)(DWORD CtrlType); +BOOL SetConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine, BOOL Add); +BOOL GenerateConsoleCtrlEvent( DWORD dwCtrlEvent, DWORD dwProcessGroupId); +BOOL AllocConsole(); +BOOL FreeConsole(); +DWORD GetConsoleTitleA(LPSTR lpConsoleTitle, DWORD nSize); +DWORD GetConsoleTitleW(LPWSTR lpConsoleTitle, DWORD nSize); +BOOL SetConsoleTitleA(LPCSTR lpConsoleTitle); +BOOL SetConsoleTitleW(LPCWSTR lpConsoleTitle); +BOOL ReadConsoleA(HANDLE hConsoleInput, LPVOID lpBuffer, DWORD nNumberOfCharsToRead, LPDWORD lpNumberOfCharsRead, LPVOID lpReserved); +BOOL ReadConsoleW(HANDLE hConsoleInput, LPVOID lpBuffer, DWORD nNumberOfCharsToRead, LPDWORD lpNumberOfCharsRead, LPVOID lpReserved); +BOOL WriteConsoleA(HANDLE hConsoleOutput, void *lpBuffer, DWORD nNumberOfCharsToWrite, LPDWORD lpNumberOfCharsWritten, LPVOID lpReserved); +BOOL WriteConsoleW(HANDLE hConsoleOutput, void *lpBuffer, DWORD nNumberOfCharsToWrite, LPDWORD lpNumberOfCharsWritten, LPVOID lpReserved); +HANDLE CreateConsoleScreenBuffer(DWORD dwDesiredAccess, DWORD dwShareMode, SECURITY_ATTRIBUTES *lpSecurityAttributes, DWORD dwFlags, LPVOID lpScreenBufferData); +UINT GetConsoleCP(); +BOOL SetConsoleCP( UINT wCodePageID); +UINT GetConsoleOutputCP(); +BOOL SetConsoleOutputCP(UINT wCodePageID); + +enum : int +{ + CONSOLE_TEXTMODE_BUFFER = 1, +} + +enum +{ + SM_CXSCREEN = 0, + SM_CYSCREEN = 1, + SM_CXVSCROLL = 2, + SM_CYHSCROLL = 3, + SM_CYCAPTION = 4, + SM_CXBORDER = 5, + SM_CYBORDER = 6, + SM_CXDLGFRAME = 7, + SM_CYDLGFRAME = 8, + SM_CYVTHUMB = 9, + SM_CXHTHUMB = 10, + SM_CXICON = 11, + SM_CYICON = 12, + SM_CXCURSOR = 13, + SM_CYCURSOR = 14, + SM_CYMENU = 15, + SM_CXFULLSCREEN = 16, + SM_CYFULLSCREEN = 17, + SM_CYKANJIWINDOW = 18, + SM_MOUSEPRESENT = 19, + SM_CYVSCROLL = 20, + SM_CXHSCROLL = 21, + SM_DEBUG = 22, + SM_SWAPBUTTON = 23, + SM_RESERVED1 = 24, + SM_RESERVED2 = 25, + SM_RESERVED3 = 26, + SM_RESERVED4 = 27, + SM_CXMIN = 28, + SM_CYMIN = 29, + SM_CXSIZE = 30, + SM_CYSIZE = 31, + SM_CXFRAME = 32, + SM_CYFRAME = 33, + SM_CXMINTRACK = 34, + SM_CYMINTRACK = 35, + SM_CXDOUBLECLK = 36, + SM_CYDOUBLECLK = 37, + SM_CXICONSPACING = 38, + SM_CYICONSPACING = 39, + SM_MENUDROPALIGNMENT = 40, + SM_PENWINDOWS = 41, + SM_DBCSENABLED = 42, + SM_CMOUSEBUTTONS = 43, + + + SM_CXFIXEDFRAME = SM_CXDLGFRAME, + SM_CYFIXEDFRAME = SM_CYDLGFRAME, + SM_CXSIZEFRAME = SM_CXFRAME, + SM_CYSIZEFRAME = SM_CYFRAME, + + SM_SECURE = 44, + SM_CXEDGE = 45, + SM_CYEDGE = 46, + SM_CXMINSPACING = 47, + SM_CYMINSPACING = 48, + SM_CXSMICON = 49, + SM_CYSMICON = 50, + SM_CYSMCAPTION = 51, + SM_CXSMSIZE = 52, + SM_CYSMSIZE = 53, + SM_CXMENUSIZE = 54, + SM_CYMENUSIZE = 55, + SM_ARRANGE = 56, + SM_CXMINIMIZED = 57, + SM_CYMINIMIZED = 58, + SM_CXMAXTRACK = 59, + SM_CYMAXTRACK = 60, + SM_CXMAXIMIZED = 61, + SM_CYMAXIMIZED = 62, + SM_NETWORK = 63, + SM_CLEANBOOT = 67, + SM_CXDRAG = 68, + SM_CYDRAG = 69, + SM_SHOWSOUNDS = 70, + SM_CXMENUCHECK = 71, + SM_CYMENUCHECK = 72, + SM_SLOWMACHINE = 73, + SM_MIDEASTENABLED = 74, + SM_CMETRICS = 75, +} + +int GetSystemMetrics(int nIndex); + +} Index: d/phobos/std/c/linux/socket.d =================================================================== --- d/phobos/std/c/linux/socket.d (Revision 199) +++ d/phobos/std/c/linux/socket.d (Arbeitskopie) @@ -235,6 +235,7 @@ MSG_OOB = 0x1, MSG_PEEK = 0x2, MSG_DONTROUTE = 0x4, + MSG_NOSIGNAL = 0x4000, } Index: d/phobos/std/c/stdlib.d =================================================================== --- d/phobos/std/c/stdlib.d (Revision 199) +++ d/phobos/std/c/stdlib.d (Arbeitskopie) @@ -1,6 +1,7 @@ /** * C's <stdlib.h> - * Authors: Walter Bright, Digital Mars, www.digitalmars.com + * D Programming Language runtime library + * Authors: Walter Bright, Digital Mars, http://www.digitalmars.com * License: Public Domain * Macros: * WIKI=Phobos/StdCStdlib Index: d/phobos/std/zlib.d =================================================================== --- d/phobos/std/zlib.d (Revision 199) +++ d/phobos/std/zlib.d (Arbeitskopie) @@ -20,7 +20,7 @@ //debug=zlib; // uncomment to turn on debugging printf's -private import etc.c.zlib, std.stdint, std.gc; +private import etc.c.zlib, std.stdint; // Values for 'mode' @@ -117,13 +117,13 @@ body { int err; - void[] destbuf; + ubyte[] destbuf; Culong_t destlen; destlen = srcbuf.length + ((srcbuf.length + 1023) / 1024) + 12; - destbuf = new void[destlen]; + destbuf = new ubyte[destlen]; std.gc.hasNoPointers(destbuf.ptr); - err = etc.c.zlib.compress2(cast(ubyte *)destbuf, &destlen, cast(ubyte *)srcbuf, srcbuf.length, level); + err = etc.c.zlib.compress2(destbuf.ptr, &destlen, cast(ubyte *)srcbuf, srcbuf.length, level); if (err) { delete destbuf; throw new ZlibException(err); @@ -153,7 +153,7 @@ void[] uncompress(void[] srcbuf, size_t destlen = 0u, int winbits = 15) { int err; - void[] destbuf; + ubyte[] destbuf; if (!destlen) destlen = srcbuf.length * 2 + 1; @@ -162,13 +162,12 @@ { etc.c.zlib.z_stream zs; - destbuf = new void[destlen]; - std.gc.hasNoPointers(destbuf.ptr); + destbuf = new ubyte[destlen]; zs.next_in = cast(ubyte*) srcbuf; zs.avail_in = srcbuf.length; - zs.next_out = cast(ubyte*)destbuf; + zs.next_out = destbuf.ptr; zs.avail_out = destlen; err = etc.c.zlib.inflateInit2(&zs, winbits); @@ -291,7 +290,7 @@ */ void[] compress(void[] buf) { int err; - void[] destbuf; + ubyte[] destbuf; if (buf.length == 0) return null; @@ -304,9 +303,8 @@ inited = 1; } - destbuf = new void[zs.avail_in + buf.length]; - std.gc.hasNoPointers(destbuf.ptr); - zs.next_out = cast(ubyte*) destbuf.ptr; + destbuf = new ubyte[zs.avail_in + buf.length]; + zs.next_out = destbuf.ptr; zs.avail_out = destbuf.length; if (zs.avail_in) @@ -455,7 +453,7 @@ } body { int err; - void[] destbuf; + ubyte[] destbuf; if (buf.length == 0) return null; @@ -470,9 +468,8 @@ if (!destbufsize) destbufsize = buf.length * 2; - destbuf = new void[zs.avail_in * 2 + destbufsize]; - std.gc.hasNoPointers(destbuf.ptr); - zs.next_out = cast(ubyte*) destbuf; + destbuf = new ubyte[zs.avail_in * 2 + destbufsize]; + zs.next_out = destbuf.ptr; zs.avail_out = destbuf.length; if (zs.avail_in) @@ -506,8 +503,8 @@ } body { - void[] extra; - void[] destbuf; + ubyte[] extra; + ubyte[] destbuf; int err; done = 1; @@ -515,9 +512,8 @@ return null; L1: - destbuf = new void[zs.avail_in * 2 + 100]; - std.gc.hasNoPointers(destbuf.ptr); - zs.next_out = cast(ubyte*) destbuf; + destbuf = new ubyte[zs.avail_in * 2 + 100]; + zs.next_out = destbuf.ptr; zs.avail_out = destbuf.length; err = etc.c.zlib.inflate(&zs, Z_NO_FLUSH); @@ -533,7 +529,7 @@ err = Z_BUF_ERROR; error(err); } - destbuf = cast(void[])((cast(ubyte*)destbuf)[0 .. zs.next_out - cast(ubyte*)destbuf]); + destbuf = destbuf.ptr[0 .. zs.next_out - destbuf.ptr]; err = etc.c.zlib.inflateEnd(&zs); inited = 0; if (err) Index: d/phobos/std/conv.d =================================================================== --- d/phobos/std/conv.d (Revision 199) +++ d/phobos/std/conv.d (Arbeitskopie) @@ -1,4 +1,3 @@ - // Written in the D programming language. /* @@ -944,6 +943,11 @@ // nan f = toFloat("nan"); assert(toString(f) == toString(float.nan)); + + bool ok = false; + try toFloat("\x00"); + catch (ConvError e) ok = true; + assert(ok); } /******************************************************* @@ -1013,6 +1017,11 @@ d = toDouble("nan"); assert(toString(d) == toString(double.nan)); //assert(cast(real)d == cast(real)double.nan); + + bool ok = false; + try toDouble("\x00"); + catch (ConvError e) ok = true; + assert(ok); } /******************************************************* @@ -1086,6 +1095,11 @@ r = toReal(toString(real.nan)); assert(toString(r) == toString(real.nan)); //assert(r == real.nan); + + bool ok = false; + try toReal("\x00"); + catch (ConvError e) ok = true; + assert(ok); } version (none) Index: d/phobos/std/thread.d =================================================================== --- d/phobos/std/thread.d (Revision 199) +++ d/phobos/std/thread.d (Arbeitskopie) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2002-2006 by Digital Mars, www.digitalmars.com + * Copyright (C) 2002-2007 by Digital Mars, www.digitalmars.com * Written by Walter Bright * * This software is provided 'as-is', without any express or implied @@ -40,6 +40,8 @@ module std.thread; +import std.c.stdio; + //debug=thread; /* ================================ Win32 ================================= */ @@ -56,6 +58,8 @@ stdfp start_addr, void* arglist, uint initflag, thread_id* thrdaddr); +private const uint WAIT_TIMEOUT = 258; + /** * The type of the thread handle used by the operating system. * For Windows, it is equivalent to a HANDLE from windows.d. @@ -69,7 +73,7 @@ */ class ThreadError : Error { - this(char[] s) + this(string s) { super("Thread error: " ~ s); } @@ -110,6 +114,17 @@ } /** + * Destructor + * + * If the thread hasn't been joined yet, detach it. + */ + ~this() + { + if (state != TS.FINISHED) + CloseHandle(hdl); + } + + /** * The handle to this thread assigned by the operating system. This is set * to thread_id.init if the thread hasn't been started yet. */ @@ -123,11 +138,11 @@ */ void start() { + synchronized (Thread.classinfo) + { if (state != TS.INITIAL) error("already started"); - synchronized (threadLock) - { for (int i = 0; 1; i++) { if (i == allThreads.length) @@ -141,17 +156,19 @@ } } nthreads++; - } state = TS.RUNNING; hdl = _beginthreadex(null, cast(uint)stacksize, &threadstart, cast(void*)this, 0, &id); if (hdl == cast(thread_hdl)0) - { state = TS.TERMINATED; + { allThreads[idx] = null; + nthreads--; + state = TS.FINISHED; idx = -1; error("failed to start"); } } + } /** * Entry point for a thread. If not overridden, it calls the function @@ -176,12 +193,15 @@ */ void wait() { - if (this is getThis()) + if (isSelf) error("wait on self"); - if (state == TS.RUNNING) + if (state != TS.FINISHED) { DWORD dw; dw = WaitForSingleObject(hdl, 0xFFFFFFFF); + state = TS.FINISHED; + CloseHandle(hdl); + hdl = null; } } @@ -193,12 +213,18 @@ */ void wait(uint milliseconds) { - if (this is getThis()) + if (isSelf) error("wait on self"); - if (state == TS.RUNNING) + if (state != TS.FINISHED) { DWORD dw; dw = WaitForSingleObject(hdl, milliseconds); + if (dw != WAIT_TIMEOUT) + { + state = TS.FINISHED; + CloseHandle(hdl); + hdl = null; + } } } @@ -209,7 +235,8 @@ { INITIAL, /// The thread hasn't been started yet. RUNNING, /// The thread is running or paused. - TERMINATED /// The thread has ended. + TERMINATED, /// The thread has ended. + FINISHED /// The thread has been cleaned up } /** @@ -228,7 +255,8 @@ INCREASE, /// Increase thread priority DECREASE, /// Decrease thread priority IDLE, /// Assign thread low priority - CRITICAL /// Assign thread high priority + CRITICAL, /// Assign thread high priority + NORMAL } /** @@ -253,6 +281,9 @@ case PRIORITY.CRITICAL: nPriority = THREAD_PRIORITY_TIME_CRITICAL; break; + case PRIORITY.NORMAL: + nPriority = THREAD_PRIORITY_NORMAL; + break; default: assert(0); } @@ -276,13 +307,8 @@ */ static Thread getThis() { - thread_id id; - Thread result; - //printf("getThis(), allThreadsDim = %d\n", allThreadsDim); - synchronized (threadLock) - { - id = GetCurrentThreadId(); + thread_id id = GetCurrentThreadId(); for (int i = 0; i < allThreadsDim; i++) { Thread t = allThreads[i]; @@ -291,10 +317,8 @@ return t; } } - } printf("didn't find it\n"); - assert(result); - return result; + assert(0); } /** @@ -302,7 +326,7 @@ */ static Thread[] getAll() { - return allThreads[0 .. allThreadsDim]; + synchronized (Thread.classinfo) return allThreads[0 .. allThreadsDim]; } /** @@ -328,38 +352,42 @@ */ static void pauseAll() { + synchronized (Thread.classinfo) + { if (nthreads > 1) { - Thread tthis = getThis(); + thread_id thisid = GetCurrentThreadId(); for (int i = 0; i < allThreadsDim; i++) - { Thread t; - - t = allThreads[i]; - if (t && t !is tthis && t.state == TS.RUNNING) + { + Thread t = allThreads[i]; + if (t && t.id != thisid && t.state == TS.RUNNING) t.pause(); } } } + } /** * Resume execution of all paused threads. */ static void resumeAll() { + synchronized (Thread.classinfo) + { if (nthreads > 1) { - Thread tthis = getThis(); + thread_id thisid = GetCurrentThreadId(); for (int i = 0; i < allThreadsDim; i++) - { Thread t; - - t = allThreads[i]; - if (t && t !is tthis && t.state == TS.RUNNING) + { + Thread t = allThreads[i]; + if (t && t.id != thisid && t.state == TS.RUNNING) t.resume(); } } } + } /** * Give up the remainder of this thread's time slice. @@ -377,7 +405,6 @@ private: static uint allThreadsDim; - static Object threadLock; static Thread[0x400] allThreads; // length matches value in C runtime TS state; @@ -390,7 +417,7 @@ int delegate() dg; - void error(char[] msg) + void error(string msg) { throw new ThreadError(msg); } @@ -413,16 +440,18 @@ } catch (Object o) { - printf("Error: "); - o.print(); + fprintf(stderr, "Error: %.*s\n", o.toString()); result = 1; } debug (thread) printf("Ending thread %d\n", t.idx); + synchronized (Thread.classinfo) + { + allThreads[t.idx] = null; + nthreads--; t.state = TS.TERMINATED; - allThreads[t.idx] = null; t.idx = -1; - nthreads--; + } return result; } @@ -433,8 +462,6 @@ public static void thread_init() { - threadLock = new Object(); - Thread t = new Thread(); t.state = TS.RUNNING; @@ -536,7 +563,7 @@ class ThreadError : Error { - this(char[] s) + this(string s) { super("Thread error: " ~ s); } @@ -568,6 +595,8 @@ { pthread_cond_destroy(&waitCond); pthread_mutex_destroy(&waitMtx); + if (state != TS.FINISHED) + pthread_detach(id); } pthread_t id; @@ -579,7 +608,7 @@ if (state != TS.INITIAL) error("already started"); - synchronized (threadLock) + synchronized (Thread.classinfo) { for (int i = 0; 1; i++) { @@ -596,14 +625,13 @@ nthreads++; state = TS.RUNNING; - int result; //printf("creating thread x%x\n", this); //result = pthread_create(&id, null, &threadstart, this); // Create with thread attributes to allow non-default stack size - Dave Fladebo - result = pthread_create(&id, &threadAttrs, &threadstart, cast(void*)this); + int result = pthread_create(&id, &threadAttrs, &threadstart, cast(void*)this); if (result) - { state = TS.TERMINATED; - allThreads[idx] = null; + { state = TS.FINISHED; + synchronized (Thread.classinfo) allThreads[idx] = null; idx = -1; error("failed to start"); // BUG: should report errno } @@ -622,25 +650,15 @@ void wait() { - if (this is getThis()) + if (isSelf) error("wait on self"); - /* Sean Kelly writes: - * Change to: - * if (state != TS.INITIAL) - * Because it is not only legal to call pthread_join on a thread that - * has run and finished, but calling pthread_join or pthread_detach is - * required for the thread resources to be released. However, it is - * illegal to call pthread_join more than once, and I believe it is also - * illegal to detach a thread that has already been joined, so 'id' - * should probably be cleared after join/detach is called, and this - * value tested along with 'state' before performing thread ops. - */ - if (state == TS.RUNNING) - { int result; + if (state != TS.FINISHED) + { void *value; - result = pthread_join(id, &value); + int result = pthread_join(id, &value); + state = TS.FINISHED; if (result) error("failed to wait"); } @@ -649,9 +667,9 @@ void wait(uint milliseconds) { // Implemented for POSIX systems by Dave Fladebo - if (this is getThis()) + if (isSelf) error("wait on self"); - if (state == TS.RUNNING) + if (state != TS.FINISHED) { timespec ts; timeval tv; @@ -683,9 +701,12 @@ pthread_setcanceltype(oldtype, null); state = TS.TERMINATED; + synchronized (Thread.classinfo) + { allThreads[idx] = null; idx = -1; nthreads--; + } pthread_mutex_unlock(&waitMtx); } @@ -699,9 +720,10 @@ enum TS { - INITIAL, - RUNNING, - TERMINATED + INITIAL, // created + RUNNING, // running + TERMINATED, // execution finished + FINISHED // pthread_join()'ed } TS getState() @@ -751,13 +773,8 @@ static Thread getThis() { - pthread_t id; - Thread result; - //printf("getThis(), allThreadsDim = %d\n", allThreadsDim); - //synchronized (threadLock) - { - id = pthread_self(); + pthread_t id = pthread_self(); //printf("id = %d\n", id); for (int i = 0; i < allThreadsDim; i++) { @@ -768,15 +785,13 @@ return t; } } - } printf("didn't find it\n"); - assert(result); - return result; + assert(null); } static Thread[] getAll() { - return allThreads[0 .. allThreadsDim]; + synchronized (Thread.classinfo) return allThreads[0 .. allThreadsDim]; } void pause() @@ -789,10 +804,9 @@ error("cannot pause"); } else - { int result; + { - result = pthread_kill(id, SIGUSR1); - if (result) + if (pthread_kill(id, SIGUSR1)) error("cannot pause"); else flagSuspend.wait(); // wait for acknowledgement @@ -812,10 +826,8 @@ error("cannot pause"); } else - { int result; - - result = pthread_kill(id, SIGUSR2); - if (result) + { + if (pthread_kill(id, SIGUSR2)) error("cannot resume"); } } @@ -825,24 +837,21 @@ static void pauseAll() { + synchronized(Thread.classinfo) + { version (GNU_pthread_suspend) { if (nthreads > 1) { - Thread tthis = getThis(); - - synchronized (threadLock) - { + pthread_t thisid = pthread_self(); for (int i = 0; i < allThreadsDim; i++) - { Thread t; + { - t = allThreads[i]; - if (t && t !is tthis && t.state == TS.RUNNING) + Thread t = allThreads[i]; + if (t && !pthread_equal(thisid, t.id) && t.state == TS.RUNNING) t.pause(); } - - } } } else @@ -850,54 +859,50 @@ if (nthreads > 1) { - Thread tthis = getThis(); + pthread_t thisid = pthread_self(); int npause = 0; - synchronized (threadLock) + for (int i = 0; i < allThreadsDim; i++) { - - for (int i = 0; i < allThreadsDim; i++) - { Thread t; - t = allThreads[i]; - if (t && t !is tthis && t.state == TS.RUNNING) - { int result; - - result = pthread_kill(t.id, SIGUSR1); - if (result) + Thread t = allThreads[i]; + if (t && !pthread_equal(thisid, t.id) && t.state == TS.RUNNING) + { + if (pthread_kill(t.id, SIGUSR1)) getThis().error("cannot pause"); else npause++; // count of paused threads } } - } - // Wait for each paused thread to acknowledge while (npause--) { flagSuspend.wait(); } } - } + } } static void resumeAll() { + synchronized (Thread.classinfo) + { if (nthreads > 1) { - Thread tthis = getThis(); + pthread_t thisid = pthread_self(); for (int i = 0; i < allThreadsDim; i++) - { Thread t; + { - t = allThreads[i]; - if (t && t !is tthis && t.state == TS.RUNNING) + Thread t = allThreads[i]; + if (t && t.id != thisid && t.state == TS.RUNNING) t.resume(); } } } + } static void yield() { @@ -909,7 +914,6 @@ private: static uint allThreadsDim; - static Object threadLock; // Set max to Windows equivalent for compatibility. // pthread_create will fail gracefully if stack limit @@ -938,7 +942,7 @@ int delegate() dg; - void error(char[] msg) + void error(string msg) { throw new ThreadError(msg); } @@ -978,7 +982,7 @@ t.id = pthread_self(); version(skyos) - installSignalHandlers(); + installSignalHandlers(t); t.stackBottom = getESP(); try @@ -989,15 +993,14 @@ } catch (Object o) { - printf("Error: "); - o.print(); + fprintf(stderr, "Error: %.*s\n", o.toString()); result = 1; } debug (thread) printf("Ending thread %d\n", t.idx); - synchronized (threadLock) + t.state = TS.TERMINATED; + synchronized (Thread.classinfo) { - t.state = TS.TERMINATED; allThreads[t.idx] = null; t.idx = -1; nthreads--; @@ -1012,8 +1015,6 @@ public static void thread_init() { - threadLock = new Object(); - Thread t = new Thread(); t.state = TS.RUNNING; @@ -1033,7 +1034,7 @@ { /* Install signal handlers so we can suspend/resume threads */ - installSignalHandlers(); + installSignalHandlers(t); } return; @@ -1047,7 +1048,7 @@ else { - private static void installSignalHandlers() + private static void installSignalHandlers(Thread t) { int result; sigaction_t sigact; @@ -1068,7 +1069,7 @@ return; Lfail: - getThis().error("cannot initialize threads"); + t.error("cannot initialize threads"); } Index: d/phobos/std/moduleinit.d =================================================================== --- d/phobos/std/moduleinit.d (Revision 199) +++ d/phobos/std/moduleinit.d (Arbeitskopie) @@ -1,3 +1,4 @@ +// Written in the D programming language /* NOTE: This file has been patched from the original DMD distribution to work with the GDC compiler. @@ -23,6 +24,7 @@ MIctordone = 2, // finished construction MIstandalone = 4, // module ctor does not depend on other module // ctors being done first + MIhasictor = 8, // has ictor member } /*********************** @@ -36,10 +38,14 @@ uint flags; // initialization state - void (*ctor)(); - void (*dtor)(); - void (*unitTest)(); + void (*ctor)(); // module static constructor (order dependent) + void (*dtor)(); // module static destructor + void (*unitTest)(); // module unit tests + void* xgetMembers; // module getMembers() function + + void (*ictor)(); // module static constructor (order independent) + /****************** * Return collection of all modules in the program. */ @@ -53,7 +59,8 @@ { this(ModuleInfo m) { - super("circular initialization dependency with module " ~ m.name); + super(cast(string) ("circular initialization dependency with module " + ~ m.name)); } } @@ -119,6 +126,7 @@ _moduleinfo_dtors = new ModuleInfo[_moduleinfo_array.length]; debug printf("_moduleinfo_dtors = x%x\n", cast(void *)_moduleinfo_dtors); + _moduleIndependentCtors(); _moduleCtor2(_moduleinfo_array, 0); version (none) @@ -227,3 +235,20 @@ } } +/********************************** + * Run unit tests. + */ + +extern (C) void _moduleIndependentCtors() +{ + debug printf("_moduleIndependentCtors()\n"); + foreach (m; _moduleinfo_array) + { + if (m && m.flags & MIhasictor && m.ictor) + { + (*m.ictor)(); + } + } +} + + Index: d/phobos/std/mmfile.d =================================================================== --- d/phobos/std/mmfile.d (Revision 199) +++ d/phobos/std/mmfile.d (Arbeitskopie) @@ -1,4 +1,6 @@ -/* Copyright 2004-2005 by Digital Mars +// Written in the D programming language + +/* Copyright 2004-2008 by Digital Mars * Written by Walter Bright and Matthew Wilson * * This software is provided 'as-is', without any express or implied @@ -105,7 +107,7 @@ * Throws: * std.file.FileException */ - this(char[] filename) + this(string filename) { this(filename, Mode.Read, 0, null); } @@ -128,7 +130,7 @@ * Throws: * std.file.FileException */ - this(char[] filename, Mode mode, ulong size, void* address, + this(string filename, Mode mode, ulong size, void* address, size_t window = 0) { this.filename = filename; @@ -194,9 +196,11 @@ assert(0); } + if (filename) + { if (useWfuncs) { - wchar* namez = std.utf.toUTF16z(filename); + auto namez = std.utf.toUTF16z(filename); hFile = CreateFileW(namez, dwDesiredAccess2, dwShareMode, @@ -207,7 +211,7 @@ } else { - char* namez = std.file.toMBSz(filename); + auto namez = std.file.toMBSz(filename); hFile = CreateFileA(namez, dwDesiredAccess2, dwShareMode, @@ -218,6 +222,9 @@ } if (hFile == INVALID_HANDLE_VALUE) goto err1; + } + else + hFile = null; int hi = cast(int)(size>>32); hFileMap = CreateFileMappingA(hFile, null, flProtect, hi, cast(uint)size, null); @@ -360,7 +367,7 @@ errNo(); hFileMap = null; - if (hFile != INVALID_HANDLE_VALUE && CloseHandle(hFile) != TRUE) + if (hFile && hFile != INVALID_HANDLE_VALUE && CloseHandle(hFile) != TRUE) errNo(); hFile = INVALID_HANDLE_VALUE; } @@ -552,7 +559,7 @@ } private: - char[] filename; + string filename; void[] data; ulong start; size_t window; @@ -634,5 +641,8 @@ assert( data2[length-1] == 'b' ); delete mf; std.file.remove("testing.txt"); + + // Create anonymous mapping + auto test = new MmFile(null, MmFile.Mode.ReadWriteNew, 1024*1024, null); } } Index: d/phobos/std/file.d =================================================================== --- d/phobos/std/file.d (Revision 199) +++ d/phobos/std/file.d (Arbeitskopie) @@ -852,11 +852,10 @@ private import std.c.unix.unix; private import std.date; +private import std.c.string; alias std.c.unix.unix unix; -extern (C) char* strerror(int); - /*********************************** */ @@ -876,7 +875,8 @@ } this(char[] name, uint errno) - { char* s = strerror(errno); + { char[80] buf = void; + auto s = strerror_r(errno, buf.ptr, buf.length); this(name, std.string.toString(s).dup); this.errno = errno; } Index: d/phobos/std/socket.d =================================================================== --- d/phobos/std/socket.d (Revision 199) +++ d/phobos/std/socket.d (Arbeitskopie) @@ -108,12 +108,10 @@ { if(errorCode > 0) { - char* cs; - size_t len; + char[80] buf; + auto cs = strerror_r(errorCode, buf.ptr, buf.length); + auto len = strlen(cs); - cs = strerror(errorCode); - len = strlen(cs); - if(cs[len - 1] == '\n') len--; if(cs[len - 1] == '\r') @@ -484,7 +482,8 @@ */ bool getHostByName(string name) { - hostent* he = gethostbyname(toStringz(name)); + hostent* he; + synchronized(this.classinfo) he = gethostbyname(toStringz(name)); if(!he) return false; validHostent(he); @@ -499,7 +498,8 @@ bool getHostByAddr(uint addr) { uint x = htonl(addr); - hostent* he = gethostbyaddr(&x, 4, cast(int)AddressFamily.INET); + hostent* he; + synchronized(this.classinfo) he = gethostbyaddr(&x, 4, cast(int)AddressFamily.INET); if(!he) return false; validHostent(he); @@ -516,7 +516,8 @@ bool getHostByAddr(string addr) { uint x = inet_addr(std.string.toStringz(addr)); - hostent* he = gethostbyaddr(&x, 4, cast(int)AddressFamily.INET); + hostent* he; + synchronized(this.classinfo) he = gethostbyaddr(&x, 4, cast(int)AddressFamily.INET); if(!he) return false; validHostent(he); @@ -764,6 +765,7 @@ OOB = MSG_OOB, /// out-of-band stream data PEEK = MSG_PEEK, /// peek at incoming data without removing it from the queue, only for receiving DONTROUTE = MSG_DONTROUTE, /// data should not be subject to routing; this flag may be ignored. Only for sending + NOSIGNAL = MSG_NOSIGNAL, /// don't send SIGPIPE signal on socket write error and instead return EPIPE } @@ -1325,6 +1327,7 @@ //returns number of bytes actually sent, or -1 on error int send(void[] buf, SocketFlags flags) { + flags |= SocketFlags.NOSIGNAL; int sent = .send(sock, buf.ptr, buf.length, cast(int)flags); return sent; } @@ -1332,7 +1335,7 @@ /// ditto int send(void[] buf) { - return send(buf, SocketFlags.NONE); + return send(buf, SocketFlags.NOSIGNAL); } /** @@ -1340,6 +1343,7 @@ */ int sendTo(void[] buf, SocketFlags flags, Address to) { + flags |= SocketFlags.NOSIGNAL; int sent = .sendto(sock, buf.ptr, buf.length, cast(int)flags, to.name(), to.nameLen()); return sent; } @@ -1355,6 +1359,7 @@ /// ditto int sendTo(void[] buf, SocketFlags flags) { + flags |= SocketFlags.NOSIGNAL; int sent = .sendto(sock, buf.ptr, buf.length, cast(int)flags, null, 0); return sent; } Index: d/phobos/unittest.d =================================================================== --- d/phobos/unittest.d (Revision 199) +++ d/phobos/unittest.d (Arbeitskopie) @@ -52,6 +52,7 @@ import std.file; import std.signals; import std.cpuid; +import std.socket; int main(char[][] args) { Index: d/phobos/std.ddoc =================================================================== --- d/phobos/std.ddoc (Revision 199) +++ d/phobos/std.ddoc (Arbeitskopie) @@ -3,7 +3,7 @@