Dir::DirEntry only works on Darwin
Reported by Tilman Sauerbeck | October 18th, 2007 @ 12:58 PM | in 1.0
In kernel/core/dir.rb, the layout of the DirEntry struct is hardcoded to the values that Darwin uses.
The structure is quite different on Linux, so it breaks horribly.
Comments and changes to this ticket
-
Eero Saynatkari November 3rd, 2007 @ 12:23 AM
- → Milestone changed from 1.0 preview to 1.0
- → State changed from new to open
-

Charles L November 11th, 2007 @ 01:34 PM
Attached patch makes the struct layout conditional on RUBY_PLATFORM which makes spec/core/dir/read_spec.rb pass on linux.
-
Tilman Sauerbeck November 12th, 2007 @ 10:27 AM
Your patch doesn't take __USE_FILE_OFFSET64 into account. Don't think we can use it like this.
I wonder whether the layout code should be generated dynamically at build time...
-
Kevin Clark November 12th, 2007 @ 10:30 AM
Can we introspect the struct layout from the C? How does that work?
Btw, you were right, we're definitely going to need off_t for FFI if we're going to use it in half the places I'd like.
-

Charles L November 12th, 2007 @ 12:27 PM
I'm not sure that USE_FILE_OFFSET64 is really a problem. Thats a build time choice, and presumably not one currently being used.
Maybe the way to do this, is when shotgun / ffi code is being built, it records size of off_t.
I doubt we'd ever be able to introspect the layout, not at runtime anyway. Although again, at build time you could store the offsets and sizes of any struct members.
-
Tilman Sauerbeck November 12th, 2007 @ 02:06 PM
Yeah, that's what I had in mind:
offsetof(struct dirent, d_name);Unfortunately, this doesn't even work in this specific case (it evaluates to 10 on my 32 bit Linux box, but the d_name array is at offset 11. Fun).
btw, atm we cannot yet add support for off_t to FFI, because sizeof(off_t) might be a 64 bit type on some systems. Lightning only supports 32 bit arguments though. There's another issue about 64 bit support for FFI somewhere.
-

Brendan MacDonell November 16th, 2007 @ 08:35 PM
offsetof isn't the kind of macro which can simply break like that, since it calculates the offset by subtracting the member address from the structure address. Chances are, if your 32-bit box is reporting an offset of 10, it lacks the d_type member, or the header is arranged differently (different gcc version, perhaps?)
The easiest way to check, of course, is
-

Brendan MacDonell November 16th, 2007 @ 08:37 PM
Whoops, looks like my misreading of the formatter ate my snippet. Not that it's important anyway, but just to complete that tangent:
struct dirent d; assert((unsigned long)(((char*)&d) + offsetof(struct dirent, d_name)) == (unsigned long)(&d.d_name)); -
Tilman Sauerbeck December 1st, 2007 @ 08:03 AM
- → State changed from open to resolved
Fixed in 5974890fcc5bf78e13bb7a30f4c6be4f721e2f77.
Please Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
