asterite changed the topic of #crystal-lang to: #crystal-lang The Crystal programming language | http://crystal-lang.org | Crystal 0.6.0 | Paste > 3 lines of text to https://gist.github.com | GH: https://github.com/manastech/crystal - Docs: http://crystal-lang.org/docs/ - API: http://crystal-lang.org/api/ - Logs: http://irclog.whitequark.org/crystal-lang
<crystal-gh> [crystal] waj pushed 2 new commits to master: http://git.io/APby
<crystal-gh> crystal/master 72670b0 Juan Wajnerman: Removed argument from Fiber#yield and Fiber#resume
<crystal-gh> crystal/master 2510492 Juan Wajnerman: Added channel specs....
waj has quit [Quit: Leaving.]
<travis-ci> manastech/crystal#2052 (master - 2510492 : Juan Wajnerman): The build was broken.
asterite has joined #crystal-lang
<asterite> jhass: maybe the GC marked that memory as free and then put some other object there?
<jhass> but 0xC? when other addresses are like 0xFFEFFF6A0 ?
<asterite> Hmmm... right
<jhass> I suspect there's something odd in how GLib/Libnotify runs the callback
<jhass> or at least not compatible
<jhass> the thing is, looking at the trace it seems that it correctly called the callback, but I think the closure data got corrupted
waj has joined #crystal-lang
<asterite> Why do you go from the callback to a tuple?
<jhass> how would you do it?
<asterite> Oh, you can try using a Box
<asterite> If that solves it, we can think what was the original problem
<asterite> Like...
<asterite> data = Box.box(block) # pass that
<asterite> On the callback: Box(ActionCallback).unbox(cb)
<asterite> But... I'm not sure that's a lot different than what you are doing
<asterite> Umm... you can try one more thing
<asterite> Run crystal h your_file.cr
<asterite> That will show you the types of your classes
<asterite> Maybe @data is a union that has Nil?
<asterite> For a few days now I started to think that type annotations are actually not a bad idea at all
<jhass> @data : {Pointer(Void), Pointer(Void)} (16 bytes)
<jhass> :(
<asterite> And where are you getting the 0xc?
<asterite> (as a side note: what does that app do?)
<jhass> display notifications!
<jhass> I'll give you the screenshot the next time I get one :P
<asterite> Cool :)
<asterite> How does it know the user?
<jhass> through asking
<asterite> Ah, nice :)
<jhass> mmh, I need more notifcations
<jhass> I should watch rails for a while or so :P
<asterite> :-D
<asterite> If you print the pointer and the closure_data before passing it to notification_add_action, and then you print it in the callback, they differ?
<jhass> note this doesn't happen always
shama has quit [Remote host closed the connection]
<jhass> it happens after some random time
<jhass> which is why suspected GC
<jhass> I'll let the Box version run for a while
shama has joined #crystal-lang
<asterite> I think the Box version might also crash, because the memory is not retained...
<jhass> since they too are called back at some random point in the future
<jhass> so GC has a chance to cleanse out the closure data or so
shama has quit [Ping timeout: 250 seconds]
<jhass> okay, the box version didn't work at all http://cloud.aeshna.de/u/mrzyx/screenshots/screenshot_20150224_021730.png
<jhass> I guess stack allocated and cleaned out right away
<asterite> It's actually heap allocated, but nobody retains a reference to it
<asterite> I guess we have to ask waj how to solve this :)
<asterite> One way is you keep a reference to that, but i'm sure that's a better way
<jhass> yeah, I'll try to just append it into a global array now
<asterite> BTW, I installed libnotify and I have it running :)
<jhass> nice
<jhass> in a VM?
<asterite> Mmm... while programming in crystal, do you have a hard time understanding compiler error messages?
<asterite> Nope, there was a package in homebrew
<asterite> there's X11 too, quartz
<jhass> some, but most are okay
<jhass> mmh
<jhass> so Box.box retuns a Void* pointer
<jhass> will storing a reference to that void pointer actually count as reference to the underlying object?
<asterite> Yes
<asterite> What would you think if in crystal you had to tell the compiler instance variables types, or maybe more?
knoopx has joined #crystal-lang
<jhass> it would loose a lot attractiveness
<asterite> Yes, I guess so :)
<jhass> not having to do that is basically the main point I got interested and started toying with it at all
shama has joined #crystal-lang
<asterite> I'm just worried that error messages might become too cryptic in big projects
<jhass> data = Box.box(block)
<jhass> @@actions << data
<jhass> doesn't help, gone right away too
<jhass> at least the closure data is
<asterite> Very strange!
<jhass> ah wait, maybe it's that I forgot to convert the string
<jhass> nope
waj has quit [Quit: Leaving.]
<asterite> So, the closure data gets corrupted but not the pointer?
<jhass> I think so
<jhass> well, the pointer is just the address of a function anyway
<jhass> that won't ever be free'd
<jhass> ah derp
<jhass> was using the wrong handler function m(
<asterite> One other thing I noticed
<asterite> cb = (cb as Pointer({Void*, Void*})).value
<asterite> Can you try using a different variable name in the left side?
<asterite> like cb2 = ...
<asterite> and then using cb2
<asterite> I suspect there might be an issue there
<jhass> still toying with the box version for now
<jhass> would be happy to rip that class out
<asterite> In any case, don't reuse that variable name there, just in case
<asterite> ("just in case" means, if that's it there might be something we need to fix in the compiler)
asterite has quit [Quit: Page closed]
waj has joined #crystal-lang
<crystal-gh> [crystal] waj pushed 1 new commit to master: http://git.io/AX44
<crystal-gh> crystal/master 82ffb3d Juan Wajnerman: Install libuv for travis builds
ismaelga has quit [Remote host closed the connection]
ismaelga has joined #crystal-lang
weskinner_work has joined #crystal-lang
weskinner_work has quit [Ping timeout: 264 seconds]
havenn has joined #crystal-lang
havenwood has quit [Ping timeout: 246 seconds]
<travis-ci> manastech/crystal#2053 (master - 82ffb3d : Juan Wajnerman): The build is still failing.
shama has quit [Remote host closed the connection]
shama has joined #crystal-lang
shama has quit [Client Quit]
<crystal-gh> [crystal] waj pushed 1 new commit to master: http://git.io/AXrf
<crystal-gh> crystal/master 2cf9a01 Juan Wajnerman: Use precompiled pcl library for travis
waj has quit [Quit: Leaving.]
shama has joined #crystal-lang
<travis-ci> manastech/crystal#2054 (master - 2cf9a01 : Juan Wajnerman): The build is still failing.
knoopx has quit [Remote host closed the connection]
shama has quit [Remote host closed the connection]
ismaelga has quit [Remote host closed the connection]
shama has joined #crystal-lang
shama has quit [Read error: Connection reset by peer]
shama has joined #crystal-lang
ismaelga has joined #crystal-lang
shama has quit [Ping timeout: 264 seconds]
ismaelga has quit [Ping timeout: 245 seconds]
ismaelga has joined #crystal-lang
ismaelga has quit [Ping timeout: 256 seconds]
bcardiff has joined #crystal-lang
havenn has quit []
ismaelga has joined #crystal-lang
ismaelga has quit [Ping timeout: 256 seconds]
bcardiff has quit [Quit: Leaving.]
bcardiff has joined #crystal-lang
bcardiff has quit [Client Quit]
ismaelga has joined #crystal-lang
ismaelga has quit [Ping timeout: 272 seconds]
ismaelga has joined #crystal-lang
ismaelga has quit [Ping timeout: 272 seconds]
ismaelga has joined #crystal-lang
ismaelga has quit [Ping timeout: 250 seconds]
leafybasil has quit [Remote host closed the connection]
leafybasil has joined #crystal-lang
ismaelga has joined #crystal-lang
ismaelga has quit [Ping timeout: 246 seconds]
waj has joined #crystal-lang
ismaelga has joined #crystal-lang
ismaelga has quit [Ping timeout: 265 seconds]
ismaelga has joined #crystal-lang
waj has quit [Quit: Leaving.]
ismaelga has quit [Ping timeout: 240 seconds]
ismaelga has joined #crystal-lang
waj has joined #crystal-lang
bcardiff has joined #crystal-lang
asterite has joined #crystal-lang
<crystal-gh> [crystal] asterite pushed 1 new commit to master: http://git.io/ADZI
<crystal-gh> crystal/master e630eac Ary Borenszweig: Improved error message when including/extending a class, and added missing location for "self" in those cases. Related to #446
<travis-ci> manastech/crystal#2055 (master - e630eac : Ary Borenszweig): The build is still failing.
havenwood has joined #crystal-lang
DeBot has quit [Quit: Crystal]
jhass has quit [Quit: Bye]
jhass has joined #crystal-lang
ismaelga has quit [Remote host closed the connection]
weskinner_mac has joined #crystal-lang
weskinner_mac has quit [Ping timeout: 255 seconds]
weskinner_mac has joined #crystal-lang
ismaelga has joined #crystal-lang
weskinner_mac has quit [Quit: weskinner_mac]
waj has quit [Quit: Leaving.]
asterite has quit [Quit: Leaving.]
wanderer has joined #crystal-lang
wanderer has quit [Client Quit]
weskinner_work has joined #crystal-lang
asterite has joined #crystal-lang
<crystal-gh> [crystal] asterite pushed 1 new commit to master: http://git.io/AyG9
<crystal-gh> crystal/master b6e9e9c Ary Borenszweig: Run hooks after visiting a class's body
DeBot has joined #crystal-lang
waj has joined #crystal-lang
<travis-ci> manastech/crystal#2056 (master - b6e9e9c : Ary Borenszweig): The build is still failing.
<jhass> asterite: so looks like all my issues are indeed GC related, in particular GC seems to cleans up objects still referenced by closure data passed to external callbacks
<jhass> I say that since it works flawlessly if I disable GC
<asterite> But that happens even if you store that closure in a global variable?
<jhass> have to check that for the GLib idle/timer stuff yet, but I mean there should be a way to solve it without
<waj> there are two options: let the GC "see" the object when it runs the mark/sweep, or don't allocate the object with the GC (use plain old malloc)
<jhass> I'm not sure I follow about the first one, the second one I cannot do as a library, each caller would need to be aware, which is bad
ismaelga has quit [Remote host closed the connection]
<waj> the first one means that the object must be reachable for the GC
<asterite> Will these callbacks ever be deregistered?
<asterite> I mean, is there a way to deregister those?
<jhass> most take a callback for when the user data should be free'd, yes
<asterite> Ah, the problems of a GC...
<asterite> I think it's what waj said: we need to add a GC.add_root(…) and GC.remove_root(…) method, or you can store that callback in a global/class variable
<jhass> the strange thing is that .closure_data seems to remain in tact, but the objects referenced by seem to be GC'd
<jhass> or mabye I'm misinterpreting .closure_data itself turns into garbage and that just causes bad references for everything else
<jhass> but doesn't error out on its own
<asterite> You mean, the address of the closure data remains the same?
<jhass> I think so, yeah
<jhass> mmh, well, the address is the only thing that I pass
<jhass> so that stays the same of course
<jhass> essentially what I'd like to have is a way to mark a closure data as "never free this or anything referenced by it", optionally with a "okay, freeing this now is okay from my side, do it when you think it's okay"
<asterite> I think that's basically GC.add_root, GC.remove_root
<asterite> which we don't have right now, but boehm provides that
<asterite> so we need to wrap it
<waj> the add_root must be called each time
<waj> so you still must have a reference somewhere
<asterite> I
<waj> the same issue exists in ruby extensions
<jhass> I never wrote any of those ;)
<jhass> what do you mean with each time?
<waj> each collection
<jhass> mh, that's a bit silly
<jhass> so much global state :/
<asterite> I don't think these things can be done without global state
<asterite> (I'm talking about the Fiber implementation)
<waj> I don't think an api developer must have to deal with GC internals :)
<jhass> so accessing a @@class_var does not create a closure btw?
<waj> I think it doesn't because that's essentially a global variable
<asterite> I'm trying to reproduce the collected object passed to C, but somehow the GC doesn't want to collect it
<jhass> yeah, as said it seems to happen after some random time here too
<jhass> and it's often like once in 15-20min with having the callback run each minute
shama has joined #crystal-lang
<asterite> Cool, I was able to reproduce it
<jhass> mmh
<jhass> >> lib Fake; fun fake(cb : Void* -> Void); end; module A; def self.cb foo; end; end; def a foo; Fake.fake(foo); end; a(->A.cb)
<DeBot> jhass: Sorry, that took too long.
<jhass> >> "hi"
<DeBot> jhass: Sorry, that took too long.
<jhass> okay, sandbox didn't survive the disk crash
<jhass> anyway ^ doesn't work
ismaelga has joined #crystal-lang
<asterite> What doesn't work?
<jhass> passing a function literal obtained via ->Foo.bar through a helper method to a binding, when it takes arguments
<asterite> Right, you have to specify the types
<jhass> note I'm not talking about def foo &block; LibFoo.foo(&block); end; foo(&->A.b), but def foo cb; LibFoo.foo(cb); end; foo(->A.b)
<jhass> and not even specifying the type seems to help in that case
<jhass> I'll open an issue
<weskinner_work> what is the NULL equivalent of C in Crystal?
<jhass> you can pass nil in many cases
<jhass> if that doesn't work, Pointer(NormalType).null
<weskinner_work> I got it working with just "nil" when I removed the type spec from that param
<jhass> you can also restrict to a union with nil, Foo|Nil, or as shorthand, Foo?
<weskinner_work> nice, that seems like what I need
<weskinner_work> does finalize get called on objects in the main scope?
ismaelga has quit [Remote host closed the connection]
<asterite> weskinner_work: I think not, they are in the main stack and the GC won't collect them
<asterite> jhass: we'll look at the GC issue later today, probably tomorrow we'll give you a fix :)
<asterite> For now, I think that if you store those actions in a global/class_variable list, the GC won't collect them
<jhass> asterite: yeah, doing that for now: http://paste.mrzyx.de/pkebq54fr
<jhass> mmh, should probably only remove one if there are multiple times the same one
<jhass> Hash with counters I guess
bcardiff has quit [Quit: Leaving.]
asterite has quit [Ping timeout: 255 seconds]
asterite has joined #crystal-lang
asterite has quit [Client Quit]
asterite has joined #crystal-lang
waj has quit [Quit: Leaving.]
waj has joined #crystal-lang
asterite has quit [Quit: Leaving.]
havenwood has quit []
asterite has joined #crystal-lang
asterite has quit [Client Quit]
ismaelga has joined #crystal-lang
leafybasil has quit [Remote host closed the connection]
leafybasil has joined #crystal-lang
waj has quit [Quit: Leaving.]
<weskinner_work> the following gist contains a commented while loop that causes a segfault: https://gist.github.com/weskinner/462cc4c24f9e78742df0
<weskinner_work> however, almost the same code wrapped in a function does not. I can't figure out why
bcardiff has joined #crystal-lang
bcardiff has quit [Quit: Leaving.]