authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-04-01 11:56:39-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-04-01 11:56:39-04:00
log553f0e0546e0ceecf2ff735443d9a2c2f282b8db
tree42257c00a7315bc9eb531718390050deffa4022e
parent7eb938c9096db54fe6e99148824252904c79c227
signaturelock-open Commit is signed but in an unrecognized format.

fixups and revert a few things


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