<postmodern>
what is the preferred/safe way of passing strings, bytes, arrays of bytes, to a C function that accepts UInt8*? #to_slice and just hope GC doesn't free the passed in data? Does one make a copy of the data?
<postmodern>
nm i'll just dup/clone and store as ivars
<postmodern>
what's this about "can't use Int as a block return type yet, use a more specific type"?
<FromGitter>
<Blacksmoke16> yea...
<FromGitter>
<Blacksmoke16> would have to use like `Int32` or whatever
<FromGitter>
<Blacksmoke16> to represent a union of all possible `Int` types, which is essentially the same thing
<postmodern>
i've noticed by default the compiler aggressively omits code that isn't called. this can lead to bugs getting past me and the compiler. i suppose i should start writing tests at this point, but is there a way to tell the compiler to type check _everything_?
<FromGitter>
<Blacksmoke16> Use it at least once?
<FromGitter>
<Blacksmoke16> What's the use case for wanting dead code in your binary?
<postmodern>
is there something like the delegate macro, but maps to a different method on the ivar?
<FromGitter>
<Blacksmoke16> Could just define it yourself, that's all delegate does
<postmodern>
true. how does documentation work with macros? will the doc-generator associate an above block of doc comments with the macro?
<FromGitter>
<Blacksmoke16> It would be with what ever the macro generates
<FromGitter>
<Blacksmoke16> Unless of course the doc comment is above the macro definition
<postmodern>
nice. that always discouraged me about ruby's meta-programming vs doc generation
<FromGitter>
<Blacksmoke16> Ofc it only works if what you want the docs on is at the"top" of the macro
<FromGitter>
<Blacksmoke16> Isn't a built in way to add separate docs to each method if a macro generates more than one
<postmodern>
so how do you wrap a closure in a proc, and pass that to C land? i don't care about the pointer argument that C passes back to the Proc, since it's the same as the struct i'm wrapping. Just want to pass in a (self) -> Int32 closure.
<FromGitter>
<Blacksmoke16> wouldnt it just be a proc?
<repo>
hi! i get a invalid memory access error when i build and run the following in the official alpine image and link statically: https://p.jokke.space/eLD/crystal
<repo>
the error is thrown before i even get into File.open
<repo>
but if i don't pass an argument, usage is shown correctly
<repo>
so i doubt it is related to the required file
Nicolab has joined #crystal-lang
<repo>
this happens both on 0.32.1 and 0.33.0
<repo>
the error is thrown twice.
<repo>
maybe 500ms apart
<repo>
never mind, it was caused by the Process.run
ur5us has joined #crystal-lang
postmodern has joined #crystal-lang
<postmodern>
what's the real difference between procs and closures? anytime my proc references variables outside it's scope, i get an exception about passing a closure to a C function.
<repo>
yes, that's the difference
<repo>
:)
<repo>
when a proc accesses variables in the scope it was defined in, that's a closure
<repo>
postmodern: it makes sense that you can't pass those to a c function
<postmodern>
odd seems a bit too implicit. was expecting like different syntax or a different type
<repo>
i guess, but i can understand why it hasn't been made explicit. Inside of crystal you can pass both around
<repo>
about my invalid memory access problem: i've narrowed it down to a simple from_yaml call
<postmodern>
alex-lairam, i think you might need to export LD_LIBRARY_PATH=/usr/local/lib
<FromGitter>
<alex-lairan> Yes, that's it thanks
<FromGitter>
<yxhuvud> procs referencing variables in the creating scope is very fragile also in pure crystal. It is *very* easy to get crashes due to the variable not being on the stack anymore.
Nicolab has quit [Quit: Leaving.]
<postmodern>
yxhuvud, isn't that why typically you'd save them into ivars or class vars?
<postmodern>
so what are the restrictions for using _ in case/when statements? seems i cannot use _ on arrays?
Human_G33k has quit [Ping timeout: 240 seconds]
masterdonx2 has quit [Ping timeout: 272 seconds]
MasterdonX has joined #crystal-lang
Human_G33k has joined #crystal-lang
<postmodern>
also how does one use vim-crystal with vim8's packadd? doesn't seem to provide the opt/ and start/ directories.
sorcus has quit [Ping timeout: 272 seconds]
sorcus has joined #crystal-lang
<FromGitter>
<yxhuvud> postmodern: Yes, storing stuff on the heap is safe. But I've seen it happen a couple of times that they refer to a local and then don't understand why things break.
<FromGitter>
<yxhuvud> Hmm, can you show an example of it not working?
<postmodern>
yxhuvud, which version would you like? i've been trying various approaches. capturing/wrapping the block, using Box, etc.
<postmodern>
think i may be being bit by local variable name shadowing
<FromGitter>
<yxhuvud> No, I meant the case statement. I really don't have any experience with callbacks except reading the gitbook page on it
<FromGitter>
<alex-lairan> Let's begin my real lib :D
return0__ has joined #crystal-lang
return0e has quit [Ping timeout: 248 seconds]
<FromGitter>
<j8r> What is the proper way to transform a `HTTP::Request#body : IO` to a `String`?
<FromGitter>
<Blacksmoke16> `.gets_to_end`?
<FromGitter>
<j8r> ha ok, I was thinking to create a buffer my self
<FromGitter>
<Blacksmoke16> yea its just an `IO`, so normal `IO` stuff applies
<FromGitter>
<j8r> I'm now struggling with the issue we talked before
<FromGitter>
<Blacksmoke16> which one? abstract parent type or?
<FromGitter>
<j8r> with `Proc(T, U)`, we can't define T
<FromGitter>
<Blacksmoke16> right so instead of doing `Route(T, U)` you'll have to do `Route(Proc(T, U))`
<FromGitter>
<Blacksmoke16> and pass the proc type itself as a generic
<FromGitter>
<Blacksmoke16> are you not using macros to build the nodes? as actually that workaround is only needed if you're using splat generics
dwdv has joined #crystal-lang
<FromGitter>
<j8r> ha ok
<FromGitter>
<j8r> what I was doing is `post return_type: SomeResponseBodyClass`
<FromGitter>
<Blacksmoke16> ah, hm
<FromGitter>
<Blacksmoke16> might be a bit trickier then
<FromGitter>
<j8r> I may have to create an intermediary generic to declare T
<FromGitter>
<Blacksmoke16> :shrug:
<FromGitter>
<j8r> I got it, I think it just have to be mandatory
postmodern has quit [Quit: Leaving]
<FromGitter>
<j8r> It doesn't seem to work when I set a default class
<FromGitter>
<Blacksmoke16> gotcha
<FromGitter>
<j8r> I'm creating base controllers. One for HTTP and the other for WebSocket
<FromGitter>
<j8r> and custom ones can be used too
<FromGitter>
<j8r> I make the request_body mandatory, it can't harm
<FromGitter>
<j8r> *type
<FromGitter>
<j8r> I works, nice! The work around I done to restrict `T forall T` is to pass `T` to another method, which has type restrictions
<FromGitter>
<Blacksmoke16> hmm
<FromGitter>
<Blacksmoke16> that'll work i guess
<FromGitter>
<jwoertink> I'm using the docker container `FROM crystallang/crystal:0.33.0` and trying to install postgres-11 on it
<FromGitter>
<jwoertink> It keeps complaining about `postgresql-11 : Depends: libicu55 (>= 55.1-1~) but it is not installable`, but crystal 0.32.0 works fine
<FromGitter>
<jwoertink> looking around it looks like maybe some llvm type deal? I'm not totally sure
<FromGitter>
<jwoertink> Has anyone else run in to this?
<FromGitter>
<tenebrousedge> why not use a separate image?
<FromGitter>
<j8r> `apt update`?
<FromGitter>
<tenebrousedge> imo this is what docker-compose is for
<FromGitter>
<jwoertink> This is on a new fresh container, but it does run apt update after setting sources
<FromGitter>
<jwoertink> I'm not great at using Docker. So maybe there's a better way to do this
<FromGitter>
<jwoertink> I do use docker-compose to install postgres server
<FromGitter>
<jwoertink> but I need my container to have postgres client too
<FromGitter>
<tenebrousedge> ahhhhhh gotcha
<FromGitter>
<tenebrousedge> can you paste your dockerfile?
<FromGitter>
<jwoertink> oh sweet. I think it's working. It got past that one step.
<FromGitter>
<jwoertink> Awesome. Thanks!
<FromGitter>
<jwoertink> yup. It's running.
beepdog has quit [Ping timeout: 240 seconds]
juanfra_ has quit [Ping timeout: 260 seconds]
fifr[m] has quit [Ping timeout: 248 seconds]
erdnaxeli has quit [Ping timeout: 256 seconds]
olbat[m] has quit [Ping timeout: 240 seconds]
<FromGitter>
<j8r> @Blacksmoke16 I've made the Router indendent of the abstactions, so others like Athena may use it and have nearly free swagger docs support (or easy to do)
<FromGitter>
<j8r> Even if Radix is used anyway, it the router could only be used for doc generation
<FromGitter>
<asterite> @jwoertink is your app with file descriptor leaks creating websockets?
<FromGitter>
<jwoertink> nope
<FromGitter>
<asterite> oh... maybe that was it :-)
<FromGitter>
<jwoertink> app just went down again. It's pretty easy to see when it does
<FromGitter>
<jwoertink> We're still trying to come up with a smaller example of how to replicate it, but it's a little tough 😅
<FromGitter>
<Blacksmoke16> @j8r how would that work? i assume the user would have to basically resetup their routes for it to know how to generate the docs?
beepdog has joined #crystal-lang
erdnaxeli has joined #crystal-lang
juanfra_ has joined #crystal-lang
<FromGitter>
<j8r> Instead of adding to Radix, the web framework can add routes to the Router
<FromGitter>
<j8r> It takes an `Array(String | PathParameter)` – that's it
<FromGitter>
<Blacksmoke16> @watzon they're there, if you look at the config examples is a `formatter: Log::DefaultFormatter` line
<FromGitter>
<watzon> Ahh ok, so I did miss it. Editing.
<FromGitter>
<Blacksmoke16> the type/api isnt there but i would assume it'll be a thing
<FromGitter>
<watzon> Awesome. I love it. Much better than what we have currently.
<FromGitter>
<Blacksmoke16> indeed
<FromGitter>
<Blacksmoke16> once thats released i can archive crylog :p
<FromGitter>
<Blacksmoke16> makes my life a bit easier haha
<FromGitter>
<watzon> And I, Strange lol
<FromGitter>
<watzon> Not that I've been working on it much anyway
<FromGitter>
<Blacksmoke16> @j8r oh i see, where the underlying router could be `Radix`
<FromGitter>
<Blacksmoke16> 👍
<FromGitter>
<j8r> The docs will depend of what's information is present in `Action` of `Router(Action)`
<FromGitter>
<Blacksmoke16> gotcha
<FromGitter>
<j8r> I'm wondering, what's the best name to name a method that returns all routes metadata – for now it is `Router#visualize`
<FromGitter>
<Blacksmoke16> the yaml implementation they have is prob more doable now with the discriminator thing
<FromGitter>
<watzon> Nah, working with objects where I only want a couple values out of the object. The above syntax is a lot nicer than ⏎ ⏎ ```def foo(ctx) ⏎ bar = ctx.bar ⏎ baz = ctx.baz ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5e4aed78d56ddb68a4aead71]
<FromGitter>
<watzon> I'm passing in a `context` to all commands which contains several objects, but things end up getting pretty verbose
<FromGitter>
<watzon> And I don't want to pass in individual items, because then every command method would have to be written out as `def some_command(client, update, message, command, text)`
<FromGitter>
<Blacksmoke16> isnt that more readable tho?
<FromGitter>
<tenebrousedge> could you do kwargs?
<FromGitter>
<watzon> More readable yes, but not a good API experience if you have to type all that out every time
<FromGitter>
<watzon> Which is why being able to destructure the `context` object would be nice
<FromGitter>
<Blacksmoke16> that would be more ideal, but considering you would just copy paste it, prob not a big deal either way
<FromGitter>
<tenebrousedge> you wouldn't necessarily have to type that out all the time
<FromGitter>
<watzon> Fair, it's just a lot to include in every message. That's why I made the `Context` struct to begin with. It would be one thing if they could just choose the items they wanted.
<FromGitter>
<watzon> So if they could just do `def some_commmand(message, text)` or `def some_command(update)`
<FromGitter>
<Blacksmoke16> couldn't you just make a macro that does it for them
<FromGitter>
<watzon> @tenebrousedge how so? You can't omit any values or it won't compile.
<FromGitter>
<tenebrousedge> they can do `somecommand(message: m, text: t)`
<FromGitter>
<Blacksmoke16> would have to give defaults to other args tho
<FromGitter>
<tenebrousedge> `""` is a pretty good default, it seems to me
<FromGitter>
<watzon> Except only one of the types is a String
<FromGitter>
<watzon> I could make them nilable and default them to nil, but then I have another issue
<FromGitter>
<watzon> Is the syntax for `pfn_notify` correct? I haven't done much with passing in callbacks.
<FromGitter>
<christopherzimmerman> I *think* so, it gets passed as null in the example I'm testing so I don't know if that would impact anything
<FromGitter>
<christopherzimmerman> I haven't done much with callbacks either
<FromGitter>
<Blacksmoke16> is there an error you're getting?
<FromGitter>
<christopherzimmerman> No crystal errors, just an opencl error that says I'm passing an argument incorrectly, but I've run the `clGet_Info` on what I'm passing and it seems to be working
<FromGitter>
<christopherzimmerman> Hoping it was something basic, but might just take a lot of messing around
<FromGitter>
<watzon> Hmm weird. C sucks guys.
juanfra_ has joined #crystal-lang
<FromGitter>
<christopherzimmerman> I feel like the lines I'm not creating right are:
<FromGitter>
<watzon> Hmm yeah actually, that could work
<FromGitter>
<Blacksmoke16> changes the dsl but :shrug:
<FromGitter>
<watzon> Similarly anyway
<FromGitter>
<watzon> I want to keep the annotation syntax though, rather than having them call a block macro, but I think I could make the annotation itself do something like that with the method it's wrapping
<FromGitter>
<watzon> I'll have to play with it
<FromGitter>
<watzon> Multiple `forward_missing_to` definitely isn't possible https://carc.in/#/r/8kt3 ⏎ `method_missing` it is
<FromGitter>
<Blacksmoke16> `parse ctx` that just plops down `message = ctx.message` etc
alexherbo2 has joined #crystal-lang
<FromGitter>
<christopherzimmerman> I hate my life, been dealing with this binding for 3 days now, passing the context properties as null infers what you need anyways
beepdog has joined #crystal-lang
olbat[m] has joined #crystal-lang
erdnaxeli has joined #crystal-lang
<FromGitter>
<christopherzimmerman> On the bright side:
<FromGitter>
<christopherzimmerman> GPU tensors are trivial now
<FromGitter>
<watzon> That's awesome
<FromGitter>
<christopherzimmerman> I think CUDA will be a lot less trouble
<FromGitter>
<watzon> I assume once we have cuda support you could easily have `Num::OpenCL` and `Num::CUDA` or something. Or maybe just have a flag that sets which to use for `Num::GPU`.
<FromGitter>
<watzon> The second would probably be better
<FromGitter>
<christopherzimmerman> I'll have to put some thought into it, but either way, I'm about to link up all of the `Clblas` and `magma` functionality, which is going to give a huge performance boost to the linear algebra routines.
<FromGitter>
<watzon> Fuck yes man. This is a huge step towards better ML compatibility in Crystal.
<FromGitter>
<watzon> Hopefully I'll have a laptop with CUDA support soon and I can try and work on those bindings
blackbeard420 has quit [Quit: ZNC 1.7.5 - https://znc.in]
<FromGitter>
<watzon> Hmm ok, here's an interesting challenge. At least I can't seem to think my way through it right now. I have the following record: ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ and the `method_missing` works great, but in some cases, like with `message` and `update`, they have some methods with the same name. Right now if it finds `call` on `message` it will attempt to call it, and potentially fail. I would like
<FromGitter>
<watzon> Compiler exception if the method signature doesn't match. The name might be the same, but the params it takes might be slightly different.
<FromGitter>
<Blacksmoke16> mm like it taking some arguments or?
<FromGitter>
<watzon> I think I may just have to say fuck it haha
<FromGitter>
<watzon> `Chat` isn't being used in this case, so it's not an issue, but these two methods have the same name but a slightly different signature
<FromGitter>
<watzon> Also I need to go through these classes and turn them all into records 😢
<FromGitter>
<Blacksmoke16> sounds like a pita
<FromGitter>
<watzon> For sure haha
<FromGitter>
<watzon> Actually I think there's a good reason I used classes. Pretty sure structs were fucking with extending abstract types or something.
<FromGitter>
<Blacksmoke16> yea you cant extend a non abstract struct
<FromGitter>
<watzon> Pretty sure that's the reason I opted to use classes. Oh well.
<infinisil>
This only produces output after the program terminates, before that nothing shows up on the other terminal
<infinisil>
Or even just `crystal main.cr | tee` without a second terminal, also doesn't produce any output until it's done
<infinisil>
I'm pretty sure this happens because stdout is getting buffered until something like 4KB of chars are written, only then it's flushed. I'd like to make this buffering line-based, such that it flushes for every new line, without having to call flush manually
<FromGitter>
<watzon> Well `STDOUT` is an `IO::FileDescriptor` which inherits from `IO::Buffered` which has a property `buffer_size=`
<FromGitter>
<watzon> So you should be able to set the buffer size of STDOUT and then write directly to it
<FromGitter>
<watzon> Idk if `buffer_size` is right though
<FromGitter>
<Blacksmoke16> Us what you want I think
<FromGitter>
<watzon> Ahhh there we go
<FromGitter>
<Blacksmoke16> Stdout
<FromGitter>
<Blacksmoke16> Ofc
<FromGitter>
<j8r> Nvidia on Linux is meh :/
<FromGitter>
<watzon> Yes it is haha
<infinisil>
Hm, it's not line buffering, just not buffering at all with this, but I guess that works
<infinisil>
Probably
<infinisil>
Actually I want to submit this as a PR to the crystal compiler, because currently --progress doesn't give any live progress if the output isn't a terminal, and making output unbuffered like this should fix it
<FromGitter>
<j8r> I wonder if ROCm will gain traction
<FromGitter>
<Blacksmoke16> There is also STDOUT.read_buffering = false
<FromGitter>
<j8r> infinisil if the outout is not a terminal, the progress will be appended
<FromGitter>
<j8r> Normally there are escape sequencies to overwrite text on TTY terminals
<infinisil>
So it would be a problem to just set STDOUT.sync = true?
ur5us has quit [Ping timeout: 240 seconds]
ur5us has joined #crystal-lang
<FromGitter>
<j8r> No, I just talked about the --progress