mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-04-27 19:09:47 +03:00
std.c reorganization
It is now composed of these main sections:
* Declarations that are shared among all operating systems.
* Declarations that have the same name, but different type signatures
depending on the operating system. Often multiple operating systems
share the same type signatures however.
* Declarations that are specific to a single operating system.
- These are imported one per line so you can see where they come from,
protected by a comptime block to prevent accessing the wrong one.
Closes #19352 by changing the convention to making types `void` and
functions `{}`, so that it becomes possible to update `@hasDecl` sites
to use `@TypeOf(f) != void` or `T != void`. Happily, this ended up
removing some duplicate logic and update some bitrotted feature
detection checks.
A handful of types have been modified to gain namespacing and type
safety. This is a breaking change.
Oh, and the last usage of `usingnamespace` site is eliminated.
This commit is contained in:
+7
-7
@@ -115,10 +115,10 @@ pub fn nanoTimestamp() i128 {
|
||||
},
|
||||
else => {
|
||||
var ts: posix.timespec = undefined;
|
||||
posix.clock_gettime(posix.CLOCK.REALTIME, &ts) catch |err| switch (err) {
|
||||
posix.clock_gettime(.REALTIME, &ts) catch |err| switch (err) {
|
||||
error.UnsupportedClock, error.Unexpected => return 0, // "Precision of timing depends on hardware and OS".
|
||||
};
|
||||
return (@as(i128, ts.tv_sec) * ns_per_s) + ts.tv_nsec;
|
||||
return (@as(i128, ts.sec) * ns_per_s) + ts.nsec;
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -229,9 +229,9 @@ pub const Instant = struct {
|
||||
return std.math.order(self.timestamp, other.timestamp);
|
||||
}
|
||||
|
||||
var ord = std.math.order(self.timestamp.tv_sec, other.timestamp.tv_sec);
|
||||
var ord = std.math.order(self.timestamp.sec, other.timestamp.sec);
|
||||
if (ord == .eq) {
|
||||
ord = std.math.order(self.timestamp.tv_nsec, other.timestamp.tv_nsec);
|
||||
ord = std.math.order(self.timestamp.nsec, other.timestamp.nsec);
|
||||
}
|
||||
return ord;
|
||||
}
|
||||
@@ -267,9 +267,9 @@ pub const Instant = struct {
|
||||
}
|
||||
|
||||
// Convert timespec diff to ns
|
||||
const seconds = @as(u64, @intCast(self.timestamp.tv_sec - earlier.timestamp.tv_sec));
|
||||
const elapsed = (seconds * ns_per_s) + @as(u32, @intCast(self.timestamp.tv_nsec));
|
||||
return elapsed - @as(u32, @intCast(earlier.timestamp.tv_nsec));
|
||||
const seconds = @as(u64, @intCast(self.timestamp.sec - earlier.timestamp.sec));
|
||||
const elapsed = (seconds * ns_per_s) + @as(u32, @intCast(self.timestamp.nsec));
|
||||
return elapsed - @as(u32, @intCast(earlier.timestamp.nsec));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user