<andrewrk>
cr1901_modern, I think you probably want std.fs.cwd().readFileAlloc
<andrewrk>
for this function you will only have to give the maximum number of bytes that are allowed before returning error.FileTooBig. if you want to allow any size, use math.maxInt(usize)
<cr1901_modern>
What is this form for, out of curiosity? const buf = try fp.readAllAlloc(allocator, 500, 1024);
<Cadey>
is it normal for std.log to not show up in release binaries?
<cr1901_modern>
Note that setting the second param to 0 causes nothing to be read, and setting to 1024 causes "endOfStream"
<andrewrk>
cr1901_modern, it's a lower-level API for when you already have done a stat syscall and know the file size
<andrewrk>
it's a common pattern in zig to expose both higher and lower level APIs
<andrewrk>
Cadey, I think std.log is documented pretty well if you have a look at lib/std/log.zig
<Cadey>
ah
* Cadey
looks
<andrewrk>
it's highly configurable, so whatever the behavior is that you want, I'm sure you can get it
<Cadey>
what's the printf equivalent for always printing things?
<andrewrk>
std.debug.print will do a mutex-protected print to stderr
<Cadey>
in release binaries too?
<andrewrk>
yes
<andrewrk>
are you sure you don't want to just use stdout like a normal file?
<andrewrk>
I can advise if you explain your use case more
waleee-cl has quit [Quit: Connection closed for inactivity]
<Cadey>
printing a logo on startup of a program :D
<daurnimator>
misc idea re: the stderr lock: when linking with libc, should we use flockfile/funlockfile?
<Cadey>
okay
<Cadey>
life pro tip
<Cadey>
when testing something that runs the reboot() system call
<Cadey>
don't run it as root
<Cadey>
that will make your system reboot
<andrewrk>
hmmm logo on startup... does it print anything else over the life of the program?
<andrewrk>
lol
<Cadey>
ikr
<andrewrk>
daurnimator, yes when linking libc, std.debug.print should use flockfile/funlockfile instead of its own mutex, assuming that's what libc does internally for fprintf
<andrewrk>
Cadey, IMO for the logo, just do in main() `std.io.getStdErr().writeAll(logo) catch {};`
<Cadey>
:+1:
<andrewrk>
daurnimator, as well as fwrite_unlocked or whatever
dongcarl has quit [Read error: Connection reset by peer]
<daurnimator>
andrewrk: did you need a "wtf is spdx and why should I care" intro?
dongcarl has joined #zig
<Cadey>
what fun is sortware unless your project names reference obscure esports players?
<cr1901_modern>
no member named 'len' in struct 'std.mem.TokenIterator'. I take it you can't iterate over tokens in a for loop?
<andrewrk>
daurnimator, yes
<Cadey>
soft*
<andrewrk>
cr1901_modern, var it = std.mem.tokenize(foo); while (it.next()) |token| { ... }
<cr1901_modern>
That would've been the next thing I tried, based on the tests for tokenize. But why isn't for() supported?
<daurnimator>
andrewrk: it was created by the linux foundation as a machine findable way to put the license into the file without having to put the whole license. Essentially because people keep copying files out of the linux kernel without a copyright attribution
<cr1901_modern>
B/c unknown len at compile time?
<daurnimator>
andrewrk: so now there are a heap of tools that compliance departments can run over their companies codebases to find SPDX lines
<fengb>
for only works on slices and arrays
<andrewrk>
daurnimator, ok that's a good "why I should care" :)
<andrewrk>
cr1901_modern, the zig language doesn't really have any abstractions beyond the type system and function calls
<andrewrk>
there's no "iterator" type
<daurnimator>
general guidance is: the *first* line in the file that isn't magic (like a #!) *should* contain an SPDX declaration
<cr1901_modern>
I can live with that
<andrewrk>
note that `while` in this example is not doing any magic, it's just unwrapping the optional value returned by next()
<andrewrk>
same as if you did `if (it.next()) |token| {...}`
dimenus has quit [Read error: Connection reset by peer]
dongcarl has quit [Read error: Connection reset by peer]
joey152 has quit [Ping timeout: 240 seconds]
dongcarl has joined #zig
cole-h has joined #zig
dongcarl has quit [Read error: Connection reset by peer]
<cr1901_modern>
Is switch supposed to not error if I don't exhaust all cases? Happy to post code
<andrewrk>
you gotta handle everything. use `else` if you need to
<cr1901_modern>
Okay I think I'm doign something wrong then
<cr1901_modern>
because this isn't erroring on my end
dongcarl has quit [Read error: Connection reset by peer]
dongcarl has joined #zig
gert_ has joined #zig
dongcarl has quit [Read error: Connection reset by peer]
dongcarl has joined #zig
ur5us has quit [Ping timeout: 260 seconds]
dongcarl has quit [Read error: Connection reset by peer]
dongcarl has joined #zig
dongcarl has quit [Read error: Connection reset by peer]
dongcarl has joined #zig
gert_ has quit [Quit: WeeChat 2.8]
dongcarl has quit [Read error: Connection reset by peer]
decentpenguin has quit [Quit: ZNC crashed or something]
dongcarl has joined #zig
decentpenguin has joined #zig
cole-h has quit [Quit: Goodbye]
xackus_ has quit [Ping timeout: 240 seconds]
dongcarl has quit [Read error: Connection reset by peer]
dongcarl has joined #zig
KoljaKube has joined #zig
dongcarl has quit [Read error: Connection reset by peer]
xackus_ has joined #zig
dongcarl has joined #zig
radgeRayden has quit [Ping timeout: 272 seconds]
xackus_ has quit [Ping timeout: 265 seconds]
scriptnull has joined #zig
dongcarl has quit [Read error: Connection reset by peer]
dongcarl has joined #zig
<scriptnull>
Hi, I am trying to find the memory page size of the underlying OS from a Zig program and couldn't figure out if it is possible in Zig. Any ideas?
<scriptnull1>
yes, checking it out and trying to understand what exactly is a page size and why there could be multiple page sizes.
<daurnimator>
scriptnull1: a good question might be: why do you want the page size?
<scriptnull1>
I am trying to build an embedded key-value store in Zig (inspired by lmdb and bolt db). As part of it, we will need to implement a B+ tree in Zig. Both lmdb and bolt db use the notion of `page` to store a node in a B+ tree. By default they seem to assign the OS's page size as the page size of pages in the B+ tree.
<daurnimator>
scriptnull1: you probably just want `std.mem.page_size`
<scriptnull1>
ah ok, thanks!
<scriptnull1>
Do you recommend any reads (like a webpage, book chapter, video) to understand about page sizes in detail?
ur5us has joined #zig
<daurnimator>
scriptnull1: I don't have any in mind
<daurnimator>
scriptnull1: the general point is: your MMU (a component in your PC) thinks in terms of "pages" of memory
<daurnimator>
which means that the kernel deals mostly in pages; rather than individual bytes
<daurnimator>
things like readable/writeable/executable are all done in terms of pages
<daurnimator>
likewise the virtual <> physical mapping is the size of a page.
dongcarl has quit [Read error: Connection reset by peer]
dongcarl has joined #zig
ur5us has quit [Remote host closed the connection]
ur5us has joined #zig
dingenskirchen has joined #zig
st4ll1 has quit [Ping timeout: 256 seconds]
st4ll1 has joined #zig
dongcarl has quit [Read error: Connection reset by peer]
dongcarl has joined #zig
dingenskirchen has quit [Quit: dingenskirchen]
dongcarl has quit [Read error: Connection reset by peer]
dongcarl has joined #zig
scriptnull1 has quit [Quit: scriptnull1]
dongcarl has quit [Read error: Connection reset by peer]
dongcarl has joined #zig
<KoljaKube>
Is it possible to reinterpret packed unions? The documentation is not entirely clear on that, and if it's possible I can't figure out the syntax
ur5us has quit [Ping timeout: 244 seconds]
<andrewrk>
@bitCast
<andrewrk>
good night
<KoljaKube>
good night
dongcarl has quit [Read error: Connection reset by peer]
dongcarl has joined #zig
<ikskuh>
huh
<KoljaKube>
Still can't seem to figure out the syntax though
cr1901_modern has quit [Ping timeout: 256 seconds]
wootehfoot has joined #zig
xackus_ has quit [Read error: Connection reset by peer]
xackus_ has joined #zig
cren has quit [Quit: Swirc IRC client]
KoljaKube has quit [Ping timeout: 240 seconds]
KoljaKube has joined #zig
ur5us has joined #zig
cr1901_modern has joined #zig
<KoljaKube>
OK, so field alignment on unions is not possible yet. But having Vector members is. Aren't Vectors aligned to do their SIMD stuff?
_whitelogger has joined #zig
dingenskirchen has joined #zig
<andrewrk>
yes
cr1901_modern has quit [Ping timeout: 240 seconds]
<KoljaKube>
But that doesn't reflect in the type's alignment, right? testing.expectEqual(@sizeOf(Mat4f.ValueType) * Mat4f.Dimension, @alignOf(Mat4f)); results in "expected 16, found 1"
<KoljaKube>
(Mat4f is a union containing 4 Vector(4, f32))
<KoljaKube>
I would have at least expected 4
<KoljaKube>
Then again, I understand what understand what alignment means, but not how it's determined
Akuli has quit [Quit: Leaving]
KoljaKube has quit [Ping timeout: 240 seconds]
<fengb>
Hmm it sounds like a bug if the union has smaller alignment than its members
wootehfoot has quit [Read error: Connection reset by peer]
traviss has quit [Remote host closed the connection]
traviss has joined #zig
dingenskirchen has quit [Quit: dingenskirchen]
<andrewrk>
yeah the union's alignment should be the alignment of the most aligned member