| author | |
| committer | |
| log | e0f0e2aace9e819545388c46547188ee6296178b |
| tree | 674a78c834c9d440e8f07da8a24bff76f35ecc71 |
| parent | f74c29b49a550e5e7029fde46de93068a9eecb46 |
| signature |
7 files changed, 172 insertions(+), 132 deletions(-)
lib/std/os.zig+41-109| ... | ... | @@ -183,7 +183,7 @@ pub fn abort() noreturn { |
| 183 | 183 | exit(127); |
| 184 | 184 | } |
| 185 | 185 | |
| 186 | pub const RaiseError = error{Unexpected}; | |
| 186 | pub const RaiseError = UnexpectedError; | |
| 187 | 187 | |
| 188 | 188 | pub fn raise(sig: u8) RaiseError!void { |
| 189 | 189 | if (builtin.link_libc) { |
| ... | ... | @@ -215,10 +215,7 @@ pub fn raise(sig: u8) RaiseError!void { |
| 215 | 215 | @compileError("std.os.raise unimplemented for this target"); |
| 216 | 216 | } |
| 217 | 217 | |
| 218 | pub const KillError = error{ | |
| 219 | PermissionDenied, | |
| 220 | Unexpected, | |
| 221 | }; | |
| 218 | pub const KillError = error{PermissionDenied} || UnexpectedError; | |
| 222 | 219 | |
| 223 | 220 | pub fn kill(pid: pid_t, sig: u8) KillError!void { |
| 224 | 221 | switch (errno(system.kill(pid, sig))) { |
| ... | ... | @@ -266,9 +263,7 @@ pub const ReadError = error{ |
| 266 | 263 | /// This error occurs when no global event loop is configured, |
| 267 | 264 | /// and reading from the file descriptor would block. |
| 268 | 265 | WouldBlock, |
| 269 | ||
| 270 | Unexpected, | |
| 271 | }; | |
| 266 | } || UnexpectedError; | |
| 272 | 267 | |
| 273 | 268 | /// Returns the number of bytes that were read, which can be less than |
| 274 | 269 | /// buf.len. If 0 bytes were read, that means EOF. |
| ... | ... | @@ -385,8 +380,7 @@ pub const WriteError = error{ |
| 385 | 380 | BrokenPipe, |
| 386 | 381 | SystemResources, |
| 387 | 382 | OperationAborted, |
| 388 | Unexpected, | |
| 389 | }; | |
| 383 | } || UnexpectedError; | |
| 390 | 384 | |
| 391 | 385 | /// Write to a file descriptor. Keeps trying if it gets interrupted. |
| 392 | 386 | /// This function is for blocking file descriptors only. |
| ... | ... | @@ -548,8 +542,7 @@ pub const OpenError = error{ |
| 548 | 542 | NotDir, |
| 549 | 543 | PathAlreadyExists, |
| 550 | 544 | DeviceBusy, |
| 551 | Unexpected, | |
| 552 | }; | |
| 545 | } || UnexpectedError; | |
| 553 | 546 | |
| 554 | 547 | /// Open and possibly create a file. Keeps trying if it gets interrupted. |
| 555 | 548 | /// See also `openC`. |
| ... | ... | @@ -748,9 +741,7 @@ pub const ExecveError = error{ |
| 748 | 741 | ProcessFdQuotaExceeded, |
| 749 | 742 | SystemFdQuotaExceeded, |
| 750 | 743 | NameTooLong, |
| 751 | ||
| 752 | Unexpected, | |
| 753 | }; | |
| 744 | } || UnexpectedError; | |
| 754 | 745 | |
| 755 | 746 | fn execveErrnoToErr(err: usize) ExecveError { |
| 756 | 747 | assert(err > 0); |
| ... | ... | @@ -808,8 +799,7 @@ pub fn getenvC(key: [*]const u8) ?[]const u8 { |
| 808 | 799 | pub const GetCwdError = error{ |
| 809 | 800 | NameTooLong, |
| 810 | 801 | CurrentWorkingDirectoryUnlinked, |
| 811 | Unexpected, | |
| 812 | }; | |
| 802 | } || UnexpectedError; | |
| 813 | 803 | |
| 814 | 804 | /// The result is a slice of out_buffer, indexed from 0. |
| 815 | 805 | pub fn getcwd(out_buffer: []u8) GetCwdError![]u8 { |
| ... | ... | @@ -846,8 +836,7 @@ pub const SymLinkError = error{ |
| 846 | 836 | NameTooLong, |
| 847 | 837 | InvalidUtf8, |
| 848 | 838 | BadPathName, |
| 849 | Unexpected, | |
| 850 | }; | |
| 839 | } || UnexpectedError; | |
| 851 | 840 | |
| 852 | 841 | /// Creates a symbolic link named `sym_link_path` which contains the string `target_path`. |
| 853 | 842 | /// A symbolic link (also known as a soft link) may point to an existing file or to a nonexistent |
| ... | ... | @@ -932,7 +921,6 @@ pub const UnlinkError = error{ |
| 932 | 921 | NotDir, |
| 933 | 922 | SystemResources, |
| 934 | 923 | ReadOnlyFileSystem, |
| 935 | Unexpected, | |
| 936 | 924 | |
| 937 | 925 | /// On Windows, file paths must be valid Unicode. |
| 938 | 926 | InvalidUtf8, |
| ... | ... | @@ -940,7 +928,7 @@ pub const UnlinkError = error{ |
| 940 | 928 | /// On Windows, file paths cannot contain these characters: |
| 941 | 929 | /// '/', '*', '?', '"', '<', '>', '|' |
| 942 | 930 | BadPathName, |
| 943 | }; | |
| 931 | } || UnexpectedError; | |
| 944 | 932 | |
| 945 | 933 | /// Delete a name and possibly the file it refers to. |
| 946 | 934 | /// See also `unlinkC`. |
| ... | ... | @@ -996,8 +984,7 @@ const RenameError = error{ |
| 996 | 984 | RenameAcrossMountPoints, |
| 997 | 985 | InvalidUtf8, |
| 998 | 986 | BadPathName, |
| 999 | Unexpected, | |
| 1000 | }; | |
| 987 | } || UnexpectedError; | |
| 1001 | 988 | |
| 1002 | 989 | /// Change the name or location of a file. |
| 1003 | 990 | pub fn rename(old_path: []const u8, new_path: []const u8) RenameError!void { |
| ... | ... | @@ -1064,8 +1051,7 @@ pub const MakeDirError = error{ |
| 1064 | 1051 | ReadOnlyFileSystem, |
| 1065 | 1052 | InvalidUtf8, |
| 1066 | 1053 | BadPathName, |
| 1067 | Unexpected, | |
| 1068 | }; | |
| 1054 | } || UnexpectedError; | |
| 1069 | 1055 | |
| 1070 | 1056 | /// Create a directory. |
| 1071 | 1057 | /// `mode` is ignored on Windows. |
| ... | ... | @@ -1116,8 +1102,7 @@ pub const DeleteDirError = error{ |
| 1116 | 1102 | ReadOnlyFileSystem, |
| 1117 | 1103 | InvalidUtf8, |
| 1118 | 1104 | BadPathName, |
| 1119 | Unexpected, | |
| 1120 | }; | |
| 1105 | } || UnexpectedError; | |
| 1121 | 1106 | |
| 1122 | 1107 | /// Deletes an empty directory. |
| 1123 | 1108 | pub fn rmdir(dir_path: []const u8) DeleteDirError!void { |
| ... | ... | @@ -1163,8 +1148,7 @@ pub const ChangeCurDirError = error{ |
| 1163 | 1148 | FileNotFound, |
| 1164 | 1149 | SystemResources, |
| 1165 | 1150 | NotDir, |
| 1166 | Unexpected, | |
| 1167 | }; | |
| 1151 | } || UnexpectedError; | |
| 1168 | 1152 | |
| 1169 | 1153 | /// Changes the current working directory of the calling process. |
| 1170 | 1154 | /// `dir_path` is recommended to be a UTF-8 encoded string. |
| ... | ... | @@ -1206,8 +1190,7 @@ pub const ReadLinkError = error{ |
| 1206 | 1190 | FileNotFound, |
| 1207 | 1191 | SystemResources, |
| 1208 | 1192 | NotDir, |
| 1209 | Unexpected, | |
| 1210 | }; | |
| 1193 | } || UnexpectedError; | |
| 1211 | 1194 | |
| 1212 | 1195 | /// Read value of a symbolic link. |
| 1213 | 1196 | /// The return value is a slice of `out_buffer` from index 0. |
| ... | ... | @@ -1247,8 +1230,7 @@ pub const SetIdError = error{ |
| 1247 | 1230 | ResourceLimitReached, |
| 1248 | 1231 | InvalidUserId, |
| 1249 | 1232 | PermissionDenied, |
| 1250 | Unexpected, | |
| 1251 | }; | |
| 1233 | } || UnexpectedError; | |
| 1252 | 1234 | |
| 1253 | 1235 | pub fn setuid(uid: u32) SetIdError!void { |
| 1254 | 1236 | switch (errno(system.setuid(uid))) { |
| ... | ... | @@ -1357,9 +1339,7 @@ pub const SocketError = error{ |
| 1357 | 1339 | |
| 1358 | 1340 | /// The protocol type or the specified protocol is not supported within this domain. |
| 1359 | 1341 | ProtocolNotSupported, |
| 1360 | ||
| 1361 | Unexpected, | |
| 1362 | }; | |
| 1342 | } || UnexpectedError; | |
| 1363 | 1343 | |
| 1364 | 1344 | pub fn socket(domain: u32, socket_type: u32, protocol: u32) SocketError!i32 { |
| 1365 | 1345 | const rc = system.socket(domain, socket_type, protocol); |
| ... | ... | @@ -1409,9 +1389,7 @@ pub const BindError = error{ |
| 1409 | 1389 | |
| 1410 | 1390 | /// The socket inode would reside on a read-only filesystem. |
| 1411 | 1391 | ReadOnlyFileSystem, |
| 1412 | ||
| 1413 | Unexpected, | |
| 1414 | }; | |
| 1392 | } || UnexpectedError; | |
| 1415 | 1393 | |
| 1416 | 1394 | /// addr is `*const T` where T is one of the sockaddr |
| 1417 | 1395 | pub fn bind(fd: i32, addr: *const sockaddr) BindError!void { |
| ... | ... | @@ -1448,9 +1426,7 @@ const ListenError = error{ |
| 1448 | 1426 | |
| 1449 | 1427 | /// The socket is not of a type that supports the listen() operation. |
| 1450 | 1428 | OperationNotSupported, |
| 1451 | ||
| 1452 | Unexpected, | |
| 1453 | }; | |
| 1429 | } || UnexpectedError; | |
| 1454 | 1430 | |
| 1455 | 1431 | pub fn listen(sockfd: i32, backlog: u32) ListenError!void { |
| 1456 | 1432 | const rc = system.listen(sockfd, backlog); |
| ... | ... | @@ -1487,9 +1463,7 @@ pub const AcceptError = error{ |
| 1487 | 1463 | |
| 1488 | 1464 | /// Firewall rules forbid connection. |
| 1489 | 1465 | BlockedByFirewall, |
| 1490 | ||
| 1491 | Unexpected, | |
| 1492 | }; | |
| 1466 | } || UnexpectedError; | |
| 1493 | 1467 | |
| 1494 | 1468 | /// Accept a connection on a socket. `fd` must be opened in blocking mode. |
| 1495 | 1469 | /// See also `accept4_async`. |
| ... | ... | @@ -1559,9 +1533,7 @@ pub const EpollCreateError = error{ |
| 1559 | 1533 | |
| 1560 | 1534 | /// There was insufficient memory to create the kernel object. |
| 1561 | 1535 | SystemResources, |
| 1562 | ||
| 1563 | Unexpected, | |
| 1564 | }; | |
| 1536 | } || UnexpectedError; | |
| 1565 | 1537 | |
| 1566 | 1538 | pub fn epoll_create1(flags: u32) EpollCreateError!i32 { |
| 1567 | 1539 | const rc = system.epoll_create1(flags); |
| ... | ... | @@ -1600,9 +1572,7 @@ pub const EpollCtlError = error{ |
| 1600 | 1572 | /// The target file fd does not support epoll. This error can occur if fd refers to, |
| 1601 | 1573 | /// for example, a regular file or a directory. |
| 1602 | 1574 | FileDescriptorIncompatibleWithEpoll, |
| 1603 | ||
| 1604 | Unexpected, | |
| 1605 | }; | |
| 1575 | } || UnexpectedError; | |
| 1606 | 1576 | |
| 1607 | 1577 | pub fn epoll_ctl(epfd: i32, op: u32, fd: i32, event: ?*epoll_event) EpollCtlError!void { |
| 1608 | 1578 | const rc = system.epoll_ctl(epfd, op, fd, event); |
| ... | ... | @@ -1643,8 +1613,7 @@ pub const EventFdError = error{ |
| 1643 | 1613 | SystemResources, |
| 1644 | 1614 | ProcessFdQuotaExceeded, |
| 1645 | 1615 | SystemFdQuotaExceeded, |
| 1646 | Unexpected, | |
| 1647 | }; | |
| 1616 | } || UnexpectedError; | |
| 1648 | 1617 | |
| 1649 | 1618 | pub fn eventfd(initval: u32, flags: u32) EventFdError!i32 { |
| 1650 | 1619 | const rc = system.eventfd(initval, flags); |
| ... | ... | @@ -1663,9 +1632,7 @@ pub fn eventfd(initval: u32, flags: u32) EventFdError!i32 { |
| 1663 | 1632 | pub const GetSockNameError = error{ |
| 1664 | 1633 | /// Insufficient resources were available in the system to perform the operation. |
| 1665 | 1634 | SystemResources, |
| 1666 | ||
| 1667 | Unexpected, | |
| 1668 | }; | |
| 1635 | } || UnexpectedError; | |
| 1669 | 1636 | |
| 1670 | 1637 | pub fn getsockname(sockfd: i32) GetSockNameError!sockaddr { |
| 1671 | 1638 | var addr: sockaddr = undefined; |
| ... | ... | @@ -1714,9 +1681,7 @@ pub const ConnectError = error{ |
| 1714 | 1681 | /// Timeout while attempting connection. The server may be too busy to accept new connections. Note |
| 1715 | 1682 | /// that for IP sockets the timeout may be very long when syncookies are enabled on the server. |
| 1716 | 1683 | ConnectionTimedOut, |
| 1717 | ||
| 1718 | Unexpected, | |
| 1719 | }; | |
| 1684 | } || UnexpectedError; | |
| 1720 | 1685 | |
| 1721 | 1686 | /// Initiate a connection on a socket. |
| 1722 | 1687 | /// This is for blocking file descriptors only. |
| ... | ... | @@ -1824,10 +1789,7 @@ pub fn waitpid(pid: i32, flags: u32) u32 { |
| 1824 | 1789 | } |
| 1825 | 1790 | } |
| 1826 | 1791 | |
| 1827 | pub const FStatError = error{ | |
| 1828 | SystemResources, | |
| 1829 | Unexpected, | |
| 1830 | }; | |
| 1792 | pub const FStatError = error{SystemResources} || UnexpectedError; | |
| 1831 | 1793 | |
| 1832 | 1794 | pub fn fstat(fd: fd_t) FStatError!Stat { |
| 1833 | 1795 | var stat: Stat = undefined; |
| ... | ... | @@ -1856,9 +1818,7 @@ pub const KQueueError = error{ |
| 1856 | 1818 | |
| 1857 | 1819 | /// The system-wide limit on the total number of open files has been reached. |
| 1858 | 1820 | SystemFdQuotaExceeded, |
| 1859 | ||
| 1860 | Unexpected, | |
| 1861 | }; | |
| 1821 | } || UnexpectedError; | |
| 1862 | 1822 | |
| 1863 | 1823 | pub fn kqueue() KQueueError!i32 { |
| 1864 | 1824 | const rc = system.kqueue(); |
| ... | ... | @@ -1922,8 +1882,7 @@ pub const INotifyInitError = error{ |
| 1922 | 1882 | ProcessFdQuotaExceeded, |
| 1923 | 1883 | SystemFdQuotaExceeded, |
| 1924 | 1884 | SystemResources, |
| 1925 | Unexpected, | |
| 1926 | }; | |
| 1885 | } || UnexpectedError; | |
| 1927 | 1886 | |
| 1928 | 1887 | /// initialize an inotify instance |
| 1929 | 1888 | pub fn inotify_init1(flags: u32) INotifyInitError!i32 { |
| ... | ... | @@ -1944,8 +1903,7 @@ pub const INotifyAddWatchError = error{ |
| 1944 | 1903 | FileNotFound, |
| 1945 | 1904 | SystemResources, |
| 1946 | 1905 | UserResourceLimitReached, |
| 1947 | Unexpected, | |
| 1948 | }; | |
| 1906 | } || UnexpectedError; | |
| 1949 | 1907 | |
| 1950 | 1908 | /// add a watch to an initialized inotify instance |
| 1951 | 1909 | pub fn inotify_add_watch(inotify_fd: i32, pathname: []const u8, mask: u32) INotifyAddWatchError!i32 { |
| ... | ... | @@ -1992,8 +1950,7 @@ pub const MProtectError = error{ |
| 1992 | 1950 | /// dle of a region currently protected as PROT_READ|PROT_WRITE would result in three map‐ |
| 1993 | 1951 | /// pings: two read/write mappings at each end and a read-only mapping in the middle.) |
| 1994 | 1952 | OutOfMemory, |
| 1995 | Unexpected, | |
| 1996 | }; | |
| 1953 | } || UnexpectedError; | |
| 1997 | 1954 | |
| 1998 | 1955 | /// `memory.len` must be page-aligned. |
| 1999 | 1956 | pub fn mprotect(memory: []align(mem.page_size) u8, protection: u32) MProtectError!void { |
| ... | ... | @@ -2007,10 +1964,7 @@ pub fn mprotect(memory: []align(mem.page_size) u8, protection: u32) MProtectErro |
| 2007 | 1964 | } |
| 2008 | 1965 | } |
| 2009 | 1966 | |
| 2010 | pub const ForkError = error{ | |
| 2011 | SystemResources, | |
| 2012 | Unexpected, | |
| 2013 | }; | |
| 1967 | pub const ForkError = error{SystemResources} || UnexpectedError; | |
| 2014 | 1968 | |
| 2015 | 1969 | pub fn fork() ForkError!pid_t { |
| 2016 | 1970 | const rc = system.fork(); |
| ... | ... | @@ -2037,8 +1991,7 @@ pub const MMapError = error{ |
| 2037 | 1991 | PermissionDenied, |
| 2038 | 1992 | LockedMemoryLimitExceeded, |
| 2039 | 1993 | OutOfMemory, |
| 2040 | Unexpected, | |
| 2041 | }; | |
| 1994 | } || UnexpectedError; | |
| 2042 | 1995 | |
| 2043 | 1996 | /// Map files or devices into memory. |
| 2044 | 1997 | /// Use of a mapped region can result in these signals: |
| ... | ... | @@ -2101,9 +2054,7 @@ pub const AccessError = error{ |
| 2101 | 2054 | |
| 2102 | 2055 | /// On Windows, file paths must be valid Unicode. |
| 2103 | 2056 | InvalidUtf8, |
| 2104 | ||
| 2105 | Unexpected, | |
| 2106 | }; | |
| 2057 | } || UnexpectedError; | |
| 2107 | 2058 | |
| 2108 | 2059 | /// check user's permissions for a file |
| 2109 | 2060 | /// TODO currently this assumes `mode` is `F_OK` on Windows. |
| ... | ... | @@ -2161,8 +2112,7 @@ pub fn accessW(path: [*]const u16, mode: u32) windows.GetFileAttributesError!voi |
| 2161 | 2112 | pub const PipeError = error{ |
| 2162 | 2113 | SystemFdQuotaExceeded, |
| 2163 | 2114 | ProcessFdQuotaExceeded, |
| 2164 | Unexpected, | |
| 2165 | }; | |
| 2115 | } || UnexpectedError; | |
| 2166 | 2116 | |
| 2167 | 2117 | /// Creates a unidirectional data channel that can be used for interprocess communication. |
| 2168 | 2118 | pub fn pipe() PipeError![2]fd_t { |
| ... | ... | @@ -2193,8 +2143,7 @@ pub const SysCtlError = error{ |
| 2193 | 2143 | PermissionDenied, |
| 2194 | 2144 | SystemResources, |
| 2195 | 2145 | NameTooLong, |
| 2196 | Unexpected, | |
| 2197 | }; | |
| 2146 | } || UnexpectedError; | |
| 2198 | 2147 | |
| 2199 | 2148 | pub fn sysctl( |
| 2200 | 2149 | name: []const c_int, |
| ... | ... | @@ -2237,10 +2186,7 @@ pub fn gettimeofday(tv: ?*timeval, tz: ?*timezone) void { |
| 2237 | 2186 | } |
| 2238 | 2187 | } |
| 2239 | 2188 | |
| 2240 | pub const SeekError = error{ | |
| 2241 | Unseekable, | |
| 2242 | Unexpected, | |
| 2243 | }; | |
| 2189 | pub const SeekError = error{Unseekable} || UnexpectedError; | |
| 2244 | 2190 | |
| 2245 | 2191 | /// Repositions read/write file offset relative to the beginning. |
| 2246 | 2192 | pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void { |
| ... | ... | @@ -2382,9 +2328,7 @@ pub const RealPathError = error{ |
| 2382 | 2328 | InvalidUtf8, |
| 2383 | 2329 | |
| 2384 | 2330 | PathAlreadyExists, |
| 2385 | ||
| 2386 | Unexpected, | |
| 2387 | }; | |
| 2331 | } || UnexpectedError; | |
| 2388 | 2332 | |
| 2389 | 2333 | /// Return the canonicalized absolute pathname. |
| 2390 | 2334 | /// Expands all symbolic links and resolves references to `.`, `..`, and |
| ... | ... | @@ -2548,10 +2492,7 @@ pub fn dl_iterate_phdr(comptime T: type, callback: extern fn (info: *dl_phdr_inf |
| 2548 | 2492 | return last_r; |
| 2549 | 2493 | } |
| 2550 | 2494 | |
| 2551 | pub const ClockGetTimeError = error{ | |
| 2552 | UnsupportedClock, | |
| 2553 | Unexpected, | |
| 2554 | }; | |
| 2495 | pub const ClockGetTimeError = error{UnsupportedClock} || UnexpectedError; | |
| 2555 | 2496 | |
| 2556 | 2497 | pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void { |
| 2557 | 2498 | switch (errno(system.clock_gettime(clk_id, tp))) { |
| ... | ... | @@ -2571,10 +2512,7 @@ pub fn clock_getres(clk_id: i32, res: *timespec) ClockGetTimeError!void { |
| 2571 | 2512 | } |
| 2572 | 2513 | } |
| 2573 | 2514 | |
| 2574 | pub const SchedGetAffinityError = error{ | |
| 2575 | PermissionDenied, | |
| 2576 | Unexpected, | |
| 2577 | }; | |
| 2515 | pub const SchedGetAffinityError = error{PermissionDenied} || UnexpectedError; | |
| 2578 | 2516 | |
| 2579 | 2517 | pub fn sched_getaffinity(pid: pid_t) SchedGetAffinityError!cpu_set_t { |
| 2580 | 2518 | var set: cpu_set_t = undefined; |
| ... | ... | @@ -2628,8 +2566,7 @@ pub const SigaltstackError = error{ |
| 2628 | 2566 | |
| 2629 | 2567 | /// Attempted to change the signal stack while it was active. |
| 2630 | 2568 | PermissionDenied, |
| 2631 | Unexpected, | |
| 2632 | }; | |
| 2569 | } || UnexpectedError; | |
| 2633 | 2570 | |
| 2634 | 2571 | pub fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) SigaltstackError!void { |
| 2635 | 2572 | if (windows.is_the_target or uefi.is_the_target or wasi.is_the_target) |
| ... | ... | @@ -2677,9 +2614,7 @@ pub const FutimensError = error{ |
| 2677 | 2614 | PermissionDenied, |
| 2678 | 2615 | |
| 2679 | 2616 | ReadOnlyFileSystem, |
| 2680 | ||
| 2681 | Unexpected, | |
| 2682 | }; | |
| 2617 | } || UnexpectedError; | |
| 2683 | 2618 | |
| 2684 | 2619 | pub fn futimens(fd: fd_t, times: *const [2]timespec) FutimensError!void { |
| 2685 | 2620 | switch (errno(system.futimens(fd, times))) { |
| ... | ... | @@ -2694,10 +2629,7 @@ pub fn futimens(fd: fd_t, times: *const [2]timespec) FutimensError!void { |
| 2694 | 2629 | } |
| 2695 | 2630 | } |
| 2696 | 2631 | |
| 2697 | pub const GetHostNameError = error{ | |
| 2698 | PermissionDenied, | |
| 2699 | Unexpected, | |
| 2700 | }; | |
| 2632 | pub const GetHostNameError = error{PermissionDenied} || UnexpectedError; | |
| 2701 | 2633 | |
| 2702 | 2634 | pub fn gethostname(name_buffer: *[HOST_NAME_MAX]u8) GetHostNameError![]u8 { |
| 2703 | 2635 | if (builtin.link_libc) { |
lib/std/special/docs/index.html+15-2| ... | ... | @@ -87,7 +87,7 @@ |
| 87 | 87 | #listPkgs li a { |
| 88 | 88 | display: block; |
| 89 | 89 | color: #000; |
| 90 | padding: 8px 16px; | |
| 90 | padding: 0.5em 1em; | |
| 91 | 91 | text-decoration: none; |
| 92 | 92 | } |
| 93 | 93 | #listPkgs li a:hover { |
| ... | ... | @@ -145,6 +145,13 @@ |
| 145 | 145 | #listSearchResults li.selected { |
| 146 | 146 | background-color: #93e196; |
| 147 | 147 | } |
| 148 | ||
| 149 | #tableFnErrors tr td:first-child{ | |
| 150 | text-align: right; | |
| 151 | font-weight: bold; | |
| 152 | vertical-align: top; | |
| 153 | } | |
| 154 | ||
| 148 | 155 | .tok-kw { |
| 149 | 156 | color: #333; |
| 150 | 157 | font-weight: bold; |
| ... | ... | @@ -262,7 +269,13 @@ |
| 262 | 269 | </div> |
| 263 | 270 | <h1 id="hdrName" class="hidden"></h1> |
| 264 | 271 | <div id="fnDocs" class="hidden"></div> |
| 265 | <div id="fnErrors" class="hidden"></div> | |
| 272 | <div id="sectFnErrors" class="hidden"> | |
| 273 | <h2>Errors</h2> | |
| 274 | <div id="fnErrorsAnyError"> | |
| 275 | <p><span class="tok-type">anyerror</span> means the error set is known only at runtime.</p> | |
| 276 | </div> | |
| 277 | <table id="tableFnErrors"><tbody id="listFnErrors"></tbody></table> | |
| 278 | </div> | |
| 266 | 279 | <div id="fnExamples" class="hidden"></div> |
| 267 | 280 | <div id="fnNoExamples" class="hidden"> |
| 268 | 281 | <p>This function is not tested or referenced.</p> |
lib/std/special/docs/main.js+70-4| ... | ... | @@ -13,7 +13,10 @@ |
| 13 | 13 | var domFnProto = document.getElementById("fnProto"); |
| 14 | 14 | var domFnProtoCode = document.getElementById("fnProtoCode"); |
| 15 | 15 | var domFnDocs = document.getElementById("fnDocs"); |
| 16 | var domFnErrors = document.getElementById("fnErrors"); | |
| 16 | var domSectFnErrors = document.getElementById("sectFnErrors"); | |
| 17 | var domListFnErrors = document.getElementById("listFnErrors"); | |
| 18 | var domTableFnErrors = document.getElementById("tableFnErrors"); | |
| 19 | var domFnErrorsAnyError = document.getElementById("fnErrorsAnyError"); | |
| 17 | 20 | var domFnExamples = document.getElementById("fnExamples"); |
| 18 | 21 | var domFnNoExamples = document.getElementById("fnNoExamples"); |
| 19 | 22 | var domSearch = document.getElementById("search"); |
| ... | ... | @@ -36,6 +39,7 @@ |
| 36 | 39 | var typeKindFloatId; |
| 37 | 40 | var typeKindIntId; |
| 38 | 41 | var typeKindBoolId; |
| 42 | var typeKindVoidId; | |
| 39 | 43 | var typeKindErrSetId; |
| 40 | 44 | var typeKindErrUnionId; |
| 41 | 45 | findTypeKinds(); |
| ... | ... | @@ -102,9 +106,11 @@ |
| 102 | 106 | domSectInfo.classList.add("hidden"); |
| 103 | 107 | domHdrName.classList.add("hidden"); |
| 104 | 108 | domSectNav.classList.add("hidden"); |
| 105 | domFnErrors.classList.add("hidden"); | |
| 109 | domSectFnErrors.classList.add("hidden"); | |
| 106 | 110 | domFnExamples.classList.add("hidden"); |
| 107 | 111 | domFnNoExamples.classList.add("hidden"); |
| 112 | domFnErrorsAnyError.classList.add("hidden"); | |
| 113 | domTableFnErrors.classList.add("hidden"); | |
| 108 | 114 | |
| 109 | 115 | renderTitle(); |
| 110 | 116 | renderInfo(); |
| ... | ... | @@ -202,6 +208,51 @@ |
| 202 | 208 | docsSource = srcNode.docs; |
| 203 | 209 | } |
| 204 | 210 | |
| 211 | var errSetTypeIndex = null; | |
| 212 | if (typeObj.ret != null) { | |
| 213 | var retType = zigAnalysis.types[typeObj.ret]; | |
| 214 | if (retType.kind === typeKindErrSetId) { | |
| 215 | errSetTypeIndex = typeObj.ret; | |
| 216 | } else if (retType.kind === typeKindErrUnionId) { | |
| 217 | errSetTypeIndex = retType.err; | |
| 218 | } | |
| 219 | } | |
| 220 | if (errSetTypeIndex != null) { | |
| 221 | var errSetType = zigAnalysis.types[errSetTypeIndex]; | |
| 222 | if (errSetType.errors == null) { | |
| 223 | domFnErrorsAnyError.classList.remove("hidden"); | |
| 224 | } else { | |
| 225 | var errorList = []; | |
| 226 | for (var i = 0; i < errSetType.errors.length; i += 1) { | |
| 227 | var errObj = zigAnalysis.errors[errSetType.errors[i]]; | |
| 228 | var srcObj = zigAnalysis.astNodes[errObj.src]; | |
| 229 | errorList.push({ | |
| 230 | err: errObj, | |
| 231 | docs: srcObj.docs, | |
| 232 | }); | |
| 233 | } | |
| 234 | errorList.sort(function(a, b) { | |
| 235 | return operatorCompare(a.err.name.toLowerCase(), b.err.name.toLowerCase()); | |
| 236 | }); | |
| 237 | ||
| 238 | resizeDomList(domListFnErrors, errorList.length, '<tr><td></td><td></td></tr>'); | |
| 239 | for (var i = 0; i < errorList.length; i += 1) { | |
| 240 | var trDom = domListFnErrors.children[i]; | |
| 241 | var nameTdDom = trDom.children[0]; | |
| 242 | var descTdDom = trDom.children[1]; | |
| 243 | nameTdDom.textContent = errorList[i].err.name; | |
| 244 | var docs = errorList[i].docs; | |
| 245 | if (docs != null) { | |
| 246 | descTdDom.innerHTML = markdown(docs); | |
| 247 | } else { | |
| 248 | descTdDom.textContent = ""; | |
| 249 | } | |
| 250 | } | |
| 251 | domTableFnErrors.classList.remove("hidden"); | |
| 252 | } | |
| 253 | domSectFnErrors.classList.remove("hidden"); | |
| 254 | } | |
| 255 | ||
| 205 | 256 | var protoSrcIndex; |
| 206 | 257 | if (typeIsGenericFn(fnDecl.type)) { |
| 207 | 258 | protoSrcIndex = fnDecl.value; |
| ... | ... | @@ -285,9 +336,11 @@ |
| 285 | 336 | var list = []; |
| 286 | 337 | for (var key in rootPkg.table) { |
| 287 | 338 | if (key === "root" && rootIsStd) continue; |
| 339 | var pkgIndex = rootPkg.table[key]; | |
| 340 | if (zigAnalysis.packages[pkgIndex] == null) continue; | |
| 288 | 341 | list.push({ |
| 289 | 342 | name: key, |
| 290 | pkg: rootPkg.table[key], | |
| 343 | pkg: pkgIndex, | |
| 291 | 344 | }); |
| 292 | 345 | } |
| 293 | 346 | list.sort(function(a, b) { |
| ... | ... | @@ -447,6 +500,12 @@ |
| 447 | 500 | } else { |
| 448 | 501 | return "bool"; |
| 449 | 502 | } |
| 503 | case typeKindVoidId: | |
| 504 | if (wantHtml) { | |
| 505 | return '<span class="tok-type">void</span>'; | |
| 506 | } else { | |
| 507 | return "void"; | |
| 508 | } | |
| 450 | 509 | case typeKindErrSetId: |
| 451 | 510 | if (typeObj.errors == null) { |
| 452 | 511 | if (wantHtml) { |
| ... | ... | @@ -580,6 +639,7 @@ |
| 580 | 639 | return false; |
| 581 | 640 | } |
| 582 | 641 | var stdPkg = zigAnalysis.packages[rootPkg.table["std"]]; |
| 642 | if (stdPkg == null) return false; | |
| 583 | 643 | return rootPkg.file === stdPkg.file; |
| 584 | 644 | } |
| 585 | 645 | |
| ... | ... | @@ -597,6 +657,8 @@ |
| 597 | 657 | typeKindIntId = i; |
| 598 | 658 | } else if (zigAnalysis.typeKinds[i] === "Bool") { |
| 599 | 659 | typeKindBoolId = i; |
| 660 | } else if (zigAnalysis.typeKinds[i] === "Void") { | |
| 661 | typeKindVoidId = i; | |
| 600 | 662 | } else if (zigAnalysis.typeKinds[i] === "ErrorSet") { |
| 601 | 663 | typeKindErrSetId = i; |
| 602 | 664 | } else if (zigAnalysis.typeKinds[i] === "ErrorUnion") { |
| ... | ... | @@ -621,6 +683,9 @@ |
| 621 | 683 | if (typeKindBoolId == null) { |
| 622 | 684 | throw new Error("No type kind 'Bool' found"); |
| 623 | 685 | } |
| 686 | if (typeKindVoidId == null) { | |
| 687 | throw new Error("No type kind 'Void' found"); | |
| 688 | } | |
| 624 | 689 | if (typeKindErrSetId == null) { |
| 625 | 690 | throw new Error("No type kind 'ErrorSet' found"); |
| 626 | 691 | } |
| ... | ... | @@ -702,10 +767,11 @@ |
| 702 | 767 | for (var key in item.pkg.table) { |
| 703 | 768 | var childPkgIndex = item.pkg.table[key]; |
| 704 | 769 | if (list[childPkgIndex] != null) continue; |
| 770 | var childPkg = zigAnalysis.packages[childPkgIndex]; | |
| 771 | if (childPkg == null) continue; | |
| 705 | 772 | |
| 706 | 773 | var newPath = item.path.concat([key]) |
| 707 | 774 | list[childPkgIndex] = newPath; |
| 708 | var childPkg = zigAnalysis.packages[childPkgIndex]; | |
| 709 | 775 | stack.push({ |
| 710 | 776 | path: newPath, |
| 711 | 777 | pkg: childPkg, |
src/all_types.hpp+1| ... | ... | @@ -2146,6 +2146,7 @@ struct ErrorTableEntry { |
| 2146 | 2146 | Buf name; |
| 2147 | 2147 | uint32_t value; |
| 2148 | 2148 | AstNode *decl_node; |
| 2149 | ErrorTableEntry *other; // null, or another error decl that was merged into this | |
| 2149 | 2150 | ZigType *set_with_only_this_in_it; |
| 2150 | 2151 | // If we generate a constant error name value for this error, we memoize it here. |
| 2151 | 2152 | // The type of this is array |
src/dump_analysis.cpp+3| ... | ... | @@ -892,6 +892,9 @@ static void anal_dump_type(AnalDumpCtx *ctx, ZigType *ty) { |
| 892 | 892 | if (type_is_global_error_set(ty)) { |
| 893 | 893 | break; |
| 894 | 894 | } |
| 895 | jw_object_field(jw, "name"); | |
| 896 | jw_string(jw, buf_ptr(&ty->name)); | |
| 897 | ||
| 895 | 898 | if (ty->data.error_set.infer_fn != nullptr) { |
| 896 | 899 | jw_object_field(jw, "fn"); |
| 897 | 900 | anal_dump_fn_ref(ctx, ty->data.error_set.infer_fn); |
src/ir.cpp+37-16| ... | ... | @@ -7892,11 +7892,14 @@ static ZigType *get_error_set_union(CodeGen *g, ErrorTableEntry **errors, ZigTyp |
| 7892 | 7892 | } |
| 7893 | 7893 | |
| 7894 | 7894 | uint32_t index = set1->data.error_set.err_count; |
| 7895 | bool need_comma = false; | |
| 7895 | 7896 | for (uint32_t i = 0; i < set2->data.error_set.err_count; i += 1) { |
| 7896 | 7897 | ErrorTableEntry *error_entry = set2->data.error_set.errors[i]; |
| 7897 | 7898 | if (errors[error_entry->value] == nullptr) { |
| 7898 | 7899 | errors[error_entry->value] = error_entry; |
| 7899 | buf_appendf(&err_set_type->name, "%s,", buf_ptr(&error_entry->name)); | |
| 7900 | const char *comma = need_comma ? "," : ""; | |
| 7901 | need_comma = true; | |
| 7902 | buf_appendf(&err_set_type->name, "%s%s", comma, buf_ptr(&error_entry->name)); | |
| 7900 | 7903 | err_set_type->data.error_set.errors[index] = error_entry; |
| 7901 | 7904 | index += 1; |
| 7902 | 7905 | } |
| ... | ... | @@ -7927,6 +7930,17 @@ static ZigType *make_err_set_with_one_item(CodeGen *g, Scope *parent_scope, AstN |
| 7927 | 7930 | return err_set_type; |
| 7928 | 7931 | } |
| 7929 | 7932 | |
| 7933 | static AstNode *ast_field_to_symbol_node(AstNode *err_set_field_node) { | |
| 7934 | if (err_set_field_node->type == NodeTypeSymbol) { | |
| 7935 | return err_set_field_node; | |
| 7936 | } else if (err_set_field_node->type == NodeTypeErrorSetField) { | |
| 7937 | assert(err_set_field_node->data.err_set_field.field_name->type == NodeTypeSymbol); | |
| 7938 | return err_set_field_node->data.err_set_field.field_name; | |
| 7939 | } else { | |
| 7940 | return err_set_field_node; | |
| 7941 | } | |
| 7942 | } | |
| 7943 | ||
| 7930 | 7944 | static IrInstruction *ir_gen_err_set_decl(IrBuilder *irb, Scope *parent_scope, AstNode *node) { |
| 7931 | 7945 | assert(node->type == NodeTypeErrorSetDecl); |
| 7932 | 7946 | |
| ... | ... | @@ -7946,18 +7960,10 @@ static IrInstruction *ir_gen_err_set_decl(IrBuilder *irb, Scope *parent_scope, A |
| 7946 | 7960 | |
| 7947 | 7961 | for (uint32_t i = 0; i < err_count; i += 1) { |
| 7948 | 7962 | AstNode *field_node = node->data.err_set_decl.decls.at(i); |
| 7949 | AstNode *symbol_node; | |
| 7950 | if (field_node->type == NodeTypeSymbol) { | |
| 7951 | symbol_node = field_node; | |
| 7952 | } else if (field_node->type == NodeTypeErrorSetField) { | |
| 7953 | symbol_node = field_node->data.err_set_field.field_name; | |
| 7954 | } else { | |
| 7955 | zig_unreachable(); | |
| 7956 | } | |
| 7957 | assert(symbol_node->type == NodeTypeSymbol); | |
| 7963 | AstNode *symbol_node = ast_field_to_symbol_node(field_node); | |
| 7958 | 7964 | Buf *err_name = symbol_node->data.symbol_expr.symbol; |
| 7959 | 7965 | ErrorTableEntry *err = allocate<ErrorTableEntry>(1); |
| 7960 | err->decl_node = symbol_node; | |
| 7966 | err->decl_node = field_node; | |
| 7961 | 7967 | buf_init_from_buf(&err->name, err_name); |
| 7962 | 7968 | |
| 7963 | 7969 | auto existing_entry = irb->codegen->error_table.put_unique(err_name, err); |
| ... | ... | @@ -7973,8 +7979,10 @@ static IrInstruction *ir_gen_err_set_decl(IrBuilder *irb, Scope *parent_scope, A |
| 7973 | 7979 | |
| 7974 | 7980 | ErrorTableEntry *prev_err = errors[err->value]; |
| 7975 | 7981 | if (prev_err != nullptr) { |
| 7976 | ErrorMsg *msg = add_node_error(irb->codegen, err->decl_node, buf_sprintf("duplicate error: '%s'", buf_ptr(&err->name))); | |
| 7977 | add_error_note(irb->codegen, msg, prev_err->decl_node, buf_sprintf("other error here")); | |
| 7982 | ErrorMsg *msg = add_node_error(irb->codegen, ast_field_to_symbol_node(err->decl_node), | |
| 7983 | buf_sprintf("duplicate error: '%s'", buf_ptr(&err->name))); | |
| 7984 | add_error_note(irb->codegen, msg, ast_field_to_symbol_node(prev_err->decl_node), | |
| 7985 | buf_sprintf("other error here")); | |
| 7978 | 7986 | return irb->codegen->invalid_instruction; |
| 7979 | 7987 | } |
| 7980 | 7988 | errors[err->value] = err; |
| ... | ... | @@ -9479,6 +9487,14 @@ static void populate_error_set_table(ErrorTableEntry **errors, ZigType *set) { |
| 9479 | 9487 | } |
| 9480 | 9488 | } |
| 9481 | 9489 | |
| 9490 | static ErrorTableEntry *better_documented_error(ErrorTableEntry *preferred, ErrorTableEntry *other) { | |
| 9491 | if (preferred->decl_node->type == NodeTypeErrorSetField) | |
| 9492 | return preferred; | |
| 9493 | if (other->decl_node->type == NodeTypeErrorSetField) | |
| 9494 | return other; | |
| 9495 | return preferred; | |
| 9496 | } | |
| 9497 | ||
| 9482 | 9498 | static ZigType *get_error_set_intersection(IrAnalyze *ira, ZigType *set1, ZigType *set2, |
| 9483 | 9499 | AstNode *source_node) |
| 9484 | 9500 | { |
| ... | ... | @@ -9505,12 +9521,17 @@ static ZigType *get_error_set_intersection(IrAnalyze *ira, ZigType *set1, ZigTyp |
| 9505 | 9521 | buf_resize(&err_set_type->name, 0); |
| 9506 | 9522 | buf_appendf(&err_set_type->name, "error{"); |
| 9507 | 9523 | |
| 9524 | bool need_comma = false; | |
| 9508 | 9525 | for (uint32_t i = 0; i < set2->data.error_set.err_count; i += 1) { |
| 9509 | 9526 | ErrorTableEntry *error_entry = set2->data.error_set.errors[i]; |
| 9510 | 9527 | ErrorTableEntry *existing_entry = errors[error_entry->value]; |
| 9511 | 9528 | if (existing_entry != nullptr) { |
| 9512 | intersection_list.append(existing_entry); | |
| 9513 | buf_appendf(&err_set_type->name, "%s,", buf_ptr(&existing_entry->name)); | |
| 9529 | // prefer the one with docs | |
| 9530 | const char *comma = need_comma ? "," : ""; | |
| 9531 | need_comma = true; | |
| 9532 | ErrorTableEntry *existing_entry_with_docs = better_documented_error(existing_entry, error_entry); | |
| 9533 | intersection_list.append(existing_entry_with_docs); | |
| 9534 | buf_appendf(&err_set_type->name, "%s%s", comma, buf_ptr(&existing_entry_with_docs->name)); | |
| 9514 | 9535 | } |
| 9515 | 9536 | } |
| 9516 | 9537 | free(errors); |
| ... | ... | @@ -12058,7 +12079,7 @@ static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCa |
| 12058 | 12079 | ZigList<ErrorTableEntry *> *missing_errors = &cast_result->data.error_set_mismatch->missing_errors; |
| 12059 | 12080 | for (size_t i = 0; i < missing_errors->length; i += 1) { |
| 12060 | 12081 | ErrorTableEntry *error_entry = missing_errors->at(i); |
| 12061 | add_error_note(ira->codegen, parent_msg, error_entry->decl_node, | |
| 12082 | add_error_note(ira->codegen, parent_msg, ast_field_to_symbol_node(error_entry->decl_node), | |
| 12062 | 12083 | buf_sprintf("'error.%s' not a member of destination error set", buf_ptr(&error_entry->name))); |
| 12063 | 12084 | } |
| 12064 | 12085 | break; |
src/parser.cpp+5-1| ... | ... | @@ -498,8 +498,12 @@ static AstNode *ast_parse_root(ParseContext *pc) { |
| 498 | 498 | } |
| 499 | 499 | |
| 500 | 500 | static Token *ast_parse_doc_comments(ParseContext *pc, Buf *buf) { |
| 501 | Token *first_doc_token = nullptr; | |
| 501 | 502 | Token *doc_token = nullptr; |
| 502 | 503 | while ((doc_token = eat_token_if(pc, TokenIdDocComment))) { |
| 504 | if (first_doc_token == nullptr) { | |
| 505 | first_doc_token = doc_token; | |
| 506 | } | |
| 503 | 507 | if (buf->list.length == 0) { |
| 504 | 508 | buf_resize(buf, 0); |
| 505 | 509 | } |
| ... | ... | @@ -507,7 +511,7 @@ static Token *ast_parse_doc_comments(ParseContext *pc, Buf *buf) { |
| 507 | 511 | buf_append_mem(buf, buf_ptr(pc->buf) + doc_token->start_pos + 3, |
| 508 | 512 | doc_token->end_pos - doc_token->start_pos - 3); |
| 509 | 513 | } |
| 510 | return doc_token; | |
| 514 | return first_doc_token; | |
| 511 | 515 | } |
| 512 | 516 | |
| 513 | 517 | // ContainerMembers |