| author | |
| committer | |
| log | df89291d1ca04a5891dd48ea5f6d1a99b6006bcb |
| tree | 83970de0fdaa7383c11f64efceff7f88d6fd9cd9 |
| parent | e9d7623e1f0300b1b652373f2e0e7b605eaf13d1 |
| parent | 019f18058bb74816f8754de63a219347597e06da |
19 files changed, 169 insertions(+), 114 deletions(-)
example/cat/main.zig+1-1| ... | ... | @@ -3,9 +3,9 @@ const io = std.io; |
| 3 | 3 | const mem = std.mem; |
| 4 | 4 | const os = std.os; |
| 5 | 5 | const warn = std.debug.warn; |
| 6 | const allocator = std.debug.global_allocator; | |
| 6 | 7 | |
| 7 | 8 | pub fn main() -> %void { |
| 8 | const allocator = &std.debug.global_allocator; | |
| 9 | 9 | var args_it = os.args(); |
| 10 | 10 | const exe = %return unwrapArg(??args_it.next(allocator)); |
| 11 | 11 | var catted_anything = false; |
src/all_types.hpp+1-5| ... | ... | @@ -1508,13 +1508,9 @@ struct CodeGen { |
| 1508 | 1508 | bool linker_rdynamic; |
| 1509 | 1509 | const char *linker_script; |
| 1510 | 1510 | |
| 1511 | // The function definitions this module includes. There must be a corresponding | |
| 1512 | // fn_protos entry. | |
| 1511 | // The function definitions this module includes. | |
| 1513 | 1512 | ZigList<FnTableEntry *> fn_defs; |
| 1514 | 1513 | size_t fn_defs_index; |
| 1515 | // The function prototypes this module includes. In the case of external declarations, | |
| 1516 | // there will not be a corresponding fn_defs entry. | |
| 1517 | ZigList<FnTableEntry *> fn_protos; | |
| 1518 | 1514 | ZigList<TldVar *> global_vars; |
| 1519 | 1515 | |
| 1520 | 1516 | OutType out_type; |
src/analyze.cpp-3| ... | ... | @@ -2121,8 +2121,6 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) { |
| 2121 | 2121 | } |
| 2122 | 2122 | |
| 2123 | 2123 | if (!fn_table_entry->type_entry->data.fn.is_generic) { |
| 2124 | g->fn_protos.append(fn_table_entry); | |
| 2125 | ||
| 2126 | 2124 | if (fn_def_node) |
| 2127 | 2125 | g->fn_defs.append(fn_table_entry); |
| 2128 | 2126 | |
| ... | ... | @@ -2162,7 +2160,6 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) { |
| 2162 | 2160 | fn_table_entry->body_node = source_node->data.test_decl.body; |
| 2163 | 2161 | fn_table_entry->is_test = true; |
| 2164 | 2162 | |
| 2165 | g->fn_protos.append(fn_table_entry); | |
| 2166 | 2163 | g->fn_defs.append(fn_table_entry); |
| 2167 | 2164 | g->test_fns.append(fn_table_entry); |
| 2168 | 2165 |
src/codegen.cpp+44-53| ... | ... | @@ -408,6 +408,7 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) { |
| 408 | 408 | LLVMValueRef existing_llvm_fn = LLVMGetNamedFunction(g->module, buf_ptr(symbol_name)); |
| 409 | 409 | if (existing_llvm_fn) { |
| 410 | 410 | fn_table_entry->llvm_value = LLVMConstBitCast(existing_llvm_fn, LLVMPointerType(fn_llvm_type, 0)); |
| 411 | return fn_table_entry->llvm_value; | |
| 411 | 412 | } else { |
| 412 | 413 | fn_table_entry->llvm_value = LLVMAddFunction(g->module, buf_ptr(symbol_name), fn_llvm_type); |
| 413 | 414 | } |
| ... | ... | @@ -493,6 +494,49 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) { |
| 493 | 494 | // use the ABI alignment, which is fine. |
| 494 | 495 | } |
| 495 | 496 | |
| 497 | if (!type_has_bits(fn_type->data.fn.fn_type_id.return_type)) { | |
| 498 | // nothing to do | |
| 499 | } else if (fn_type->data.fn.fn_type_id.return_type->id == TypeTableEntryIdPointer || | |
| 500 | fn_type->data.fn.fn_type_id.return_type->id == TypeTableEntryIdFn) | |
| 501 | { | |
| 502 | addLLVMAttr(fn_table_entry->llvm_value, 0, "nonnull"); | |
| 503 | } else if (handle_is_ptr(fn_type->data.fn.fn_type_id.return_type) && | |
| 504 | calling_convention_does_first_arg_return(fn_type->data.fn.fn_type_id.cc)) | |
| 505 | { | |
| 506 | addLLVMArgAttr(fn_table_entry->llvm_value, 0, "sret"); | |
| 507 | addLLVMArgAttr(fn_table_entry->llvm_value, 0, "nonnull"); | |
| 508 | } | |
| 509 | ||
| 510 | ||
| 511 | // set parameter attributes | |
| 512 | for (size_t param_i = 0; param_i < fn_type->data.fn.fn_type_id.param_count; param_i += 1) { | |
| 513 | FnGenParamInfo *gen_info = &fn_type->data.fn.gen_param_info[param_i]; | |
| 514 | size_t gen_index = gen_info->gen_index; | |
| 515 | bool is_byval = gen_info->is_byval; | |
| 516 | ||
| 517 | if (gen_index == SIZE_MAX) { | |
| 518 | continue; | |
| 519 | } | |
| 520 | ||
| 521 | FnTypeParamInfo *param_info = &fn_type->data.fn.fn_type_id.param_info[param_i]; | |
| 522 | ||
| 523 | TypeTableEntry *param_type = gen_info->type; | |
| 524 | if (param_info->is_noalias) { | |
| 525 | addLLVMArgAttr(fn_table_entry->llvm_value, (unsigned)gen_index, "noalias"); | |
| 526 | } | |
| 527 | if ((param_type->id == TypeTableEntryIdPointer && param_type->data.pointer.is_const) || is_byval) { | |
| 528 | addLLVMArgAttr(fn_table_entry->llvm_value, (unsigned)gen_index, "readonly"); | |
| 529 | } | |
| 530 | if (param_type->id == TypeTableEntryIdPointer) { | |
| 531 | addLLVMArgAttr(fn_table_entry->llvm_value, (unsigned)gen_index, "nonnull"); | |
| 532 | } | |
| 533 | // Note: byval is disabled on windows due to an LLVM bug: | |
| 534 | // https://github.com/zig-lang/zig/issues/536 | |
| 535 | if (is_byval && g->zig_target.os != ZigLLVM_Win32) { | |
| 536 | addLLVMArgAttr(fn_table_entry->llvm_value, (unsigned)gen_index, "byval"); | |
| 537 | } | |
| 538 | } | |
| 539 | ||
| 496 | 540 | return fn_table_entry->llvm_value; |
| 497 | 541 | } |
| 498 | 542 | |
| ... | ... | @@ -4297,59 +4341,6 @@ static void do_code_gen(CodeGen *g) { |
| 4297 | 4341 | var->value_ref = global_value; |
| 4298 | 4342 | } |
| 4299 | 4343 | |
| 4300 | // Generate function prototypes | |
| 4301 | for (size_t fn_proto_i = 0; fn_proto_i < g->fn_protos.length; fn_proto_i += 1) { | |
| 4302 | FnTableEntry *fn_table_entry = g->fn_protos.at(fn_proto_i); | |
| 4303 | ||
| 4304 | TypeTableEntry *fn_type = fn_table_entry->type_entry; | |
| 4305 | FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id; | |
| 4306 | ||
| 4307 | LLVMValueRef fn_val = fn_llvm_value(g, fn_table_entry); | |
| 4308 | ||
| 4309 | if (!type_has_bits(fn_type->data.fn.fn_type_id.return_type)) { | |
| 4310 | // nothing to do | |
| 4311 | } else if (fn_type->data.fn.fn_type_id.return_type->id == TypeTableEntryIdPointer || | |
| 4312 | fn_type->data.fn.fn_type_id.return_type->id == TypeTableEntryIdFn) | |
| 4313 | { | |
| 4314 | addLLVMAttr(fn_val, 0, "nonnull"); | |
| 4315 | } else if (handle_is_ptr(fn_type->data.fn.fn_type_id.return_type) && | |
| 4316 | calling_convention_does_first_arg_return(fn_type->data.fn.fn_type_id.cc)) | |
| 4317 | { | |
| 4318 | addLLVMArgAttr(fn_val, 0, "sret"); | |
| 4319 | addLLVMArgAttr(fn_val, 0, "nonnull"); | |
| 4320 | } | |
| 4321 | ||
| 4322 | ||
| 4323 | // set parameter attributes | |
| 4324 | for (size_t param_i = 0; param_i < fn_type_id->param_count; param_i += 1) { | |
| 4325 | FnGenParamInfo *gen_info = &fn_type->data.fn.gen_param_info[param_i]; | |
| 4326 | size_t gen_index = gen_info->gen_index; | |
| 4327 | bool is_byval = gen_info->is_byval; | |
| 4328 | ||
| 4329 | if (gen_index == SIZE_MAX) { | |
| 4330 | continue; | |
| 4331 | } | |
| 4332 | ||
| 4333 | FnTypeParamInfo *param_info = &fn_type_id->param_info[param_i]; | |
| 4334 | ||
| 4335 | TypeTableEntry *param_type = gen_info->type; | |
| 4336 | if (param_info->is_noalias) { | |
| 4337 | addLLVMArgAttr(fn_val, (unsigned)gen_index, "noalias"); | |
| 4338 | } | |
| 4339 | if ((param_type->id == TypeTableEntryIdPointer && param_type->data.pointer.is_const) || is_byval) { | |
| 4340 | addLLVMArgAttr(fn_val, (unsigned)gen_index, "readonly"); | |
| 4341 | } | |
| 4342 | if (param_type->id == TypeTableEntryIdPointer) { | |
| 4343 | addLLVMArgAttr(fn_val, (unsigned)gen_index, "nonnull"); | |
| 4344 | } | |
| 4345 | // Note: byval is disabled on windows due to an LLVM bug: | |
| 4346 | // https://github.com/zig-lang/zig/issues/536 | |
| 4347 | if (is_byval && g->zig_target.os != ZigLLVM_Win32) { | |
| 4348 | addLLVMArgAttr(fn_val, (unsigned)gen_index, "byval"); | |
| 4349 | } | |
| 4350 | } | |
| 4351 | } | |
| 4352 | ||
| 4353 | 4344 | // Generate function definitions. |
| 4354 | 4345 | for (size_t fn_i = 0; fn_i < g->fn_defs.length; fn_i += 1) { |
| 4355 | 4346 | FnTableEntry *fn_table_entry = g->fn_defs.at(fn_i); |
src/ir.cpp-1| ... | ... | @@ -10584,7 +10584,6 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 10584 | 10584 | impl_fn->analyzed_executable.source_node = call_instruction->base.source_node; |
| 10585 | 10585 | impl_fn->analyzed_executable.parent_exec = ira->new_irb.exec; |
| 10586 | 10586 | |
| 10587 | ira->codegen->fn_protos.append(impl_fn); | |
| 10588 | 10587 | ira->codegen->fn_defs.append(impl_fn); |
| 10589 | 10588 | } |
| 10590 | 10589 |
std/array_list.zig+1-1| ... | ... | @@ -101,7 +101,7 @@ pub fn ArrayList(comptime T: type) -> type{ |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | test "basic ArrayList test" { |
| 104 | var list = ArrayList(i32).init(&debug.global_allocator); | |
| 104 | var list = ArrayList(i32).init(debug.global_allocator); | |
| 105 | 105 | defer list.deinit(); |
| 106 | 106 | |
| 107 | 107 | {var i: usize = 0; while (i < 10) : (i += 1) { |
std/buffer.zig+1-1| ... | ... | @@ -135,7 +135,7 @@ pub const Buffer = struct { |
| 135 | 135 | test "simple Buffer" { |
| 136 | 136 | const cstr = @import("cstr.zig"); |
| 137 | 137 | |
| 138 | var buf = %%Buffer.init(&debug.global_allocator, ""); | |
| 138 | var buf = %%Buffer.init(debug.global_allocator, ""); | |
| 139 | 139 | assert(buf.len() == 0); |
| 140 | 140 | %%buf.append("hello"); |
| 141 | 141 | %%buf.appendByte(' '); |
std/c/darwin.zig+14-12| ... | ... | @@ -6,26 +6,28 @@ pub const _errno = __error; |
| 6 | 6 | |
| 7 | 7 | /// Renamed to Stat to not conflict with the stat function. |
| 8 | 8 | pub const Stat = extern struct { |
| 9 | dev: u32, | |
| 9 | dev: i32, | |
| 10 | 10 | mode: u16, |
| 11 | 11 | nlink: u16, |
| 12 | 12 | ino: u64, |
| 13 | 13 | uid: u32, |
| 14 | 14 | gid: u32, |
| 15 | rdev: u64, | |
| 16 | ||
| 17 | atim: timespec, | |
| 18 | mtim: timespec, | |
| 19 | ctim: timespec, | |
| 20 | ||
| 21 | size: u64, | |
| 22 | blocks: u64, | |
| 23 | blksize: u32, | |
| 15 | rdev: i32, | |
| 16 | atime: usize, | |
| 17 | atimensec: usize, | |
| 18 | mtime: usize, | |
| 19 | mtimensec: usize, | |
| 20 | ctime: usize, | |
| 21 | ctimensec: usize, | |
| 22 | birthtime: usize, | |
| 23 | birthtimensec: usize, | |
| 24 | size: i64, | |
| 25 | blocks: i64, | |
| 26 | blksize: i32, | |
| 24 | 27 | flags: u32, |
| 25 | 28 | gen: u32, |
| 26 | 29 | lspare: i32, |
| 27 | qspare: [2]u64, | |
| 28 | ||
| 30 | qspare: [2]i64, | |
| 29 | 31 | }; |
| 30 | 32 | |
| 31 | 33 | pub const timespec = extern struct { |
std/c/index.zig+1| ... | ... | @@ -14,6 +14,7 @@ pub extern "c" fn exit(code: c_int) -> noreturn; |
| 14 | 14 | pub extern "c" fn isatty(fd: c_int) -> c_int; |
| 15 | 15 | pub extern "c" fn close(fd: c_int) -> c_int; |
| 16 | 16 | pub extern "c" fn fstat(fd: c_int, buf: &Stat) -> c_int; |
| 17 | pub extern "c" fn @"fstat$INODE64"(fd: c_int, buf: &Stat) -> c_int; | |
| 17 | 18 | pub extern "c" fn lseek(fd: c_int, offset: isize, whence: c_int) -> isize; |
| 18 | 19 | pub extern "c" fn open(path: &const u8, oflag: c_int, ...) -> c_int; |
| 19 | 20 | pub extern "c" fn raise(sig: c_int) -> c_int; |
std/debug.zig+4-3| ... | ... | @@ -38,7 +38,7 @@ fn getStderrStream() -> %&io.OutStream { |
| 38 | 38 | /// Tries to print a stack trace to stderr, unbuffered, and ignores any error returned. |
| 39 | 39 | pub fn dumpStackTrace() { |
| 40 | 40 | const stderr = getStderrStream() %% return; |
| 41 | writeStackTrace(stderr, &global_allocator, stderr_file.isTty(), 1) %% return; | |
| 41 | writeStackTrace(stderr, global_allocator, stderr_file.isTty(), 1) %% return; | |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /// This function invokes undefined behavior when `ok` is `false`. |
| ... | ... | @@ -86,7 +86,7 @@ pub fn panic(comptime format: []const u8, args: ...) -> noreturn { |
| 86 | 86 | |
| 87 | 87 | const stderr = getStderrStream() %% os.abort(); |
| 88 | 88 | stderr.print(format ++ "\n", args) %% os.abort(); |
| 89 | writeStackTrace(stderr, &global_allocator, stderr_file.isTty(), 1) %% os.abort(); | |
| 89 | writeStackTrace(stderr, global_allocator, stderr_file.isTty(), 1) %% os.abort(); | |
| 90 | 90 | |
| 91 | 91 | os.abort(); |
| 92 | 92 | } |
| ... | ... | @@ -967,7 +967,8 @@ fn readILeb128(in_stream: &io.InStream) -> %i64 { |
| 967 | 967 | } |
| 968 | 968 | } |
| 969 | 969 | |
| 970 | pub var global_allocator = mem.Allocator { | |
| 970 | pub const global_allocator = &global_allocator_state; | |
| 971 | var global_allocator_state = mem.Allocator { | |
| 971 | 972 | .allocFn = globalAlloc, |
| 972 | 973 | .reallocFn = globalRealloc, |
| 973 | 974 | .freeFn = globalFree, |
std/hash_map.zig+1-1| ... | ... | @@ -232,7 +232,7 @@ pub fn HashMap(comptime K: type, comptime V: type, |
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | test "basicHashMapTest" { |
| 235 | var map = HashMap(i32, i32, hash_i32, eql_i32).init(&debug.global_allocator); | |
| 235 | var map = HashMap(i32, i32, hash_i32, eql_i32).init(debug.global_allocator); | |
| 236 | 236 | defer map.deinit(); |
| 237 | 237 | |
| 238 | 238 | assert(%%map.put(1, 11) == null); |
std/io.zig+30-9| ... | ... | @@ -20,6 +20,12 @@ const fmt = std.fmt; |
| 20 | 20 | const is_posix = builtin.os != builtin.Os.windows; |
| 21 | 21 | const is_windows = builtin.os == builtin.Os.windows; |
| 22 | 22 | |
| 23 | test "import io tests" { | |
| 24 | comptime { | |
| 25 | _ = @import("io_test.zig"); | |
| 26 | } | |
| 27 | } | |
| 28 | ||
| 23 | 29 | /// The function received invalid input at runtime. An Invalid error means a |
| 24 | 30 | /// bug in the program that called the function. |
| 25 | 31 | error Invalid; |
| ... | ... | @@ -247,17 +253,32 @@ pub const File = struct { |
| 247 | 253 | } |
| 248 | 254 | |
| 249 | 255 | pub fn getEndPos(self: &File) -> %usize { |
| 250 | var stat: system.Stat = undefined; | |
| 251 | const err = system.getErrno(system.fstat(self.handle, &stat)); | |
| 252 | if (err > 0) { | |
| 253 | return switch (err) { | |
| 254 | system.EBADF => error.BadFd, | |
| 255 | system.ENOMEM => error.OutOfMemory, | |
| 256 | else => os.unexpectedErrorPosix(err), | |
| 256 | if (is_posix) { | |
| 257 | var stat: system.Stat = undefined; | |
| 258 | const err = system.getErrno(system.fstat(self.handle, &stat)); | |
| 259 | if (err > 0) { | |
| 260 | return switch (err) { | |
| 261 | system.EBADF => error.BadFd, | |
| 262 | system.ENOMEM => error.OutOfMemory, | |
| 263 | else => os.unexpectedErrorPosix(err), | |
| 264 | } | |
| 257 | 265 | } |
| 258 | } | |
| 259 | 266 | |
| 260 | return usize(stat.size); | |
| 267 | return usize(stat.size); | |
| 268 | } else if (is_windows) { | |
| 269 | var file_size: system.LARGE_INTEGER = undefined; | |
| 270 | if (system.GetFileSizeEx(self.handle, &file_size) == 0) { | |
| 271 | const err = system.GetLastError(); | |
| 272 | return switch (err) { | |
| 273 | else => os.unexpectedErrorWindows(err), | |
| 274 | }; | |
| 275 | } | |
| 276 | if (file_size < 0) | |
| 277 | return error.Overflow; | |
| 278 | return math.cast(usize, u64(file_size)); | |
| 279 | } else { | |
| 280 | unreachable; | |
| 281 | } | |
| 261 | 282 | } |
| 262 | 283 | |
| 263 | 284 | pub fn read(self: &File, buffer: []u8) -> %usize { |
std/io_test.zig created+45| ... | ... | @@ -0,0 +1,45 @@ |
| 1 | const std = @import("index.zig"); | |
| 2 | const io = std.io; | |
| 3 | const allocator = std.debug.global_allocator; | |
| 4 | const Rand = std.rand.Rand; | |
| 5 | const assert = std.debug.assert; | |
| 6 | const mem = std.mem; | |
| 7 | const os = std.os; | |
| 8 | ||
| 9 | test "write a file, read it, then delete it" { | |
| 10 | var data: [1024]u8 = undefined; | |
| 11 | var rng = Rand.init(1234); | |
| 12 | rng.fillBytes(data[0..]); | |
| 13 | const tmp_file_name = "temp_test_file.txt"; | |
| 14 | { | |
| 15 | var file = %%io.File.openWrite(tmp_file_name, allocator); | |
| 16 | defer file.close(); | |
| 17 | ||
| 18 | var file_out_stream = io.FileOutStream.init(&file); | |
| 19 | var buf_stream = io.BufferedOutStream.init(&file_out_stream.stream); | |
| 20 | const st = &buf_stream.stream; | |
| 21 | %%st.print("begin"); | |
| 22 | %%st.write(data[0..]); | |
| 23 | %%st.print("end"); | |
| 24 | %%buf_stream.flush(); | |
| 25 | } | |
| 26 | { | |
| 27 | var file = %%io.File.openRead(tmp_file_name, allocator); | |
| 28 | defer file.close(); | |
| 29 | ||
| 30 | const file_size = %%file.getEndPos(); | |
| 31 | const expected_file_size = "begin".len + data.len + "end".len; | |
| 32 | assert(file_size == expected_file_size); | |
| 33 | ||
| 34 | var file_in_stream = io.FileInStream.init(&file); | |
| 35 | var buf_stream = io.BufferedInStream.init(&file_in_stream.stream); | |
| 36 | const st = &buf_stream.stream; | |
| 37 | const contents = %%st.readAllAlloc(allocator, 2 * 1024); | |
| 38 | defer allocator.free(contents); | |
| 39 | ||
| 40 | assert(mem.eql(u8, contents[0.."begin".len], "begin")); | |
| 41 | assert(mem.eql(u8, contents["begin".len..contents.len - "end".len], data)); | |
| 42 | assert(mem.eql(u8, contents[contents.len - "end".len ..], "end")); | |
| 43 | } | |
| 44 | %%os.deleteFile(allocator, tmp_file_name); | |
| 45 | } |
std/linked_list.zig+1-1| ... | ... | @@ -195,7 +195,7 @@ pub fn LinkedList(comptime T: type) -> type { |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | test "basic linked list test" { |
| 198 | const allocator = &debug.global_allocator; | |
| 198 | const allocator = debug.global_allocator; | |
| 199 | 199 | var list = LinkedList(u32).init(); |
| 200 | 200 | |
| 201 | 201 | var one = %%list.createNode(1, allocator); |
std/mem.zig+2-2| ... | ... | @@ -331,8 +331,8 @@ pub fn join(allocator: &Allocator, sep: u8, strings: ...) -> %[]u8 { |
| 331 | 331 | } |
| 332 | 332 | |
| 333 | 333 | test "mem.join" { |
| 334 | assert(eql(u8, %%join(&debug.global_allocator, ',', "a", "b", "c"), "a,b,c")); | |
| 335 | assert(eql(u8, %%join(&debug.global_allocator, ',', "a"), "a")); | |
| 334 | assert(eql(u8, %%join(debug.global_allocator, ',', "a", "b", "c"), "a,b,c")); | |
| 335 | assert(eql(u8, %%join(debug.global_allocator, ',', "a"), "a")); | |
| 336 | 336 | } |
| 337 | 337 | |
| 338 | 338 | test "testStringEquality" { |
std/os/darwin.zig+1-1| ... | ... | @@ -129,7 +129,7 @@ pub fn isatty(fd: i32) -> bool { |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | pub fn fstat(fd: i32, buf: &c.Stat) -> usize { |
| 132 | errnoWrap(c.fstat(fd, buf)) | |
| 132 | errnoWrap(c.@"fstat$INODE64"(fd, buf)) | |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | pub fn lseek(fd: i32, offset: isize, whence: c_int) -> usize { |
std/os/index.zig+3-4| ... | ... | @@ -562,7 +562,7 @@ pub fn getCwd(allocator: &Allocator) -> %[]u8 { |
| 562 | 562 | |
| 563 | 563 | test "os.getCwd" { |
| 564 | 564 | // at least call it so it gets compiled |
| 565 | _ = getCwd(&debug.global_allocator); | |
| 565 | _ = getCwd(debug.global_allocator); | |
| 566 | 566 | } |
| 567 | 567 | |
| 568 | 568 | pub fn symLink(allocator: &Allocator, existing_path: []const u8, new_path: []const u8) -> %void { |
| ... | ... | @@ -1432,10 +1432,10 @@ test "windows arg parsing" { |
| 1432 | 1432 | fn testWindowsCmdLine(input_cmd_line: &const u8, expected_args: []const []const u8) { |
| 1433 | 1433 | var it = ArgIteratorWindows.initWithCmdLine(input_cmd_line); |
| 1434 | 1434 | for (expected_args) |expected_arg| { |
| 1435 | const arg = %%??it.next(&debug.global_allocator); | |
| 1435 | const arg = %%??it.next(debug.global_allocator); | |
| 1436 | 1436 | assert(mem.eql(u8, arg, expected_arg)); |
| 1437 | 1437 | } |
| 1438 | assert(it.next(&debug.global_allocator) == null); | |
| 1438 | assert(it.next(debug.global_allocator) == null); | |
| 1439 | 1439 | } |
| 1440 | 1440 | |
| 1441 | 1441 | test "std.os" { |
| ... | ... | @@ -1500,4 +1500,3 @@ pub fn isTty(handle: FileHandle) -> bool { |
| 1500 | 1500 | } |
| 1501 | 1501 | } |
| 1502 | 1502 | } |
| 1503 |
std/os/path.zig+16-16| ... | ... | @@ -41,23 +41,23 @@ pub fn joinPosix(allocator: &Allocator, paths: ...) -> %[]u8 { |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | test "os.path.join" { |
| 44 | assert(mem.eql(u8, %%joinWindows(&debug.global_allocator, "c:\\a\\b", "c"), "c:\\a\\b\\c")); | |
| 45 | assert(mem.eql(u8, %%joinWindows(&debug.global_allocator, "c:\\a\\b\\", "c"), "c:\\a\\b\\c")); | |
| 44 | assert(mem.eql(u8, %%joinWindows(debug.global_allocator, "c:\\a\\b", "c"), "c:\\a\\b\\c")); | |
| 45 | assert(mem.eql(u8, %%joinWindows(debug.global_allocator, "c:\\a\\b\\", "c"), "c:\\a\\b\\c")); | |
| 46 | 46 | |
| 47 | assert(mem.eql(u8, %%joinWindows(&debug.global_allocator, "c:\\", "a", "b\\", "c"), "c:\\a\\b\\c")); | |
| 48 | assert(mem.eql(u8, %%joinWindows(&debug.global_allocator, "c:\\a\\", "b\\", "c"), "c:\\a\\b\\c")); | |
| 47 | assert(mem.eql(u8, %%joinWindows(debug.global_allocator, "c:\\", "a", "b\\", "c"), "c:\\a\\b\\c")); | |
| 48 | assert(mem.eql(u8, %%joinWindows(debug.global_allocator, "c:\\a\\", "b\\", "c"), "c:\\a\\b\\c")); | |
| 49 | 49 | |
| 50 | assert(mem.eql(u8, %%joinWindows(&debug.global_allocator, | |
| 50 | assert(mem.eql(u8, %%joinWindows(debug.global_allocator, | |
| 51 | 51 | "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std", "io.zig"), |
| 52 | 52 | "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std\\io.zig")); |
| 53 | 53 | |
| 54 | assert(mem.eql(u8, %%joinPosix(&debug.global_allocator, "/a/b", "c"), "/a/b/c")); | |
| 55 | assert(mem.eql(u8, %%joinPosix(&debug.global_allocator, "/a/b/", "c"), "/a/b/c")); | |
| 54 | assert(mem.eql(u8, %%joinPosix(debug.global_allocator, "/a/b", "c"), "/a/b/c")); | |
| 55 | assert(mem.eql(u8, %%joinPosix(debug.global_allocator, "/a/b/", "c"), "/a/b/c")); | |
| 56 | 56 | |
| 57 | assert(mem.eql(u8, %%joinPosix(&debug.global_allocator, "/", "a", "b/", "c"), "/a/b/c")); | |
| 58 | assert(mem.eql(u8, %%joinPosix(&debug.global_allocator, "/a/", "b/", "c"), "/a/b/c")); | |
| 57 | assert(mem.eql(u8, %%joinPosix(debug.global_allocator, "/", "a", "b/", "c"), "/a/b/c")); | |
| 58 | assert(mem.eql(u8, %%joinPosix(debug.global_allocator, "/a/", "b/", "c"), "/a/b/c")); | |
| 59 | 59 | |
| 60 | assert(mem.eql(u8, %%joinPosix(&debug.global_allocator, "/home/andy/dev/zig/build/lib/zig/std", "io.zig"), | |
| 60 | assert(mem.eql(u8, %%joinPosix(debug.global_allocator, "/home/andy/dev/zig/build/lib/zig/std", "io.zig"), | |
| 61 | 61 | "/home/andy/dev/zig/build/lib/zig/std/io.zig")); |
| 62 | 62 | } |
| 63 | 63 | |
| ... | ... | @@ -453,7 +453,7 @@ pub fn resolvePosix(allocator: &Allocator, paths: []const []const u8) -> %[]u8 { |
| 453 | 453 | } |
| 454 | 454 | |
| 455 | 455 | test "os.path.resolve" { |
| 456 | const cwd = %%os.getCwd(&debug.global_allocator); | |
| 456 | const cwd = %%os.getCwd(debug.global_allocator); | |
| 457 | 457 | if (is_windows) { |
| 458 | 458 | assert(mem.eql(u8, testResolveWindows([][]const u8{"."}), cwd)); |
| 459 | 459 | } else { |
| ... | ... | @@ -492,11 +492,11 @@ test "os.path.resolvePosix" { |
| 492 | 492 | } |
| 493 | 493 | |
| 494 | 494 | fn testResolveWindows(paths: []const []const u8) -> []u8 { |
| 495 | return %%resolveWindows(&debug.global_allocator, paths); | |
| 495 | return %%resolveWindows(debug.global_allocator, paths); | |
| 496 | 496 | } |
| 497 | 497 | |
| 498 | 498 | fn testResolvePosix(paths: []const []const u8) -> []u8 { |
| 499 | return %%resolvePosix(&debug.global_allocator, paths); | |
| 499 | return %%resolvePosix(debug.global_allocator, paths); | |
| 500 | 500 | } |
| 501 | 501 | |
| 502 | 502 | pub fn dirname(path: []const u8) -> []const u8 { |
| ... | ... | @@ -899,12 +899,12 @@ test "os.path.relative" { |
| 899 | 899 | } |
| 900 | 900 | |
| 901 | 901 | fn testRelativePosix(from: []const u8, to: []const u8, expected_output: []const u8) { |
| 902 | const result = %%relativePosix(&debug.global_allocator, from, to); | |
| 902 | const result = %%relativePosix(debug.global_allocator, from, to); | |
| 903 | 903 | assert(mem.eql(u8, result, expected_output)); |
| 904 | 904 | } |
| 905 | 905 | |
| 906 | 906 | fn testRelativeWindows(from: []const u8, to: []const u8, expected_output: []const u8) { |
| 907 | const result = %%relativeWindows(&debug.global_allocator, from, to); | |
| 907 | const result = %%relativeWindows(debug.global_allocator, from, to); | |
| 908 | 908 | assert(mem.eql(u8, result, expected_output)); |
| 909 | 909 | } |
| 910 | 910 | |
| ... | ... | @@ -1022,5 +1022,5 @@ pub fn real(allocator: &Allocator, pathname: []const u8) -> %[]u8 { |
| 1022 | 1022 | |
| 1023 | 1023 | test "os.path.real" { |
| 1024 | 1024 | // at least call it so it gets compiled |
| 1025 | _ = real(&debug.global_allocator, "some_path"); | |
| 1025 | _ = real(debug.global_allocator, "some_path"); | |
| 1026 | 1026 | } |
std/os/windows/index.zig+3| ... | ... | @@ -46,6 +46,8 @@ pub extern "kernel32" stdcallcc fn GetEnvironmentVariableA(lpName: LPCSTR, lpBuf |
| 46 | 46 | |
| 47 | 47 | pub extern "kernel32" stdcallcc fn GetExitCodeProcess(hProcess: HANDLE, lpExitCode: &DWORD) -> BOOL; |
| 48 | 48 | |
| 49 | pub extern "kernel32" stdcallcc fn GetFileSizeEx(hFile: HANDLE, lpFileSize: &LARGE_INTEGER) -> BOOL; | |
| 50 | ||
| 49 | 51 | pub extern "kernel32" stdcallcc fn GetLastError() -> DWORD; |
| 50 | 52 | |
| 51 | 53 | pub extern "kernel32" stdcallcc fn GetFileInformationByHandleEx(in_hFile: HANDLE, |
| ... | ... | @@ -115,6 +117,7 @@ pub const ULONG_PTR = usize; |
| 115 | 117 | pub const UNICODE = false; |
| 116 | 118 | pub const WCHAR = u16; |
| 117 | 119 | pub const WORD = u16; |
| 120 | pub const LARGE_INTEGER = i64; | |
| 118 | 121 | |
| 119 | 122 | pub const TRUE = 1; |
| 120 | 123 | pub const FALSE = 0; |