Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions spec/support/time.cr
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ end
fun SetDynamicTimeZoneInformation(lpTimeZoneInformation : DYNAMIC_TIME_ZONE_INFORMATION*) : BOOL
end

private SeTimeZonePrivilege = Crystal::System.to_wstr("SeTimeZonePrivilege")

module Crystal::System::Time
private SeTimeZonePrivilege = System.wstr_literal "SeTimeZonePrivilege"

# Enable the `SeTimeZonePrivilege` privilege before changing the system time
# zone. This is necessary because the privilege is by default granted but
# disabled for any new process. This only needs to be done once per run.
Expand Down
2 changes: 1 addition & 1 deletion src/crystal/system/win32/mime.cr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "./windows_registry"

module Crystal::System::MIME
CONTENT_TYPE = "Content Type".to_utf16
CONTENT_TYPE = System.wstr_literal "Content Type"

# Load MIME types from operating system source.
def self.load
Expand Down
8 changes: 4 additions & 4 deletions src/crystal/system/win32/time.cr
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,10 @@ module Crystal::System::Time
return stdname, dstname
end

REGISTRY_TIME_ZONES = %q(SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones).to_utf16
Std = "Std".to_utf16
Dlt = "Dlt".to_utf16
TZI = "TZI".to_utf16
REGISTRY_TIME_ZONES = System.wstr_literal %q(SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones)
Std = System.wstr_literal "Std"
Dlt = System.wstr_literal "Dlt"
TZI = System.wstr_literal "TZI"

# Searches the registry for an English name of a time zone named *stdname* or *dstname*
# and returns the English name.
Expand Down
4 changes: 2 additions & 2 deletions src/crystal/system/win32/user.cr
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ module Crystal::System::User
end
end

private REGISTRY_PROFILE_LIST = %q(SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList).to_utf16
private ProfileImagePath = "ProfileImagePath".to_utf16
private REGISTRY_PROFILE_LIST = System.wstr_literal %q(SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList)
private ProfileImagePath = System.wstr_literal "ProfileImagePath"

private def self.lookup_home_directory(uid : String, username : String) : String?
# If this user has logged in at least once their home path should be stored
Expand Down
8 changes: 4 additions & 4 deletions src/crystal/system/win32/windows_sdk.cr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
require "./windows_registry"

module Crystal::System::WindowsSDK
REGISTRY_WIN10_SDK_64 = %q(SOFTWARE\WOW6432Node\Microsoft\Microsoft SDKs\Windows\v10.0).to_utf16
REGISTRY_WIN10_SDK_32 = %q(SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0).to_utf16
REGISTRY_WIN10_SDK_64 = System.wstr_literal %q(SOFTWARE\WOW6432Node\Microsoft\Microsoft SDKs\Windows\v10.0)
REGISTRY_WIN10_SDK_32 = System.wstr_literal %q(SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0)

InstallationFolder = "InstallationFolder".to_utf16
ProductVersion = "ProductVersion".to_utf16
InstallationFolder = System.wstr_literal "InstallationFolder"
ProductVersion = System.wstr_literal "ProductVersion"

def self.find_win10_sdk_libpath : ::Path?
# ported from Common7\Tools\vsdevcmd\core\winsdk.bat (loaded by the MSVC
Expand Down
16 changes: 16 additions & 0 deletions src/crystal/system/windows.cr
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@ module Crystal::System
str.check_no_null_byte(name).to_utf16.to_unsafe
end

# Converts the string literal *str* into a `Slice` of UTF-16 code points.
# *str* must not contain embedded null characters.
#
# This is equivalent to the macro `StringLiteral#to_utf16` if slice literals
# are available, and the normal `String#to_utf16` otherwise. This is useful
# for passing constant string arguments to Win32 functions.
{% if compare_versions(Crystal::VERSION, "1.16.0") >= 0 %}
macro wstr_literal(str)
\{{ str.to_utf16 }}
end
{% else %}
macro wstr_literal(str)
(\{{ str }}).check_no_null_byte.to_utf16
end
{% end %}

def self.sid_to_s(sid : LibC::SID*) : String
if LibC.ConvertSidToStringSidW(sid, out ptr) == 0
raise RuntimeError.from_winerror("ConvertSidToStringSidW")
Expand Down
1 change: 1 addition & 0 deletions src/crystal/tracing.cr
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ module Crystal
{% if flag?(:win32) %}
buf = uninitialized UInt16[256]

# FIXME: use `System.wstr_literal` after #15746 is available
name = UInt16.static_array({% for chr in "CRYSTAL_TRACE".chars %}{{chr.ord}}, {% end %} 0)
len = LibC.GetEnvironmentVariableW(name, buf, buf.size)
parse_sections(buf.to_slice[0...len]) if len > 0
Expand Down