<crystal-gh>
crystal/master 7dc8f8a Ary Borenszweig: Make BufferedIO try to read `count` bytes, don't limit it at the internal's buffer size. Fixes #813.
<crystal-gh>
crystal/master 625570d Ary Borenszweig: Use "Crystal" as default user agent for HTTP::Client
Codcore has joined #crystal-lang
<Codcore>
how to use 'before_each' in specs? tried before_each do ... code ... end, output is "undefined local variable or method 'before_each'"
<jhass>
Spec.before_each, it's global for all specs for now and intended for things like mocking libraries
vikaton has quit [Quit: Connection closed for inactivity]
asterite has joined #crystal-lang
<asterite>
jhass: http://carc.in/#/r/3bh is definitely a bug, should give a compile error when casting to String
<jhass>
figured
<asterite>
jhass: did you see the comments about the null pointer exception blog post?
<jhass>
re. #ruby ?
<jhass>
I didn't fully read them I think
<waj>
jhass: crystal_ruby should be possible
<asterite>
waj: what about the type ids?
<waj>
what about them?
<asterite>
jhass: oh, because somebody made some comments and use that `nil as Object` to show that the language is not robust, while it turned out to be a bug... so probably he tried that in play.crystal-lang too
<asterite>
waj: every time you compile an app, a class Foo might get a different type id
<asterite>
is_a? uses that type id to work
<asterite>
and also method dispatch
<jhass>
ah no, I'm still just skipping through all the runs ;)
<asterite>
waj: so two different libraries built by crystal, used by Ruby, won't be compatible
<jhass>
mmh, but then how likely is it that you pass unwrapped crystal objects from one to the other?
<waj>
ok, but why would you want two libraries to interact with each other directly?
<asterite>
hehehe, are you in the same room? :-)
<asterite>
I guess we'll have to try. That's just my main "fear" (well, not like fearing a monster)
<waj>
anyway… that raises a valid question: which library will initialize the GC?
<jhass>
what happens if it's initialized twice?
<waj>
however, I think it might be possible to use the Ruby GC instead
<waj>
m… maybe nothing happens
<jhass>
worst case scenario I can think of is it crashes, second worst case leaks everything allocated between the first and the second init
<waj>
regarding binary compatibility between libraries, one wouldn’t expect more compatibility that the one we use when passing structs to other C libraries
<jhass>
using Ruby GC sounds interesting, a lot of work went into it recently
<waj>
jhass: actually I’m pretty sure nothing happens and everything works just fine, at least if the GC is not statically linked in any of the libraries
<waj>
yes, but if you can control the memory allocated by the library then the GC will see the references to the closures
<jhass>
mmh
<waj>
not every library allow that anyway
<jhass>
yeah, doubt glib/gobject does
<jhass>
they implement their own reference counting to some degree iirc
<waj>
another option would be giving a more friendly interface to “push_other_roots”
<waj>
that’s being used by the fibers to keep references on the fiber stacks
<willl>
tangentially related, palloc is really nice http://www.postgresql.org/docs/current/static/spi-memory.html it creates contexts, and then you just drop the whole context when you're done rather than keeping track of every individual thing. more work than a general GC, but not much work in practice
<waj>
that’s nice
<jhass>
"with 'n' being 'n'" :D
<unshadow>
OMFG asterite you are crazy hahaha so many mails XD
<waj>
imagine for example if you can asure a fiber is short lived and it doesn’t send references to new object to other fibers, instead of a heap it could use a simple memory region with a pointer that’s incremented each time an allocation is made
<waj>
the GC wouldn’t bother to clean up those objects
<waj>
and the whole buffer could be released once the fiber ends
<willl>
I don't know if it's feasible to have both that and a gc, but creating a context for like a single web request, then dropping it seems like it'd be good
<unshadow>
jhass: yeha, I was on my phone, so no close option for issues
<asterite>
unshadow: sorry, today is June 16, "international day of cleaning up github issues and pull requests"
<asterite>
waj: I still agree with jhass, we should add a GC.pin and GC.unpin to make it easier to deal with those things
<BlaXpirit>
wait, what exactly would it do?
<BlaXpirit>
i skimmed through prev. messages
<jhass>
prevent the GC from releasing the object
<jhass>
until unpin
<BlaXpirit>
ok
<jhass>
or whatever the API will actually be called
<waj>
well… we can do that very quickly just adding a reference in a global hash
<BlaXpirit>
but uhhh how is this different from saving a reference?
<BlaXpirit>
in user code, that is
<jhass>
it's not, it saves everybody reimplementing it
<waj>
no difference at all
<BlaXpirit>
ok
<jhass>
though the question of whether to count references or not stays open
<jhass>
like does GC.pin a; GC.ping a; GC.unpin a; remove the reference or not
<waj>
we can have a Hash(Void*, Int32) with the reference counts
<waj>
and have a GC.unpin! also to force removal
<waj>
this would be pretty slow anyway
<waj>
I’m thinking now something like having a Pineable module that can be included
<waj>
Pinnable, Pinable or Pineable? :)
<waj>
this module could add the reference count inside the objects
<waj>
and build a linked list with the pinned objects
<waj>
that way, pin and unpin doesn’t require a lookup in a hash table
<asterite>
I think in jhass' case he sends an object to C, doesn't keep a reference to it but doesn't want the GC to delete its memory. I'm not sure it's the same use case
<asterite>
I also think it was a closure (a Proc), so I don't think he'll make Proc include that Pinnable module
<jhass>
;)
<waj>
mm… good point
<jhass>
Ruby has several markers in Object, #freeze & #taint for example
<thor77>
is there some way to iterate over lines in a file?
<asterite>
thor77: each_line
<thor77>
each_line do |line| ?
<asterite>
Yes
<thor77>
fine, ty
asterite has quit [Quit: Page closed]
<thor77>
i'm iterating over a file and want to match a regex on each line. the compiler says "undefined method '[]' for Nil" if i try to access the match-obj
<jhass>
thor77: since the regex might not match, check you got a match with if match
<thor77>
yeah, thought so, too. but still the same warning
<jhass>
got an example?
<thor77>
huh, wtf.
<thor77>
now it works with "if match"
<thor77>
seems like there was another error
<thor77>
thank you, anyway
<jhass>
yw
genixefr has quit [Ping timeout: 256 seconds]
genixefr has joined #crystal-lang
<unshadow>
Would calling unpin just notify the GC that this object is now under it's control, or will it tell it something like Clean this now ! ?
<jhass>
I'd say the former
bcardiff has quit [Quit: Leaving.]
<crystal-gh>
[crystal] asterite pushed 3 new commits to master: http://git.io/vLZmO
<crystal-gh>
crystal/master 8856662 Ary Borenszweig: Small fix in OAuth for empt uri paths
<crystal-gh>
crystal/master b96bb81 Ary Borenszweig: Fixed #817: parse error when using __DIR__ in call beginning
<crystal-gh>
crystal/master 35e4e92 Ary Borenszweig: Fixed #816: incorrectly parsed call instead of var
<BlaXpirit>
latter is inherently unsafe
<crystal-gh>
[crystal] asterite pushed 1 new commit to master: http://git.io/vLZGJ
<crystal-gh>
crystal/master e202d54 Ary Borenszweig: Disallow casting to Object (for now, because it's a nop). Fixes #815
jua_ has quit [Quit: Vision[0.9.7-H-20140108]: i've been blurred!]