copy has quit [Read error: Connection reset by peer]
aerona has joined #zig
ur5us has joined #zig
jmiven has quit [Quit: bye]
jmiven has joined #zig
jmiven has quit [Client Quit]
jmiven has joined #zig
<bnbn>
I recently updated from 0.5.0 to 0.6.0. I interface with a c library (stbi_image.h) to load images into memory. In 0.5.0, I could successfully pass a []const u8 via .ptr to a c function looking for a constant null-terminated string. Now in 0.6.0, it does not work. I've been trying to convert a []const u8 to the new [*:0]const u8, but I can't quite get it. Any advice/examples would be appreciated, thanks!
kristoff_it has joined #zig
<pixelherodev>
bnbn, make sure the slice is marked as null-terminated?
<pixelherodev>
`[:0]const u8`
<bnbn>
Is there an easy way to convert a []const u8 to a [:0]const u8?
<bnbn>
Yeah that's what I thought because I remember when upgrading from 0.4.0 to 0.5.0 I could remove all the c"strings" everywhere. And it did work, so it was null terminated.
<pixelherodev>
Yeah literals are null-terminated
<pixelherodev>
and anything coming from a C-ish environment (including syscalls) is almost certainly null-terminated
<pixelherodev>
So, it 's probably safe to @ptrCast it
<pixelherodev>
`@ptrCast([:0]const u8, val)`
<bnbn>
ok, I will try that, thanks!
<pixelherodev>
:)
<bnbn>
hmm get this error ` error: expected pointer, found '[:0]const u8'` when trying to cast with `const tpath = @ptrCast([:0]const u8, path);` path is a []const u8
<pixelherodev>
Ah right hmm
<pixelherodev>
I had this exact issue multiple times
<pixelherodev>
and I never remember how I solved it
<pixelherodev>
std.mem.toSlice might work
<pixelherodev>
s/Slice/SliceConst
aerona has quit [Remote host closed the connection]
<pixelherodev>
I don't *think* @as would
aerona has joined #zig
aerona has quit [Remote host closed the connection]
aerona has joined #zig
aerona has quit [Remote host closed the connection]
<bnbn>
Ok I'll check those methods out, as well as @as. I see that toSlice/toSliceConst are now deprecated in 0.6.0, replaced with spanZ
aerona has joined #zig
marijnfs has joined #zig
klltkr has quit [Ping timeout: 258 seconds]
marijnfs1 has quit [Ping timeout: 260 seconds]
salotz has joined #zig
<salotz>
hello, is tgschultz around? Reading your blog posts (rants). I'm also thinking about "Operating" Environments
zannzen has quit [Remote host closed the connection]
joey152 has quit [Ping timeout: 256 seconds]
kristoff_it has joined #zig
kristoff_it has quit [Ping timeout: 256 seconds]
layneson has quit [Ping timeout: 240 seconds]
aerona has quit [Remote host closed the connection]
aerona has joined #zig
<mikdusan>
foobles: ZigValue can hold a ZigType and inside const_values_equal() all it does is `return a->data.x_type == b->data.x_type`; in other words compare pointers. because types or interned. but it sounds like peer-type resolution is what you need
salotz has quit [Ping timeout: 265 seconds]
StateOff has joined #zig
<foobles>
mikdusan thanks!
<foobles>
so just comparing the type pointers directly should work?
<foobles>
because the proposal doesn't say anything about implicit conversions
<foobles>
its just ?T and T
<mikdusan>
tbh that proposal is pretty thin. it doesn't answer a lot of questions that arise during impl
<foobles>
yeah :P
<foobles>
so how does the type interning work?
<foobles>
like im just wondering
<foobles>
that seems pretty complicated
<mikdusan>
well here's a simple example. if you want a bool type, that's builtin. the `ZigType *` for bool is just the start of all things - codegen.builtin_types
<mikdusan>
now for let's any arbitrary sized ints. someone asks for u187 . they both get back the intern'd pointer because you go through make_int_type()
<mikdusan>
sorry you go through get_int_type()
<mikdusan>
which if it's not already there according to parameters such as is_signed and size_in_bits, it will be created and put in a table
<mikdusan>
for future matches the one already in table is returned
<mikdusan>
same goes for structs --> get_struct_type() and it has the criteria to judge if two structs are identical
<foobles>
oh awesome
<foobles>
so even arbitrarily complex generic types have that going all the way down?
<mikdusan>
yes
<foobles>
:O
<foobles>
thats very cool
<mikdusan>
so right now compiler is single-threaded; it'll get twice as cool when self-hosted comes out and multiple threads are dancing and creating types, interning will of course be sync'd
aerona has quit [Remote host closed the connection]
bnbn has joined #zig
bnbn has quit [Quit: leaving]
cole-h has quit [Quit: Goodbye]
kristoff_it has joined #zig
foobles has quit [Ping timeout: 240 seconds]
kristoff_it has quit [Ping timeout: 240 seconds]
ur5us has quit [Ping timeout: 256 seconds]
dermetfan has joined #zig
_whitelogger has joined #zig
StateOff has quit [Read error: Connection reset by peer]
StateOff has joined #zig
<pmwhite>
mikdusan: I'd be somewhat surprised if multithreading gives more than a 2 times speedup due to dependencies. My hope would be that compiler performance is considered from the beginning and that Andrew is just better and making compilers.
<pmwhite>
In other words, I'm looking forward to systemic improvements more than "for-free" speedups like multithreading
ur5us has joined #zig
StateOff has quit [Ping timeout: 256 seconds]
<mikdusan>
I don't have andy's design in my brain, but my thought is incr builds will have to establish build segments of what today is global and those segments should be suitable for job scheduling
wootehfoot has joined #zig
qazo has joined #zig
qazo_ has joined #zig
qazo has quit [Ping timeout: 250 seconds]
<gonz_>
My immediate thought is that I'd rather see a simple compiler than a complicated one reaching a local maximum with tons of threading.
<gonz_>
This is a straw man or false dichotomy, of course.
Invader_Bork has joined #zig
<gonz_>
Some of this is embarassingly parallel
<gonz_>
But I'm convinced that what we know as slow compilers (`ghc` & co.) have massive speedups hiding in there somewhere, but no one can get at them because they're too complex.
<mikdusan>
so `hello.zir` is already targeted? ie: it's at a point where we know the machine/asm
qazo has joined #zig
kristoff_it has joined #zig
kristoff_it has quit [Ping timeout: 256 seconds]
dingenskirchen has quit [Quit: dingenskirchen]
dingenskirchen has joined #zig
<Snektron>
<BaroqueLarouche "speaking of OS, I have done a li"> Good luck writing custom gpu driver that supports Vulkan
<Snektron>
Do you think its possible to reuse amdgpu?
antaoiseach has joined #zig
antaoiseach has quit [Quit: Lost terminal]
FireFox317 has quit [Quit: Leaving]
daex has quit [Ping timeout: 256 seconds]
<GreaseMonkey>
yeah i second that notion, don't bother with Vulkan at this point, *especially* if you've never managed to do a Hello Triangle using Vulkan
retrhelo has joined #zig
<GreaseMonkey>
if anyone does want to make a GUI-first operating system i'd highly recommend working in 32-bit ARGB rectangles with only one possible component order, if you want anything higher depth allow 64-bit ARGB rectangles
<retrhelo>
Hello, I met a problem while learning to use zig. The character '\t' is seen as invalid while compiling. I wonder if there is a way to solve this problem. Thanks!
dingenskirchen has quit [Remote host closed the connection]
dingenskirchen has joined #zig
Ekho has quit [Quit: An alternate universe was just created where I didn't leave. But here, I left you. I'm sorry.]
st4ll1 has quit [Ping timeout: 264 seconds]
ifreund has joined #zig
utzig has joined #zig
<Snektron>
So when exactly is Allocator.realloc allowed to fail?
<Snektron>
nevermind, i think it works out
Ekho has joined #zig
<nephele>
what would be the equivalent to posix_spawn for zig? it does not seem to be in std/os at all (or maybe i suck at searching :g)
<pixelherodev>
nephele, child_process ?
<ikskuh>
std.ChildProcess
<ikskuh>
according to std/build/run.zig
<nephele>
thanks
<pixelherodev>
Oh I was looking at file name, not type name :P
nickster has quit [Quit: Ping timeout (120 seconds)]
dddddd has joined #zig
omglasers2 has joined #zig
st4ll1 has joined #zig
r4pr0n has joined #zig
<r4pr0n>
are we sure that llvm overrides the stack with garbage when inlining posixCallMainAndExit()?
<r4pr0n>
i changed it to always_inline and built https://bpaste.net/IZJQ with --release-fast, it gets inlined into _start but works normally
nickster has joined #zig
<Sphax>
Hello. I managed to create a repro for the error I got yesterday which I still don't understand: https://gcc.godbolt.org/z/w4_rTJ if you move the `age: u32` field in the Row struct below `set: []u8` it compiles fine, so I'm not sure why it fails here.
<Sphax>
am I doing something wrong or is this a bug ?
utzig has quit [Ping timeout: 256 seconds]
dingenskirchen has quit [Remote host closed the connection]
dingenskirchen has joined #zig
shakesoda has quit [Quit: Connection closed for inactivity]
basedtho has quit [Ping timeout: 260 seconds]
StateOff has joined #zig
utzig has joined #zig
xackus has joined #zig
antaoiseach has joined #zig
<antaoiseach>
hey folks... anybody know the status of the macOS homebrew+llvm issue? Right now I'm making do with an old commit
antaoiseach has left #zig [#zig]
layneson has joined #zig
utzig has quit [Ping timeout: 264 seconds]
TheLemonMan has joined #zig
<TheLemonMan>
r4pr0n, _start is naked, you want to take the original stack pointer value and then create a frame for the other functions
<r4pr0n>
why though?
<TheLemonMan>
because you need the sp to find the argc/argv/auxv
<TheLemonMan>
if you allocate a stack frame for _start you're thrashing the kernel-supplied stack pointer
<pixelherodev>
Even if you know the size of that stack frame?
<pixelherodev>
Can't you do `current_sp + @sizeOf(@StackFrame(_start))` (not real code)
<TheLemonMan>
yes
<TheLemonMan>
but you usually don't know the size of the stack frame
<pixelherodev>
Ahh, right
<pixelherodev>
Wait, isn't knowing stack frame size an accepted part of safe recursion?
<TheLemonMan>
that's vapourware atm
<TheLemonMan>
you really know how big the frame is after LLVM starts the codegen phase, when all the inlining and other optimizations are done
<layneson>
does anyone know of a way to force (all) functions to go in a certain section?
<fengb>
All a bunch of magic numbers lol
<TheLemonMan>
layneson, write a custom linker script
<layneson>
TheLemonMan: I'll take a look at that, thanks!
<TheLemonMan>
the bitcast is the lea+or
<fengb>
Oh so I can do better if I used a raw u32?
<TheLemonMan>
nah it should produce the same code
<oats>
speaking of which, any good linker script "tutorials" out there?
dingenskirchen has quit [Remote host closed the connection]
<ikskuh>
the documentation for the linker script
<ikskuh>
it's the only reliable source i found
dingenskirchen has joined #zig
<oats>
which linker script?
<ikskuh>
afaik only GNU ld supports linker scripts
<ikskuh>
and lld can parse the ld format
<oats>
ah
<andrewrk>
oats, I think there are some on os dev wiki
<andrewrk>
it helps if you start by thinking about what a linker script should let you do in theory, and then mapping your ideas to reality
<oats>
andrewrk: lol I have no idea what that sentence means
<oats>
or are you saying that it helps to understand what a linker script does, first
dingenskirchen has quit [Quit: dingenskirchen]
<TheLemonMan>
lots of trial&error required, that's what it means :P
<pixelherodev>
Is there any reason not to use e.g. `_ = std.os.write(std.os.STDOUT_HANDLE, "") catch 0` instead of std.debug.warn?
<pixelherodev>
(aside from stdout vs stderr)
<pixelherodev>
(and formatting)
<pixelherodev>
(and you know what that's two reasons already)
<ikskuh>
i use warn only for debugging stuff
<ikskuh>
and for app logic i use
<ikskuh>
try std.io.getStdOut().writeAll(msg);
<fengb>
`and r2, r2, r0, lsl #6` that doesn't look too reduced 🙃
watzon has joined #zig
<TheLemonMan>
reduced?
<fengb>
RISC. The inline `lsl` is a lie!
<TheLemonMan>
that's the barrel shifter for you
<TheLemonMan>
you get a shift! you get a shift! everybody gets a shift!
* yrashk
finally found a toy project to do in Zig -- working on a atomic & non-atomic reference counter (Rc/Arc in Rust). Yay!
<companion_cube>
too bad there's no RAII there, too
<shakesoda>
raii is a plague upon software anyways
omglasers2 has quit [Quit: Leaving]
<pixelherodev>
Rai is that? (I'm kidding, I agree, I just couldn't resist the pun)
utzig has joined #zig
tritao has joined #zig
wootehfoot has quit [Read error: Connection reset by peer]
wootehfoot has joined #zig
frenata has quit [Ping timeout: 250 seconds]
wootehfoot has quit [Read error: Connection reset by peer]
wootehfoot has joined #zig
Flaminator has joined #zig
dingenskirchen has joined #zig
StateOff__ has joined #zig
StateOffGames has quit [Ping timeout: 264 seconds]
dingenskirchen has quit [Quit: dingenskirchen]
<Flaminator>
I have a question that is probably really easy to answer but if const TypeName = @import("typename.zig"); and I use @typeName(TypeName); why does it use the filename for the name?
marijnfs_ has joined #zig
dingenskirchen has joined #zig
<fengb>
@typeName uses the original names. const Foo = Bar assigns an alias such that Foo == Bar
<fengb>
When you assign "anon", like `const Foo = struct`, it'll use the target variable as the name, but it seems that @import() itself assigns a name
<Flaminator>
Yeah I was using the typename.zig as a struct itself.
r4pr0n has quit [Ping timeout: 240 seconds]
marijnfs1 has joined #zig
marijnfs_ has quit [Ping timeout: 256 seconds]
marler8997 has joined #zig
<marler8997>
got a quick question, is there any way to include/exclude a struct function based on a comptime condition?
<ikskuh>
marler8997: don't use it?
<ikskuh>
if(condition) call_it();
<marler8997>
the caller needs to know whether or not the function can be called at comptime
<marler8997>
so it uses @hasDecl(T, "foo")
<marler8997>
it takes a different code path based on whether or not the struct implements that function
<marler8997>
hmmm, I should have clarified that they were instance functions
marijnfs_ has joined #zig
<andrewrk>
marler8997, `pub usingnamespace switch (foo) { a => struct {}, b => struct {} };`
marijnfs1 has quit [Ping timeout: 260 seconds]
<marler8997>
I have struct Foo, and I'm creating a struct Bar that wraps Foo, and uses @hasDecl to check whether it should wrap N functions...
<marler8997>
Actually I think what I'll do is have the underlying type define a boolean for each function that it implements. That way, it MUST explicitly indicate whether it supports all functions which will prevent errors from typos
<marler8997>
Then a wrapper type won't have to indicate support by conditionally defining member functions, it can just use the boolean interface as well
Xavi92 has joined #zig
<marler8997>
sorry for the noise, thanks for the tips
r4pr0n has joined #zig
ur5us has quit [Ping timeout: 256 seconds]
dermetfan has joined #zig
wootehfoot has quit [Ping timeout: 240 seconds]
wootehfoot has joined #zig
<mikdusan>
tritao: fix for macos version detection merged in master
TheLemonMan has quit [Quit: "It's now safe to turn off your computer."]
Xavi92 has quit [Remote host closed the connection]
<tritao>
does zig cc work on macosx for macosx targets? from a quick test it seems to complain about stdio.h not found
<tritao>
mikdusan: is your macho ld64.lld PR related to this?
<mikdusan>
tritao: unrelated
<mikdusan>
that PR was driven by the 3rd item ".... when running zig0" which is not interesting unless modifying the compiler on macos
<mikdusan>
s/modifying/developing
<tritao>
ok cool. do you know if anyone if working on zig cc for macosx?
<mikdusan>
not specifically for mac. are there some things you have in mind?
<tritao>
from a quick test (`./zig cc -target x86_64-macosx-gnu hello.c`) it fails on macosx
<tritao>
id like to get it to work
<tritao>
think maybe i just need to teach the driver how to pass the right include paths, either from xcode or `/usr/include`
<tritao>
but for linking im not sure if it should use the system linker or macho lld
<mikdusan>
hmmm that cmd works for me, latest master
<mikdusan>
(just an empty int main() {})
<tritao>
i get `hello.c:1:10: fatal error: 'stdio.h' file not found`
<tritao>
i do have some custom changes related to this, dunno if they are affecting anything
<mikdusan>
I think you may have some old artifacts no longer required find and nuke these 2 files, if they exist: zig-cache/native_libc.txt and ~/Library/Application\ Support/zig/native_libc.txt
klltkr has joined #zig
<tritao>
removed `~/Library/Application\ Support/zig/stage1/native_libc.txt`but same issue
<mikdusan>
and `clang` (or more specifically, `cc`) is in your path?
<tritao>
yeah the one from Xcode (clang.1000)
<mikdusan>
can you paste the output from: `cc -E -Wp,-v -xc /dev/null`
<mikdusan>
oh one sec. let me do more than an empty main
<nephele>
Hey, are there some zig examples for allocating a buffer to pass to syscalls? (I am trying this with readlink, but the type system is giving me major issues (because i don't understand it yet :g))
<mikdusan>
ah i see it now
<mikdusan>
tritao: also tried ld64 PR; doesn't do anything to fix this issue
<tritao>
ok i can take a look at this
Xavi92 has joined #zig
<mikdusan>
hmm I think this has to do with the concept of "is the build for host, or for another target"
<mikdusan>
so because the OS is no longer "native" it changes things. this works btw: -target x86_64-native-gnu , or native-native-gnu
<tritao>
hmm right if i dont pass an explicit target it works
<tritao>
good find
<marijnfs_>
where can i find the c allocator?
Akuli has quit [Quit: Leaving]
<mikdusan>
i must admit I'm having trouble with the issue that this breaks things: 1. `zig targets` to find my target --> `x86_64-macosx.10.15.4...10.15.4-gnu` and then using x86_64-macosx causes a compile error
<ifreund>
ok, does std.mem.eql not work with sentinal terminated pointers? or am I doing something wrong?
<fengb>
Most of stdlib doesn’t understand it
<ifreund>
hmm, how do i best compare them then? iterate manually?
neptunepink has quit [Remote host closed the connection]
halbeno has quit [Remote host closed the connection]
neptunepink has joined #zig
halbeno has joined #zig
gpanders has joined #zig
marijnfs has quit [Ping timeout: 265 seconds]
marijnfs has joined #zig
nia has joined #zig
dermetfan has quit [Ping timeout: 265 seconds]
ifreund has quit [Quit: WeeChat 2.8]
ifreund has joined #zig
ur5us has joined #zig
Xavi92 has quit [Remote host closed the connection]
<andrewrk>
mikdusan, done
mschwaig has joined #zig
r4pr0n has quit [Quit: r4pr0n]
ur5us has quit [Read error: Connection reset by peer]
fsx_ has joined #zig
ur5us has joined #zig
FSX has quit [Ping timeout: 272 seconds]
layneson has quit [Quit: WeeChat 2.8]
ifreund has quit [Ping timeout: 258 seconds]
<Snektron>
error: out of bounds pointer access in mem.zeroes?
<Snektron>
Thats odd
utzig has quit [Ping timeout: 240 seconds]
<Snektron>
ah its one of those odd things again, maybe related to the bug i ran into earlier
<mikdusan>
andrewrk: I'm seeing a few holes in target triple and how it's used; but before I write an issue up, is -target spec syntax meant to be loosely familiar? does `zig cc` or anything else tie our hands in what the syntax is?
<mikdusan>
as compared to what `clang` might use for target. or llvm.