"bad file descriptor" in Win32 DLL

Using Ruby 1.81, the DLL (msvcrt-ruby18.dll) sometimes raises an exception
"Bad file descriptor" in “write”.

The DLL of 1.6.8 (mswin32-ruby16.dll) does not show this behaviour.

Is that known, and if yes, how can I get rid of it? Any hints appreciated.

Thanks,

Christian

Christian Kaiser wrote:

Using Ruby 1.81, the DLL (msvcrt-ruby18.dll) sometimes raises an exception
“Bad file descriptor” in “write”.

The DLL of 1.6.8 (mswin32-ruby16.dll) does not show this behaviour.

Is that known, and if yes, how can I get rid of it? Any hints appreciated.

I get that too, but often because I try to #write to something I cannot
write to. The error message is not descriptive, but there is often a cause.

When exactly do you get the message and why do you think you should not
be getting it ?

kaspar - code philosopher

  • – stolen off the net –
    Ban the bomb. Save the world for conventional warfare.

Kaspar,

because it is at a simple code like

logstring = “#{self.type}: hallo”

and the trace is then:

'write'
'type'
...

(why does ‘type’ call write? And why on an invalid descriptor?)

or at a Regexp comparison:

if sPart =~ "^--(?:[\r\n]|$)" # end of multi-part mail

I get it with a call stack of:

'write'
'=~'
...

Again, why does ‘=~’ call ‘write’? Strange, isn’t it?

Christian

“Kaspar Schiess” eule@space.ch wrote in message
news:407FE344.3050600@space.ch…

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Christian Kaiser wrote:

Using Ruby 1.81, the DLL (msvcrt-ruby18.dll) sometimes raises an
exception
“Bad file descriptor” in “write”.

The DLL of 1.6.8 (mswin32-ruby16.dll) does not show this behaviour.

Is that known, and if yes, how can I get rid of it? Any hints
appreciated.

I get that too, but often because I try to #write to something I cannot
write to. The error message is not descriptive, but there is often a
cause.

···

When exactly do you get the message and why do you think you should not
be getting it ?

kaspar - code philosopher

  • – stolen off the net –
    Ban the bomb. Save the world for conventional warfare.
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.2.4 (MingW32)
    Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFAf+NEFifl4CA0ImQRAtzMAJ9JH6wRoueiiFEecEN2Yk+S1FVCbACeMDcB
ayV3fiuaJtr89l9Ff+Kwv6w=
=z+Dy
-----END PGP SIGNATURE-----

logstring = “#{self.type}: hallo”
(why does ‘type’ call write? And why on an invalid descriptor?)
… warning: Object#type is deprecated; use Object#class

or at a Regexp comparison:
if sPart =~ “^–(?:[\r\n]|$)” # end of multi-part mail
Again, why does ‘=~’ call ‘write’? Strange, isn’t it?
…warning: string =~ string will be obsolete; use explicit regexp

Ruby writes warnings to stdout. Did you close it somehow ?
kaspar - code philosopher

  • – stolen off the net –
    “Having major planets disappear is always a bad sign.”
    – Jim Blinn

I don’t ever open or close stdout - I wrote a DLL which itself loads the
Ruby DLL. Strange that this exception is only thrown irregularly, once in
hundreds of calls. I would have expected such a behaviour, if it were
reproducable. It just happens sometimes, then a few minutes later again, …

Oh, I hoped Ruby code could be kept compatible between versions. Seems I
need to decide for one version. Hmmmm… I did not expect this and I don’t
like it. I come from the C/C++/Pascal/… side, and they keep newer versions
code compatible (as good as they can), so switching to a new version of a
compiler does not need much of code rewrites.

If they are changing it, I hope they change all the names of several
procedures (chomp, chop, …) to ones that are memorizable and programmers
from other languages are used to or are more syntactically correct
(includes? instead of include?, …) :))) My main problem with Ruby is that
I always need a reference manual helping me, as the routine names are not
easly memorizable :expressionless:

But that’s not the topic I wanted to have solved, and I guess innumerable
mails have been posted concerning it.

Thanks for your help. I vote for a change that this stdout behaviour will
not raise an exception any more, as it makes no sense to get an exception
from this.

Christian

“Kaspar Schiess” eule@space.ch wrote in message
news:407FFF58.20704@space.ch…

···

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

logstring = “#{self.type}: hallo”
(why does ‘type’ call write? And why on an invalid descriptor?)
… warning: Object#type is deprecated; use Object#class

or at a Regexp comparison:
if sPart =~ “^–(?:[\r\n]|$)” # end of multi-part mail
Again, why does ‘=~’ call ‘write’? Strange, isn’t it?
…warning: string =~ string will be obsolete; use explicit regexp

