ChanServ changed the topic of #zig to: zig programming language | | be excellent to each other | channel logs:
<pixelherodev> andrewrk, regarding the benchmark, after looking at the other language examples, this wasn't an attack on Zig.
<pixelherodev> They are just bad benchmarks in general
<pixelherodev> Bad code too
<pixelherodev> Their C code is even *worse*
<pixelherodev> I was about to comment that I doubted the other implementations were that bad when I decided to check first. This is honestly just... really, really stupid.
<pixelherodev> I guess I'll have to wait for the benchmarks game instead
<tgschultz> yeah, *windows* is the nightmare os. don't get me started.
return0e has quit [Remote host closed the connection]
<andrewrk> I could point to windows API that is better than POSIX API and POSIX API that is better than Windows API
<andrewrk> neither one is strictly worse
<andrewrk> emekankurumeh[m], thanks to midipix I found some very useful information regarding windows
<andrewrk> we can actually do mov %%gs:0x60, %0 to get a pointer to the "Process Environment Block" (see
<andrewrk> this is guaranteed to succeed, and it contains a lot of information, such as: * stdin, stdout, stderr handles * cwd handle * cwd path name * the command line * the executable's own path
<andrewrk> bottom line... we can make a bunch of std lib APIs no longer have the possibility of failure!
<andrewrk> the env vars are there too
<pixelherodev> That's brilliant!
<pixelherodev> Intriguing to me in terms of how that's implemented but still
muffindrake has quit [Ping timeout: 245 seconds]
muffindrake has joined #zig
<andrewrk> it works
<andrewrk> it's the next best thing after a comptime initialized integer
benjif has joined #zig
return0e has joined #zig
return0e has quit [Ping timeout: 268 seconds]
<pixelherodev> Wow, that's actually really impressive
THFKA4 has quit [Ping timeout: 250 seconds]
chemist69 has quit [Ping timeout: 245 seconds]
chemist69 has joined #zig
<andrewrk> wait, NtCreateFile supports case sensitivity
<andrewrk> "This value can be zero or OBJ_CASE_INSENSITIVE, which indicates that name-lookup code should ignore the case of the ObjectName member rather than performing an exact-match search"
benjif has quit [Quit: Leaving]
dingenskirchen has quit [Quit: dingenskirchen]
dingenskirchen has joined #zig
ltriant has quit [Quit: leaving]
mahmudov has joined #zig
return0e has joined #zig
return0e has quit [Ping timeout: 268 seconds]
<telemach> β€” first thought when I saw this was "can I now write unikernels in Zig?"
daurnimator has quit [Read error: Connection reset by peer]
ceymard has quit [Quit: WeeChat 2.2]
joethephish has joined #zig
<odc> ^ cool project! Though he didn't even need to write his own dhcp client. Linux has one builtin with the kernel parameter "ip=dhcp"
<mq32> i have to start a "kernel" project with zig... :D
riba has joined #zig
joethephish has quit [Remote host closed the connection]
<riba> i'm a bit confused how to allocate a struct on the heap because all the allocation functions seem to take arrays
<riba> and it seems i have to init an allocator in any case instead of using some global function?
<riba> in any case, i just made the global, static struct var instead of const and i can use a cast
<riba> but now the compiler tells me i should use -fPIC even though i do, is there a wrong way to do it?
<riba> i put it right after build-lib
occivink has joined #zig
joethephish has joined #zig
return0e has joined #zig
return0e has quit [Ping timeout: 265 seconds]
<Snektron> I think you can allocate a struct on the heap with allocator.create
<Snektron> That returns a single struct
<riba> Snektron: the function is defined on Allocator and not in std.mem, is it still okay to use it?
<Snektron> You do have to init an allocator in any case, but you can use malloc and free by linking with libc and using std.heap.c_allocator
<riba> is std.heap.c_allocator inited?
<Snektron> create is a member function of the std.mem.Allocator struct, but thats an interface
<Snektron> Usually you init one in std.heap (for example DirectAllocator) and then its `allocator` is the actual allocator
<riba> what i meant is, to me it seemed like you are supposed to use the std.mem functions and pass them an allocator
<Snektron> c_allocator is initialized
<riba> and the function will use the allocator as necessary
<riba> so calling stuff on an allocator yourself might be wrong
<Snektron> Its just a member function of the allocator
<Snektron> std.mem.Allocator is an interface in effect
<Snektron> Theres also a global direct allocator, its std.heap.direct_allocator
<riba> i get that, i just wasn't sure if you're "allowed" to use the allocator directly instead of through the std.mem functions
<riba> but i'll try create with the c_allocator, thanks
<riba> maybe that will help with my fpic error after all
<Snektron> The allocator contains the std.mem functions
<Snektron> Say you have a direct allocator
<Snektron> (in the variable `direct`)
<Snektron> You call direct.allocator.create(i32) to allocate an int
<Snektron> You can use reallocFn but thats annoying
<Snektron> So std.mem.Allocator exists to wrap that and provide a more useful interface
<Snektron> So whats confusing is that both DirectAllocator and DirectAllocator.allocator are referred to as an allocator
<Snektron> Even though they dont have the same interface
<riba> i just thought the intended use of the api is e.g. std.mem.alloc(allocator, size) and allocator is just visible so you can implement it yourself
<mq32> riba: i don't think std.mem.alloc exists
<mq32> there is std.mem.Allocator.alloc(allocator, T, size)
<riba> mq32: it doesn't, it was just an example
<riba> but now i guess i get the std.mem functions are "helpers"
<mq32> yeah, most of the stuff in std.mem is helpers or non-allocator functions
lunamn_ has joined #zig
lunamn has quit [Ping timeout: 265 seconds]
<bgiannan> what makes a function 'inlinable'?
doublex has quit [Ping timeout: 250 seconds]
doublex has joined #zig
<muffindrake> It can't refer to a global object, if I recall correctly
<mq32> muffindrake: that would be a pure function
<muffindrake> The C standard says "An inine definition of a function with external linkage shall not contain a definition of a modifiable object with static or thread storage ration, and shall not contain a reference to an identifier with internal linkage."
<muffindrake> How far that applies to Zig, I'm not sure
<muffindrake> Uh, I should reread my messages with this keyboard :(
joethephish has quit [Ping timeout: 260 seconds]
return0e has joined #zig
batok has joined #zig
waleee-cl has joined #zig
hoppetosse has quit [Quit: Quit]
mahmudov has quit [Ping timeout: 265 seconds]
<muffindrake> Has anyone written a wrapper for libcurl for zig, or is there a comparable library already?
<nrdmn> unlikely and no
<donpdonp> muffindrake: while not a library, this is a zig file that uses libcurl.
<muffindrake> That's not really a wrapper, and I'm familiar enough with libcurl to write that myself, but thanks anyway.
<muffindrake> alloc(..) catch unreachable;
<muffindrake> Humm.
<companion_cube> also, no dealloc? :D
<muffindrake> Indeed, as it is, the function is just leaking memory
<muffindrake> the libcurl routine for cleanup is called at the end, but other allocations are unfazed
<companion_cube> I guess allocator.create not being followed by defer is a redflag :p
<muffindrake> I'd have said something similar. I did write some C wrapping code in D, and there you would use the equivalent of defer. It's strange that they called it 'scope (exit)', though.
<donpdonp> muffindrake: it was some of my first zig. i do need to clean up those leaks :O
sossy has joined #zig
<donpdonp> companion_cube: unless the dealloc happens somewhere else?
<muffindrake> authbuf goes out of scope before any reference to it is passed anywhere it could be deallocated. It's only passed to bufPrint.
* donpdonp nods in agreement
lunamn_ has quit [Ping timeout: 268 seconds]
lunamn has joined #zig
<companion_cube> donpdonp: at least a errdefer
<muffindrake> I'm still confused when you want to use defer, and where errdefer
<companion_cube> if you return the value, use errdefer; if it's purely local, defer
<muffindrake> So deallocation of local buffers strictly uses defer then
<muffindrake> I see.
<companion_cube> if the buffer shouldn't survive after the function returns, yep
<nrdmn> muffindrake: "has anyone written..." ->
<muffindrake> That's very new
<muffindrake> Thanks!
lunamn has quit [Ping timeout: 246 seconds]
lunamn has joined #zig
batok has quit [Remote host closed the connection]
batok has joined #zig
marler8997 has joined #zig
<marler8997> for anonymous structs, will there be a way to access the fields by an index? in the lexical order they were given?
ofelas has quit [Quit: shutdown -h now]
<tgschultz> It's a very doable thing with @typeInfo inspeciont, so at the very least it could be a std.meta function
keithdc has quit [Ping timeout: 265 seconds]
<marler8997> there's a "field" member in the Struct TypeInfo, but I'm not sure what order it's in
<nrdmn> marler8997: perhaps you can combine @memberName and @field
<marler8997> but how do you access them in lexical order?
<nrdmn> oh in lexical order
ofelas has joined #zig
<nrdmn> I assumed @memberName gets the member's name in the order they're defined in
<marler8997> I'm not sure if anonymous structs with unnamed fields will have a name
<marler8997> but reading more, it looks like you will be able to use array syntax to access the fields
<nrdmn> anonymous structs with unnamed fields?
<marler8997> The very last line of that comment
<nrdmn> huh, do tuples work already?
<marler8997> no this is a new feature that's been proposed, I think it's been accepted as well
<marler8997> oh wait, here's the accepted proposal:
<marler8997> it's not called "tuples", but they look very similar
<marler8997> .{a, b, c} is syntax sugar for .{._0 = a, ._1 = b, ._2 = c}
<companion_cube> that kind of looks like a tuple ;)
<marler8997> yeah they are very similar, but we're able to piggy-back off of structs so we don't need to invent new semantics for tuples
Akuli has joined #zig
drazan5 has quit [Ping timeout: 240 seconds]
<tgschultz> the field members in a structs type info are in the order they are declared in.
<marler8997> tgshultz: thanks, where is that documented?
mahmudov has joined #zig
<tgschultz> I'm not sure it is, actually.
<tgschultz> but but serialize/deserialize relies on it
<tgschultz> actually it is documented: For structs, unions, enums, and error sets, the fields are guaranteed to be in the same order as declared. For declarations, the order is unspecified.
<tgschultz> it's at the bottom of the @typeInfo section
<marler8997> ah perfect
wootehfoot has joined #zig
batok has quit [Remote host closed the connection]
batok has joined #zig
wootehfoot has quit [Quit: Leaving]
wootehfoot has joined #zig
mahmudov has quit [Remote host closed the connection]
wootehfoot has quit [Quit: Leaving]
wootehfoot has joined #zig
batok has quit [Remote host closed the connection]
doublex has quit [Ping timeout: 264 seconds]
batok has joined #zig
doublex has joined #zig
ky0ko has joined #zig
Barabas has joined #zig
<Barabas> Good evening
<Barabas> Good evening
<Barabas> How do you do something like this?
<Barabas> fn readDocument(stream: *io.BufferedInStream) !void {
<Barabas> It gives an error, because BufferedInStream is actually a function returning a struct.
<Barabas> That makes sense, but... how then do I take something like that as input?
doublex has quit [Ping timeout: 250 seconds]
batok has quit [Remote host closed the connection]
<donpdonp> well look at that, std lib docs.;io.BufferedInStream
<Barabas> Not really
<Barabas> Wow, amazing!
batok has joined #zig
<Barabas> Still doesn't answer my question though.
<Barabas> Is the only way to make a 'templated' function by putting it in a struct which you create by calling a function with some comptime parameter(s)?
tane has joined #zig
<tane> howdy
<Barabas> hello
<tane> the docs seem rather broken here and there
<Barabas> Yeah well, it's a new thing ^^
<tane> yeah :)
<andrewrk> tane, generated docs are brand new and still a few open issues
<tane> andrewrk, yeah, thanks for all the work btw :)
<via> win 40
<via> dammit
<donpdonp> this might have been mentioned before but it'd be very handy to see the zig implementation code from the man page
<tane> so I guess the zig tokenizer in the src folder is still the main one, and not the one in the self-hosted dir?
<donpdonp> andrewrk: sweeet.
firefox317 has joined #zig
<firefox317> Barabas: The current way of doing that is by having a 'var' as a function parameter i think
<Barabas> Hmm... I see
<Barabas> I made a struct in the meantime, so I guess I'll go with that (at least for now)
<firefox317> But I think it should be possible to have something like `stream: *io.BufferedInStream(anytype)` as a function parameter. There is probably an open issue for this
sossy has quit [Remote host closed the connection]
<firefox317> Barabas: ^^
Akuli has quit [Quit: Leaving]
<Barabas> Yes, exactly that.
<Barabas> Tricky stuff
<tgschultz> Barabas, doesn't seem to have been mentioned yet, but you can take `stream: var`: `fn readDocument(stream: var) @typeOf(stream).Error!void { ... }`.
<Barabas> firefox317 mentioned that. It's an option, but also not very nice imho as it doesn't tell you anything of what you should put in there.
<riba> i'm struggling to allocate memory the size of a struct and then copying a struct into there
<riba> do i need to cast the pointer to a u8 pointer? can that really be the right thing?
<tgschultz> Barabas no disgreement here. There are several open issues in regards to this.
<riba> alternatively, what is the reason the compiler might tell me to use -fPIC if i already use it
<riba> when trying to use a global var instead of trying to make something on the heap and copying the const struct in there
doublex has joined #zig
<mikdusan> riba: see allocator.create for single-allocations:;mem.Allocator
<Barabas> I get this amazing error
<Barabas> ...\lib\zig\std\io.zig:188:52: error: function with inferred error set must return at least one possible error...\lib\zig\std\io.zig:184:45: error: expected type 'fn(*, []u8)!usize', found 'fn(*, []u8)
<Barabas> @typeOf(,!usize'
<riba> mikdusan: i used create, now i have empty memory the size of T, correct?
<mikdusan> yes
<riba> now i already have a struct i wanna memcpy in there, or i can also make a new one i don't care
<riba> how do i do it
<riba> @memcpy expects [*]u8 and not my struct pointer
<mikdusan> so `p.* = what_i_want_copied;`
<companion_cube> seems like the doc could put `stuff` in a `<pre>`…
<riba> mikdusan: it seems i need to unlearn some of my patterns
<riba> thanks
<riba> okay, that didn't help unfortunately
<tgschultz> Barabas: ugh, yeah sorry, that's and error set inference problem, another big issue with status quo io streams. If you don't care about the errorset, you could use `anyerror!void` as your return type and that should shut it up
<riba> lld: error: relocation R_X86_64_PC32 cannot be used against symbol xoob_info; recompile with -fPIC
<riba> but i do compile it with -fPIC
<riba> am i putting it in the wrong place?
<Barabas> tgschultz, thanks. It actually already goes wrong when I do this
<Barabas> var stream = io.SliceInStream.init("test"); var bufferedStream = io.BufferedInStream(io.SliceInStream.Error).init(&;
batok has quit [Remote host closed the connection]
<riba> i actually get the same thing 6 times for some reason
batok has joined #zig
<Barabas> Oh I see, because SliceInStream doesn't actually have any errors?
<tgschultz> possibly. inferring empty errorset is yet another open issue
<Barabas> cool =D
s-ol has joined #zig
<s-ol> hello :)
<mikdusan> riba: which platform?
<s-ol> Been playing with zig a bit at the suggestion of daurnimator
doublex_ has joined #zig
<tgschultz> the idea is that the empty errorset should be distinct from no errorset, but it isn't currently handled correctly.
<Barabas> I see.
<tgschultz> yeah
<riba> mikdusan: i didn't specify one so i think it's using mine? x86_64 sounds correct
<mikdusan> which OS are you building things on
doublex has quit [Ping timeout: 265 seconds]
<riba> mikdusan: fedora
<s-ol> is there a way to get the type of a struct member, having only the struct type?
<tgschultz> yes
<mikdusan> riba: if you have a reduction or repo i can try to duplication
<mikdusan> *duplicate
<s-ol> guess I could crrate a variable and return @typeOf from a comptime block, but that seems cumbersome
<s-ol> (create an instance in a variable i mean)
<tgschultz> s-ol: `const FieldType = std.meta.fieldInfo("field_name").field_type;` I think
<tgschultz> `const FieldType = std.meta.fieldInfo(Type, "field_name").field_type;`
<tgschultz> missed a parameter
<Snektron> s-ol, you can use @TypeInfo probably
<Snektron> or @field: @field(struct_type, "field_name")
<Snektron> the "recommended" zig style is to name enums in snake case right?
doublex has joined #zig
<Snektron> is it maybe an idea to build a warning and optional fix into zig-fmt? because im noticing an inconsistency in the stdlib
<riba> mikdusan: thanks, just a moment
doublex_ has quit [Ping timeout: 268 seconds]
doublex_ has joined #zig
doublex has quit [Ping timeout: 268 seconds]
tane has quit [Quit: Leaving]
<riba> mikdusan: but i realized you need the headers, you can just use the dir from this other repo:
doublex_ has quit [Ping timeout: 265 seconds]
Ichorio has joined #zig
marijnfs has joined #zig
batok has quit [Remote host closed the connection]
<marler8997> so the "accept" function in the standard library is assuming that a pointer to sockaddr is the same size as sockaddr
<marler8997> but that's not how the accept function works
<marler8997> the size of sockaddr will depend on the protocol you are using, which is determined at runtime
<marler8997> the only requirement is that it fits at least 16 bits to store the address family value
<s-ol> Snektron: isnt @field for fiel access on an instance?
doublex has joined #zig
<Snektron> s-ol, yes, did you want access to a static struct?
<Snektron> static field
batok has joined #zig
ForLoveOfCats has joined #zig
<s-ol> Snektron: i wanted to access a nested type from an imported C struct, without actually having a value of that struct type
wootehfoot has quit [Quit: Leaving]
<s-ol> i think tgschultz got it. should that maybe be itd own @-intrinsic?
firefox317 has quit [Remote host closed the connection]
<s-ol> its* (sorry, that was all phone-typing until here)
wootehfoot has joined #zig
<tgschultz> the trend has been to move @ functions for type inspection into userland code. there are a few notable exceptions: @hasField, @hasDecl, @typeName, possibly a few others.
casaca has quit [Ping timeout: 265 seconds]
ltriant has joined #zig
doublex_ has joined #zig
casaca has joined #zig
doublex has quit [Ping timeout: 268 seconds]
<s-ol> huh, just looked through the IRC logs for something entirely unrelated and here I go discovering hoppetosse and keith52 talking about Dear ImGui (and cimgui)
<s-ol> that is exactly what I was just meaning to post: as my example thingy I've been porting the glfw-opengl3 example implementation, just got it working today
lunamn has quit [Ping timeout: 240 seconds]
<mikdusan> riba: try dropping the `extern` keyword:
Barabas has quit [Ping timeout: 260 seconds]
wootehfoot has quit [Quit: Leaving]
lunamn has joined #zig
<riba> mikdusan: thanks for finding this out. i put it there because i originally wanted to pass it directly to the C code, which now i'm not
<riba> at least it compiles now, let's see if it works as intended
<mq32> marler8997: if sockaddr is the same size as sockaddr_storage, it should be sufficient for all supported AFs
waleee-cl has quit [Quit: Connection closed for inactivity]
<riba> awesome, it works
<riba> thanks a lot :D
<mikdusan> πŸ‘
casaca has quit [Ping timeout: 240 seconds]
<riba> now let's see if i can make it do anything usefil except getting loaded too
casaca has joined #zig
<andrewrk> argh, my std.fs improvement branch is stalled because I have code that works on windows and wine 32 bit but not wine 64 bit
<mq32> andrewrk finding bugs in wine now? not only llvm and QEMU... :D
riba has quit [Ping timeout: 276 seconds]
<Snektron> does it work on win64
<andrewrk> yes it works on native windows 64 bit
wootehfoot has joined #zig
<Snektron> Is there some way to deal with utf8 input streams?
<fengb> What do you mean by deal with?
<fengb> The long answer is, we'll need a library to do UTF correctly, but the short answer is you might not need it
<Snektron> I just want a PeekInStream for utf8 really, c++ wchar32_t-style
<Snektron> but if theres nothing yet, i'll just adapt what i have now and make a custom one
<Snektron> i'm not even sure if wchar-style is the right approach here
<Snektron> i guess i might as well, that probably helps avoiding problems related to dealing with unicode input
<fengb> To do things right, you should be peeking by code point (?)
<fengb> I always get confused at the terminology >_>
<fengb> Seems like I meant grapheme
<Snektron> yes, thats what i do
<Snektron> but i realized i need more lookahead
<Snektron> So it would be nice if i could have used but with another type
<Snektron> but i guess i need something thats more like an iterator here anyway
wootehfoot has quit [Quit: sleepy time]
marijnfs has quit [Quit: WeeChat 2.6]
<andrewrk> I created but now I have to figure out how to work around it, or give up the ability to test cross compiled windows std lib tests
<lunamn> andrewrk: is it intended for tests to not output anything with the std.progress integration?
<andrewrk> lunamn, yes; they will output something if it takes a long time or something is unsuccessful
<andrewrk> the bigger test suite itself needs some improvement /integration with this since it can output nothing for a long time
plumm has joined #zig
<plumm> andrewrk: is a bad try included in "something is unsuccessful"
<andrewrk> plumm, yes:
<plumm> before it would print the test before the test's output
mahmudov has joined #zig
<plumm> am I supposed to use the error return trace to see which test it failed on?
<andrewrk> plumm, ah, thanks for mentioning this. this was a mistake. I just pushed 16a91e which fixes it
<andrewrk> new output:
<plumm> andrewrk: thank you!
dimenus has joined #zig
mahmudov has quit [Remote host closed the connection]
<dimenus> is there any way to get the compiler to spit out the contents of the 'builtin' namespace?
<andrewrk> dimenus, `zig builtin`
<dimenus> fml, sorry
<andrewrk> it also accepts flags so you can see how this source will change
<dimenus> thanks!
<dimenus> andrewrk: many thanks
<andrewrk> haha it just means you had the same good idea that I did :)
<fengb> It’s also in the docs now!
<dimenus> good good, going to tinker with some rpi4 stuff hopefully later this week
<dimenus> being able to dump a stack or error trace on an embedded platform over a serial port is a pretty huge win
<plumm> andrewrk: it's not a little odd that the test output comes before the test name? is debugging with tests even encouraged?
<andrewrk> dimenus, ah right, fengb means this:
<andrewrk> plumm, what are you observing? this progress thing is very new. if it turns out to be nice, it stays. if it's problematic, it gets modified or removed
<dimenus> also, aren't `namespaces` not really a thing anymore? it's just a struct? :)
<andrewrk> yes this is just a helpful organization thing the generated docs are doing. a struct with no fields is put in the "namespaces" section
<andrewrk> likewise a function which is only called at comptime and always returns a type is put in the Types section even though it's a function
<andrewrk> there's still lots to do but even still the docs are more sophisticated than you might realize :)
mahmudov has joined #zig
<plumm> ok, lol
<andrewrk> wow, how did you get that fancy cat output?
<plumm> it supports syntax highlighting too, might add zig
<fengb> should we be linking std docs?
<andrewrk> fengb, I took a brief detour, but still planning on spending a few more days on docs and then hooking that up
<andrewrk> I'm going to make a breaking change to the URL syntax
<andrewrk> plumm, I made another adjustment to the test runner, try your example after 859cbef
<plumm> k rebuilding
<plumm> andrewrk: fixed :)
<plumm> jeez you work fast
batok has quit [Remote host closed the connection]
<andrewrk> some stuff is easy to edit & test
batok has joined #zig