From: Sean O'Dell Date: 2004-06-26T02:22:57+09:00 Subject: Re: Is it considered Harmful? On Friday 25 June 2004 10:04, Dave Thomas wrote: > On Jun 25, 2004, at 11:55, Sean O'Dell wrote: > > a.read would do what #read does when it can't read because there's no > > open > > file. What does #read do now when it encounters an error it can't > > handle? > > Raise an exception? > > How does it know there's no open file? Go have a look at the code. My guess is here: #define GetOpenFile(obj,fp) rb_io_check_closed((fp) = RFILE(rb_io_taint_check(obj))->fptr) ...because io_read, the C implementation of the File.read method, passes the "self" VALUE to this macro, which assumes the object is an RFILE, and immediately uses the fptr member, without checking that the "self" object contains a valid fptr value. If you change the class of an object to something else, it still does this, even when fptr is not a valid member (which, when used, causes the crash). Now, if Ruby does this in a lot of places, then yeah, changing an object's class is not going to be possible. What I think would settle this simply, is if R_CAST was changed to actually perform a type check and raise an exception when an attempt is made to cast a VALUE to something it's not. Sean O'Dell