Ruby writes warnings to stdout. Did you close it somehow ?
kaspar - code philosopher

  • – stolen off the net –
    “Having major planets disappear is always a bad sign.”
    – Jim Blinn
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.2.4 (MingW32)
    Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFAf/9YFifl4CA0ImQRAsDjAKChViauyTnaT8FT0Gd6cGxUVz7FdACZASHW
DnfH/MOVjl1jFvi40RBRH3k=
=wqq/
-----END PGP SIGNATURE-----

BTW: the code before had sequences like:

return true if sSubject =~ /abcxyz/
return true if sSubject =~ /d/
return true if sSubject =~ /ef/

Will that now need that I write

return true if /abcxyz/ =~ sSubject
return true if /d/ =~ sSubject
return true if /ef/ =~ sSubject

which is less readable as the formatting becomes ragged? OK, I can create an
array of Regexp’s, but for 3 lines this is overkill.

Christian

return true if / abcxyz | ef | d /x.match(sSubject)

···

On Fri, 16 Apr 2004 20:00:40 +0200, Christian Kaiser wrote:

Will that now need that I write

return true if /abcxyz/ =~ sSubject
return true if /d/ =~ sSubject
return true if /ef/ =~ sSubject

which is less readable as the formatting becomes ragged? OK, I can create an
array of Regexp’s, but for 3 lines this is overkill.


Simon Strandgaard

Christian Kaiser wrote:

BTW: the code before had sequences like:

return true if sSubject =~ /abcxyz/
return true if sSubject =~ /d/
return true if sSubject =~ /ef/

Will that now need that I write

return true if /abcxyz/ =~ sSubject
return true if /d/ =~ sSubject
return true if /ef/ =~ sSubject

which is less readable as the formatting becomes ragged? OK, I can create an
array of Regexp’s, but for 3 lines this is overkill.

Another option:

case aSubject when /abcxyz/, /d/, /ef/: return end

Hi,

At Sat, 17 Apr 2004 01:59:11 +0900,
Christian Kaiser wrote in [ruby-talk:97372]:

I don’t ever open or close stdout - I wrote a DLL which itself loads the
Ruby DLL. Strange that this exception is only thrown irregularly, once in
hundreds of calls. I would have expected such a behaviour, if it were
reproducable. It just happens sometimes, then a few minutes later again, …

Your program may be GUI mode? stdin/stdout/stderr are not
opened for GUI mode program. By setting $VERBOSE to nil, all
warnings will be suppressed.

···


Nobu Nakada

Simon,

yes, but I have that many expressions that are 50-70 chars long, that I
would need hundreds of chars in one line for the expression, which is
neither good style nor readable. The text of my mail was just an example to
show the ruggedness:)))

And it’s not even only ruggedness - in

if a =~ /.../

it’s much faster (and “logical” for humans) to see that the variable “a” is
being tested as in

if /.../ =~ a

so in my eyes the new convention reduces readbility.

Real code looks now like

BADWORDS =

pharmacy

BADWORDS <<
/(?:vicodin|viagra|sildenafil|citrate|xanax|xnax|valium|norco|levsitra)/
BADWORDS <<
/(?:cialis|phentermine|aseptic|pharmacy|medication|pharmaceuticals?|medical)
/
BADWORDS << /\b(?:meds|drugs)\b/

money

BADWORDS << /(?:mortgages?)/
BADWORDS << /\b(?:cable bils?|busines ofers?|casino|life insurance)\b/

sex

BADWORDS << /(?:orgasms?)/
BADWORDS << /\b(?:*****|sex|enlarge it)\b/

and

sSubject = reduceSubjectToASCII(sSubjectIn)
BADWORDS.each { |re| return true if re =~ sSubject }
return false

Christian

“Simon Strandgaard” neoneye@adslhome.dk wrote in message
news:pan.2004.04.16.17.45.04.206212@adslhome.dk…

Will that now need that I write

return true if /abcxyz/ =~ sSubject
return true if /d/ =~ sSubject
return true if /ef/ =~ sSubject

which is less readable as the formatting becomes ragged? OK, I can
create an

···

On Fri, 16 Apr 2004 20:00:40 +0200, Christian Kaiser wrote:

array of Regexp’s, but for 3 lines this is overkill.

return true if / abcxyz | ef | d /x.match(sSubject)


Simon Strandgaard

Joel,

thanks - that’s a nice idea!

Christian

“Joel VanderWerf” vjoel@PATH.Berkeley.EDU wrote in message
news:408035F7.9090401@path.berkeley.edu…

Christian Kaiser wrote:

BTW: the code before had sequences like:

return true if sSubject =~ /abcxyz/
return true if sSubject =~ /d/
return true if sSubject =~ /ef/

