Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

"bad file descriptor" in Win32 DLL

0 views
Skip to first unread message

Christian Kaiser

unread,
Apr 16, 2004, 8:58:17 AM4/16/04
to
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


Kaspar Schiess

unread,
Apr 16, 2004, 9:42:10 AM4/16/04
to
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Christian Kaiser wrote:

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-----


Christian Kaiser

unread,
Apr 16, 2004, 9:59:24 AM4/16/04
to
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" <eu...@space.ch> wrote in message
news:407FE344...@space.ch...

Kaspar Schiess

unread,
Apr 16, 2004, 11:41:59 AM4/16/04
to
-----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-----


Christian Kaiser

unread,
Apr 16, 2004, 12:54:18 PM4/16/04
to
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 :|

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" <eu...@space.ch> wrote in message

news:407FFF5...@space.ch...

Christian Kaiser

unread,
Apr 16, 2004, 1:00:40 PM4/16/04
to
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


Simon Strandgaard

unread,
Apr 16, 2004, 1:45:04 PM4/16/04
to
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.


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


--
Simon Strandgaard

Christian Kaiser

unread,
Apr 16, 2004, 2:34:19 PM4/16/04
to
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" <neo...@adslhome.dk> wrote in message
news:pan.2004.04.16....@adslhome.dk...

Joel VanderWerf

unread,
Apr 16, 2004, 3:37:31 PM4/16/04
to
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


Simon Strandgaard

unread,
Apr 16, 2004, 3:45:51 PM4/16/04
to
On Fri, 16 Apr 2004 21:34:19 +0200, Christian Kaiser wrote:
> 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?


server> 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
server> 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
server>

--
Simon Strandgaard

Christian Kaiser

unread,
Apr 16, 2004, 4:11:37 PM4/16/04
to
Joel,

thanks - that's a nice idea!

Christian

"Joel VanderWerf" <vj...@PATH.Berkeley.EDU> wrote in message
news:408035F7...@path.berkeley.edu...

Christian Kaiser

unread,
Apr 16, 2004, 4:29:19 PM4/16/04
to
Oh well, these things do look good. I'll look at it deeper tomorrow. Thanks!

May ways to rome... :)

Christian

"Simon Strandgaard" <neo...@adslhome.dk> wrote in message
news:pan.2004.04.16....@adslhome.dk...

Simon Strandgaard

unread,
Apr 16, 2004, 4:32:20 PM4/16/04
to
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... :)
>

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

--
Simon Strandgaard

nobu....@softhome.net

unread,
Apr 18, 2004, 9:11:32 PM4/18/04
to
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


0 new messages