<crystal-gh>
crystal/master 65336de Ary Borenszweig: Fixed #585: if `crystal run/spec` fails, exit with code 1
<crystal-gh>
crystal/master 2051494 Ary Borenszweig: Fixed #584: give correct error instead of crash for wrong static array restriction. Also cleaned up some code.
Regexident has joined #crystal-lang
Regexident has quit [Remote host closed the connection]
ismaelga has quit [Remote host closed the connection]
leafybasil has quit [Remote host closed the connection]
jua_ has joined #crystal-lang
Regexident has quit [Ping timeout: 264 seconds]
harisamin has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
<BlaXpirit>
this .not_nil! stuff is getting on my nerve
<BlaXpirit>
why is it "!" anyway?
<jhass>
because it may raise
<jhass>
I guess
<BlaXpirit>
and i thought ! means mutating
<jhass>
yeah, I guess they cargo culted it from Rails where things like .save on a model return true/false and .save! raises
<BlaXpirit>
:|
<jhass>
I'd like distinct signals for raises/modifies self and returns bool/may return nil too
<jhass>
but it's hard to find new symbols I guess
<strcmp1>
in ruby it doesn't strictly mean mutate either, just that it's "dangerous"
<jhass>
in core ruby it means that strictly
<strcmp1>
not according to matz
<jhass>
but in practice
<jhass>
in rails it means "the variant that raises"
<jhass>
many rails people use it as "dangerous" in their application code
<BlaXpirit>
screw that
<strcmp1>
idk, it seems like a silly thing to argue but according to matz definition the ! is for methods that are "dangerous", so i usually use it along those lines which probably be closer to how rails uses it as well
<strcmp1>
but then again, a lot of non-bang methods i write can raise as well
<strcmp1>
the one use case that stands out is using something called shrink! to downsize a process pool forcefully(through SIGKILL), and that fitted along the lines of 'dangerous' as well, so i implemented that once.
<jhass>
oO SIGKILL before trying SIGTERM is very bad practice
<jhass>
and yeah, I know many rubyists use it that way
<jhass>
but I like clear rules when to apply it better
<jhass>
and in practice ruby core is "if there's a bang method, there exists a non-bang method that returns a modified copy"
<strcmp1>
well, there is a "shrink" variant that used SIGUSR1 to do a graceful shutdown.
<jhass>
and in practice the Rails API is "if there's a bang method that raises and there's a non-bang method that returns true/false"
<strcmp1>
yeah, is there other cases than save! though?
<jhass>
so I try follow these rules depending on the project I'm in
leafybasil has joined #crystal-lang
HakanD___ has quit [Quit: Be back later ...]
harisamin has joined #crystal-lang
JBat has quit [Ping timeout: 264 seconds]
shama has joined #crystal-lang
wanderer_ has joined #crystal-lang
HakanD___ has joined #crystal-lang
HakanD___ has quit [Quit: Be back later ...]
<wanderer_>
jhass: hey, when you use dup2, don't you normally close the handle you copied?
<wanderer_>
I'm trying to understand pipes and dup atm
<jhass>
mh, the reopen API seems to be the wrong way around if I look at it again though
bcardiff has joined #crystal-lang
<jhass>
it should be STDOUT.reopen(null), semantically
<wanderer_>
null.reopen(STDOUT); null.close, so it's like a `STDOUT = null`
barosl has joined #crystal-lang
ismaelga has joined #crystal-lang
<wanderer_>
STDOUT.reopen(null) would make more sense, reopen should then call `LibC.dup2(other.fd, self.fd)` instead of `LibC.dup2(self.fd, other.fd)`
<jhass>
yeah
<jhass>
and I think it's in ruby that way
<wanderer_>
afaik this sets STDOUT to null by duplicating the handle, so null needs to get closed
<jhass>
Reassociates ios with the I/O stream given in other_IO or to a new stream opened on path. This may dynamically change the actual class of this stream.
<jhass>
that's ruby's docs
<jhass>
"If fildes2 is already a valid open file descriptor, it shall be closed first" are you referring to this?
<wanderer_>
where does it come from?
<jhass>
the posix uses some more difficult language there, they describe what the function should do (and thus indeed does), not what the caller should do
<jhass>
man dup2
<wanderer_>
I've read that dup duplicates the handle, so two handles = two close I'd say
<jhass>
The dup2() function shall cause the file descriptor fildes2 to refer to the same open file description as the file descriptor fildes and to share any locks,
<jhass>
and shall return fildes2
<jhass>
it's not really a copy
<jhass>
more like a hardlink, two pointers to the same resource
<jhass>
after all a filedescriptor is just a number
ismaelga has quit [Remote host closed the connection]
<jhass>
and that function changes what that number is associated with
<wanderer_>
"// Close original write end of pipe" and "Then, use _dup or _dup2 to create an inheritable copy of the pipe descriptor that you want to pass to the child. "
<jhass>
anyway, we definitely should swap around the API
<jhass>
it's confusing that way around
<wanderer_>
def reopen(other); if LibC.dup2(other.fd, self.fd) == -1; raise Errno.new("Could not reopen file descriptor"); end; self; end
<jhass>
yeah
<jhass>
I'm currently trying to think of something where it would break because other.fd is of another class
<jhass>
er, other is of another class than self
<jhass>
but I think it's the saner API and we can deal with that if we actually run into it
bcardiff has quit [Quit: Leaving.]
harisamin has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
<wanderer_>
jhass: does a spawned child process get the parent's input and output handles? in the msdn example 2, a pipe is created and the parent's stdout is redirected, then the child process is created and the parent's stdout is restored, so there's no explicit `child.stdout = xyz` which is why I assume that the child gets the parent's stdout
<jhass>
fork copies a processes memory and FD
<jhass>
s
<wanderer_>
example 2 doesn't use fork, though, as there is no such thing on windows :P
<wanderer_>
I'll have to test it to get a precise answer
ponga has joined #crystal-lang
<jhass>
so if you do nothing the child process has the same stdout, stdin and stderr
<wanderer_>
I find the msdn docs kinda lacking on that part
<jhass>
if you want to communicate with the child process a common approach is to create a pipe (or two if you want it bidirectional), and close the end you don't need after the fork
<jhass>
so you can't clone a process in windows?
<wanderer_>
nope
<jhass>
how do you spawn a child process?
<wanderer_>
CreateProcess
<wanderer_>
or wrappers around it, like spawnv
BlaXpirit has quit [Read error: Connection reset by peer]
BlaXpirit has joined #crystal-lang
waterlink has joined #crystal-lang
ismaelga has joined #crystal-lang
ismaelga has quit [Remote host closed the connection]
ismaelga has joined #crystal-lang
ismaelga has quit [Remote host closed the connection]
ismaelga has joined #crystal-lang
HakanD___ has quit [Quit: Be back later ...]
<wanderer_>
jhass: why does Process.waitpid right-shift the exit_code by 8 bits?
<crystal-gh>
[crystal] jhass opened pull request #588: Raise JSON::ParseException in json_mapping (master...json_mapping_exception) http://git.io/vfh7k
<jhass>
If status is not NULL, wait() and waitpid() store status information in the int to which it points. This integer can be inspected with the following macros
<jhass>
returns the exit status of the child. This consists of the least significant 8 bits of the status argument that the child specified
<wanderer_>
ah
<wanderer_>
wait, least significant 8 bits, wouldn't that mean `status & 0xff`?
<wanderer_>
fowl: thx, I already found the same link but haven't read through it yet
<wanderer_>
libevent uses IOCP as well
<wanderer_>
fowl: are you familiar with that? it probably needs refactoring the whole code
<fowl>
i'm trying to build the windows branch but getting error for File::PATH_SEPARATOR undefined, do i need to set a variable so it finds this std lib
<jhass>
most likely, check bin/crystal
<wanderer_>
path = Dir.working_directory + "#{File::SEPARATOR}src" if path.length == 0
<wanderer_>
what is your working directory?
ponga has joined #crystal-lang
<fowl>
~/src/crystal-win
<wanderer_>
you're building it on linux?
<fowl>
yea
ponga has quit [Remote host closed the connection]
<wanderer_>
are you using the shellscript bin/crystal?
<fowl>
no because there is no built crystal so its trying to use the crystal on $PATH
<wanderer_>
bin/crystal sets stuff like `ENV["CRYSTAL_PATH"]`
<fowl>
ah ok
<wanderer_>
I'm atm applying the windows changes to crystal HEAD
ismaelga has quit [Remote host closed the connection]
<fowl>
CRYSTAL_PATH="$(pwd)/src:libs" ~/src/crystal/.build/crystal build src/compiler/crystal.cr -- looks like LLVM library is out of sync or something
<fowl>
ah ok
<wanderer_>
you'd also need a bunch of libs for linking
<fowl>
you could share yours possibly? :]
<wanderer_>
yes, I gave them asterite, but he didn't upload them to github
<wanderer_>
I can upload them for you to some one click hoster
<wanderer_>
you also need mingw-w64
jua_ has quit [Quit: Vision[0.9.7-H-20140108]: i've been blurred!]
<travis-ci>
manastech/crystal#2266 (master - b3f6d6a : Ary Borenszweig): The build was broken.
<wanderer_>
fowl: do you know why writing to the new process via a pipe doesn't work here: http://pastebin.com/T2Xe5KUa ? I'm starting a cmd.exe and want to write "exit" to the pipe that's connected to the child's stdin