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/
marijnfs has joined #zig
marijnfs1 has quit [Ping timeout: 246 seconds]
ifreund has quit [Ping timeout: 256 seconds]
a_chou has joined #zig
DrDeano has quit [Ping timeout: 245 seconds]
<leeward> So...I need to cast away a const (because I'm calling a C function, and it's poorly specified). Am I hosed?
<leeward> Hmm, looks like @bitCast handled it.
a_chou has quit [Quit: a_chou]
doublex has quit [Ping timeout: 260 seconds]
<Xavi92> leeward: yeah, many C libraries around do not handle const-correctness, unfortunately
<leeward> Don't I know it.
<leeward> It's disappointing, but at least I can wrap it up in something that looks like Zig code.
<Xavi92> yeah
doublex has joined #zig
<leeward> I find wrapping C libraries in Zig pretty fun. I can take the awkward error handling and turn it into something sensible, and take the awkward array passing and turn it into slices.
xackus has quit [Ping timeout: 246 seconds]
doublex has quit [Ping timeout: 256 seconds]
doublex has joined #zig
marijnfs1 has joined #zig
<leeward> I want to return a `!struct{foo:u32}`, but my `return .{.foo = 7}` fails with an error because error unions don't support struct initialization syntax. Is there a way to do this with anonymous structs?
marijnfs_ has quit [Ping timeout: 246 seconds]
nephele_ has joined #zig
nephele has quit [Ping timeout: 272 seconds]
nephele_ is now known as nephele
guan has quit [Ping timeout: 240 seconds]
betawaffle has quit [Read error: Connection reset by peer]
aerona has joined #zig
wjlroe has quit [Ping timeout: 265 seconds]
betawaffle has joined #zig
rappet_ has quit [Ping timeout: 272 seconds]
rappet has joined #zig
betawaffle has quit [Max SendQ exceeded]
Xavi92 has quit [Quit: https://quassel-irc.org - Chat comfortably. Anywhere.]
betawaffle has joined #zig
guan has joined #zig
wjlroe has joined #zig
dingenskirchen has quit [Quit: dingenskirchen]
dingenskirchen1 has joined #zig
dingenskirchen1 is now known as dingenskirchen
betawaffle has quit [Ping timeout: 272 seconds]
guan has quit [Ping timeout: 256 seconds]
<pixelherodev> Second LLVM bug with JITs that I've had.
<pixelherodev> Ugh.
<pixelherodev> Going to have to run an *unoptimized build* for Showtime :(
wjlroe has quit [Ping timeout: 256 seconds]
wjlroe has joined #zig
guan has joined #zig
betawaffle has joined #zig
guan has quit [Read error: Connection reset by peer]
guan has joined #zig
<leeward> There are worse things.
<pixelherodev> I know
<pixelherodev> Also
<pixelherodev> Ha, workaround
<pixelherodev> Now to actually focus on perf
<pixelherodev> callgrind, away!
<leeward> whee
<pixelherodev> Improving generated codegen is, as expected, the single most important factor
<pixelherodev> s/generated codegen/codegen
<pixelherodev> Some low-hanging fruit though :)
<pixelherodev> ... oh. wow.
<pixelherodev> cache checking is ~40% of CPU time
<leeward> hooray for measuring
<pixelherodev> yeah
<pixelherodev> Going to try a different strategy
<pixelherodev> Most-recently-used, maybe?
<pixelherodev> hmm, size-limiting it to 8 or something like that might help too
aerona has quit [Remote host closed the connection]
zenxhd has quit [Quit: Connection closed for inactivity]
knebulae has quit [Read error: Connection reset by peer]
_whitelogger has joined #zig
waleee-cl has quit [Quit: Connection closed for inactivity]
marijnfs has quit [Ping timeout: 260 seconds]
dermetfan has joined #zig
zenxhd has joined #zig
marnix has joined #zig
tdc has joined #zig
marijnfs has joined #zig
marijnfs_ has quit [Ping timeout: 256 seconds]
marnix has quit [Ping timeout: 265 seconds]
dingenskirchen1 has joined #zig
dingenskirchen has quit [Ping timeout: 256 seconds]
dingenskirchen1 is now known as dingenskirchen
dddddd has quit [Ping timeout: 246 seconds]
neceve_ has joined #zig
<Tharro> Is using return; in a for () || {} loop not supported?
<Tharro> Never mind, something else goes terribly wrong.
<Tharro> Got a condition if (!object.bool) { ... } else { ... } and it always seemed to execute the else {} branch regardless of the value of the bool. When I reverse the statement if (object.bool) {} else {} it seems to execute properly (zig 0.6.0 on linux x86_64).
marnix has joined #zig
zenxhd has quit [Quit: Connection closed for inactivity]
tane has joined #zig
<dch> leeward: that sounds like a very useful blog post (walking through wrapping a c library)
ifreund has joined #zig
marijnfs_ has joined #zig
marijnfs has quit [Ping timeout: 265 seconds]
FireFox317 has joined #zig
<ifreund> I feel like I've seen a proposal for removing implicit copying of structs but can't find the link
<ifreund> anyone remember something like that?
marijnfs has joined #zig
marijnfs_ has quit [Ping timeout: 260 seconds]
knebulae has joined #zig
marler8997_ has quit [Remote host closed the connection]
marijnfs_ has joined #zig
marijnfs has quit [Ping timeout: 246 seconds]
marnix has quit [Remote host closed the connection]
ur5us has joined #zig
r4pr0n has joined #zig
ur5us has quit [Quit: Leaving]
dermetfan has quit [Ping timeout: 260 seconds]
_Vi has joined #zig
marnix has joined #zig
r4pr0n has quit [Remote host closed the connection]
dddddd has joined #zig
_Vi has quit [Ping timeout: 260 seconds]
DrDeano has joined #zig
<bsrd> Is pointer arithmetic in imported c lib illegal?
<ifreund> bsrd: should be allowed, you might need to @ptrCast() first though
<ifreund> or just do like const my_ptr: ?[*]u32 = that_c_ptr; ([*c] pointers will coerce to zig pointers)
<bsrd> ifreund: It's a zig pointer given to c lib that keeps complaining about this line https://github.com/h2o/picohttpparser/blob/master/picohttpparser.c#L386
<ifreund> hmm, could I see your zig code?
<ifreund> bsrd: could you try passing @ptrCast([*]u8, &buf) ?
<ifreund> &buf will be a *[1024]u8 which is a pointer-to-one not a pointer-to-many
<bsrd> Yeah, it failed https://pastebin.com/aKpKgSKW
<ifreund> huh, what OS are you targeting?
<bsrd> Just running 'zig build run' in a x86-64.
<ifreund> ok I'm not sure what's going wrong here, would you mind opening an issue?
<ifreund> seems like a possible ABI compatibility bug
<FireFox317> You are hitting an illegal instruction, which is what clang does when it detects undefined behavior in c.
<FireFox317> That is probably what is happening here
<ifreund> Is adding pointers UB though?
<FireFox317> I have no idea, i'm not a c expert, I just know that we enable these illegal instructions in debug mode for building c code.
<bsrd> Ran their test https://github.com/h2o/picohttpparser/blob/master/test.c#L53 with uses the exact function with `zig cc` and it ran just fine.
<ifreund> yeah I don't think there's any UB in this C code
<FireFox317> try compiling it in release-fast, do you get the same error?
<FireFox317> i thought that disables the checks, but i might be wrong there
<FireFox317> or `zig -fno-sanitize-c`
<bsrd> How do I set '-fno-sanitize-c' in a 'zig build run'?
dermetfan has joined #zig
<FireFox317> Hmm, so it segfaults in release fast it looks like. in build.zig you can do b.disable_sanitize_c = true
<alexnask> (its on the LibExeObjStep, not the builder)
<FireFox317> whoeps, my bad
KoljaKube has joined #zig
<KoljaKube> How do I write slice literals?
marijnfs has joined #zig
<greenfork> KoljaKube: slices are just pointers, there are no literals for slices. you can write array literal and take a slice of it
<KoljaKube> Ah, ok
<KoljaKube> When I think about it, since you can take slices of slices, slices can not own their memory
marijnfs_ has quit [Ping timeout: 265 seconds]
<bsrd> FireFox317: That actually got me further ^^ Thanks a lot!
<KoljaKube> That also explains why I can't slice array literals I guess
<dermetfan> KoljaKube: the closest thing would probably be a slice of a comptime array ([_]u32{1, 2, 3})[1..]
<bsrd> ifreund: FYI setting 'exe.disable_sanitize_c = true;' in build.zig did the trick.
<ifreund[m]> weird, i wonder where the UB is hiding
<bsrd> And somehow running their test with `zig cc` runs just fine....
<KoljaKube> dermetfan: I'll keep that in mind, thanks
<bsrd> With is using clang.
<bsrd> *Which
<FireFox317> Yeah it is defintely weird bsrd
Akuli has joined #zig
tsmall has joined #zig
tsmall has quit [Remote host closed the connection]
tsmall has joined #zig
KoljaKube has quit [Quit: WeeChat 2.8]
marijnfs_ has joined #zig
neceve_ has quit [Read error: Connection reset by peer]
marijnfs has quit [Ping timeout: 246 seconds]
<bsrd> What should my zig type be when a c imported function required a [*c][*c]u8 and what should I cast it to? Right now I set it to `[*c][*c]` in zig, but it segfaults when it runs `*method = NULL;` in the c lib. I tried adding ? to the type, but now it can't compile with `./src/main.zig:37:54: error: expected type '[*c][*c]u8', found '?[*c][*c]u8'` and I can't seem to cast the optional away.
<FireFox317> bsrd, So in zig a pointer cannot be a nullptr, it always point to one object. In c that is obviously not the case, and a pointer can point to one, many or none. So in zig we have a [*]T for a type that point to a unknown length of items or just *T for one item. Now to handle the case where the pointer can be null we wrap it in an optional.
<FireFox317> So a char* would be a ?[*]u8 in zig
xackus has joined #zig
<bsrd> Ty ^^ I had to add an extra ?[*]u8, i.e. use ?[*]u8?[*]u8 as type.
andrii has joined #zig
dermetfan has quit [Ping timeout: 256 seconds]
andrii has quit [Ping timeout: 264 seconds]
bjornroberg has quit [Remote host closed the connection]
cole-h has joined #zig
leeward has quit [Remote host closed the connection]
marijnfs has joined #zig
marijnfs_ has quit [Ping timeout: 265 seconds]
leeward has joined #zig
_Vi has joined #zig
<ifreund> note that zig also has sentinal terminated pointers, which may be more appropriate when working with c-style strings: [*:0]u8
marler8997_ has joined #zig
<marler8997_> anyone familair with invoking build.zig files from other build.zig files, is that a thing?
<alexnask> You should be able to import another build file and call its build function
<marler8997_> ok I'll play with that
<alexnask> You can even create a separate builder and pass that one in
<alexnask> If you want to for some reason
<marler8997_> Hmmm, this may not be the right way to accomplish what I'm doing
<marler8997_> build.zig is in another repo, which I'm assuming is outside my current repo, so it doesn't allow me to import because it's outside my package path
<alexnask> Hm I dont think you can circumvent this actually, I was assuming the second build file lived in a subdirectory
andrii has joined #zig
<marler8997_> Maybe you have a better suggestion for how I can use a dependency from another repo?
<marler8997_> In the past, I just add the dependencies "index file" (the main zig file) as a package
<marler8997_> but now I'd like to take the settings from it's build.zig file, so I don't have to duplicate them
<alexnask> Right. I think the dependency should provide a way to set settings if you have to do more than add the main zig file
<alexnask> I realize this doesnt help :P
<alexnask> For example bearssl-zig provides a linkBearSSL function that takes your exe step and target and sets up the C file compilation
<marler8997_> that's alright, I think in the end, the zig build system would probably download the dependency into the zig-cache
<marler8997_> for now I'll just make it work without referencing the dependencie's build.zig file
<greenfork> can I create a hashmap at comptime? I want it to be created on stack, which allocator should I use?
<ifreund> greenfork: see this PR https://github.com/ziglang/zig/pull/5359
<ifreund> and this one if you want just strings https://github.com/ziglang/zig/pull/5452
<greenfork> ifreund: thanks!
<marler8997_> greenfork: out of curiosity are the keys strings or some other type?
<greenfork> marler8997_: they are strings
<ifreund> no problem!
m910q has quit [Ping timeout: 256 seconds]
r4pr0n has joined #zig
marijnfs_ has joined #zig
marijnfs has quit [Ping timeout: 258 seconds]
tsmall has left #zig ["ERC (IRC client for Emacs 26.3)"]
tsmall has joined #zig
<leeward> I might should put that on reddit or something.
reductum has joined #zig
reductum has quit [Ping timeout: 246 seconds]
dongcarl has quit [Ping timeout: 256 seconds]
reductum has joined #zig
marijnfs has joined #zig
marijnfs_ has quit [Ping timeout: 256 seconds]
nycex- has joined #zig
nycex has quit [Quit: Quit]
reductum has quit [Quit: WeeChat 2.8]
marnix has quit [Ping timeout: 260 seconds]
oats is now known as didymos
waleee-cl has joined #zig
reductum has joined #zig
marijnfs_ has joined #zig
aerona has joined #zig
marijnfs has quit [Ping timeout: 246 seconds]
reductum has quit [Client Quit]
Akuli has quit [Quit: Leaving]
andrii has quit [Quit: Leaving]
aerona has quit [Quit: Leaving]
marijnfs_ has quit [Quit: Lost terminal]
r4pr0n has quit [Quit: r4pr0n]
<shcv> is there a base16 encoder?
<shcv> or just base64?
tane has quit [Quit: Leaving]
wootehfoot has quit [Read error: Connection reset by peer]
tdc has quit [Ping timeout: 260 seconds]
nycex- is now known as nycex
ifreund has quit [Quit: WeeChat 2.8]
ifreund has joined #zig
st4ll1 has quit [Ping timeout: 256 seconds]
DrDeano has quit [Ping timeout: 245 seconds]
didymos is now known as oats