<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>
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
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>
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?
<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
<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]
<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)?
<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]
<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
<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(*std.io.in_stream.InStream(std.io.Error), []u8) std.io.Error!usize', found 'fn(*std.io.in_stream.InStream(std.io.Error), []u8)
<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(&stream.stream);
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
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
<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 std.io.PeekInStream 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 https://bugs.winehq.org/show_bug.cgi?id=47979 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, 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 :)