Will that now need that I write

return true if /abcxyz/ =~ sSubject
return true if /d/ =~ sSubject
return true if /ef/ =~ sSubject

which is less readable as the formatting becomes ragged? OK, I can
create an

···

array of Regexp’s, but for 3 lines this is overkill.

Another option:

case aSubject when /abcxyz/, /d/, /ef/: return end

yes, but I have that many expressions that are 50-70 chars long, that I
would need hundreds of chars in one line for the expression, which is
neither good style nor readable. The text of my mail was just an example to
show the ruggedness:)))

I made a few improvements… what do you think?

ruby a.rb
BAD: do DrUgS… experience new things
BAD: play on casino and win big money
OK: pleasure with Ruby. BTW: its free
BAD: buy viagra
BAD: christina agulera caught backstage
BAD: britney spears
BAD: get your university diploma here
expand -t2 a.rb
input = <<WORDS

pharmacy

vicodin viagra sildenafil citrate xanax xnax valium norco levsitra
cialis phentermine aseptic pharmacy medication pharmaceuticals? medical
meds drugs

money

mortgages? cable_bils? life_insurance busines_ofers? casino

music

britney_spears christina_agulera

misc

diploma
WORDS

lines = input.to_a

remove comments

lines.delete_if {|line| line.match(/^#/)}

transform lines into words

words = lines.inject() {|result, line| result + line.split(/\s/) }

replace underscores with spaces

words.map!{|word| word.gsub!(/_/, ’ '); word}
words.delete_if {|word| word == ‘’}
#p words

lets make a big regexp

regexp_str = words.map{|word| Regexp.escape(word)}.join(‘|’)
regexp = Regexp.new(regexp_str, Regexp::IGNORECASE)
#p regexp.inspect

testdata = [
“do DrUgS… experience new things”,
“play on casino and win big money”,
“pleasure with Ruby. BTW: its free”,
“buy viagra”,
“christina agulera caught backstage”,
“britney spears”,
“get your university diploma here”
]
testdata.each do |str|
res = regexp.match(str) ? “BAD” : " OK"
puts “#{res}: #{str}”
end

···

On Fri, 16 Apr 2004 21:34:19 +0200, Christian Kaiser wrote:


Simon Strandgaard

Oh well, these things do look good. I’ll look at it deeper tomorrow. Thanks!

May ways to rome… :slight_smile:

Christian

“Simon Strandgaard” neoneye@adslhome.dk wrote in message
news:pan.2004.04.16.19.45.50.835557@adslhome.dk…

yes, but I have that many expressions that are 50-70 chars long, that I
would need hundreds of chars in one line for the expression, which is
neither good style nor readable. The text of my mail was just an example
to

···

On Fri, 16 Apr 2004 21:34:19 +0200, Christian Kaiser wrote:

show the ruggedness:)))

I made a few improvements… what do you think?

ruby a.rb
BAD: do DrUgS… experience new things
BAD: play on casino and win big money
OK: pleasure with Ruby. BTW: its free
BAD: buy viagra
BAD: christina agulera caught backstage
BAD: britney spears
BAD: get your university diploma here
expand -t2 a.rb
input = <<WORDS

pharmacy

vicodin viagra sildenafil citrate xanax xnax valium norco levsitra
cialis phentermine aseptic pharmacy medication pharmaceuticals? medical
meds drugs

money

mortgages? cable_bils? life_insurance busines_ofers? casino

music

britney_spears christina_agulera

misc

diploma
WORDS

lines = input.to_a

remove comments

lines.delete_if {|line| line.match(/^#/)}

transform lines into words

words = lines.inject() {|result, line| result + line.split(/\s/) }

replace underscores with spaces

words.map!{|word| word.gsub!(/_/, ’ '); word}
words.delete_if {|word| word == ‘’}
#p words

lets make a big regexp

regexp_str = words.map{|word| Regexp.escape(word)}.join(‘|’)
regexp = Regexp.new(regexp_str, Regexp::IGNORECASE)
#p regexp.inspect

testdata = [
“do DrUgS… experience new things”,
“play on casino and win big money”,
“pleasure with Ruby. BTW: its free”,
“buy viagra”,
“christina agulera caught backstage”,
“britney spears”,
“get your university diploma here”
]
testdata.each do |str|
res = regexp.match(str) ? “BAD” : " OK"
puts “#{res}: #{str}”
end


Simon Strandgaard

The better one starts out, the better chances for success.
wish you luck. Just ask if you have any problems with it.

···

On Fri, 16 Apr 2004 23:29:19 +0200, Christian Kaiser wrote:

Oh well, these things do look good. I’ll look at it deeper
tomorrow. Thanks!

May ways to rome… :slight_smile:


Simon Strandgaard