<FromGitter>
<splattael> I tried to intercept `GC.malloc` calls etc. but I got segfaults when trying to create a `CallStack` during `GC.malloc` :worried:
vivus-ignis has joined #crystal-lang
Kug3lis has joined #crystal-lang
damireh has joined #crystal-lang
Kug3lis has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
A124 has quit [Read error: Connection reset by peer]
A124 has joined #crystal-lang
<FromGitter>
<cschlack> Hi! I'm trying to call C code that potentially blocks for a long time (libgit2 in my case). How would you call a blocking function without blocking other fibers?
pawnbox_ has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
<FromGitter>
<cschlack> The code above works for me. But as soon, as I'm trying to communicate anything from the background thread to the main thread, that contains a string, I'm seeing something like this:
<BlaXpirit>
cschlack, means you're doing something that you can't do
<BlaXpirit>
standard library and mainly GC crashes when you use threads
Yxhuvud has joined #crystal-lang
<BlaXpirit>
thread support is high priority but is not possible currently
<BlaXpirit>
only very limited and very careful usages are possible, but channel communication is not one of them. i can'tcome up with any way to accomplish this, other than checking whether a boolean has been set in a busy loop
damireh has quit [Quit: My iMac has gone to sleep. ZZZzzz…]
<FromGitter>
<cschlack> @BlaXpirit: Thanks, I tried that as well. It works with just a boolean flag. The problem remains: How to transport a String from the background thread without crash (String.new doesn't seem to work).
<FromGitter>
<cschlack> OR: is it possible to detect crystal from C side and yield control to the main loop while waiting for io?
<FromGitter>
<mjago> What is the idiomatic way to do UInt8 => ascii or unicode (i.e. build a string from slice(UInt8))?
mgarciaisaia has joined #crystal-lang
<FromGitter>
<mjago> ahh .chr
mgarciaisaia has quit [Ping timeout: 246 seconds]
mgarciaisaia has joined #crystal-lang
<BlaXpirit>
cschlack, you don't transport a string
<BlaXpirit>
because you don't create a string in a background thread because it's not allowed
bjz_ has quit [Ping timeout: 245 seconds]
<BlaXpirit>
real question is, why do you need a Crystal String in a background thread
bjz has joined #crystal-lang
<BlaXpirit>
cschlack, maybe you should pass the struct pointer to the main thread, get info from it and free it from there
<BlaXpirit>
your idea about yielding control to main loop is interesting
<BlaXpirit>
but if it's made in recursive calls, maybe it'll bust the stack. not sure what other way to do it
vivus-ignis has joined #crystal-lang
Kug3lis has joined #crystal-lang
Kug3lis has quit [Client Quit]
Kug3lis has joined #crystal-lang
pawnbox has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<RX14>
@cschlack if you want to do it the hard way, you can write a C wrapper which does all the blocking stuff in threads in C, then exposes the results on a pipe or fifo
<RX14>
then you can bind your wrapper C lib
<RX14>
and pass back file descriptors
<RX14>
which you listen on to recieve results from threads
<RX14>
I think zmq does this
<RX14>
although I think the best route for implementing zmq in crystal is to implement zmtp in pure cr
Yxhuvud has quit [Ping timeout: 265 seconds]
w0ls0n has joined #crystal-lang
w0ls0n has left #crystal-lang [#crystal-lang]
<FromGitter>
<cschlack> @RX14: thanks. I'd rather not do it 'the hard way', but what are my options...
Yxhuvud has joined #crystal-lang
Philpax_ has quit [Ping timeout: 258 seconds]
Kug3lis has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Kug3lis has joined #crystal-lang
bcardiff has joined #crystal-lang
braidn[m] has joined #crystal-lang
<RX14>
@cschlack reimplementing the library in crystal is harder :)
<RX14>
you might want to look at how nodejs binds libgit2 then
<FromGitter>
<martinium> undefined method gsub for Nil
<FromGitter>
<martinium> trying to do gets.gsub(/\s+/, “”)
<FromGitter>
<martinium> or STDIN.gets.gsub(/\s+/, “”)
<FromGitter>
<martinium> do I need to require any specific module?
<FromGitter>
<martinium> gsub is an instance method so seems I need to create a string instance
<FromGitter>
<Exilor> IO#gets can return nil, thats why the compiler complains
<FromGitter>
<Exilor> you can use gets.not_nil! if you're sure it won't be returning nil, or gets.to_s if you don't mind an empty string if there's nothing to read
hako has joined #crystal-lang
<FromGitter>
<martinium> yep that helped
<FromGitter>
<martinium> got it to work
<FromGitter>
<martinium> :D
<FromGitter>
<martinium> believe it it or not I used gets.not_nil!.delete(' ')
<FromGitter>
<martinium> to remove all whitespace
<FromGitter>
<martinium> from a string
<FromGitter>
<martinium> no fancy gsub regex needed
<FromGitter>
<martinium> works for my simplistic use case
<RX14>
yes
<RX14>
"delete spaces" and "delete whitespace" are totally different problems
<RX14>
well
<FromGitter>
<Exilor> there's also String#strip to remove whitespace
<RX14>
i forget half the string ops...
<FromGitter>
<martinium> isn’t a space and whitespace basically the same thing
<RX14>
too many is a better problem to have than too little though
<FromGitter>
<martinium> yeah, choice is good
<RX14>
whitespace includes \n,\r,\s,\t
<RX14>
space is just \s
<FromGitter>
<Exilor> there's non-breaking space which looks like whitespace but isn't
<RX14>
and yeas
<FromGitter>
<martinium>  
<RX14>
unicode whitespace
<RX14>
unicode whitespace is even more of a pain
<FromGitter>
<martinium> the rabbit holes goes deep
<RX14>
well
<RX14>
Crystal has Char#whitespace?
<FromGitter>
<Exilor> sublime text + macos = nonbreaking space everywhere
<RX14>
...why?
<FromGitter>
<Exilor> no idea. especially around { |x| ...
<RX14>
@andyfleming there is no private and public for instance variables
<RX14>
in your example, how would you access @example_one from the outside?
<FromGitter>
<andyfleming> I was under the impression that it was public. So `person = Person.new`, the n`person. example_one # => "instance variable" : String`
<FromGitter>
<mverzilli> I was about to ask the same, but then I added `puts Person.new.@example_one` to the end of his snippet and it works