forgot-password has quit [Ping timeout: 240 seconds]
forgot-password has joined #zig
forgot-password has quit [Ping timeout: 240 seconds]
forgot-password has joined #zig
forgot-password has quit [Ping timeout: 265 seconds]
forgot-password has joined #zig
dimenus has quit [Read error: Connection reset by peer]
dimenus has joined #zig
kllr_sbstn has quit [Remote host closed the connection]
forgot-password has quit [Ping timeout: 265 seconds]
forgot-password has joined #zig
lunamn has quit [Ping timeout: 268 seconds]
lunamn has joined #zig
forgot-password has quit [Ping timeout: 276 seconds]
forgot-password has joined #zig
forgot-password has quit [Ping timeout: 240 seconds]
forgot-password has joined #zig
forgot-password has quit [Ping timeout: 265 seconds]
forgot-password has joined #zig
marijnfs has quit [Ping timeout: 276 seconds]
<keithdc>
I'm importing some c headers that have enums where a value is used for multiple tags (I.e enum Example {A = 0, B = 0}) and it's causing compile errors. Any advice on what I should do to get around this? I could modify the headers to remove conflicts but would be tedious..
forgot-password has quit [Ping timeout: 240 seconds]
<keithdc>
Yup, that's the one. That's fine, I'll manually remove the conflicts for now. Thanks.
<traviss>
i saw andrew ran into a similar issue in his 'porting vulkan tutorial' video. i can't remember exactly what he did. this is close to where he runs into the problem: https://youtu.be/oCzAqclwJFA?t=5136
<traviss>
i believe he used `zig translate-c` and then cleaned up the resulting zig code.
forgot-password has quit [Ping timeout: 240 seconds]
forgot-password has joined #zig
<keithdc>
Yeah, that's probably a good idea. I watched it but don't think I finished it, I'm pretty much doing the exact same thing.
forgot-password has quit [Ping timeout: 276 seconds]
forgot-password has joined #zig
forgot-password has quit [Ping timeout: 245 seconds]
forgot-password has joined #zig
lunamn has quit [Quit: leaving]
forgot-password has quit [Ping timeout: 240 seconds]
forgot-password has joined #zig
dingenskirchen has quit [Quit: dingenskirchen]
dingenskirchen1 has joined #zig
dingenskirchen1 is now known as dingenskirchen
forgot-password has quit [Ping timeout: 240 seconds]
forgot-password has joined #zig
Ichorio_ has joined #zig
Jezza__ has quit [Ping timeout: 250 seconds]
muffindrake has quit [Ping timeout: 245 seconds]
muffindrake has joined #zig
forgot-password has quit [Ping timeout: 240 seconds]
forgot-password has joined #zig
doublex has quit [Ping timeout: 265 seconds]
forgot-password has quit [Ping timeout: 268 seconds]
forgot-password has joined #zig
forgot-password has quit [Ping timeout: 252 seconds]
forgot-password has joined #zig
keithdc has quit [Quit: leaving]
chemist69 has quit [Ping timeout: 276 seconds]
chemist69 has joined #zig
forgot-password has quit [Ping timeout: 240 seconds]
forgot-password has joined #zig
_whitelogger has joined #zig
doublex has joined #zig
rjtobin has quit [Quit: Leaving]
redj has quit [Read error: Connection reset by peer]
redj has joined #zig
forgot-password has quit [Ping timeout: 268 seconds]
forgot-password has joined #zig
<daurnimator>
mq32: FYI reading a socket and reading a file unfortunatly *are* different. though read() and write() work on both; in certain circumstances sendmsg()/recvmsg() have different effects
bakedpineapple has joined #zig
forgot-password has quit [Ping timeout: 265 seconds]
bakedpineapple has quit [Quit: Lost terminal]
forgot-password has joined #zig
forgot-password has quit [Ping timeout: 276 seconds]
forgot-password has joined #zig
doublex has quit [Ping timeout: 250 seconds]
forgot-password has quit [Ping timeout: 240 seconds]
forgot-password has joined #zig
forgot-password has quit [Ping timeout: 240 seconds]
forgot-password has joined #zig
forgot-password has quit [Ping timeout: 276 seconds]
forgot-password has joined #zig
forgot-password has quit [Ping timeout: 265 seconds]
forgot-password has joined #zig
doublex has joined #zig
forgot-password has quit [Ping timeout: 240 seconds]
<daurnimator>
Pistahh: I'm confused a bit.... I didn't think godbolt ran on windows.....
<daurnimator>
Pistahh: unrelated: why did you say your main returns anyerror?
<Pistahh>
daurnimator: this is the error I see when I run it on (arch) linux too.. thats why it is so weird :)
<Pistahh>
daurnimator: dunno, probably copypasted from somewhere.. just starting with the language, I'M not always quite sure I do the best thing :)
<daurnimator>
Pistahh: *most* of the time you should just use `!void` for your main signature and let the error set be inferred.
_whitelogger has joined #zig
_whitelogger has joined #zig
achaninja has joined #zig
<achaninja>
Hi there
<achaninja>
are there any really simple wrapper libraries for zig that just wrap the posix apis
<achaninja>
directly
<achaninja>
just adding error handling on top of things like waitpid
<Pistahh>
achaninja: there is an std.os.linux.waitpid, but it uses the syscall directly. I'm a zig noob so I may tell lies :) and hope others will correct me, zig by default tries not to rely on libc, so it cannot wrap the libc defined waitpid
<Pistahh>
achaninja: when trying to answer questions like yours for yourself, I find it very useful to grep (ripgrep) the zig sources for answers.
<achaninja>
except my question was about a library
<achaninja>
e.g. external to the sources
<achaninja>
but sure
<achaninja>
I actually searched in the documentation, but the waitpid definition was grayed out as it has no doc comment and is not tested
<achaninja>
there are lots of reasons why you could end up waiting for a process that doesn't exist outside your control.
<daurnimator>
achaninja: like what?
<gonz_>
"If there are no children not previously awaited, -1 is returned with errno set to ECHILD". Non-zero is specifically cited as being errors.
<daurnimator>
gonz_: ??
<achaninja>
if you are pid 1 and want to check for zombies for example
<gonz_>
I don't see how you can claim it doesn't return errors when the documentation gives clear examples of errors being returned.
<daurnimator>
achaninja: that would be wait() though; not waitpid()
<achaninja>
waitpid(-1)
<daurnimator>
ah I see waitpid() can take a -1.
<daurnimator>
I don't think that was considered for the zig wrapper
<gonz_>
https://manpage.me/?q=waitpid in "Return Values" has clear examples of error return values for each of the variants.
<daurnimator>
gonz_: yes; and the zig code I linked above explains why each of them is ignored/unreachable. (and EINTR is handled by repeating the wait)
<achaninja>
its not unreachable though
<achaninja>
but anyway, it can be fixed
<achaninja>
I also think automatically handling EINTR is not helpful
<achaninja>
because sometimes if you are doing low level programming, you actually need the EINTR
<achaninja>
because you got interrupted
<daurnimator>
achaninja: in those circumstances you would usually reach for the lower level os-specific interface, e.g. os.linux.waitpid
<achaninja>
umm
<achaninja>
that code is os.linux.waitpid
<daurnimator>
that code is os.waitpid
<achaninja>
oh sorry
<achaninja>
my mistake
<achaninja>
ah im sorry
<daurnimator>
achaninja: its only unreachable if you pass -1 or 0 as the pid. I think it would be sensible for zig to assert the pid argument is not 0 or -1; and provide another function wait() that does the non-specfic-pid bits that *does* handle ECHLD
<achaninja>
yes, for os its ok.
<achaninja>
I somewhat disagree with the term 'unreachable'
<achaninja>
i think 'unexpected'
<achaninja>
though i guess its programmer intent
<daurnimator>
achaninja: how would it be reachable under documented usage (assume we document that -1 and 0 are not valid input; and say that the pid must exist)
dingenskirchen has quit [Remote host closed the connection]
<achaninja>
because you might be in a multithreaded application who waits for a pid when you don't expect
dingenskirchen has joined #zig
<achaninja>
its a bug yeah, im just talking about the terminiology
<daurnimator>
achaninja: that would be a race condition in your application
<achaninja>
I know
<achaninja>
but thats why I disagree with the term unreachable haha
<achaninja>
so anyway
<achaninja>
std.os.linux is unadorned C api
<achaninja>
std.os has zig errors but is not the linux api
<achaninja>
is there a location for the raw linux api, but with error values
<daurnimator>
achaninja: no I don't think so..... cause then it's not "raw" any more
<achaninja>
yeah, I guess errors.EINTR
<achaninja>
for example
<achaninja>
The reason I ask is because Im looking at porting some fairly low level code
<achaninja>
and improved error handling would be nice
<achaninja>
I guess I can wrap them myself
<daurnimator>
achaninja: assuming we add an `assert(pid != 0 and pid != -1)`, how is the std.os wrapper not suitable for you? (you're passing 0/-1?)
<achaninja>
it depends on the application. The last 3 things i wrote were an init daemon, a sandbox, and a shell. In those 3 cases it was more useful to just have the C api exactly as it's specified.
<achaninja>
but C error handling sucks
<achaninja>
I don't mind though, what zig does is sensible
<achaninja>
I was mainly just trying to find out if someone had done that as a library, thats all.
shakesoda has quit [Quit: Connection closed for inactivity]
<gonz_>
Does the docs generation also have a static mode to generate a set of docs from a project? It'd be interesting to have static pages, plus it might be useful for things like Zeal/Dash(?).
<daurnimator>
gonz_: yes... that's pretty much what it does
<gonz_>
Not according to the demo
<daurnimator>
hmm?
<gonz_>
it's using JavaScript with just a static frame that's filled in
<gonz_>
so it's pretty much the opposite
<gonz_>
I haven't watched the whole demo
<daurnimator>
The build process emits a .json file with all the docs/details. The doc page itself is generated (yes at runtime) from that
<gonz_>
but what andrewrk was demoing so far is the opposite of a bunch of static pages
<daurnimator>
Usually "static" in a web context means "doesn't require server roundtrips" not "no javascript"
<gonz_>
Fair enough, I don't particularly care about the definition. Executing JS unnecessarily would complicate addition to things like Zeal/Dash, AFAIK, so that's the operative part.
jjido has joined #zig
<gonz_>
In general there ought also to be an option that can be passed to do the rendering work beforehand regardless.
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
achaninja has quit [Remote host closed the connection]
<scientes>
daurnimator, it can be no javascript too
<scientes>
but yeah, more like static backend, static frontend
jjido has joined #zig
kenaryn has joined #zig
<kenaryn>
Hello, please what does it mean "token/tokenize/tokenisation"? e.g. Zig has line-independant tokenization, a \\ token, each line of code can be tokenized out of context, etc.
frmdstryr has quit [Ping timeout: 265 seconds]
<Sahnvour>
kenaryn: tokenization is the process of identifying _tokens_ (strings, identifiers, operators, keywords ...) in an input string, based on language rules
forgot-password has quit [Quit: leaving]
<kenaryn>
Thank you Sahnvour, it seems like an exhaustive definition!
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<daurnimator>
Pistahh: oh. I figured out your issue: printing a File currently requires evaluating all the method signatures in the struct; which includes windows things..... which aren't available on non-windows.
<daurnimator>
Pistahh: stop printing File and you'll be fine :P
<mq32>
is an allocator allowed to @panic if i try to release an object not allocated with the allocator?
<daurnimator>
mq32: sure.
<daurnimator>
mq32: unreachable (and hence nose demons in release mode) would be expected IMO, so a @panic is one level nicer
mahmudov has joined #zig
<mq32>
okay, good
<mq32>
i'm writing a "bitmap allocator"
<mq32>
or do we have that in std already?
<mq32>
so "all objects have the same size"
<mq32>
and you have a fixed number of objects
<daurnimator>
mq32: with multiple bucket sizes?
<mq32>
no, fixed bucket size
<mq32>
hmm. i can probably make that even dynamic…
<mq32>
have to think about it a moment, if i need "full dynamic" allocation
<daurnimator>
mq32: might be able to write a "single size" implementation that takes a size as a parameter; then we can stack several together
<mq32>
oh that sounds good :D
<mq32>
beeing on freestanding sure has it's ... implications :D
<daurnimator>
mq32: FWIW if you're looking to write things to make a good allocator; the thing we need most right now is a radix tree
<mq32>
for now i'm happy with "i can do alloc(FixedObject)" ^^
jjido has joined #zig
lunamn has joined #zig
mahmudov has quit [Ping timeout: 268 seconds]
deesix has joined #zig
<daurnimator>
oh my.... I made a discovery of a new idiom I think
<scientes>
I just wrote a slick bisection of variable-length strings (with reserved character, like UTF-8 or null-terminated has)
<daurnimator>
scientes: utf8 doesn't really have a reserved character. it's got an invalid range...
<scientes>
daurnimator, \xfe and \xff
<scientes>
and also \xfd and \xfc
<scientes>
and IIRC \xfb and \xfa
<Sahnvour>
daurnimator: pretty slick
<Sahnvour>
closer and closer to reification :)
<daurnimator>
scientes: \xc0, \xc1 and \xf5-\xff
<daurnimator>
scientes: but well formed utf8 is more than that.. e.g. you need to check the leading codepoint indicates the correct length. and that all continuation bytes have the continuation sequence
<scientes>
ahh yes, but only \xff and \xfe in the original definition
<daurnimator>
scientes: "original".... being superceded in general by 97 and officially in 2003.
<scientes>
anyways, its easy to pass the reserved byte in a register
<daurnimator>
scientes: but there's many reserved bytes here.... how is that helpful?
<scientes>
and escaping is possible, but doesn't seem needed
<scientes>
daurnimator, the string set is comptime
<scientes>
so you just pick what works
<daurnimator>
then what does passing in a register mean?
<scientes>
is there anything like ? : GNU extension?
<scientes>
oh yeah "else"
<scientes>
"orelse"
forgot-password has joined #zig
forgot-password has quit [Client Quit]
<daurnimator>
how can I turn a *T into a slice of length 1?
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<daurnimator>
`@ptrCast([*]T, x)[0..1]` I guess?
mahmudov has joined #zig
<mq32>
daurnimator, yeah that's afaik the "official way"
deesix has quit [Ping timeout: 265 seconds]
<daurnimator>
TIL our current out stream can't indicate a partial write...
Akuli has joined #zig
protty has joined #zig
<protty>
Does anyone know how you could go about exiting and thread and decommitting its stack without creating a new thread?
<daurnimator>
protty: well how did you create the thread?
<protty>
by using a custom stack for clone()
<protty>
was thinking of using @newStackCall to switch to a different stack, decommit the old one and then pthread_exit() or similar. But couldnt figure out where this new stack would live
<daurnimator>
protty: generally whoever creates something is responsible for deleting it
<daurnimator>
==> whatever spawned the thread should be responsible for waiting on it
<protty>
the spawner in this case doesnt join() until much later on as it does other work in between. thread stacks being recycled during that work and wanted to decrease memory usage of old stacks if possible
gsomix has joined #zig
batmanaod has joined #zig
<protty>
oh pthread_exit() is thread safe. might have an idea now. sorry for the rubber ducking..
<daurnimator>
Where `Mixin` could be something like: `fn Mixin(Self: type) type { return struct { pub fn foo(self: *Self) void {} pub fn bar(self: Self) usize { return self.otherThing(); }; } }`
<daurnimator>
idea: `InStream` could be a Mixin => it assumes that `self.read()` exists; and adds in all the other utility `readXYZ` methods
<daurnimator>
andrewrk: ^ did I stumble on good? :)
<nrdmn>
mq32: are you going to bring stickers to 36c3?
<protty>
daurnimator: is that like `impl` trait extensions in rust?
<daurnimator>
protty: I'm not familiar with those in rust; so can't say
<andrewrk>
hi protty
<protty>
ello andrewrk
shakesoda has joined #zig
<daurnimator>
I think the above scheme would remove the need for stack_size_std_io_InStream....
<andrewrk>
daurnimator, we can avoid that hack (and the error set annoyances!) if we avoid runtime-known function pointers
<daurnimator>
andrewrk: exactly; the Mixin strategy I mention above would do that!
<andrewrk>
that's definitely worth looking into
<daurnimator>
I think I'll have a go at it
<andrewrk>
the only downside is that apis which want to accept a stream will have to take a `var` (which is currently already true because of the error set)
<daurnimator>
not now.... its 4:30am and I've spent all night thinking about std.fifo :P
<andrewrk>
but that might be worth it because that stack size thing is really bad
<andrewrk>
it addresses some of the issues but I wouldn't call it a full solution
<shakesoda>
i asked yesterday, but is there a reasonable way with builder to generate a config.h for a dependency in place of whatever its original build system would make
<shakesoda>
i saw some stuff for getting output h path but it errored out when i tried to use it
<andrewrk>
shakesoda, there is not a high level convenient API yet but you can use the build script to build & run a .zig file which generates your config.h file
<andrewrk>
this will give you @import("build_options")
<andrewrk>
also happy to accept PRs to improve the build system API
<shakesoda>
andrewrk: thanks, i'll see what i can come up with
adam98 has joined #zig
clktmr has joined #zig
SimonN has quit [Remote host closed the connection]
forgot-password has joined #zig
adam98 has quit [Ping timeout: 268 seconds]
mikdusan has quit [Quit: WeeChat 2.5]
<shakesoda>
is it documented anywhere how to deal with linking in windows deps? for example i need user32.lib, opengl32.lib etc and i'm not sure what to do about it
<andrewrk>
foo.linkSystemLibrary("user32")
<shakesoda>
hmmm, i tried that, maybe i put it on the wrong thing
<andrewrk>
shakesoda, hmm that seems like a bug. are you able to learn what the error is in this case?
doublex has quit [Ping timeout: 276 seconds]
<andrewrk>
(side note: zig should be improved to treat that situation the same way it does as `catch unreachable` so that you can see the error return trace)
<shakesoda>
andrewrk: i'm not sure what the real error is, my guess is hitting the else case in the error switch in linkSystemLibraryPkgConfigOnly and passing that through
<shakesoda>
if i change the else => unreachable to else => {} i get further, at least
<shakesoda>
actually, i can successfully link if i do that
<andrewrk>
shakesoda, change it to else => |e| e catch unreachable,
<shakesoda>
trying
<andrewrk>
as a temporary workaround, so that it gives you an error return trace
<andrewrk>
maybe you need @as(anyerror!void, e) catch unreachable
<shakesoda>
does that need a git build? that fails on 0.5.0
<andrewrk>
there have been multiple bug fixes related to the code you are looking at since 0.5.0
<shakesoda>
okay, i'll update and see how it goes
<lunamn>
andrewrk: question regarding #3635, would Address.initUnix stay as-is with returning error.UnsupportedOS?
<lunamn>
I forgot to replace its switch on builtin.os to using has_unix_sockets and thought about that for a bit
jjido has joined #zig
doublex has joined #zig
<shakesoda>
andrewrk: @as(anyerror!void, e) catch unreachable works with master, big trace now which is showing me windows.CreateProcessW throwing error.FileNotFound (presumably for pkg-config) ...
<shakesoda>
andrewrk: but that should be handled already...
<andrewrk>
lunamn, thanks for the PR! will merge soon
<andrewrk>
have you been trying out your patch locally?
wootehfoot has joined #zig
<andrewrk>
I'll solve the SIGPIPE problem soon. I've been discussing with Rich Felker the best way to handle this
<shakesoda>
andrewrk: that works
SimonNa has joined #zig
<andrewrk>
shakesoda, ok, I'll push to master
<lunamn>
andrewrk: yep, it works, at least on linux :P
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
jjido has joined #zig
<Pistahh>
daurnimator: btw, you asked why I used anyerror on fn main.. well, zig init-exe generates it :P :D
<andrewrk>
anyerror!void is a perfectly reasonable return type on main
<shakesoda>
i'm trying to throw around some c function pointers and i'm not entirely sure how to address this error: expected type 'extern fn([*c]const u8) ?*c_void', found 'extern fn([*c]const u8) ?extern fn() void'
<shakesoda>
i see some optionals involved, but have no idea how to convince it that yes i did mean that
Akuli has quit [Quit: Leaving]
doublex has quit [Ping timeout: 276 seconds]
<andrewrk>
arguably that type coercion should be allowed
<andrewrk>
but you can work around with @ptrCast
<andrewrk>
I suggest [*]const u8 instead of [*c]const u8 though. assuming that's a c string
<shakesoda>
doesn't it need to be *c? i'm passing this between two c libraries
<andrewrk>
(also, it would have saved me some time if you included the notes in the error paste earlier, I had to type out the example to get the extra information)
<andrewrk>
the zig build fix is pushed to master
<shakesoda>
sorry, was just trying to keep noise down in the log
<andrewrk>
no problem
<shakesoda>
for the apis i am passing these between, it's completely legal for the pointers to be null, and i don't use anything in this struct in my code
<shakesoda>
i certainly don't believe *c to be the right answer in anything i am using myself
<shakesoda>
zig is very clear to me about this lol
<andrewrk>
if they can be null then use optional pointers
<andrewrk>
`?[*]const u8` "optional unknown-length pointer to constant elements of type u8"
<shakesoda>
yeah, that builds for me
<shakesoda>
?*const u8 worked too, but that is wrong
<shakesoda>
andrewrk: thanks, this makes sense
<andrewrk>
np
<shakesoda>
is there a cleaner way to or flag values together defined in an enum in c header than a ton of bitcasts? this solution seems a bit heavy handed: https://hastebin.com/lopolanono.js
<andrewrk>
that also has the disadvantage of using runtime state instead of keeping everything comptime
<andrewrk>
I think that should be compile error too, the proper cast here is @enumToInt
<shakesoda>
that certainly sounds better, although i think it makes sense that bit cast at least builds
ltriant has joined #zig
<andrewrk>
C lets you implicitly cast an enum value to an int. zig doesn't. so you have to use @enumToInt in this case
batmanaod has quit [Ping timeout: 245 seconds]
<andrewrk>
type theory wise, enum values are not bit flags. it's not really correct for that .h file to do that
<shakesoda>
that's reasonable, seems i still have to bitcast back to the flag type too
<andrewrk>
@intToEnum
<shakesoda>
crashes my program
<shakesoda>
i tried that one first
<shakesoda>
crashes with invalid enum value, which makes sense
<shakesoda>
since what the function is actually taking isn't represented in the enum any longer
<andrewrk>
ah. yeah this is why flags should not be enums
<shakesoda>
i can accept the bitcast, i should make a note to myself to make the typing more sound on this api in the future
<shakesoda>
enums with bit flags aren't that uncommon, but i should certainly drop the enum type when it's expected to pass things which can't be represented with it anymore
<shakesoda>
s/pass/accept/
doublex has quit [Remote host closed the connection]
doublex has joined #zig
_whitelogger has joined #zig
kllr_sbstn has joined #zig
kllr_sbstn has quit [Quit: leaving]
forgot-password has quit [Quit: Leaving]
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]