From 74873949364f16980a338ec0ef82901dcd63b68d Mon Sep 17 00:00:00 2001 From: Jonathan Marler Date: Sat, 18 Jul 2026 13:09:55 -0600 Subject: [PATCH] remove unicode aliases and UNICODE option --- examples/basewin.zig | 4 +-- src/genzig.zig | 19 ----------- src/genzigexports.zig | 3 -- src/metadata.zig | 1 - src/static/win32/windowlongptr.zig | 12 ------- src/static/win32/zig.zig | 35 ------------------- src/textparse.zig | 55 +----------------------------- 7 files changed, 3 insertions(+), 126 deletions(-) diff --git a/examples/basewin.zig b/examples/basewin.zig index 7c1d0e9..40e340c 100644 --- a/examples/basewin.zig +++ b/examples/basewin.zig @@ -18,11 +18,11 @@ pub fn BaseWindow(comptime DERIVED_TYPE: type) type { if (uMsg == win32.WM_NCCREATE) { const pCreate: *win32.CREATESTRUCTW = @ptrFromInt(@as(usize, @bitCast(lParam))); pThis = @ptrCast(@alignCast(pCreate.lpCreateParams)); - _ = windowlongptr.SetWindowLongPtr(hwnd, win32.GWL_USERDATA, @bitCast(@intFromPtr(pThis))); + _ = windowlongptr.SetWindowLongPtrW(hwnd, win32.GWL_USERDATA, @bitCast(@intFromPtr(pThis))); pThis.?.base.m_hwnd = hwnd; } else { //pThis = @intToPtr(?*DERIVED_TYPE, @bitCast(usize, windowlongptr.GetWindowLongPtr(hwnd, win32.GWL_USERDATA))); - pThis = @ptrFromInt(@as(usize, @bitCast(windowlongptr.GetWindowLongPtr(hwnd, win32.GWL_USERDATA)))); + pThis = @ptrFromInt(@as(usize, @bitCast(windowlongptr.GetWindowLongPtrW(hwnd, win32.GWL_USERDATA)))); } if (pThis) |this| { return this.HandleMessage(uMsg, wParam, lParam); diff --git a/src/genzig.zig b/src/genzig.zig index 1d8eaf9..abf3bfc 100644 --- a/src/genzig.zig +++ b/src/genzig.zig @@ -871,10 +871,6 @@ fn generateFile(module_dir: std.fs.Dir, module: *Module, api: metadata.Api) !voi } std.debug.assert(api.Functions.len >= sdk_file.func_exports.count()); try writer.line(""); - try writer.line("//--------------------------------------------------------------------------------"); - try writer.linef("// Section: Unicode Aliases ({})", .{api.UnicodeAliases.len}); - try writer.line("//--------------------------------------------------------------------------------"); - try generateUnicodeAliases(sdk_file, writer, api.UnicodeAliases); const import_total = @intFromBool(sdk_file.uses_guid) + sdk_file.top_level_api_imports.count(); try writer.line("//--------------------------------------------------------------------------------"); try writer.linef("// Section: Imports ({})", .{import_total}); @@ -3137,21 +3133,6 @@ fn generateParams( } } -fn generateUnicodeAliases(sdk_file: *SdkFile, writer: *CodeWriter, unicode_aliases: []const []const u8) !void { - for (unicode_aliases) |alias| { - try writer.linef( - "pub const {s} = switch (@import(\"{s}zig.zig\").unicode_mode) {{", - .{ alias, sdk_file.getWin32DirImportPrefix() }, - ); - try writer.linef(" .ansi => @This().{s}A,", .{alias}); - try writer.linef(" .wide => @This().{s}W,", .{alias}); - try writer.line(" .unspecified => if (@import(\"builtin\").is_test) void else @compileError("); - try writer.linef(" \"'{0s}' requires that UNICODE be set to true or false in the root module\",", .{alias}); - try writer.line(" ),"); - try writer.line("};"); - } -} - pub fn formatArchesCase(filter: metadata.Architectures.Filter, buf: []u8) !usize { var fbs = std.io.fixedBufferStream(buf); const arch_writer = fbs.writer(); diff --git a/src/genzigexports.zig b/src/genzigexports.zig index 4a035a6..a5f7f3f 100644 --- a/src/genzigexports.zig +++ b/src/genzigexports.zig @@ -2,9 +2,6 @@ const std = @import("std"); const win32_stub = @import("win32_stub"); const zig = win32_stub.zig; -// make win32/zig.zig happy -pub const UNICODE = true; - pub fn main() !void { var arena_instance = std.heap.ArenaAllocator.init(std.heap.page_allocator); const arena = arena_instance.allocator(); diff --git a/src/metadata.zig b/src/metadata.zig index fa1a32e..b5839fd 100644 --- a/src/metadata.zig +++ b/src/metadata.zig @@ -2,7 +2,6 @@ pub const Api = struct { Constants: []const Constant, Types: []const Type, Functions: []const Function, - UnicodeAliases: []const []const u8, }; pub const ValueType = enum { diff --git a/src/static/win32/windowlongptr.zig b/src/static/win32/windowlongptr.zig index 8ffff2c..0cc2512 100644 --- a/src/static/win32/windowlongptr.zig +++ b/src/static/win32/windowlongptr.zig @@ -21,15 +21,3 @@ pub const GetWindowLongPtrW = if (@sizeOf(usize) == 8) win32.ui.windows_and_messaging.GetWindowLongPtrW else win32.ui.windows_and_messaging.GetWindowLongW; - -pub const SetWindowLongPtr = switch (@import("zig.zig").unicode_mode) { - .ansi => SetWindowLongPtrA, - .wide => SetWindowLongPtrW, - .unspecified => if (@import("builtin").is_test) *opaque {} else @compileError("'SetWindowLongPtr' requires that UNICODE be set to true or false in the root module"), -}; - -pub const GetWindowLongPtr = switch (@import("zig.zig").unicode_mode) { - .ansi => GetWindowLongPtrA, - .wide => GetWindowLongPtrW, - .unspecified => if (@import("builtin").is_test) *opaque {} else @compileError("'GetWindowLongPtr' requires that UNICODE be set to true or false in the root module"), -}; diff --git a/src/static/win32/zig.zig b/src/static/win32/zig.zig index 0e0eda1..4add366 100644 --- a/src/static/win32/zig.zig +++ b/src/static/win32/zig.zig @@ -45,27 +45,8 @@ const win32 = struct { const GetDpiForWindow = mod_root.ui.hi_dpi.GetDpiForWindow; }; -const root = @import("root"); -pub const UnicodeMode = enum { ansi, wide, unspecified }; -pub const unicode_mode: UnicodeMode = if (@hasDecl(root, "UNICODE")) (if (root.UNICODE) .wide else .ansi) else .unspecified; - pub const L = std.unicode.utf8ToUtf16LeStringLiteral; -pub const TCHAR = switch (unicode_mode) { - .ansi => u8, - .wide => u16, - .unspecified => if (builtin.is_test) void else @compileError("'TCHAR' requires that UNICODE be set to true or false in the root module"), -}; -pub const _T = switch (unicode_mode) { - .ansi => (struct { - pub fn _T(comptime str: []const u8) *const [str.len:0]u8 { - return str; - } - })._T, - .wide => L, - .unspecified => if (builtin.is_test) void else @compileError("'_T' requires that UNICODE be set to true or false in the root module"), -}; - pub const Arch = enum { X86, X64, Arm64 }; pub const arch: Arch = switch (builtin.target.cpu.arch) { .x86 => .X86, @@ -402,22 +383,6 @@ pub const has_window_longptr = switch (arch) { .X64, .Arm64 => true, }; -pub const getWindowLongPtr = switch (unicode_mode) { - .ansi => getWindowLongPtrA, - .wide => getWindowLongPtrW, - .unspecified => if (builtin.is_test) struct {} else @compileError( - "getWindowLongPtr requires that UNICODE be set to true or false in the root module", - ), -}; - -pub const setWindowLongPtr = switch (unicode_mode) { - .ansi => setWindowLongPtrA, - .wide => setWindowLongPtrW, - .unspecified => if (builtin.is_test) struct {} else @compileError( - "setWindowLongPtr requires that UNICODE be set to true or false in the root module", - ), -}; - pub fn getWindowLongPtrA(hwnd: win32.HWND, index: i32) usize { if (!has_window_longptr) @compileError("this arch does not have GetWindowLongPtr"); return @bitCast(win32.GetWindowLongPtrA(hwnd, @enumFromInt(index))); diff --git a/src/textparse.zig b/src/textparse.zig index 7f25882..c0a4128 100644 --- a/src/textparse.zig +++ b/src/textparse.zig @@ -2,7 +2,7 @@ //! see dumpwinmd-grammar.md) and rebuilds `metadata.Api`, applying the win32 //! corrections that dumpwinmd deliberately leaves out — patches, the //! MediaFoundation constant filter, ComClassID/not_com derivation, MissingClrType -//! classification, UnicodeAliases, and the platform string->enum mapping. +//! classification, and the platform string->enum mapping. //! This is the generator's input path: winmd -> text (dumpwinmd) -> model (here) //! -> bindings. It reads text only; it does not depend on `winmd`. @@ -387,12 +387,10 @@ fn finalize( ) void { switch (frame.data) { .api => |*a| { - const aliases = deriveAliases(arena, a.types.items, a.funcs.items); result.append(arena, .{ .name = a.name, .api = .{ .Constants = a.consts.items, .Types = a.types.items, .Functions = a.funcs.items, - .UnicodeAliases = aliases, } }) catch |e| oom(e); }, .enum_ => |*e| attachType(arena, stack, .{ @@ -562,57 +560,6 @@ fn deriveComment(arena: std.mem.Allocator, constfields: []const ConstField) ?[]c return aw.written(); } -// Derives UnicodeAliases from the type and function names (base names that have -// both an "A" and a "W" variant). Types are visited -// before functions, in declaration order. -fn deriveAliases(arena: std.mem.Allocator, types: []const metadata.Type, funcs: []const metadata.Function) []const []const u8 { - var ua: UnicodeAliases = .{}; - for (types) |t| ua.add(arena, t.Name); - for (funcs) |f| ua.add(arena, f.Name); - var aliases: std.ArrayListUnmanaged([]const u8) = .empty; - var it = ua.map.iterator(); - while (it.next()) |entry| switch (entry.value_ptr.*) { - .base_exists, .a_only, .w_only => {}, - .both => aliases.append(arena, entry.key_ptr.*) catch |e| oom(e), - }; - return aliases.items; -} - -const UnicodeAliases = struct { - map: std.StringArrayHashMapUnmanaged(State) = .{}, - const State = enum { base_exists, a_only, w_only, both }; - pub fn add(aliases: *UnicodeAliases, allocator: std.mem.Allocator, name: []const u8) void { - if (name.len <= 1) return; - const kind: enum { a, w, base }, const key = blk: { - if (std.mem.endsWith(u8, name, "A")) break :blk .{ .a, name[0 .. name.len - 1] }; - if (std.mem.endsWith(u8, name, "W")) break :blk .{ .w, name[0 .. name.len - 1] }; - break :blk .{ .base, name }; - }; - const entry = aliases.map.getOrPut(allocator, key) catch |e| oom(e); - const sub_kind: enum { a, w } = switch (kind) { - .a => .a, - .w => .w, - .base => { - entry.value_ptr.* = .base_exists; - return; - }, - }; - if (entry.found_existing) switch (entry.value_ptr.*) { - .base_exists => return, - .a_only => if (sub_kind == .w) { - entry.value_ptr.* = .both; - }, - .w_only => if (sub_kind == .a) { - entry.value_ptr.* = .both; - }, - .both => {}, - } else entry.value_ptr.* = switch (sub_kind) { - .a => .a_only, - .w => .w_only, - }; - } -}; - // Windows.* CLR types that are referenced but not defined in this winmd (dumpwinmd // emits them as `extref`); the reference generator classified these as MissingClrType. fn isKnownMissingClrType(namespace: []const u8, name: []const u8) bool {