소스 검색

fix sokol-zig codegen for zig 0.15.0-dev.1034+bd97b6618 (callconv and removed Writer usage)

Andre Weissflog 1 주 전
부모
커밋
199dc85b61
1개의 변경된 파일6개의 추가작업 그리고 26개의 파일을 삭제
  1. 6 26
      bindgen/gen_zig.py

+ 6 - 26
bindgen/gen_zig.py

@@ -352,7 +352,7 @@ def gen_struct(decl, prefix):
         elif is_const_prim_ptr(field_type):
             l(f"    {field_name}: ?[*]const {as_zig_prim_type(util.extract_ptr_type(field_type))} = null,")
         elif util.is_func_ptr(field_type):
-            l(f"    {field_name}: ?*const fn ({funcptr_args_c(field_type, prefix)}) callconv(.C) {funcptr_result_c(field_type)} = null,")
+            l(f"    {field_name}: ?*const fn ({funcptr_args_c(field_type, prefix)}) callconv(.c) {funcptr_result_c(field_type)} = null,")
         elif util.is_1d_array_type(field_type):
             array_type = util.extract_array_type(field_type)
             array_sizes = util.extract_array_sizes(field_type)
@@ -507,33 +507,13 @@ def gen_helpers(inp):
         l('}')
         l('')
     if inp['prefix'] == 'sdtx_':
-        l('// std.fmt compatible Writer')
-        l('pub const Writer = struct {')
-        l('    pub const Error = error{};')
-        l('    pub fn writeAll(self: Writer, bytes: []const u8) Error!void {')
-        l('        _ = self;')
-        l('        for (bytes) |byte| {')
-        l('            putc(byte);')
-        l('        }')
-        l('    }')
-        l('    pub fn writeByteNTimes(self: Writer, byte: u8, n: usize) Error!void {')
-        l('        _ = self;')
-        l('        var i: u64 = 0;')
-        l('        while (i < n) : (i += 1) {')
-        l('            putc(byte);')
-        l('        }')
-        l('    }')
-        l('    pub fn writeBytesNTimes(self: Writer, bytes: []const u8, n: usize) Error!void {')
-        l('        var i: usize = 0;')
-        l('        while (i < n) : (i += 1) {')
-        l('            try self.writeAll(bytes);')
-        l('        }')
-        l('    }')
-        l('};')
         l('// std.fmt-style formatted print')
         l('pub fn print(comptime fmt: anytype, args: anytype) void {')
-        l('    const writer: Writer = .{};')
-        l('    @import("std").fmt.format(writer, fmt, args) catch {};')
+        l('    const cbuf = getClearedFmtBuffer();')
+        l('    const p: [*]u8 = @constCast(@ptrCast(cbuf.ptr));')
+        l('    const buf = p[0..cbuf.size];')
+        l('    const out = @import("std").fmt.bufPrint(buf, fmt, args) catch "";')
+        l('    for (out) |c| putc(c);')
         l('}')
         l('')