| author | |
| committer | |
| log | 553f0e0546e0ceecf2ff735443d9a2c2f282b8db |
| tree | 42257c00a7315bc9eb531718390050deffa4022e |
| parent | 7eb938c9096db54fe6e99148824252904c79c227 |
| signature |
9 files changed, 55 insertions(+), 83 deletions(-)
lib/std/array_list.zig+17-19| ... | ... | @@ -189,32 +189,30 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type { |
| 189 | 189 | self.len += items.len; |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | pub usingnamespace if (T == u8) | |
| 193 | struct { | |
| 194 | /// Same as `append` except it returns the number of bytes written, which is always the same | |
| 195 | /// as `m.len`. The purpose of this function existing is to match `std.io.OutStream` API. | |
| 196 | fn appendWrite(self: *Self, m: []const u8) !usize { | |
| 197 | try self.appendSlice(m); | |
| 198 | return m.len; | |
| 199 | } | |
| 200 | ||
| 201 | pub fn outStream(self: *Self) std.io.OutStream(*Self, error{OutOfMemory}, appendWrite) { | |
| 202 | return .{ .context = self }; | |
| 203 | } | |
| 204 | } | |
| 205 | else | |
| 206 | struct {}; | |
| 192 | /// Same as `append` except it returns the number of bytes written, which is always the same | |
| 193 | /// as `m.len`. The purpose of this function existing is to match `std.io.OutStream` API. | |
| 194 | /// This function may be called only when `T` is `u8`. | |
| 195 | fn appendWrite(self: *Self, m: []const u8) !usize { | |
| 196 | try self.appendSlice(m); | |
| 197 | return m.len; | |
| 198 | } | |
| 199 | ||
| 200 | /// Initializes an OutStream which will append to the list. | |
| 201 | /// This function may be called only when `T` is `u8`. | |
| 202 | pub fn outStream(self: *Self) std.io.OutStream(*Self, error{OutOfMemory}, appendWrite) { | |
| 203 | return .{ .context = self }; | |
| 204 | } | |
| 207 | 205 | |
| 208 | /// Append a value to the list `n` times. Allocates more memory | |
| 209 | /// as necessary. | |
| 206 | /// Append a value to the list `n` times. | |
| 207 | /// Allocates more memory as necessary. | |
| 210 | 208 | pub fn appendNTimes(self: *Self, value: T, n: usize) !void { |
| 211 | 209 | const old_len = self.len; |
| 212 | 210 | try self.resize(self.len + n); |
| 213 | 211 | mem.set(T, self.items[old_len..self.len], value); |
| 214 | 212 | } |
| 215 | 213 | |
| 216 | /// Adjust the list's length to `new_len`. Doesn't initialize | |
| 217 | /// added items if any. | |
| 214 | /// Adjust the list's length to `new_len`. | |
| 215 | /// Does not initialize added items if any. | |
| 218 | 216 | pub fn resize(self: *Self, new_len: usize) !void { |
| 219 | 217 | try self.ensureCapacity(new_len); |
| 220 | 218 | self.len = new_len; |
lib/std/build.zig-1| ... | ... | @@ -1961,7 +1961,6 @@ pub const LibExeObjStep = struct { |
| 1961 | 1961 | } |
| 1962 | 1962 | } else { |
| 1963 | 1963 | var mcpu_buffer = std.ArrayList(u8).init(builder.allocator); |
| 1964 | errdefer mcpu_buffer.deinit(); | |
| 1965 | 1964 | |
| 1966 | 1965 | try mcpu_buffer.outStream().print("-mcpu={}", .{cross.cpu.model.name}); |
| 1967 | 1966 |
lib/std/child_process.zig-1| ... | ... | @@ -757,7 +757,6 @@ fn windowsCreateProcess(app_name: [*:0]u16, cmd_line: [*:0]u16, envp_ptr: ?[*]u1 |
| 757 | 757 | } |
| 758 | 758 | |
| 759 | 759 | /// Caller must dealloc. |
| 760 | /// Guarantees a null byte at result[result.len]. | |
| 761 | 760 | fn windowsCreateCommandLine(allocator: *mem.Allocator, argv: []const []const u8) ![:0]u8 { |
| 762 | 761 | var buf = try Buffer.initSize(allocator, 0); |
| 763 | 762 | defer buf.deinit(); |
lib/std/zig/cross_target.zig+1-1| ... | ... | @@ -504,7 +504,7 @@ pub const CrossTarget = struct { |
| 504 | 504 | const os_name = if (self.os_tag) |os_tag| @tagName(os_tag) else "native"; |
| 505 | 505 | |
| 506 | 506 | var result = std.ArrayList(u8).init(allocator); |
| 507 | errdefer result.deinit(); | |
| 507 | defer result.deinit(); | |
| 508 | 508 | |
| 509 | 509 | try result.outStream().print("{}-{}", .{ arch_name, os_name }); |
| 510 | 510 |
src-self-hosted/libc_installation.zig+27-54| ... | ... | @@ -327,20 +327,14 @@ pub const LibCInstallation = struct { |
| 327 | 327 | var search_buf: [2]Search = undefined; |
| 328 | 328 | const searches = fillSearch(&search_buf, sdk); |
| 329 | 329 | |
| 330 | var result_buf = std.ArrayList([]const u8).init(allocator); | |
| 331 | defer result_buf.deinit(); | |
| 332 | ||
| 330 | 333 | for (searches) |search| { |
| 331 | const dir_path = try fs.path.join( | |
| 332 | allocator, | |
| 333 | &[_][]const u8{ | |
| 334 | search.path, | |
| 335 | "Include", | |
| 336 | search.version, | |
| 337 | "ucrt", | |
| 338 | }, | |
| 339 | ); | |
| 340 | var found = false; | |
| 341 | defer if (!found) allocator.free(dir_path); | |
| 342 | ||
| 343 | var dir = fs.cwd().openDir(dir_path, .{}) catch |err| switch (err) { | |
| 334 | result_buf.shrink(0); | |
| 335 | try result_buf.outStream().print("{}\\Include\\{}\\ucrt", .{ search.path, search.version }); | |
| 336 | ||
| 337 | var dir = fs.cwd().openDir(result_buf.span(), .{}) catch |err| switch (err) { | |
| 344 | 338 | error.FileNotFound, |
| 345 | 339 | error.NotDir, |
| 346 | 340 | error.NoDevice, |
| ... | ... | @@ -355,8 +349,7 @@ pub const LibCInstallation = struct { |
| 355 | 349 | else => return error.FileSystem, |
| 356 | 350 | }; |
| 357 | 351 | |
| 358 | found = true; | |
| 359 | self.include_dir = dir_path; | |
| 352 | self.include_dir = result_buf.toOwnedSlice(); | |
| 360 | 353 | return; |
| 361 | 354 | } |
| 362 | 355 | |
| ... | ... | @@ -373,6 +366,9 @@ pub const LibCInstallation = struct { |
| 373 | 366 | var search_buf: [2]Search = undefined; |
| 374 | 367 | const searches = fillSearch(&search_buf, sdk); |
| 375 | 368 | |
| 369 | var result_buf = try std.ArrayList([]const u8).init(allocator); | |
| 370 | defer result_buf.deinit(); | |
| 371 | ||
| 376 | 372 | const arch_sub_dir = switch (builtin.arch) { |
| 377 | 373 | .i386 => "x86", |
| 378 | 374 | .x86_64 => "x64", |
| ... | ... | @@ -381,20 +377,10 @@ pub const LibCInstallation = struct { |
| 381 | 377 | }; |
| 382 | 378 | |
| 383 | 379 | for (searches) |search| { |
| 384 | const dir_path = try fs.path.join( | |
| 385 | allocator, | |
| 386 | &[_][]const u8{ | |
| 387 | search.path, | |
| 388 | "Lib", | |
| 389 | search.version, | |
| 390 | "ucrt", | |
| 391 | arch_sub_dir, | |
| 392 | }, | |
| 393 | ); | |
| 394 | var found = false; | |
| 395 | defer if (!found) allocator.free(dir_path); | |
| 396 | ||
| 397 | var dir = fs.cwd().openDir(dir_path, .{}) catch |err| switch (err) { | |
| 380 | result_buf.shrink(0); | |
| 381 | try result_buf.outStream().print("{}\\Lib\\{}\\ucrt\\{}", .{ search.path, search.version, arch_sub_dir }); | |
| 382 | ||
| 383 | var dir = fs.cwd().openDir(result_buf.span(), .{}) catch |err| switch (err) { | |
| 398 | 384 | error.FileNotFound, |
| 399 | 385 | error.NotDir, |
| 400 | 386 | error.NoDevice, |
| ... | ... | @@ -409,8 +395,7 @@ pub const LibCInstallation = struct { |
| 409 | 395 | else => return error.FileSystem, |
| 410 | 396 | }; |
| 411 | 397 | |
| 412 | found = true; | |
| 413 | self.crt_dir = dir_path; | |
| 398 | self.crt_dir = result_buf.toOwnedSlice(); | |
| 414 | 399 | return; |
| 415 | 400 | } |
| 416 | 401 | return error.LibCRuntimeNotFound; |
| ... | ... | @@ -434,6 +419,10 @@ pub const LibCInstallation = struct { |
| 434 | 419 | |
| 435 | 420 | var search_buf: [2]Search = undefined; |
| 436 | 421 | const searches = fillSearch(&search_buf, sdk); |
| 422 | ||
| 423 | var result_buf = try std.ArrayList([]const u8).init(allocator); | |
| 424 | defer result_buf.deinit(); | |
| 425 | ||
| 437 | 426 | const arch_sub_dir = switch (builtin.arch) { |
| 438 | 427 | .i386 => "x86", |
| 439 | 428 | .x86_64 => "x64", |
| ... | ... | @@ -442,20 +431,11 @@ pub const LibCInstallation = struct { |
| 442 | 431 | }; |
| 443 | 432 | |
| 444 | 433 | for (searches) |search| { |
| 445 | const dir_path = try fs.path.join( | |
| 446 | allocator, | |
| 447 | &[_][]const u8{ | |
| 448 | search.path, | |
| 449 | "Lib", | |
| 450 | search.version, | |
| 451 | "um", | |
| 452 | arch_sub_dir, | |
| 453 | }, | |
| 454 | ); | |
| 455 | var found = false; | |
| 456 | defer if (!found) allocator.free(dir_path); | |
| 457 | ||
| 458 | var dir = fs.cwd().openDir(dir_path, .{}) catch |err| switch (err) { | |
| 434 | result_buf.shrink(0); | |
| 435 | const stream = result_buf.outStream(); | |
| 436 | try stream.print("{}\\Lib\\{}\\um\\{}", .{ search.path, search.version, arch_sub_dir }); | |
| 437 | ||
| 438 | var dir = fs.cwd().openDir(result_buf.span(), .{}) catch |err| switch (err) { | |
| 459 | 439 | error.FileNotFound, |
| 460 | 440 | error.NotDir, |
| 461 | 441 | error.NoDevice, |
| ... | ... | @@ -470,8 +450,7 @@ pub const LibCInstallation = struct { |
| 470 | 450 | else => return error.FileSystem, |
| 471 | 451 | }; |
| 472 | 452 | |
| 473 | found = true; | |
| 474 | self.kernel32_lib_dir = dir_path; | |
| 453 | self.kernel32_lib_dir = result_buf.toOwnedSlice(); | |
| 475 | 454 | return; |
| 476 | 455 | } |
| 477 | 456 | return error.LibCKernel32LibNotFound; |
| ... | ... | @@ -489,13 +468,7 @@ pub const LibCInstallation = struct { |
| 489 | 468 | const up1 = fs.path.dirname(msvc_lib_dir) orelse return error.LibCStdLibHeaderNotFound; |
| 490 | 469 | const up2 = fs.path.dirname(up1) orelse return error.LibCStdLibHeaderNotFound; |
| 491 | 470 | |
| 492 | const dir_path = try fs.path.join( | |
| 493 | allocator, | |
| 494 | &[_][]const u8{ | |
| 495 | up2, | |
| 496 | "include", | |
| 497 | }, | |
| 498 | ); | |
| 471 | const dir_path = try fs.path.join(allocator, &[_][]const u8{ up2, "include" }); | |
| 499 | 472 | errdefer allocator.free(dir_path); |
| 500 | 473 | |
| 501 | 474 | var dir = fs.cwd().openDir(dir_path, .{}) catch |err| switch (err) { |
src-self-hosted/stage2.zig+2-2| ... | ... | @@ -413,11 +413,11 @@ fn printErrMsgToFile( |
| 413 | 413 | |
| 414 | 414 | var text_buf = std.ArrayList(u8).init(allocator); |
| 415 | 415 | defer text_buf.deinit(); |
| 416 | const out_stream = &text_buf.outStream(); | |
| 416 | const out_stream = text_buf.outStream(); | |
| 417 | 417 | try parse_error.render(&tree.tokens, out_stream); |
| 418 | 418 | const text = text_buf.span(); |
| 419 | 419 | |
| 420 | const stream = &file.outStream(); | |
| 420 | const stream = file.outStream(); | |
| 421 | 421 | try stream.print("{}:{}:{}: error: {}\n", .{ path, start_loc.line + 1, start_loc.column + 1, text }); |
| 422 | 422 | |
| 423 | 423 | if (!color_on) return; |
src-self-hosted/translate_c.zig-1| ... | ... | @@ -297,7 +297,6 @@ pub fn translate( |
| 297 | 297 | }; |
| 298 | 298 | |
| 299 | 299 | var source_buffer = std.ArrayList(u8).init(arena); |
| 300 | errdefer source_buffer.deinit(); | |
| 301 | 300 | |
| 302 | 301 | var context = Context{ |
| 303 | 302 | .tree = tree, |
src/codegen.cpp+6-3| ... | ... | @@ -9123,17 +9123,20 @@ static void detect_libc(CodeGen *g) { |
| 9123 | 9123 | g->libc_include_dir_len = 0; |
| 9124 | 9124 | g->libc_include_dir_list = heap::c_allocator.allocate<const char *>(dir_count); |
| 9125 | 9125 | |
| 9126 | g->libc_include_dir_list[g->libc_include_dir_len] = buf_ptr(buf_create_from_mem(g->libc->include_dir, g->libc->include_dir_len)); | |
| 9126 | g->libc_include_dir_list[g->libc_include_dir_len] = buf_ptr(buf_create_from_mem( | |
| 9127 | g->libc->include_dir, g->libc->include_dir_len)); | |
| 9127 | 9128 | g->libc_include_dir_len += 1; |
| 9128 | 9129 | |
| 9129 | 9130 | if (want_sys_dir) { |
| 9130 | g->libc_include_dir_list[g->libc_include_dir_len] = buf_ptr(buf_create_from_mem(g->libc->sys_include_dir, g->libc->sys_include_dir_len)); | |
| 9131 | g->libc_include_dir_list[g->libc_include_dir_len] = buf_ptr(buf_create_from_mem( | |
| 9132 | g->libc->sys_include_dir, g->libc->sys_include_dir_len)); | |
| 9131 | 9133 | g->libc_include_dir_len += 1; |
| 9132 | 9134 | } |
| 9133 | 9135 | |
| 9134 | 9136 | if (want_um_and_shared_dirs != 0) { |
| 9135 | 9137 | Buf *include_dir_parent = buf_alloc(); |
| 9136 | os_path_join(buf_create_from_mem(g->libc->include_dir, g->libc->include_dir_len), buf_create_from_str(".."), include_dir_parent); | |
| 9138 | os_path_join(buf_create_from_mem(g->libc->include_dir, g->libc->include_dir_len), | |
| 9139 | buf_create_from_str(".."), include_dir_parent); | |
| 9137 | 9140 | |
| 9138 | 9141 | Buf *buff1 = buf_alloc(); |
| 9139 | 9142 | os_path_join(include_dir_parent, buf_create_from_str("um"), buff1); |
src/link.cpp+2-1| ... | ... | @@ -1595,7 +1595,8 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file, Stage2Pr |
| 1595 | 1595 | } else { |
| 1596 | 1596 | assert(parent->libc != nullptr); |
| 1597 | 1597 | Buf *out_buf = buf_alloc(); |
| 1598 | os_path_join(buf_create_from_mem(parent->libc->crt_dir, parent->libc->crt_dir_len), buf_create_from_str(file), out_buf); | |
| 1598 | os_path_join(buf_create_from_mem(parent->libc->crt_dir, parent->libc->crt_dir_len), | |
| 1599 | buf_create_from_str(file), out_buf); | |
| 1599 | 1600 | return buf_ptr(out_buf); |
| 1600 | 1601 | } |
| 1601 | 1602 | } |