ChanServ changed the topic of #zig to: zig programming language | ziglang.org | be excellent to each other | channel logs: https://irclog.whitequark.org/zig/
<dimenus> oooo an llvm crash when using opengl
<dimenus> oh wow, it's codeview causing the crash
<dimenus> interesting
cenomla has quit [Quit: cenomla]
<andrewrk> dimenus, I believe the codeview llvm code is young and they are interested in bug reports
<andrewrk> > Bring on the Bugs!
<dimenus> hmmm, an issue with libepoxy
<dimenus> not exporting symbols correctly on windows
<dimenus> guess this isn't just our problem!
<dimenus> :)
<dimenus> i'll just use gl3w/opengl32.lib
cenomla has joined #zig
arBmind1 has joined #zig
<dimenus> andrewrk, for now we can @cDefine WIN32_LEAN_AND_MEAN to use windows.h without including COM etc
arBmind has quit [Ping timeout: 248 seconds]
<andrewrk> good idea
<dimenus> it's probably best practice anyway as windows.h includes a bunch of very old apis
<dimenus> that are rarely used
<andrewrk> dimenus, we also have std.os.windows
<andrewrk> so that one can avoid parsing windows.h
<dimenus> i should probably just add LoadLibraryA to that
<dimenus> rather than include the whole header
<andrewrk> I think you want LoadLibraryW
<andrewrk> please correct me in this issue if I have the situation wrong
<dimenus> no you're right, we shouldn't depend on that
<andrewrk> dimenus, also I was thinking, about the whitespace issue, maybe we can add `zig fmt` which fixes whitespace issues in files
<andrewrk> so you could run that before zig build
<andrewrk> to work around not being able to configure one's editor
jfo has quit [Ping timeout: 255 seconds]
<dimenus> hmmm, that may work
<dimenus> i'm going to wrap LoadLibraryW in a os.windows function that takes a regular []const u8
<andrewrk> that sounds good. sounds like you're working on std lib code for utf-16le encoding/decoding and utf-8 encoding/decoding
<andrewrk> I'm also ok with using the A versions of windows functions until #534 is solved
<dimenus> kernel32 has functions to encode UTF-8 in utf-16LE
<dimenus> should we write our own functions? I thought UTF16-LE was generally discouraged
<andrewrk> yes we should write our own, there's no reason to add a dependency on a syscall for something that isn't fundamentally a dependency
<andrewrk> UTF-8 is encouraged in zig std lib
<andrewrk> but we have to have UTF16-LE to communicate with windows. So we do it
<andrewrk> it should be hidden by the OS abstraction layer
<dimenus> i don't mean to steal from rust, but it looks like this is pretty robust: https://github.com/hsivonen/encoding_rs
<dimenus> also, UTF16LE encoding is not high on my priority list at the moment
<dimenus> i will probably just mark it as a TODO and call LoadLibraryA for now
<andrewrk> it's ok to copy code from other projects if the license is compatible
<andrewrk> that sounds fine about TOD
<andrewrk> *TODO
jfo has joined #zig
jfo has quit [Ping timeout: 248 seconds]
dimenus has quit [Quit: Leaving]
dimenus has joined #zig
tiehuis has joined #zig
<dimenus> andrewrk, can you test &@opaqueType() for nulls at all?
<dimenus> i'm just wondering of the utility here, since a lot of those win32 calls can return null in the case of a failure
<andrewrk> dimenus, you can if you make it nullable: ?&OpaqueType()
<andrewrk> when we parse .h files, we assume every pointer is nullable
<dimenus> nice, that works just as expected
dimenus has quit [Quit: Leaving]
dimenus has joined #zig
dimenus has quit [Client Quit]
cenomla has quit [Quit: cenomla]
jfo has joined #zig
jfo has quit [Ping timeout: 255 seconds]
PV has quit [Ping timeout: 260 seconds]
arBmind1 has quit [Quit: Leaving.]
jfo has joined #zig
jfo has quit [Ping timeout: 255 seconds]
tiehuis has quit [Quit: WeeChat 1.9.1]
arBmind has joined #zig
arBmind has quit [Quit: Leaving.]
jfo has joined #zig
jfo has quit [Ping timeout: 248 seconds]
jfo has joined #zig
arBmind has joined #zig
arBmind1 has joined #zig
arBmind has quit [Ping timeout: 240 seconds]
jfo has quit [Ping timeout: 255 seconds]
jfo has joined #zig
arBmind has joined #zig
arBmind has quit [Read error: Connection reset by peer]
arBmind1 has quit [Ping timeout: 268 seconds]
arBmind has joined #zig
arBmind has quit [Read error: Connection reset by peer]
arBmind has joined #zig
arBmind1 has joined #zig
arBmind has quit [Ping timeout: 248 seconds]
jfo has quit [Ping timeout: 255 seconds]
dimenus has joined #zig
<dimenus> andrewrk, have a quick question when you have a minute
<andrewrk> hello
<dimenus> so, going to wrap LoadLibraryA in a function call in std.os.windows
<dimenus> because i need to create a cstr, i need to allocate
<dimenus> i don't really want to pass an allocator into the new function though
<dimenus> is it against zig zen to just set an allocator within the file itself and use that>?
<andrewrk> yes
<andrewrk> the established pattern is to accept an allocator
<dimenus> got it
<andrewrk> however, you can make the allocator nullable
<andrewrk> and if it's null, try to use stack memory, but if the name won't fit in the stack memory, return error.NameTooLong
<andrewrk> or just make the allocator mandatory and call it a day
<dimenus> do we have default arguments in zig?
<andrewrk> we do not
<andrewrk> the recommended way to do default arguments is to have similarly named functions, where one of them has all the args, and the other one dispatches to the first one with the default argument
<dimenus> having a nullable type basically does what i want anyway I think
<andrewrk> zig's idea about allocators is that, yes, it's more annoying to write code when you have to think about them. but ultimately the code will be reusable in more environments, and when reading code, the fact that a given piece of code depends on memory allocation is helpful to know
<andrewrk> we want someone to call std.loadLibrary or whatever, and see the API, and think WTF why do I need an allocator? and then they learn, yes, we have to allocate memory just to put a stupid null byte at the end
<andrewrk> also to decode-reencode unicode
<dimenus> lol
<dimenus> yeah not hiding the allocator does make the most sense and i ultimately agree with it
jfo has joined #zig
arBmind has joined #zig
arBmind1 has quit [Ping timeout: 240 seconds]
jfo has quit [Ping timeout: 260 seconds]
jfo has joined #zig
jfo has quit [Ping timeout: 248 seconds]
jfo has joined #zig
<dimenus> andrewrk, i'm starting to like the feel of errors in zig
<dimenus> const handle = os.windowsLoadDll(allocator, OpenGLDLL) %% |err| {
<dimenus> return;
<dimenus> debug.warn("{}: {}", @errorName(err), OpenGLDLL);
<dimenus> };
<dimenus> concise
<andrewrk> nice :)
<andrewrk> concise, and robust
<andrewrk> no errors left behind
<dimenus> the standard lib function returns a %HMODULE which is a &OpaqueType()
<dimenus> null pointer test is handled in thes standard lib rather than the user function
<dimenus> which seems to be what you were giong for
<andrewrk> that seems good
<dimenus> is %defer only fired in the event of an error or always even in the event of an error?
<dimenus> nevermind, docs answered my question
<andrewrk> dimenus, I have basic union support working in the unions branch
<andrewrk> I still need to add the parsec.cpp code though
<dimenus> nice
<dimenus> i think i might have run into an issue with opaque types
<dimenus> calling FreeLibrary on the @OpaqueType seems to silently crash the program
<dimenus> what is the storage for OpaqueType like under the hood?
<andrewrk> dimenus, unknown storange. one is only allowed to have a pointer to an opaque type
<andrewrk> *storage
<andrewrk> can I see the code?
<dimenus> i just copied the relevant parts
<dimenus> oops, tops hould be HMODULE not HINSTANCE
<dimenus> same type though
<andrewrk> hm yeah this looks good
<andrewrk> I think the problem is unrelated to @OpaqueType()
<andrewrk> if you still suspect it, you can use a debugger and make sure we are doing a function call giving the same pointer address to FreeLibraryA that we got from windowsLoadDll
<dimenus> i coudln't get it to work with c_void or just a straight int either (HMODULE is a struct typedef with just an int inside)
<andrewrk> do we need CoInitializeEx or something like that?
<dimenus> no, COM isn't needed in this case
<dimenus> i'm going to run a debug build in a second and take a look
<andrewrk> were you able to call a function from the DLL?
<dimenus> didn't test that yet
jfo has quit [Ping timeout: 258 seconds]
<andrewrk> I suspect that might not also be working
ofelas has joined #zig
ofelas has quit [Remote host closed the connection]
<dimenus> hah, i'm just an idiot
<dimenus> the symbol is FreeLibrary not FreeLibraryA
<dimenus> debugging in VS caught it instantly
<dimenus> wonder why it linked successfully though....
<dimenus> oooh that might be a bug
<dimenus> llvm generated a kernel32.lib with a symbol that says its FreeLibraryA even though that symbol doesn't exist in the real kernel32.lib
<dimenus> i wonder if by being an idiot I found an llvm bug
<andrewrk> hmm very interesting
<andrewrk> ha, I found an llvm bug by being an idiot last night working on unions
<andrewrk> hm we should be able to make it a better error message if someone mistypes a DLL function name
<dimenus> the problem is lld links the lib successfully
<dimenus> soooo we no idea it was a problem
<andrewrk> that makes sense, because we want to be able to cross-compile a .exe without having access to the .dll
<andrewrk> but we should detect if we're compiling natively
<andrewrk> and then try to validate the lib calls
jfo has joined #zig
arBmind has quit [Quit: Leaving.]
<dimenus> We can call GetProcAddress at compile time to validate that the entries in the def file are all accurate
<andrewrk> good idea
<andrewrk> LoadLibrary gives the DLL we call ability to crash the program. So we would have to spawn a child process to do the LoadLibrary and GetProcAddress
<andrewrk> and if we're going to spawn a child process, we can write that child process in zig :)
<dimenus> that isn't a bug in llvm btw, it's just how import libs work
<dimenus> I didn't realize there wasn't any magic to them
ofelas has joined #zig
arBmind has joined #zig
<andrewrk> agreed
<andrewrk> yeah they're surprisingly simple
<andrewrk> makes you want to work on hot code swapping, eh?
<dimenus> i did that without knowing what i was doing on my game originally
<dimenus> a la casey muratori
<dimenus> LARGE MEMORY LEAKS
<dimenus> i wish we could add an attribute to c datatypes to make them coercible into zig datatypes
<dimenus> so with a c function that returns a BOOL i can do
<dimenus> if(returnedGood())
<andrewrk> a BOOL is an integer, it's not actually true or false
<andrewrk> so the best way to handle this would be a function like this
<dimenus> i know but from a zig perspective, we define what BOOL is
<dimenus> if we define it as a c_int but that it's capable of being a bool
<andrewrk> fn toBool(windows_bool: BOOL) -> bool { return windows_bool != 0; }
<dimenus> idk
<andrewrk> the problem is that is magic
<andrewrk> it feels good when writing the code
<dimenus> the std function could just not return the windows bool
<dimenus> hmmm
<andrewrk> yeah
<dimenus> solution in search of a problem
<dimenus> lol
<andrewrk> but it increases the surface area of the language people have to understand when reading
<andrewrk> we have that in the posix abstraction layer - translating errno into zig error codes
<andrewrk> and in windows utility functions
<andrewrk> here we translate BOOL into %void
<dimenus> yeah i spose it should really assert
<dimenus> there's no valid case I can think of where we would want to ignore the 0
<dimenus> if we got a 0, means we're trying to close a dll we didn't load somehow
<andrewrk> for LoadLibrary?
<dimenus> FreeLibrary
<andrewrk> hmmm. I think it is a design flaw in the windows API that FreeLibrary can fail
<andrewrk> I think we may need to assume that FreeLibrary cannot fail
<andrewrk> free(), deinit(), close(), destroy(), etc, in zig these functions must not fail
<andrewrk> I don't understand how FreeLibrary can possibly fail
cenomla has joined #zig
<dimenus> maybe if you have another thread that's calling it and you try to free it
<dimenus> but that's your own design flaw
<dimenus> so we should assert anyway
<dimenus> short lived processes really shouldn't be unloading dlls anyway
<dimenus> that's a waste of everyone's time
<andrewrk> yeah. I think we assert that FreeLibrary never fails
ofelas has quit [Quit: shutdown -h now]
cenomla has quit [Quit: cenomla]
dimenus has quit [Quit: Leaving]
dimenus has joined #zig
<dimenus> andrewrk, is compile time execution of functions on your radar at all for zig?
cenomla has joined #zig
<dimenus> **are