ChanServ changed the topic of #zig to: zig programming language | | be excellent to each other | channel logs:
Avila has joined #zig
<andrewrk> it pads with a null byte. that function should return a `![]null u8` (once null terminated pointers are implemented) and add 1 to max size. so I think it's a bug
<andrewrk> hmm actually I take back what I said. I'll need to re-examine the code
kristate has joined #zig
reductum has joined #zig
noonien has quit [Quit: Connection closed for inactivity]
kristate has quit [Ping timeout: 246 seconds]
<daurnimator> andrewrk: #1873 contained more than just a rename
<daurnimator> andrewrk: seems like you did something similar but different in dfbc063f79dc1358208216b466c1bf8c44baa430
Avila has quit [Ping timeout: 244 seconds]
MajorLag has joined #zig
_whitelogger has joined #zig
reductum has quit [Quit: WeeChat 2.3]
jevinski_ has joined #zig
jevinskie has quit [Ping timeout: 250 seconds]
kristate has joined #zig
<andrewrk> hey kristate - I just wanted to say that I appreciate you. Thanks for being a positive contributor to the Zig community
<andrewrk> emekankurumeh[m], I think you may have had some dropped messages - the only one I see is "andrewrk: something like the rust playground."
<andrewrk> oh, are you responding to my question about a docker image?
<emekankurumeh[m]> yeah
<andrewrk> so the pre-built executable on is truly static
<andrewrk> that means it works on all linuxes, and in all docker images
<kristate> andrewrk: hey Andrew, thanks for the message. I am hoping that we can get everyone into the same room together this year.
<andrewrk> so there would be no added benefit to an official zig docker image
<andrewrk> emekankurumeh[m], it sounds like what you want to achieve is some sandboxing. if you choose to use docker for sandboxing - which may have security concerns, I'm not sure - it could be any docker image and the static build would work just fine
<kristate> andrewrk: btw, almost have the rebase complete for #1864
<andrewrk> (side note - the static build of zig from the download page is, in fact, built on alpine linux in a docker image. Have a look at the README)
<emekankurumeh[m]> the rust sandbox repo readme does have some notes about security related stuff
<andrewrk> kristate, ambitious goal!
<kristate> andrewrk: I wouldn't mind buying a ticket for you, hejsil and tiehuis
<kristate> it's surprising, but tiehuis and jimmi are pretty close
<kristate> I think that if everyone was hacking away in the same room for a week, we could get a lot of code out and work-out core problems
jevinskie has joined #zig
jevinski_ has quit [Ping timeout: 244 seconds]
<daurnimator> kristate: where are you thinking?
<kristate> daurnimator: Japan -- you're in aus, right?
<daurnimator> kristate: yep
<kristate> everyone is weirdly close to JP
<daurnimator> not andrewrk :P
<andrewrk> I do enjoy visiting other countries
<kristate> daurnimator: how does April sound?
<daurnimator> kristate: not great for me. I'm in africa most of april
<kristate> the cherry blossoms are great in April
<kristate> checking the sakura schedule
<daurnimator> kristate: though japan isn't bad for me: flights can be quite cheap sometimes from here.
<kristate> looks like 3/26 is a good time
<kristate> daurnimator: yes, kansai international should have good rates with jetstar
<kristate> here is an article in english:
<daurnimator> kristate: I probably can't make those dates. I'm in africa march 30-march until 17-april.
<daurnimator> but I'm not that important anyway
<kristate> daurnimator: maybe you can stop-by anyway on your way back
<daurnimator> ha. no. not only are the flights already booked, but that's one hell of a detour.
<kristate> Are you going to S. Africa?
<andrewrk> kristate, if you're taking me into account - I'm training for a marathan until June 2 which makes travel difficult, and I'm doing a talk in Philadelphia on April 23
<daurnimator> kristate: yep. "just add a casual extra 30 hours to the trip"
<daurnimator> andrewrk: I'd say you're the most important person to have in attendence :P
<daurnimator> andrewrk: can't you train for a marathon anywhere? :)
<andrewrk> sure - it just makes it more difficult. I find a routine schedule to be helpful in beingmore productive and motivated
<kristate> andrewrk: daurnimator jokes, but japan has really good air and the river in Kyoto is known for trainers :-)
<andrewrk> that does look lovely
<daurnimator> kristate: woah that looks way too busy
<kristate> daurnimator: I think everyone is out for cherry blossoms
<daurnimator> kristate: heh. reminds me of this area I go through most days:
<kristate> daurnimator: yes, they look similar :-)
kristate has quit [Remote host closed the connection]
schme245 has joined #zig
kristate has joined #zig
schme245 has quit [Ping timeout: 240 seconds]
darithorn has quit [Quit: Leaving]
schme245 has joined #zig
kristate has quit [Remote host closed the connection]
kristate has joined #zig
<kristate> andrewrk: took a look at my email and the patreon subscription didn't go through on time -- is everything okay? The card listed expired and so I updated the account with a new card.
kristate has quit [Remote host closed the connection]
<emekankurumeh[m]> `` will download the latest linux build of zig but shows a 403 page
kristate has joined #zig
schme245 has quit [Remote host closed the connection]
schme245 has joined #zig
schme245 has quit [Remote host closed the connection]
kristate has quit [Remote host closed the connection]
kristate has joined #zig
kristate has quit [Remote host closed the connection]
schme245 has joined #zig
<schme245> the code below segfaults for me, but I'm not sure why. Zig is my first systems language, so bear with me: is `bytes` allocated on the stack? is the segfault due to a stack overflow?
<schme245> pub fn main() void {
<schme245> const bytes: [1000 * 1000 * 1000]u8 = undefined;
<schme245> }
<schme245> if yes, would it be possible to catch this somehow in debug mode and give a nicer error message?
kristate has joined #zig
kristate_ has joined #zig
kristat__ has joined #zig
kristate has quit [Read error: Connection reset by peer]
kristat__ has quit [Remote host closed the connection]
kristate_ has quit [Ping timeout: 240 seconds]
allan0 has joined #zig
<wilsonk> schme245: that code doesn't segfault for me on MacOS with the newest master branch. Are you using the latest branch
<schme245> no, it's like a week old
<schme245> let me try with master
kristate has joined #zig
<schme245> still segfaults for me on osx with 0.3.0+dfbc063f
<wilsonk> woops, yes I am getting that also...I was using the wrong version!! Sorry about that. One second here
<wilsonk> schme245: you can use @newStackCall(func, newstack, arg); to get around that problem
<wilsonk> technically the signature is: @newStackCall(new_stack: []u8, function: var, args: ...) var
<schme245> neat! the reason I stumbled on this is that I forgot that this is not Java and I actually wanted to do a heap allocation... so the solution in my case is to do that :) but I'm still curious as to exactly why this happens and if it's possible to provide a better error message rather than a segfault
kristate has quit [Remote host closed the connection]
kristate has joined #zig
kristate has quit [Ping timeout: 246 seconds]
allochi has joined #zig
<allochi> Hi, I'm trying to build zig on macOS, I used to be able to do that, today I got "Could NOT find CLANG (missing: CLANG_LIBRARIES CLANG_INCLUDE_DIRS)", any idea how to fix this? thanks!
<wilsonk> schme245: That code returns a EXC_BAD_ACCESS, so I would think that is a stack overflow. I believe there will be a way to stop stack overflow coming soon (#1639). You can use an allocator to dynamically allocate, but there is no documentation on it yet in the main docs. Probably have to look at examples or std/heap
<wilsonk> allochi: did you follow the build instructions again for MacOS? Especially the 'cmake .. -DCMAKE_PREFIX_PATH=/usr/local/opt/llvm@7/' part? I would do a 'make clean', remove CMakeCache.txt, use that cmake command and then 'make install'
<schme245> wilsonk: where do you see the EXC_BAD_ACCESS?
<wilsonk> use lldb and run the will display the bad access
<schme245> man, I've got a lot of catching up to do
<schme245> thanks for the help!
<allochi> I'll try this now, thanks!
<allochi> I did follow the build instruction from the as usual
<allochi> wilsonk: same error
<wilsonk> allochi: hmm, you might have to reinstall @llvm7. 'brew reinstall llvm@7' I think it is. I had a similar problem a while ago and I think a reinstall fixed it. Will take a while to compile though :(
kristate has joined #zig
<allochi> wilsonk: Ok, I will try that, but first, it seems that cmake doesn't recognize where clang lib and include folders are, I don't know cmake, but I will see if I can set it up first, I need to read cmake docs.
<wilsonk> allochi: cmake should find those automatically with the 'cmake' command from above but I have seen a case where cmake gets messed up and cant figure out where libs are. I assume you can still use clang, correct? Resetting with @llvm7 using brew really should fix things. (or you may need to reinstall cmake is just really strange that it cant find those include dirs, as it should be dead simple to find!)
<allochi> wilsonk: I will try this now
<euantor> emekankurumeh[m]: Check out - I run a nightly cron job to publish new master images as `euantorano/zig:master`
<wilsonk> oh, sweet
<wilsonk> off to sleep...g'night all
<allochi> wilsonk, you were correct, I reinstalled llvm and it works, I have to say I replaced `export LDFLAGS="-L/usr/local/opt/llvm/lib"` with `export LDFLAGS="-L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib"`
<daurnimator> wilsonk: schme245: sounds like a bug.
<schme245> should I open an issue?
<daurnimator> schme245: yes I think so. I think it's cause by a lack of stack probing
* schme245 test
<schme245> ok, will do!
* schme245 pretends to know what's going on while ducking down behind the screen typing "stack probing" into Google
<daurnimator> schme245: thanks. will wait for our benevolent dictator (andrewrk) to have a look.
steveno has joined #zig
iamthad has quit [Quit: ZNC -]
schme245 has quit [Remote host closed the connection]
schme245 has joined #zig
schme245 has quit [Ping timeout: 268 seconds]
iamthad has joined #zig
schme245 has joined #zig
schme245 has quit [Read error: Connection reset by peer]
steveno has quit [Ping timeout: 250 seconds]
eagle2com has joined #zig
jevinskie has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
steveno has joined #zig
halosghost has joined #zig
eagle2com has quit [Ping timeout: 256 seconds]
<emekankurumeh[m]> euantor: thanks!
allochi has quit [Quit: Page closed]
steveno has quit [Ping timeout: 240 seconds]
schme245 has joined #zig
allochi has joined #zig
schme245 has quit [Ping timeout: 268 seconds]
<emekankurumeh[m]> has anyone made any compression libraries in zig?
<emekankurumeh[m]> specifically LZMA2.
darithorn has joined #zig
steveno has joined #zig
Akuli has joined #zig
Zaab1t has joined #zig
steveno has quit [Ping timeout: 250 seconds]
redj has joined #zig
kristate has quit [Remote host closed the connection]
schme245 has joined #zig
schme245 has quit [Remote host closed the connection]
<allochi> \q
schme245 has joined #zig
allochi has quit [Quit: leaving]
schme245 has quit [Ping timeout: 268 seconds]
Ichorio has joined #zig
steveno has joined #zig
wootehfoot has joined #zig
<andrewrk> euantor, did you see my explanation of why you don't need a zig docker image?
<euantor> andrewrk: I did, yes. It still helps with my workflow though. I have a fish alias configured to `zig-master` that I know will always invoke the latest master build of Zig as of midnight the day before
<Akuli> today i wrote a script that fetches the latest zig
<andrewrk> oh, is it because there is no reliable redirect link to the latest download?
<Akuli> cds to the cloned repo, pulls, builds, installs
<euantor> Yeah, there’s no mention of a redirect link on the downloads page
<euantor> And I wanted the latest stable-ish (eg: CI passing) release, not just HEAD
<euantor> I’m also planning a Zig playground service using it. I started some prototyping before Christmas then ended up stupidly busy
<andrewrk> euantor, s3 (the hosting service of has a metadata feature for a redirect, but sadly the http code is always a permanent redirect and not configurable, so it gets incorrectly cached
<euantor> I wonder if it would be possible to just create a GitHub release? I know you can do so via their API
<Akuli> would github's list of releases get kinda cluttered if there were things like alpha releases in the list?
<euantor> Not sure. I know you can tag release as pre-release etc. Might be worth looking at another project that makes use of them
<andrewrk> euantor, you mean github releases in between the official tagged version releases?
<euantor> Yeah, with perhaps one continuously updates `master` pre-release, though I can see how that would become confusing
<euantor> The real answer is that I don’t really have any solutions honestly
schme245 has joined #zig
<emekankurumeh[m]> @euantor: talk about a coincidence, I was asking about a docker image for the exact same reason!
<euantor> Yeah, it’s how the Nim playground works and it’s fairly simple to set up
<andrewrk> you can use any docker image and download the zig static build to it
<andrewrk> it has no dependencies except for a linux kernel and file system
<euantor> Yeah, which is basically all my image is with a check of the download’s checksum thrown in
<emekankurumeh[m]> does your image do version caching?
<Akuli> how do i tell build.zig to use --library c, --no-rosegment (in non-release mode only, if possible), and a custom executable name? currently i'm using a makefile because i couldn't get build.zig to work like i wanted
<Akuli> --library c is most important, of course
<andrewrk> Akuli, exe.linkSystemLibrary("c");
<andrewrk> exe.setNoRoSegment(true);
<euantor> emekankurumeh[m]: there’s a tag published for every version on docker hub, so you can just pull a specific tag
<andrewrk> Akuli, for non release mode only, you can use standardReleaseOptions like this: and then look at `mode`
<Akuli> awesome :D
<Akuli> what does @import("builtin") do? does it load a file literally named 'builtin' or something else?
<Akuli> ummm nevermind
<Akuli> std/build.zig uses it enough for me to figure it out
<andrewrk> Akuli, you can use the command `zig builtin` to see what source @import("builtin") sees
<andrewrk> (also try `zig builtin --release-fast` and see what happens)
<Akuli> ooo this is like in python 3, i get it now
<Akuli> or
<Akuli> no it isn't :D anyway, thanks
<Akuli> can i write zig code that has import cycles? does it work, crash, or work but not be guaranteed to work?
<andrewrk> Akuli, top level declarations in zig are order independent, and it makes no difference which files your declarations are in
<Akuli> hmmmm that's neat
<andrewrk> you will get a compile error if any of your top level declarations (directly or indirectly) depend on themselves
<andrewrk> e.g.: const Foo = struct { x: Foo };
<Akuli> but can i do this: file A defines a struct and uses a union type from file B, and file B defines the union type using the struct from file A
<andrewrk> there are a couple cases where zig has a false dependency for this. there are open issues with workarounds you can do
<andrewrk> *false positive
<Akuli> the struct won't use the union type, but file A will use it elsewhere
<andrewrk> all that works fine. files/imports/namespaces don't depend on each other in that sense
<Akuli> this is an awesome language :D
<Akuli> even in languages like python where you can do all kinds of crazy stuff, you "can" do this but it's ugly and bad style
<schme245> how can I convert a value from `u64` to `[]u8`?
<schme245> *how do
<Akuli> schme245, there are some functions somewhere in std, grep for endian or something
<Akuli> let me find
<schme245> there is `readIntSlice` and co in std/mem, but they go the other way
<andrewrk> schme245, []u8 is a reference type (a pointer and a length) so first you will have to decide where the memory of the u64 will live
<Akuli> there's a family of functions in std.mem, maybe you want those? readIntLittle and friends
<andrewrk> if you explain what you're trying to do in more detail I can probably advise better
<schme245> I have this: `const testData: u64 = 0x0123456789ABCDEF;` and I want to "view" it a byte array rather than a long
<schme245> I know I can bitshift and get the bytes that way, but I'm curious if I can "cast" it somehow
<Akuli> writeUintLittle or writeUintBig does that, i never remember which way to represent the bytes is called big-endian and which is little-endian but those will work :D
<Akuli> one of them will do what you want, that is
<andrewrk> schme245, right now this would be the recommended way:
<andrewrk> after one of those casts can disappear
<andrewrk> so what this looks like is: take address of variable. cast to single-item pointer to array of length 1. cast to slice of u64. @sliceToBytes.
<andrewrk> it's ugly but all those constructs are guaranteed safe and work at comptime
<schme245> I see, and the difference between that and `writeIntSlice` and co is that this doesn't allocate any new memory, either on the heap or the stack?
<andrewrk> correct: your only memory is the 8 bytes for the u64 and the (on 64-bit arch) 16 bytes for the slice (pointer+length)
<andrewrk> with writeIntSlice you would need an additional array of 8 bytes to put the result in
<schme245> excellent, thanks Akuli and andrewrk!
<andrewrk> I'm pretty sure that in release modes, either way will be identical. we could experiment with that with godbolt
<schme245> on the topic of casting, I did not know that Java-style `(T) x` casting works in Zig, I don't think that's mentioned in the docs
<schme245> is `(u64) x` the same as `@intCast(u64, x)`?
<andrewrk> it's actually function call syntax
<andrewrk> explains the difference between @intCast and u64(x)
<andrewrk> also there's a proposal to change "implicit casting" syntax (which probably needs to be renamed now) to syntax that is distinct from function calls:
<schme245> gotcha, I have read that section before but I must have glanced over this, I'll give a more thorough read
<andrewrk> admittedly there are quite a few TODOs in the docs
<schme245> really appreciate all the effort you put into helping and communicating, it invaluable for someone like me who is a a newcomer both to Zig and systems programming
<andrewrk> I am thrilled that people are learning systems programming with zig and I hope I can improve the learning experience
<Akuli> it's awesome that the creator of a language helps people on the irc channel :D
<Akuli> that doesn't happen much with other languages
Akuli has quit [Read error: Connection reset by peer]
forgot-password has joined #zig
<forgot-password> Is it possible to have a pointer to values of variable types?
Akuli has joined #zig
<andrewrk> forgot-password, you could look into using a union for that
<forgot-password> Right, I did that for some cases, but for what I'm doing now I'd like to express it in a more generic way. Is there another approach?
<forgot-password> I'm writing a simple physics simulation and for that I have a PhysicsManager, which I'd like to handle any struct with a velocity, acceleration and position. Currently I have an intermediate struct that contains the pointers to these fields, but this gets uncomfortable to deal with once I add more fields.
<MajorLag> andrewrk, schme245: `const bytes = mem.asBytes(&long_var);`. 'bytes' will be a `*[@sizeOf(long_var)]u8`
<MajorLag> `*[@sizeOf(@typeOf(long_var))]u8`
steveno has quit [Ping timeout: 268 seconds]
<schme245> nice!
<Akuli> mem.asBytes sounds like something that might depend on the host's byte order?
<andrewrk> MajorLag, ah, thanks, I forgot about that
<andrewrk> Akuli, yes - same as the other code that I shared above
<Akuli> i thought defer runs at the end of a block? but then contents and slice_list would contain freed values?
<andrewrk> how does defer work?
<andrewrk> Akuli, ah I see your question. Your understanding of defer is correct. contents.append here is std.Buffer.append which copies the bytes
<Akuli> thanks! makes sense now
<andrewrk> slice_list is a list of `usize` not slices (sorry for the bad name)
schme245 has quit [Remote host closed the connection]
<Akuli> how do i allocate an array of n u8s with an allocator? in c i would do malloc(n)
<Akuli> i'm guessing allocator.alloc(u8, n)
<MajorLag> `var x = try my_allocator.alloc(u8, n);`. x will be a []u8 with a size of n.
<Akuli> nice, do i also use `defer`?
<MajorLag> typically yes, if you plan to free it in the same scope.
<Akuli> nice
<andrewrk> Akuli, similarly, you would use `errdefer;` if you wanted to keep the memory past the end of the function, but only if the function doesn't error out
<Akuli> yes, i'm familiar with errdefer
schme245 has joined #zig
Zaab1t has quit [Quit: bye bye friends]
<Akuli> style question: i want a variable called type, which is st, type_ or typ or tybe?
<Akuli> s/st/best/
<Akuli> btw i really like how there's std/unicode.zig :D that's one of the (many) things i ended up writing myself in c when i needed
<Akuli> i'll be back, i'll find the answer in irc logs if i care enough
Akuli has quit [Quit: Leaving]
<MajorLag> Akuli: I think the best way is to just use a synonym, like `kind` or a more descriptive name, like `packet_type`. Unless `type`'s type is `type`, then use `Type`.
forgot-password has quit [Ping timeout: 240 seconds]
adrusi has quit [Read error: Connection reset by peer]
adrusi has joined #zig
forgot-password has joined #zig
forgot-password has quit [Ping timeout: 250 seconds]
<emekankurumeh[m]> does `mem.asBytes` copy?
<andrewrk> no, it's a pointer cast
<emekankurumeh[m]> i tried to something similar and i kept getting a copy instead of a pointer to the same memory.
<andrewrk> are you thinking of toBytes?
<emekankurumeh[m]> no i tried the manual cast
halosghost has quit [Quit: WeeChat 2.3]
forgot-password has joined #zig
wootehfoot has quit [Read error: Connection reset by peer]
forgot-password has quit [Quit: leaving]
Ichorio has quit [Ping timeout: 272 seconds]
qbradley has joined #zig