<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]
<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>
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?