laaron has quit [Remote host closed the connection]
laaron has joined #zig
kristoff_it has quit [Ping timeout: 240 seconds]
avoidr has quit [Quit: leaving]
qazo_ has joined #zig
kristoff_it has joined #zig
kristoff_it has quit [Ping timeout: 245 seconds]
kristoff_it has joined #zig
kristoff_it has quit [Ping timeout: 276 seconds]
donpdonp has quit [Read error: Connection reset by peer]
samtebbs has joined #zig
donpdonp has joined #zig
Ichorio has joined #zig
laaron has quit [Remote host closed the connection]
laaron has joined #zig
marmotini_ has quit [Quit: Leaving]
laaron has quit [Remote host closed the connection]
laaron has joined #zig
kristoff_it has joined #zig
kristoff_it has quit [Ping timeout: 246 seconds]
fgenesis has joined #zig
waleee-cl has joined #zig
Ichorio has quit [Ping timeout: 245 seconds]
Hirezias has joined #zig
avoidr has joined #zig
<Hirezias>
Hello, does something equivalent to __attribute__((constructore))/((destructor) exist in zig ?
<fengb>
No constructors/destructors
<Hirezias>
I'm not talking about OO programming, I'm talking about dynamic library loading/unloading, right ?
<fengb>
Oh. I don't think zig will support that since it falls under hidden behavior
halosghost has joined #zig
<Hirezias>
Ok, it makes sense. Thank you :)
dimenus_ has joined #zig
<samtebbs>
Hirezias: Just for my interest, what do they do?
<Hirezias>
I'm not really sure about how it works exactly, but this attributes are a way to specify a function must be called at dynamic library load or unload
<Hirezias>
A use case I have is to build a library A with the same symbols than another one (B) used by a program. I use LD_PRELOAD in order to load A before B at program startup, wich link my functions instead of the B one's.
dimenus_ has quit [Read error: Connection reset by peer]
<Hirezias>
I use __attribute__((constructor)) in order to run a function between library loading and the program execution in wich I get the B symbols with delsym in order to call it in my wrapper functions, even if thez have the same symbols names.
TheLemonMan has joined #zig
<Hirezias>
*dlsym (sorry, I hope my explanation is clear)
<mikdusan>
zig has a built-in clang compiler. i suppose you could make a c-func to invoke zig code
<TheLemonMan>
please keep in mind that you have to link against the libc in order to have the crt process the init/fini
<mikdusan>
TheLemonMan: which os supports those link sections?
<TheLemonMan>
the only ones that matter, linux (and I guess the BSDs)
<TheLemonMan>
for osx you may be able to use __mod_init_func/__mod_term_func for the same purpose
<fgenesis>
windows does too but it's some magic the CRT invokes at DLlMain(), iirc
<fgenesis>
*DllMain()
<TheLemonMan>
yeah, it has more to do with the libc's CRT than with the OS itself
<mikdusan>
also .dylib on macos has old convention of _init() and _fini() . which sounds like windows mechanism. linux also has linker-line to add functions via -init and -fini flags
<Hirezias>
When I include dlfcn.h and write const RTLD_NEXT = c.RTLD_NEXT; I have an error saying that a C pointers cannot point to non-C-ABI-compatible type 'void' (in cimport.zig)
<Tetralux>
mikdusan: Why would you want to make defer free illegal in a particular instance?
<meowray>
mikdusan: elf linkers don't have options to add .init_aray or .fini_array
<TheLemonMan>
meowray, the -init/-fini switches in LLD should append/remove entries in the init/fini arrays
<mikdusan>
Tetralux: why would i want the option to defer a no-op ?
Ichorio has joined #zig
<Tetralux>
mikdusan: In case it isn't xD
<Tetralux>
I'm assuming it's library code.
<Tetralux>
Because otherwise, if you knew it was always a no-op, you wouldn't write that code.
<Tetralux>
(.. you'd omit the defer.)
<mikdusan>
statically in my case it is always a no-op because i'll always be using an allocator that only free's in bulk
<Tetralux>
In such a case, is the free a no-op in the output?
<Tetralux>
Or does it still do a fnptr call that does nothing?
<mikdusan>
let's assume the best-case scenerio that the compiler elide's it entirely.
<Tetralux>
Indeed.
<Tetralux>
I'm not entirely clear what the reasoning is here.
<Tetralux>
You want to be able to get an error if you attempt to free something that does a no-op?
<mikdusan>
i want to prevent someone from sticking an unsuitable allocator into the struct
<Tetralux>
You want to only allow a push-buffer style allocator?
<Tetralux>
.. or rather, one that frees everything at once, or nothing.
<Tetralux>
.. but without using a custom allocator interface.
dimenus_ has joined #zig
samtebbs has quit [Quit: leaving]
wootehfoot has joined #zig
<mikdusan>
i have a struct init that accepts an *Allocator and the "doc" would stipulate that it must be arena-style because I won't be adding defer's all over the place for nothing. and so if the wrong allocator is passed in, it's an automatic leak
Ichorio has quit [Ping timeout: 245 seconds]
<mikdusan>
i mean yeah the caller is doing it wrong. but shouldn't there be a way for me to statically prevent this?
<Tetralux>
The obvious way to statically do it would be as you suggested: have an allocator type that does not free.
<Tetralux>
Docs wise, you could just simply include "Does not free".
<Tetralux>
And then if you pass a direct_allocator or something, you expect it to leak
<Tetralux>
Which may be absolutely fine.
<fengb>
So if shrinkFn is optional, you can add an assert
<Tetralux>
Making shrinkFn optional definitely means that it would not get optimized.
<Tetralux>
I'd just make it either do literally nothing, or panic.
<fengb>
None of this is optimized since they're all function pointers
<Tetralux>
Then it's probably better just to make it do nothing.
<Tetralux>
You don't want users of allocators to have to check that.
<Tetralux>
The whole point is that they don't.
<Tetralux>
The whole point generally is that they will use whatever allocator you give them.
<Tetralux>
So far, they assume that they must call free.
<Tetralux>
This pattern of never freeing though is perhaps what temporary storage could be used for.
<Tetralux>
But I don't that zigian.
<Tetralux>
It's basically just push buffer that the user resets on demand where the whole point is that you allocate it all up front and then when you want to make a cstring version of a string, or format a string to be output every frame, you want it to be fast and not allocate, but still be able to be used with otherwise allocating functions.
<Tetralux>
In Zig, you're expected to make an fixedbufferallocator, though you can't reset that.
<Tetralux>
Might make a PR for that at some point actually.
<Tetralux>
fba.reset(); // forgets you ever alloc'd anything
<Tetralux>
But yes, I think I'd just doc it and allow any allocator.
Akuli has joined #zig
lunamn_ has joined #zig
lunamn has quit [Ping timeout: 245 seconds]
<Hirezias>
TheLemonMan: Thank you very much for your help :)
laaron has quit [Remote host closed the connection]
ky1ko is now known as ky0ko
laaron has joined #zig
<TheLemonMan>
np, it's a nice party trick :)
kristoff_it has joined #zig
kristoff_it has quit [Ping timeout: 276 seconds]
<Tetralux>
We should have a better error message if you attempt to 'try' from within a fn that does not return an error.
<fengb>
Like injecting a yodaism?
wootehfoot has quit [Read error: Connection reset by peer]