<FromGitter>
<tenebrousedge> probably trying to use C at all here is my first mistake
<FromGitter>
<naqvis> i would say its `empties` which is causing this segfault. as simply calling `sscanf` like below works ⏎ ⏎ ```val = uninitialized Int32 ⏎ LibC.sscanf("aa bb a 2 ee", "aa bb a %d ee",pointerof(val))``` [https://gitter.im/crystal-lang/crystal?at=5eaa29df14b48f06989d265e]
<FromGitter>
<tenebrousedge> yeah I figured that I should probably be using pointers
<FromGitter>
<tenebrousedge> this is probably mostly a stupid idea
<FromGitter>
<naqvis> your idea is neat
<FromGitter>
<naqvis> and that macro thing is too scary for me
<FromGitter>
<tenebrousedge> oh well ty
<FromGitter>
<naqvis> 😆
<FromGitter>
<tenebrousedge> well I'll poke at it tomorrow
<FromGitter>
<naqvis> sure thing
<FromGitter>
<tenebrousedge> thanks for the tip
<FromGitter>
<naqvis> thanks and just shared my thoughts
deavmi has quit [Ping timeout: 264 seconds]
deavmi has joined #crystal-lang
<FromGitter>
<jwaldrip> @tenebrousedge I use it to switch on log/debug settings
<FromGitter>
<jwaldrip> but the release flag would tell me that its optimized
<FromGitter>
<Blacksmoke16> @jwaldrip you make an issue about that yet?
<FromGitter>
<jwaldrip> @Blacksmoke16 one better, here is the PR
<FromGitter>
<ImAHopelessDev_gitlab> i am starting to express abstract ideas and convert them into code. better and better. i think i'm doing something right
<FromGitter>
<ImAHopelessDev_gitlab> maybe just practice
<FromGitter>
<tenebrousedge> :plus1:
alexherbo2 has joined #crystal-lang
<FromGitter>
<naqvis> 👍 Girng
<FromGitter>
<naqvis> Girng shouldn't you now change your id to `ImAHopefulDev` lol
<FromGitter>
<alehander92> yeah i like your progress man
<FromGitter>
<alehander92> very hopeful!
sagax has quit [Read error: Connection reset by peer]
straight-shoota has quit [Read error: Connection reset by peer]
alexherbo26 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 260 seconds]
alexherbo26 is now known as alexherbo2
<FromGitter>
<watzon> Is there an easy way to perform a strip operation on an IO without converting it to a string and back?
<FromGitter>
<watzon> Or a slice for that matter. I just need to remove null bytes from the end.
<FromGitter>
<tenebrousedge> hmmm, maybe there's a chomp option
<FromGitter>
<tenebrousedge> but why does it have null bytes?
<FromGitter>
<watzon> For padding
<FromGitter>
<tenebrousedge> what are you doing with it?
<FromGitter>
<watzon> I guess if I could find the index of the first null byte I could actually create a new slice from a pointer of the section that doesn't have the null bytes
<FromGitter>
<tenebrousedge> that sounds reasonable
<FromGitter>
<watzon> I need to convert a bytes slice into a UInt32 slice, but that requires that values be properly padded to 4 bytes
<FromGitter>
<watzon> Then I need to be able to convert it back, but that ends up giving me the padding so I just need a way to remove it, and I want to not perform any unnecessary string allocations.
<FromGitter>
<naqvis> doesn't your slice contains byte encoded UInt32?
<FromGitter>
<tenebrousedge> can you use `IO::Delimited` ?
<FromGitter>
<watzon> Ooh didn't even know that was a thing
<FromGitter>
<watzon> I've never used it
<FromGitter>
<tenebrousedge> I think that might help
<FromGitter>
<watzon> I wish adding slices together was an easier task, it would make adding the padding in the first place a little easier
<FromGitter>
<tenebrousedge> <_< that seems like it's verging on an x y problem
<FromGitter>
<naqvis> you could do that `Pointer` and `realloc` and then `copy_from` to concatenate slices
<FromGitter>
<watzon> Yeah that's what I figured
<FromGitter>
<naqvis> or simple solution would be to create a new slice of combined size and then copy them into appropriately
<FromGitter>
<tenebrousedge> ^
<FromGitter>
<naqvis> kind of requesting extra space before discarding the existing slices (provided slice size isn't that huge)
<FromGitter>
<watzon> How do do you to `#copy_to` at a specific offset?
<FromGitter>
<tenebrousedge> `[]` says it returns a new slice
<FromGitter>
<watzon> It does
<FromGitter>
<watzon> There's probably a better way to do this, but at the very least this should be more efficient than converting slices to Strings and then back again
<FromGitter>
<tenebrousedge> well, right on. Whatever works
<FromGitter>
<watzon> I just want to figure out a better way to do the `unpad_slice` function. Right now it will just take the first null byte and get its index, but I want it to only do grab null bytes at the end
<FromGitter>
<watzon> But for now it should work. The byte slices I'm dealing with shouldn't have any null bytes until they're padded.
<FromGitter>
<naqvis> @tenebrousedge documentation is somewhat misleading, `[]` doesn't allocate new memory, but just move the slice already allocated pointer to particular offset
<FromGitter>
<naqvis> that's why this works
<FromGitter>
<naqvis> i've used it extensively
<FromGitter>
<tenebrousedge> kk
<yxhuvud>
it creates a new slice but reuses the pointer
zorp_ has joined #crystal-lang
<FromGitter>
<naqvis> it creates a new reference to already allocated slice block and so i said "doesn't allocate new memory"
<FromGitter>
<naqvis> kind of mutable view of already created slice
<FromGitter>
<naqvis> mutability depends on how initial slice (against which you are requesting this view). If initial slice was read-only, then you will get read-only view
<oprypin>
tenebrousedge, wait i'm not sure what you're referring to. do you still have union types in the return type? didnt my sugestion resolve that?
<FromGitter>
<tenebrousedge> no but if I rewrite this as a runtime method instead of a macro then I'll have the union type problem
<oprypin>
yea
<FromGitter>
<tenebrousedge> but I'd have more tools to write it with, and be able to handle arbitrarily long strings
<oprypin>
but you can't create an arbitrary tuple in a runtime function
<oprypin>
so you'll have to return an array of union of everything
<oprypin>
i think it's a no-go for this purpose
<oprypin>
you can always still involve runtime components while writing the macro
<oprypin>
the macro can just be a wrapper that calls whatever runtime function and then at the end return `{ result[0].value.as({{type[0]}}), result[1].value.as({{type[1]}}) }`
<FromGitter>
<tenebrousedge> hmmm
<oprypin>
but the parsing of the format specifier also has to be part of the macro
<FromGitter>
<tenebrousedge> well that is done I guess?
<FromGitter>
<tenebrousedge> it's `O(n^2)` but it works
<oprypin>
compile time is constant time 😎
<FromGitter>
<tenebrousedge> haha
<FromGitter>
<naqvis> +1
<FromGitter>
<tenebrousedge> that could be a good way to go, then
<oprypin>
tenebrousedge, nice work though. it was good to see that macros can do this
<FromGitter>
<tenebrousedge> I mean I think it worked fine without the `as`?
<oprypin>
tenebrousedge, it returned a tuple of unions
<oprypin>
wait maybe not, nvm
<FromGitter>
<tenebrousedge> hmm, I found this before, it doesn't like when there's a token at the end of a string: ⏎ https://play.crystal-lang.org/#/r/8zmv
<oprypin>
without that, also note that instead of `{LibC::Long, (flag?(:win32) || flag?(:i386) || flag?(:arm)) ? 0_i32 : 0_i64},` you could have done `LibC::Long.new(0)`
<FromGitter>
<tenebrousedge> I thought that I couldn't do `new` in a macro
<oprypin>
oh macro. yeah perhaps
<oprypin>
then you just do `t = LibC::Long` in a macro but the rest at runtime. `{{t}}.new(0)`
<oprypin>
and doesnt matter anyway because (see my code paste)
<FromGitter>
<tenebrousedge> yeah, thanks
<oprypin>
note about the %variables, it's important not to pollute the namespace of the caller
<oprypin>
so use guaranteed unique names instead of `a1` and such which the caller could already be using for themselves
lanodan has joined #crystal-lang
<FromGitter>
<tenebrousedge> but they're in a proc ?
<oprypin>
oh. you're right :p
<oprypin>
still doesnt hurt / best practice
sz0 has quit [Quit: Connection closed for inactivity]
<oprypin>
oh wow i just noticed in the stdout - you see all that scary looking stuff at the top?
<oprypin>
it inserts those expressions into the resulting code because u used `{{ r = stuff }}` instead of `{% r = stuff %}`
<FromGitter>
<tenebrousedge> 😅
<FromGitter>
<tenebrousedge> okay, so it's `[i..j]` instead of `[i...j]`