ChanServ changed the topic of #zig to: zig programming language | https://ziglang.org | be excellent to each other | channel logs: https://irclog.whitequark.org/zig/
jonase has joined #zig
jonase has quit [Ping timeout: 264 seconds]
ur5us has quit [Ping timeout: 264 seconds]
xackus_ has joined #zig
xentec has quit [Quit: memento mori]
xentec has joined #zig
nycex has joined #zig
ur5us has joined #zig
ur5us_ has joined #zig
ur5us has quit [Ping timeout: 264 seconds]
techtirade_ has quit [Ping timeout: 264 seconds]
<andrewrk> is it possible to pass a wasm-allocated string to javascript? or does the js have to supply the buffer if you want this?
<fengb> You need to copy the bytes into the wasm memory
<fengb> Oh wait... the opposite
<fengb> Yeah you need to look it up
<fengb> Need to create a Uint8Array from wasm.memory.buffer, pointer, and length
<fengb> wasm = the module instance
<andrewrk> what does it looks like on the zig side/
<fengb> Returning a pointer and length
<fengb> Pointer is implicitly the offset to the memory buffer
<fengb> I have a dumb hack to kludge both into a f64
<fengb> Because JS doesn’t support u64 yet
<andrewrk> but how do you write the bytes into the buffer on the zig side
<fengb> Hmm, on the Zig side, you can return an allocated buffer or global buffer
jonase has joined #zig
<fengb> In fundude, I pass in the byte buffer from JS, but that’s manually allocated via a shim
<andrewrk> extern fn stderr(msg_ptr: [*]const u8, msg_len: usize) void; this prints some integers to the console on the js side but there doesn't appear to be a way to access the wasm memory buffer
<fengb> Yeah that’s a raw pointer
<fengb> You need to fetch the wasm instance and grab the memory off it
techtirade has joined #zig
<fengb> I remember having problems trying to reference the instance before it’s created hmmm
<andrewrk> I don't think the wasm instance has a memory property
<fengb> It does
jonase has quit [Ping timeout: 240 seconds]
<andrewrk> `memory` property is undefined
<andrewrk> oh there's extra stuff inside exports
<andrewrk> thanks
<fengb> np
terinjokes has quit [Quit: ZNC - http://znc.in]
<leeward> I have a construct that's not behaving the way I expect. Am I being an idiot, or is this a bug in Zig? `var on = false; while (true) { light(on); on = !on; delay(500) }`
nycex- has joined #zig
<leeward> I expect this to alternate between on and off, but when I set a breakpoint inside the loop, the debugger tells me that on is always false.
<leeward> And when I look at the assembler output, I see nothing that suggests it's changing on's value.
nycex has quit [Ping timeout: 240 seconds]
<andrewrk> leeward, looks like the value gets changed to me: https://godbolt.org/z/vfon1e
<andrewrk> fengb, if you hit unreachable in a debug wasm build is there a way to find out which one it hit?
xackus has joined #zig
xackus_ has quit [Ping timeout: 272 seconds]
ur5us_ has quit [Ping timeout: 272 seconds]
<andrewrk> oh snap chromium supports stack traces from webassembly
ur5us_ has joined #zig
<leeward> andrewrk: Yeah, it works fine on my desktop too. This is on an msp430, and I'm still digging at it.
ky0ko has quit [Quit: http://quassel-irc.org - Chat comfortably. Anywhere.]
<andrewrk> leeward, I see an xor in there: https://godbolt.org/z/89b1Wo
<leeward> Yeah, I don't in my actual code. It could be that my light function is doing something unexpected.
<leeward> ok, this is special: `const mask = ~(various() | functions()) & old;` and my debugger says old is 0x0. What's mask? 0x3b
<vesim> is the debug info generated by zig compiler valid?
<daurnimator> vesim: should be.
<leeward> Yep, I use it all the time.
<vesim> I tried to set breakpoint at codegen.c.genHeader and it is never hit, but the file was generated
* leeward currently has a debugger attached
<vesim> setting it at c.zig:394 doesnt work either
<vesim> or the -femit-h is using different code path? O_o
<leeward> And you're running stage2?
heronwr has joined #zig
<vesim> yep
<leeward> head scratchy
<vesim> i built it using ./zig build -Dstage1=false and after that running it like this ./zig-cache/bin/zig test lib/std/child_process.zig -fno-emit-bin -femit-h=foo.h
<vesim> and also for me -fno-emit-bin is still hitting the linker, so i had to modify the allocateDeclIndexes function to do nothing for .elf, otherwise it was crashing the compiler
heronwr has quit [Quit: WeeChat 3.1-dev]
jonase has joined #zig
<leeward> Well, my problem was indeed something going on in the function.
<leeward> Not sure why it's doing what it's doing though.
jonase has quit [Ping timeout: 256 seconds]
owner has joined #zig
owner is now known as heronwr
ur5us_ has quit [Ping timeout: 264 seconds]
<vesim> hmmm, is -femit-h even supossed to work? O_o
heronwr has quit [Quit: WeeChat 3.1-dev]
waleee-cl has quit [Quit: Connection closed for inactivity]
<leeward> oh, hey, I think it's not
<leeward> I vaguely remember something about that...
<leeward> It might be in release notes. I don't see it in bugs.
hspak has quit [Quit: Ping timeout (120 seconds)]
hspak has joined #zig
techtirade has quit [Quit: ZNC 1.8.2 - https://znc.in]
techtirade has joined #zig
sord937 has joined #zig
jonase has joined #zig
jonase has quit [Ping timeout: 264 seconds]
<mikdusan> does zig0 have any dependency-file generator?
jonase has joined #zig
r4pr0n has joined #zig
ncon has quit [Remote host closed the connection]
tines9 has quit [Ping timeout: 256 seconds]
ncon has joined #zig
tines9 has joined #zig
sord937 has quit [Ping timeout: 240 seconds]
sord937 has joined #zig
quint has quit [Disconnected by services]
quint0 has joined #zig
quint0 is now known as kwintt
osa1 has quit [Quit: osa1]
osa1 has joined #zig
kwintt is now known as quint0
jonase has quit [Quit: leaving]
quint0 is now known as di-wu
cole-h has quit [Ping timeout: 240 seconds]
hnOsmium0001 has quit [Quit: Connection closed for inactivity]
gazler__ has joined #zig
gazler_ has quit [Ping timeout: 264 seconds]
tnorth has joined #zig
l1x has joined #zig
leon-p has quit [Quit: leaving]
kbd has joined #zig
<kbd> I didn't see `unsetenv` exposed within Zig stdlib. Is there a better way than @cImport(@cInclude("stdlib.h")).unsetenv()?
<ifreund> kbd: I believe andrewrk's stance is that setenv/unsetenv are inherently racy and don't belong in the zig std
<ifreund> though in single threaded programs they are totally fine IMO
<ifreund> intstead of using the cImport() you could also define the extern function manually:
<ifreund> extern unsetenv(name: [*:0]const u8) c_int;
<kbd> 🤔
<kbd> *John Travolta looking around gif* for things in the stdlib.
<kbd> thanks ifreund!
nycex- has quit [Remote host closed the connection]
nycex has joined #zig
<ifreund> heh, no problem
r4pr0n has quit [Quit: r4pr0n]
ltr has joined #zig
<daurnimator> kbd: why do you need unsetenv?
<daurnimator> I think only valid reason would be other libc-using things in-process that you want to have fail a `getenv`...
<kbd> a program called by my zig program looks for an env var, and I want to unset it.
<ifreund> you can modify the environment map passed to your child process
<kbd> ok switched to that. Bit more cumbersome in my case but it works: https://github.com/kbd/prompt/commit/0918f937f621e2d5f9060ab209dc39e76955b786
<ifreund> Yeah, I'm also really not a fan of that API
<ifreund> still using setenv in river myself as I don't use childprocess
<ifreund> and I haven't had time to improve std.ChildProcess or relace it with something nicer yet
<mikdusan> "don't use childprocess" <-- what are you using?
<ifreund> fork and exec
<kbd> I'd still prefer unsetenv here, since it happens once at the beginning of the program and not in every call to `run` (+ getEnvMap, + .delete).
<mikdusan> execve ?
<ifreund> yes, that
<mikdusan> 🍴💣
<ifreund> well, it's a little more complicated in one case as I double fork and do some cleanup to get the child process inherited by pid 1
<daurnimator> ifreund: but why? that's so 90s
<ifreund> river has a command that lets you run arbitrary programs. I don't want to need to wait(2) all of them
<ifreund> that's the job of pid 1
<daurnimator> I guess...
<ifreund> if there's some other way that's better I'd be open to it, but I don't know of any /shrug
kbd has quit [Quit: My Mac Mini has gone to sleep. ZZZzzz…]
<daurnimator> ifreund: more that I like my processes to.... be in a tree. if I started a program from river I usually would want it to stay in the tree under river
mokafolio has quit [Quit: Bye Bye!]
<xyproto> when calling a C library that expects a pointer to a struct, and has it's own "init" function, how can that be done from Zig? I have a failed attempt at finding the right type for gmp.mpz_init here: https://0bin.net/paste/OeZx2juV#yZ3VaGbKbff1MuFrnNPeRSRKZWqDzDuveRcbntISiv1
mokafolio has joined #zig
<daurnimator> xyproto: mpz_init takes a pointer-to MP_INT
<daurnimator> xyproto: you're going to want to do: `var x: MP_INT = undefined; gmp.mpz_init(&x);`
<xyproto> daurnimator: thanks! I'll try that.
<daurnimator> and don't forget `defer gmp.mpz_clear(&x);`
Cynthia has left #zig [#zig]
<xyproto> cool, thanks. I'm trying to port the one benchmark program from the Benchmark Game where C is faster than Rust, to Zig, to compare the performance.
<xyproto> There are probably faster ways than using gmp, but I want to try that first.
<daurnimator> xyproto: go for it :)
<daurnimator> xyproto: your 2nd version could try zig std libraries built in bignum support. but it probably isn't as fast as gmp... but maybe it is
<xyproto> daurnimator: I'll compare them both, if I can make the gmp version work :)
greeb has left #zig ["WeeChat 2.9"]
olabaz has joined #zig
<olabaz> Is there a way to redirect std.log.info to a file?
<daurnimator> olabaz: declare a `pub fn log` in your root file
<olabaz> hmm, and then what?
<daurnimator> write to the file you want?
<xyproto> then use the log function, where the body of the function writes to the file you want?
<daurnimator> olabaz: see the big doc-comment in std/log.zig
<olabaz> ok thanks I'll take a look
<daurnimator> xyproto: okay now I'm looking closer... which benchmark is this?
marijnfs has joined #zig
mokafolio has quit [Quit: Bye Bye!]
mokafolio has joined #zig
ltr has quit [Quit: leaving]
marijnfs has quit [Quit: Lost terminal]
tosemusername has joined #zig
nvmd has quit [Ping timeout: 265 seconds]
sawzall has quit [Read error: Connection reset by peer]
donniewest has joined #zig
sawzall has joined #zig
<daurnimator> xyproto: https://zig.godbolt.org/z/8YEPxn
<daurnimator> need to use a buffered stdout.... more time spent in printing than anything else :P
<olabaz> How can I check if an array is undefined?
<daurnimator> olabaz: you don't
<olabaz> daurnimator: hmm, what's the approach if I want to do something like: var input = read_line() catch undefined; if (input == undefined) { a();} else { b();}?
<daurnimator> olabaz: undefined isn't what you're looking for, try `null`
<daurnimator> xyproto: https://zig.godbolt.org/z/7cc1zo not very fast compared to gmp. seems like our multiplication routine could be a lot faster
<daurnimator> (I'm getting 0.5 seconds for gmp vs 2.5 seconds for pure-zig)
<olabaz> once I have checked that input != null, how can I change it from optional to its child type?
<daurnimator> olabaz: `if (optional) |not_optional|` or just `.?`
<olabaz> daurnimator: passing in input.? to a function I'm getting an error about acessing union field 'Pointer' while field 'Optional' is set
<olabaz> oh wait nvm
<olabaz> I was freeing input instead of input.?
kbd has joined #zig
l1x has quit [Quit: Connection closed for inactivity]
ehaas has joined #zig
waleee-cl has joined #zig
tosemusername is now known as nvmd
hnOsmium0001 has joined #zig
jokoon has joined #zig
kbd_ has joined #zig
kbd has quit [Ping timeout: 264 seconds]
tosemusername has joined #zig
nvmd has quit [Ping timeout: 260 seconds]
sawzall has quit [Read error: Connection reset by peer]
sawzall has joined #zig
fputs has joined #zig
Akuli has joined #zig
xackus has quit [Ping timeout: 256 seconds]
gpanders is now known as greande
sawzall has quit [Read error: Connection reset by peer]
LanceThePants has joined #zig
LanceThePants has quit [Read error: Connection reset by peer]
LanceThePants has joined #zig
tnorth has quit [Ping timeout: 260 seconds]
tosemusername is now known as nvmd
GreaseMonkey has quit [Remote host closed the connection]
marler8997 has quit [Ping timeout: 260 seconds]
greande has quit [Quit: ZNC - https://znc.in]
leon-p has joined #zig
gpanders has joined #zig
jokoon has quit [Quit: Leaving]
gpanders has quit [Quit: ZNC - https://znc.in]
gpanders has joined #zig
ky0ko has joined #zig
ltr has joined #zig
<olabaz> what is a `[]const []const u8`?
<justin_smith> a const slice of const slices of 8 bit unsigned values - eg. if you split stdin by lines where each line is a slice
danyspin97 has left #zig ["WeeChat 3.0"]
<olabaz> ah ok makes sense
cole-h has joined #zig
xackus has joined #zig
cren has joined #zig
marijnfs has joined #zig
marler8997 has joined #zig
donniewest has quit [Read error: Connection reset by peer]
donniewest has joined #zig
leeward has quit [Ping timeout: 260 seconds]
owner has joined #zig
owner is now known as heronwr
waleee-cl has quit [Read error: Connection reset by peer]
waleee-cl has joined #zig
ur5us_ has joined #zig
<marijnfs> I'm using a c-library with aio callbacks, but they are in callconv(.C). Is there a way to still use async there?
<andrewrk> marijnfs, no, C does not support zig's async calling convention
ltr has quit [Read error: Connection reset by peer]
<marijnfs> :(
<marijnfs> yeah i figured, but is there maybe a pattern
ur5us has joined #zig
ur5us_ has quit [Ping timeout: 264 seconds]
<marijnfs> i guess i could hand over the resources in the c callback, into my own event loop
<marijnfs> there i can use async
<andrewrk> there is a pattern you can do
<andrewrk> you'll have your function suspend, put its frame pointer into some data structure, then in the callconv(.C) callback, you have it mark the frame pointer as "ready" in the data structure, then you wake up the event loop so that it gets looked at and the event loop calls resume
<andrewrk> zig's async/await semantics are extremely flexible, I promise you can accomplish what you want to
<marijnfs> ah that's cool
<marijnfs> yeah you can store the anyframe anywhere, seems very flexible
<marijnfs> it's hard for your brain though
<marijnfs> is my whole callstack stored in there or something?
<marijnfs> even loris said he didn't quite understand it fully, and he wrote the main tutorial:P
<fengb> I can grok the low levels of where the frame is and how the suspend/resume works, and the high level of awaiting for data
<fengb> My brain gets fried whenever I try connecting the two
<andrewrk> marijnfs, just the 1 call frame is stored in that function's frame
<andrewrk> but the callsite probably is storing the callee's frame in its own, and so on
<andrewrk> at every call site though, it is obvious where the frame memory is stored
cren has quit [Quit: cren]
sord937 has quit [Quit: sord937]
<marijnfs> but how is the memory of all these frames handled
<andrewrk> marijnfs, pick any async function. where its local variables are stored is decided by the callsite
<andrewrk> if you do `var x = async foo();` then the frame of foo is stored in x
<marijnfs> and whats exactly in the frame
<marijnfs> return address and local variables/
<marijnfs> ?
<andrewrk> local variables only
xackus has quit [Ping timeout: 240 seconds]
<marijnfs> that's actually not so complicated
<marijnfs> but also it needs to know where in the code to continue?
<marijnfs> or is that comptime
<andrewrk> yeah it stores that in there too, so that when you resume it, it goes to the correct place
<companion_cube> but can you suspend from a function inside?
<andrewrk> can you refrase that?
<andrewrk> *rephrase
<andrewrk> I don't understand the question
<companion_cube> as in, could a "frame" contain several stack frames, where the yield/suspend is from an inner function
<companion_cube> not the outer one
<andrewrk> calling an async function is a suspend point
<andrewrk> an async function suspends itself in order to call an async function. then when the function returns it resumes the callee
<companion_cube> hmm so by construction, each async function has its own separate frame?
<companion_cube> (psosibly allocated in a different place)
<marijnfs> i think this is the main confusion
benjif has joined #zig
marijnfs has quit [Ping timeout: 256 seconds]
marijnfs has joined #zig
<andrewrk> yes exactly
<andrewrk> this is also known as "stackless coroutines"
nvmd has quit [Quit: Later nerds.]
<companion_cube> interesting
<companion_cube> it's a bit more manual than stackfull ones, but also easier I guess
Akuli has quit [Quit: Leaving]
<andrewrk> they play more nicely with manual memory management
<companion_cube> and yet, I suppose it'd work well with a local allocator
<andrewrk> or a statically allocated global variable
<marijnfs> this might be a good talk?
<companion_cube> andrewrk: personally I'd avoid ever using global variables…
<companion_cube> I imagine it's ok in embedded contexts
<marijnfs> i guess what you resume is always some code that simply ends, or some code that returns a value that goes into the await
<marijnfs> but you are free to put in the return what you want
olabaz has left #zig ["WeeChat 2.3"]
<andrewrk> marijnfs, yes all those concepts apply to zig's async functions as well, with some asterisks here and there
<ugla> Is there a fixed-point Zig lib?
donniewest has quit [Quit: WeeChat 3.0]
heronwr has quit [Ping timeout: 264 seconds]
nvmd has joined #zig
heronwr has joined #zig
heronwr has quit [Client Quit]