mgarciaisaia has quit [Read error: Connection reset by peer]
mgarciaisaia has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Ping timeout: 264 seconds]
Kug3lis_off is now known as Kug3lis
Kug3lis is now known as Kug3lis_off
Kug3lis_off is now known as Kug3lis
Kug3lis is now known as Kug3lis_off
Kug3lis_off is now known as Kug3lis
balduin has quit [Ping timeout: 255 seconds]
mgarciaisaia has quit [Quit: Leaving.]
Kug3lis is now known as Kug3lis_off
<FromGitter>
<ezrast> What is the literal syntax for empty Tuples / NamedTuples?
<FromGitter>
<ezrast> Sorry, not the literal, the class name
<FromGitter>
<ezrast> like I can do `if kwargs.is_a? NamedTuple(a: String)` but I don't know how to check for the empty NamedTuple type.
<FromGitter>
<ezrast> Or more specific to my actual problem, I have a generic class `Foo(T)` and sometimes need `T` to be a 0-length named tuple (and there is no `T` argument in the constructor to infer from).
ssvb has quit [Read error: Connection reset by peer]
<jeromegn>
I'm trying to implement the LibreSSL C bindings to compare with OpenSSL (in terms of performance), but I can't get the reading or writing from the socket to work. I think it has something to do with non blocking file descriptors. If I specify I want them to block, reading and writing seems to work, but never seems to return. The lib docs suggest to wait for
<jeromegn>
the IOs to be readable / writable before retrying if I'm using non-blocking IO and the lib spits out a specific documented error. It does spit out that error, so I tried `IO.select` before every read/write, but that didn't work either. Anybody had this issue before? Non-blocking file descriptors and C bindings? Here are the lib docs:
gloscombe has quit [Remote host closed the connection]
gloscombe has joined #crystal-lang
<jhass>
did they really change the API for that in libressl? that is can't you just reuse/copy-paste the openssl implementation?
akwiatkowski has quit [Ping timeout: 258 seconds]
<jeromegn>
well, libtls is a different API yes. Initially I tried loading the LibreSSL libs (which include the openssl stuff) but got compile errors. I didn't bother too long since the libtls API is much simpler and thought it would be a quick implementation :)
<jeromegn>
I'll give that another shot though
<jeromegn>
some symbols are not implemented it seems
<jeromegn>
it's API compatible with OpenSSL 1.0.1, but not with 1.0.2
<jeromegn>
basically, their docs suggests using poll() or select() on the non blocking IO. crystal seems to suggest using fibers and channels instead of IO.select.
<RX14>
jeromegn, IO.select shouldn't really be used
<RX14>
it helps to understand what crystal is doing internally
<RX14>
instead of viewing it as just "fibers and channels"
<RX14>
it's implemented entirely within the stdlib using libevent
<RX14>
we set the FD as nonblocking, call read() or write(), if it returns EAGAIN we ask libevent to wake up the fiber when the FD is readable/writable again
<jeromegn>
oh, I see that now
<RX14>
not sure how that fits in with libtls
<jeromegn>
libtls has its own API for reading and writing to/from a socket. my implementation just calls those functions. they wanted to make a simple API and they succeeded. but now I find myself wanting more granular functions for my implementation.
<jeromegn>
setting my IO as blocking (with `io.blocking = true`) kind of works, but I wonder about unintended consequences on it.
<jeromegn>
*of this
<RX14>
well, your IO won't be blocking
<RX14>
is the first one
<jeromegn>
hmm, I guess the OpenSSL impl also uses the LibSSL read and write functions and it works fine. I imagine the implementation on those vs the ones on LibTLS' are different.
<jeromegn>
ha
balduin has joined #crystal-lang
<Yxhuvud>
Blocking IO doesn't block?
<RX14>
i said that wrong
<RX14>
i meant it would block the whole application
<jeromegn>
right
<jeromegn>
I figured
<jeromegn>
looking at LibSSL (not TLS), it looks like it should be suffering from the same issues within Crystal.
<RX14>
which calls the normal io.read/io.write which is written in crystal
<jeromegn>
ah
<jeromegn>
yes
<RX14>
so looks like you can't do the same thing
<RX14>
jeromegn, you want to detect the TLD_WANT_POLLIN/TLS_WANT_POLLOUT and do the same thing as IO::FileDescriptor
<jeromegn>
ah
<jeromegn>
that makes sense
<jeromegn>
want_readable and such
<RX14>
yes
<jeromegn>
*wait_readable
<RX14>
you can inherit IO::FileDescriptor as it would make it easier to reuse
<RX14>
but just overload unbuffered_read/write to call the correct thing
<RX14>
instead of LibC.read/LibC.write
<jeromegn>
good idea
<RX14>
although thats probably quite a lot of a hack
<RX14>
because it will then only be able to work on filedescriptors
<RX14>
oh jeromegn
<RX14>
tld_connect_cba
<RX14>
tls_connect_cbs
<RX14>
seems to be analogous to openSSL's BIO somewhat
<RX14>
ok
<RX14>
that's nice
<RX14>
that seems to be the way to go here
<jeromegn>
hmm
<jeromegn>
oh that seems new
<jeromegn>
not in my version of libressl :) I'll update.
<RX14>
you can paraphrase the impl from the openssl BIO even though they have different interfaces
<RX14>
actually i'm not sure if you need the box
<RX14>
hmm
soveran has quit [Remote host closed the connection]
soveran has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Changing host]
soveran has quit [Remote host closed the connection]
<jeromegn>
I'm not sure that function is available in the portable libressl
<jeromegn>
I'm a bit confused by their openbsd vs portable repos
<RX14>
well, thats the most correct function to use so...
<jeromegn>
yes
<jeromegn>
installing the latest, I'll check if it includes that function
<jeromegn>
ah, it has it
<jeromegn>
good
<RX14>
huh
<RX14>
it's not in the github repo
<RX14>
is there really no way to stream a HTTP::Client request body without using an IO.pipe?
<RX14>
it seems stupid
<RX14>
there seems to be no way to get an io which you write to which is your "request body"
mark_66 has quit [Remote host closed the connection]
<jeromegn>
IO.copy maybe?
<RX14>
that requires an IO to write to
<RX14>
HTTP::Client accepts an IO in the constructor
<RX14>
which it using IO.copy on internally
<RX14>
uses*
<jeromegn>
ah
<RX14>
so you have to pass in a pipe
<RX14>
because cryatl doesn't seem to have an entirely userspace multi-fiber IO
<RX14>
cross-fiber IO
<RX14>
or really any way to do it as simply as parsing in the http server
soveran has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Changing host]
<jeromegn>
RX14: thanks to you I'm making a lot of progress :)
<RX14>
no problem
<FromGitter>
<JekoTronik> Hi fellows!
<RX14>
@JekoTronik hi!
<FromGitter>
<JekoTronik> I discovered crystal i forgot how. Anyway it sounds fun and pretty so as a low level C programmer i am wondering if it could be used to generate something like .hex file for microcontroller?
<RX14>
which microcontroller?
<RX14>
we can do ARM and x86 only currently
<RX14>
and the crystal stdlib can't really be used without an OS
<RX14>
so you have to go without the stdlib which is a pain
<RX14>
it's probably *technically* possible to use crystal on some ARM-based microcontrollers, but I wouldn't recommend it
<RX14>
unless you're willing to essentially create your own stdlib from scratch
<FromGitter>
<JekoTronik> Actually it is just for recreation. Looking for something else. Is crystal crystal compilée
<FromGitter>
<JekoTronik> Is crystal compiled in C then C in manchine code?
<RX14>
crystal uses llvm to compile directly to machine code
<RX14>
no C intermediate
<RX14>
only llvm-ir intermediate
<FromGitter>
<JekoTronik> Cool. I will read about it.
<RX14>
the crystal compiler itself is also written in crystal
<FromGitter>
<JekoTronik> As I just want to experiment, maybe lighting a LED on bare metal could be reachable even for me x_x if I start with little microcontroller
mgarciaisaia has joined #crystal-lang
<RX14>
which microcontroller is it?
<FromGitter>
<JekoTronik> I dont see the work behind the scene yet
<FromGitter>
<JekoTronik> I have some 32bit arm cortex m4 and also some atmega 8bit
<FromGitter>
<JekoTronik> (The idea of coding a uC with no C++ OO language turn me on)
<FromGitter>
<JekoTronik> Haha
<RX14>
the cortex m4 should be possible
<RX14>
but you'll have to figure out how to boot the thing
<RX14>
the AVR isn't possible currently
<RX14>
at least not without some crystal compiler modifications
<FromGitter>
<JekoTronik> Ok si
<RX14>
there was someone else in here working on crystal on raw ARM, i forgot who
<FromGitter>
<JekoTronik> Ok so i will give the m4 a try
<RX14>
oh, it was jokke I think
<jokke>
yup
<RX14>
well, you can collaborate then :)
<FromGitter>
<JekoTronik> Hi jokke
<jokke>
hi o/
<jokke>
so yeah i managed to compile a binary for m0 from crystal
<RX14>
did it work?
<jokke>
i haven't got a board here, so i couldn't flash. also it didn't really do anyhting
<jokke>
there are a few caveats however
<jokke>
as of now crystal doesn't support setting a linker section for variables/constants
<jokke>
RX14: nah. no tests. i don't know how to test it tbh
<RX14>
hmm
<RX14>
compile the binary then dump the sections?
<RX14>
must be possible
<jokke>
heh sure
<jokke>
i actually did just that
<RX14>
we have an ELF parser in crystal...
<jokke>
objdump does the trick
<jokke>
@JekoTronik you need the attribute to be able to write an interrupt vector in pure crystal
<jokke>
basically you define a constant static array with function pointers to your interrupt handlers
<jokke>
also you will need a linker script for your board
<jokke>
@JekoTronik i plan to start working on a microcrystal lib which will be a tiny version of the crystal standard library
<RX14>
i think that's a really good idea
<RX14>
make it a shard
<jokke>
sure
<RX14>
i was thinking of that earlier
<RX14>
a super-portable crystal prelude
<jokke>
yeah
balduin has quit [Ping timeout: 255 seconds]
<jokke>
but it's a lot of work
<RX14>
it seems you can use quite a bit of the crystal stdlib
<RX14>
if you're careful
<jokke>
sure but it's always better to have a stripped down version so you wont make the mistake of using stuff which will fail silently until being linked
<RX14>
well that's what specs are for
<jokke>
how do you run specs then?
<jokke>
you will have to use --cross-compile and link manually so that crystal doesn't link the libs you would need and then you couldn't run your test because linking would fail
<RX14>
you would crystal build --cross-compile spec/**
<RX14>
then link manually with nothing in your makefile
<RX14>
and you could run that
<RX14>
it'd just be a statically linked executable
Kug3lis_off is now known as Kug3lis
<jokke>
yes sure. but as i said: instead of getting a NoMethodError you will get a linker error
<FromGitter>
<renich> También, a los desarrolladores, si quieren, se les otorgará dueñez (ownership) si quieren
<FromGitter>
<renich> Y, quisiera pedirles, publiquen de su existencia en el blog; aunque sea una pequeña línea, no?
<BlaXpirit>
TheGillies, there is a branch but probably not worth trying. why not tell us what you want to do
DeBot has quit [Remote host closed the connection]
DeBot has joined #crystal-lang
<FromGitter>
<fridgerator> @adam12 is there an example of communicating cross process using channels somewhere?
<adam12>
@fridgerator My best guess would be the source code for the channels library, or the docs for Channel.
<adam12>
I think there were examples in the source, with one of them being a channel implementation, but not 100% on that.
<RX14>
i'm not sure you can do that
<jeromegn>
I've been wondering about that too, communicating across processes (across forks)
<jeromegn>
maybe through some IO somewhere.
<adam12>
err, you're right
<adam12>
I think IO.pipe was the option
<adam12>
;\
<RX14>
yup
<RX14>
that would work
soveran has joined #crystal-lang
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 260 seconds]
Raimondii is now known as Raimondi
<jeromegn>
so if I compile my program, do I need all the libs it require to run the compiled binary? could I put it in a "scratch" (empty) docker image like it's possible to do with golang binaries?
<RX14>
jeromegn, nope
<RX14>
you need the libs
<jeromegn>
ah, yea, just found an issue about htat
<jeromegn>
*that
<RX14>
static compilation has some benefits but it's not really the standard
<jeromegn>
indeed
<jeromegn>
we'd have to write everything native to crystal I guess
<RX14>
i'd rather link openssl than doing what go does
<jeromegn>
RX14: why's that? I heard it has a good ssl/tls lib by default.
<RX14>
i'd rather every langauge didn't have it's own implementation of crypto
<jeromegn>
right
<jeromegn>
I've been writing one of our golang programs using Crystal and it's almost twice as fast...
<RX14>
there should be a few, good, implementations that everyone uses
<tilpner>
What about statically linkined openssl?
<jeromegn>
(not related to what I was asking about before)
<tilpner>
*linking
<RX14>
an impl-per-langue doesn't compete with other impls
<RX14>
so you get the worst of both worlds:
<RX14>
no competition, and loads of implementations to patch
<RX14>
and maintain
<jeromegn>
I guess if I want a small container, I can always use alpine with the few libs required.
<RX14>
crystal on alpine doesn't have any packages unfortunately
<RX14>
it should...
<jeromegn>
can't it be compiled though?
<RX14>
there's a few dependant packages that weren't up-to-date/available though
<RX14>
or there was last time I checked
<RX14>
plus you need to cross-compile for alpine
<RX14>
so
<RX14>
not really
<jeromegn>
RX14: I just read that comment on an issue where you're saying you'd be happy to work on submitting a package for alpine :D
<FromGitter>
<martinium> or can you create a variable using an If block within a method that would be available through the entire function/method’s scope?
<jokke>
TheGillies: nope
<jokke>
sorry
<jokke>
Yxhuvud:
<Yxhuvud>
you may still steal the idea to compare trigrams though
<RX14>
so what happens if the if statement doesn't get triggered?
<RX14>
what would api_query be then?
<FromGitter>
<martinium> wonder if a case statement would be better suited here
<RX14>
api_query would be nil
<RX14>
so the type is String or nil
<RX14>
which is why you're getting the error
<FromGitter>
<martinium> let me try and change
<RX14>
if you put a raise in your else statement the variable can't be nil
<RX14>
so thats one option
soveran has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Changing host]
<FromGitter>
<martinium> yeah changed else clause to = “” as a test and it fixed the error
<RX14>
the error message does make sense if you read it
<FromGitter>
<martinium> it did
<FromGitter>
<martinium> I’m at work sneaking in coding time
<FromGitter>
<martinium> lol
<FromGitter>
<martinium> Cool I am on the right path again
<FromGitter>
<martinium> @RX14 do you work on Crystal itself?
<RX14>
i do sometimes, yes
<RX14>
not too much as i'm quite busy
<RX14>
but I have had my fair share of PRs
<RX14>
and I'm quite active on the issue tracker
<FromGitter>
<martinium> nice
<FromGitter>
<martinium> you are a big help usually whenever I come in here. It is appreciated.
<FromGitter>
<martinium> Noobs like me would get nowhere without willing helpers like yourself.
<FromGitter>
<martinium> Well I’d get there but after lots of needless frustration lol
<FromGitter>
<martinium> in short thank you
<FromGitter>
<martinium> :-p @RX14
<RX14>
not a problem
<FromGitter>
<paulcsmith> Is it possible to capture a method and use it as a block? Something like `[1, 2, 3].map ->double(Int32)`. Full example: https://play.crystal-lang.org/#/r/1lhl
<FromGitter>
<asterite> &->
ssvb has joined #crystal-lang
mgarciaisaia1 has joined #crystal-lang
<FromGitter>
<paulcsmith> Awesome! Thanks @asterite. What is that called? I tried looking in the docs and wasn't able to find it
<RX14>
it's a combination of 2 operators
<RX14>
-> converts it to a proc like usual
<RX14>
the & just pastes that proc in as the block
<RX14>
it ends up looking like map { |*args| proc.call(*args) } eventually
<RX14>
so it's not as cheap as a method call to do it that way
<RX14>
at least iirc, @asterite can correct me on that
mgarciaisaia has quit [Ping timeout: 258 seconds]
<FromGitter>
<paulcsmith> Ah so -> makes it look like `proc.call` and the `&` wraps it in `{ | args|...`?
<RX14>
yes, & can pass a proc into a function
<RX14>
as it's block
<FromGitter>
<paulcsmith> Very cool. Thanks for the explanation :)
<FromGitter>
<paulcsmith> I'm sure the performance hit is probably small so it's probably fine in most cases. I'm just glad this can be done. Makes some code a lot easier to read and share :thumbsup:
<RX14>
yep, unless it's in a tight loop
<RX14>
main thing is it makes it transparent to llvm actually
<RX14>
so it can't inline and merge
<RX14>
i mean opaque to llvm
<FromGitter>
<ezrast> I'm getting `Bug: already had enclosing call` from `crystal spec`; is that referring to a bug that should be reported?
<RX14>
yes, a message containing "Bug:" from the crystal compiler is a compiler internal bug
<RX14>
try and reduce the code needed to reproduce it, and post it to github
<FromGitter>
<ezrast> Will do
soveran has quit [Remote host closed the connection]
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
mgarciaisaia1 has left #crystal-lang [#crystal-lang]