From f416f6c4814a45ab93e5f881dfdd380a47983f36 Mon Sep 17 00:00:00 2001 From: Evgenii Guryanov Date: Thu, 7 Sep 2017 23:10:29 +0300 Subject: [PATCH] fun can start with with an uppercase letter --- src/lib_c/x86_64-windows-msvc/c/winapi.cr | 92 +++++++++++------------ src/winerror.cr | 4 +- 2 files changed, 48 insertions(+), 48 deletions(-) diff --git a/src/lib_c/x86_64-windows-msvc/c/winapi.cr b/src/lib_c/x86_64-windows-msvc/c/winapi.cr index 5be837139bfa..bda7cfea4077 100644 --- a/src/lib_c/x86_64-windows-msvc/c/winapi.cr +++ b/src/lib_c/x86_64-windows-msvc/c/winapi.cr @@ -33,7 +33,7 @@ lib LibC INVALID_HANDLE_VALUE = Pointer(Void).new((-1).to_u64) INFINITY = 0xFFFFFFFF_u32 - fun _DuplicateHandle = DuplicateHandle(source_process : Handle, source : Handle, target_process : Handle, target : Handle*, desired_access : DWord, inherit_handle : Bool, options : DWord) : Bool + fun DuplicateHandle(source_process : Handle, source : Handle, target_process : Handle, target : Handle*, desired_access : DWord, inherit_handle : Bool, options : DWord) : Bool # member names are not original otherwise they would be really confusing struct OVERLAPPED @@ -49,18 +49,18 @@ lib LibC bInheritHandle : BOOL end - fun _GetStdHandle = GetStdHandle(std_handle : DWord) : Handle - fun _GetFileType = GetFileType(file : Handle) : DWord - fun _CreateFileA = CreateFileA(filename : UInt8*, access : DWord, sharemode : DWord, security_attributes : SECURITY_ATTRIBUTES*, creation : DWord, flags : DWord, template : Handle) : Handle - fun _ReadFile = ReadFile(file : Handle, buffer : UInt8*, size : DWord, read : DWord*, overlapped : OVERLAPPED*) : Bool - fun _WriteFile = WriteFile(file : Handle, buffer : UInt8*, size : DWord, written : DWord*, overlapped : OVERLAPPED*) : Bool - fun _CloseHandle = CloseHandle(file : Handle) : Bool + fun GetStdHandle(std_handle : DWord) : Handle + fun GetFileType(file : Handle) : DWord + fun CreateFileA(filename : UInt8*, access : DWord, sharemode : DWord, security_attributes : SECURITY_ATTRIBUTES*, creation : DWord, flags : DWord, template : Handle) : Handle + fun ReadFile(file : Handle, buffer : UInt8*, size : DWord, read : DWord*, overlapped : OVERLAPPED*) : Bool + fun WriteFile(file : Handle, buffer : UInt8*, size : DWord, written : DWord*, overlapped : OVERLAPPED*) : Bool + fun CloseHandle(file : Handle) : Bool - fun _GetCurrentDirectoryA = GetCurrentDirectoryA(size : DWord, buffer : UInt8*) : DWord - fun _SetCurrentDirectoryA = SetCurrentDirectoryA(path : UInt8*) : BOOL - fun _CreateDirectoryA = CreateDirectoryA(path : UInt8*, security_attribute : Void*) : BOOL - fun _RemoveDirectoryA = RemoveDirectoryA(path : UInt8*) : BOOL - fun _GetTempPathA = GetTempPathA(len : DWord, buffer : UInt8*) : DWord + fun GetCurrentDirectoryA(size : DWord, buffer : UInt8*) : DWord + fun SetCurrentDirectoryA(path : UInt8*) : BOOL + fun CreateDirectoryA(path : UInt8*, security_attribute : Void*) : BOOL + fun RemoveDirectoryA(path : UInt8*) : BOOL + fun GetTempPathA(len : DWord, buffer : UInt8*) : DWord MAX_PATH = 260 @@ -98,40 +98,40 @@ lib LibC FILE_END = 2_i32 INVALID_SET_FILE_POINTER = (-1).to_u32 - fun _FindFirstFileA = FindFirstFileA(fileName : UInt8*, filedata : WIN32_FIND_DATA_A*) : Handle - fun _FindNextFileA = FindNextFileA(file : Handle, filedata : WIN32_FIND_DATA_A*) : BOOL - fun _FindClose = FindClose(file : Handle) : BOOL - fun _GetFileAttributesA = GetFileAttributesA(filename : UInt8*) : DWord - fun _GetFileSize = GetFileSize(file : Handle, fileSizeHigh : DWord*) : DWord - fun _GetFileSizeEx = GetFileSizeEx(file : Handle, size : UInt64*) : BOOL - fun _GetFileTime = GetFileTime(file : Handle, lpCreationTime : FILETIME*, lpLastAccessTime : FILETIME*, lpLastWriteTime : FILETIME*) : BOOL - fun _SetFilePointer = SetFilePointer(file : Handle, lDistanceToMove : Long, lpDistanceToMoveHigh : Long*, dwMoveMethod : DWord) : DWord - fun _SetEndOfFile = SetEndOfFile(file : Handle) : BOOL - fun _DeleteFileA = DeleteFileA(filename : UInt8*) : BOOL - fun _GetFullPathNameA = GetFullPathNameA(filename : UInt8*, buf_len : DWord, lpBuffer : UInt8*, lpFilePart : UInt8**) : DWord + fun FindFirstFileA(fileName : UInt8*, filedata : WIN32_FIND_DATA_A*) : Handle + fun FindNextFileA(file : Handle, filedata : WIN32_FIND_DATA_A*) : BOOL + fun FindClose(file : Handle) : BOOL + fun GetFileAttributesA(filename : UInt8*) : DWord + fun GetFileSize(file : Handle, fileSizeHigh : DWord*) : DWord + fun GetFileSizeEx(file : Handle, size : UInt64*) : BOOL + fun GetFileTime(file : Handle, lpCreationTime : FILETIME*, lpLastAccessTime : FILETIME*, lpLastWriteTime : FILETIME*) : BOOL + fun SetFilePointer(file : Handle, lDistanceToMove : Long, lpDistanceToMoveHigh : Long*, dwMoveMethod : DWord) : DWord + fun SetEndOfFile(file : Handle) : BOOL + fun DeleteFileA(filename : UInt8*) : BOOL + fun GetFullPathNameA(filename : UInt8*, buf_len : DWord, lpBuffer : UInt8*, lpFilePart : UInt8**) : DWord # from Shlwapi.lib # fun _PathFileExistsA = PathFileExistsA(path : UInt8*) : BOOL - fun _MoveFileA = MoveFileA(lpExistingFileName : UInt8*, lpNewFileName : UInt8*) : BOOL - fun _GetTempFileNameA = GetTempFileNameA(path_name : UInt8*, prefix : UInt8*, unique_num : UInt32, temp_file_name : UInt8*) : UInt32 + fun MoveFileA(lpExistingFileName : UInt8*, lpNewFileName : UInt8*) : BOOL + fun GetTempFileNameA(path_name : UInt8*, prefix : UInt8*, unique_num : UInt32, temp_file_name : UInt8*) : UInt32 - fun _CreateIoCompletionPort = CreateIoCompletionPort(file : Handle, port : Handle, data : Void*, threads : DWord) : Handle - fun _GetQueuedCompletionStatus = GetQueuedCompletionStatus(port : Handle, bytes_transfered : DWord*, data : Void**, entry : OVERLAPPED**, timeout_millis : DWord) : Bool - fun _PostQueuedCompletionStatus = PostQueuedCompletionStatus(port : Handle, bytes_transfered : DWord, data : Void*, entry : OVERLAPPED*) : Bool - fun _GetCurrentProcess = GetCurrentProcess : Handle - fun _GetCurrentThread = GetCurrentThread : Handle - fun _CreatePipe = CreatePipe(hReadPipe : UInt64*, hWritePipe : UInt64*, lpPipeAttributes : SECURITY_ATTRIBUTES*, nSize : DWord) : BOOL - fun _PeekNamedPipe = PeekNamedPipe(hNamedPipe : Handle, lpBuffer : UInt8*, nBufferSize : DWord, lpBytesRead : DWord*, lpTotalBytesAvail : DWord*, lpBytesLeftThisMessage : DWord*) : BOOL + fun CreateIoCompletionPort(file : Handle, port : Handle, data : Void*, threads : DWord) : Handle + fun GetQueuedCompletionStatus(port : Handle, bytes_transfered : DWord*, data : Void**, entry : OVERLAPPED**, timeout_millis : DWord) : Bool + fun PostQueuedCompletionStatus(port : Handle, bytes_transfered : DWord, data : Void*, entry : OVERLAPPED*) : Bool + fun GetCurrentProcess : Handle + fun GetCurrentThread : Handle + fun CreatePipe(hReadPipe : UInt64*, hWritePipe : UInt64*, lpPipeAttributes : SECURITY_ATTRIBUTES*, nSize : DWord) : BOOL + fun PeekNamedPipe(hNamedPipe : Handle, lpBuffer : UInt8*, nBufferSize : DWord, lpBytesRead : DWord*, lpTotalBytesAvail : DWord*, lpBytesLeftThisMessage : DWord*) : BOOL WAIT_ABANDONED = 0x00000080_u32 WAIT_OBJECT_0 = 0x00000000_u32 WAIT_TIMEOUT = 0x00000102_u32 WAIT_FAILED = 0xFFFFFFFF_u32 - fun _WaitForSingleObject = WaitForSingleObject(handle : Handle, timeout_millis : DWord) : DWord - fun _CreateTimerQueueTimer = CreateTimerQueueTimer(timer_handle : Handle*, queue_handle : Handle, callback : (Void*, Bool) ->, data : Void*, due : DWord, period : DWord, flags : SizeT) : Bool - fun _DeleteTimerQueueTimer = DeleteTimerQueueTimer(queue_handle : Handle, timer_handle : Handle, completion_event : Handle) : Bool - fun _GetLastError = GetLastError : DWord - fun _SetLastError = SetLastError(code : DWord) : Void + fun WaitForSingleObject(handle : Handle, timeout_millis : DWord) : DWord + fun CreateTimerQueueTimer(timer_handle : Handle*, queue_handle : Handle, callback : (Void*, Bool) ->, data : Void*, due : DWord, period : DWord, flags : SizeT) : Bool + fun DeleteTimerQueueTimer(queue_handle : Handle, timer_handle : Handle, completion_event : Handle) : Bool + fun GetLastError : DWord + fun SetLastError(code : DWord) : Void # STARTUPINFOA.deFlags STARTF_USESTDHANDLES = 0x00000100_u32 @@ -168,12 +168,12 @@ lib LibC dwThreadId : DWord end - fun _CreateProcessA = CreateProcessA(lpApplicationName : UInt8*, lpCommandLine : UInt8*, + fun CreateProcessA(lpApplicationName : UInt8*, lpCommandLine : UInt8*, lpProcessAttributes : SECURITY_ATTRIBUTES*, lpThreadAttributes : SECURITY_ATTRIBUTES*, bInheritHandles : BOOL, dwCreationFlags : DWord, lpEnvironment : Void*, lpCurrentDirectory : UInt8*, lpStartupInfo : STARTUPINFOA*, lpProcessInformation : PROCESS_INFORMATION*) : BOOL - fun _KillProcess = KillProcess(hProcess : Handle, uExitCode : UInt32) : BOOL - fun _GetExitCodeProcess = GetExitCodeProcess(hProcess : Handle, lpExitCode : DWord*) : BOOL + fun KillProcess(hProcess : Handle, uExitCode : UInt32) : BOOL + fun GetExitCodeProcess(hProcess : Handle, lpExitCode : DWord*) : BOOL FORMAT_MESSAGE_ALLOCATE_BUFFER = 0x00000100_u32 FORMAT_MESSAGE_IGNORE_INSERTS = 0x00000200_u32 @@ -182,7 +182,7 @@ lib LibC FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000_u32 FORMAT_MESSAGE_ARGUMENT_ARRAY = 0x00002000_u32 - fun _FormatMessageA = FormatMessageA(flags : DWord, source : Void*, msg : DWord, lang : DWord, buffer : UInt8*, size : DWord, args : Void*) : DWord + fun FormatMessageA(flags : DWord, source : Void*, msg : DWord, lang : DWord, buffer : UInt8*, size : DWord, args : Void*) : DWord WSASYSNOTREADY = 10091 WSAVERNOTSUPPORTED = 10092 @@ -201,7 +201,7 @@ lib LibC lpVendorInfo : UInt8* end - fun _WSAStartup = WSAStartup(version : Int16, data : WSAData*) : Int32 + fun WSAStartup(version : Int16, data : WSAData*) : Int32 # source https://msdn.microsoft.com/en-us/library/windows/desktop/ms724950(v=vs.85).aspx struct SystemTime @@ -226,12 +226,12 @@ lib LibC _DaylightBias : Long end - fun _GetTimeZoneInformation = GetTimeZoneInformation(tz_info : TIME_ZONE_INFORMATION*) : DWord - fun _GetSystemTimeAsFileTime = GetSystemTimeAsFileTime(time : FILETIME*) + fun GetTimeZoneInformation(tz_info : TIME_ZONE_INFORMATION*) : DWord + fun GetSystemTimeAsFileTime(time : FILETIME*) - fun _GetComputerNameA = GetComputerNameA(buffer : UInt8*, size : DWord*) : BOOL + fun GetComputerNameA(buffer : UInt8*, size : DWord*) : BOOL - fun _CxxThrowException = _CxxThrowException(exception_object : Void*, throw_info : Void*) : NoReturn + fun _CxxThrowException(exception_object : Void*, throw_info : Void*) : NoReturn end module WindowsExt diff --git a/src/winerror.cr b/src/winerror.cr index c107dab01845..00a6ddd39fd9 100644 --- a/src/winerror.cr +++ b/src/winerror.cr @@ -2,12 +2,12 @@ class WinError < Errno # NOTE: `get_last_error` must be called BEFORE an instance of this class # is malloced as it would change the "last error" to SUCCESS def self.new(message) - new(message, LibC._GetLastError) + new(message, LibC.GetLastError) end def initialize(message, code) buffer = uninitialized UInt8[256] - size = LibC._FormatMessageA(LibC::FORMAT_MESSAGE_FROM_SYSTEM, nil, code, 0, buffer, buffer.size, nil) + size = LibC.FormatMessageA(LibC::FORMAT_MESSAGE_FROM_SYSTEM, nil, code, 0, buffer, buffer.size, nil) details = String.new(buffer.to_unsafe, size).strip super("#{message}: [WinError #{code}, #{details}]", winerror_to_errno(code)) end