www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Re: Converting Fuse headers

reply Jesse Phillips <jessekphillips+D gmail.com> writes:
I have some good news! It works (Simplest test case). I spent several hours
trying to track down where my code translation could be causing problems. And
have concluded that core.sys.posix.sys.stat.stat_t is not correct for my 32bit
Debian Linux machine.

I realize this is a big claim, so I'm going to look into it some more. But to
get my code working I moved the getattr function into a C file and called that
instead of using it from D. I also noticed that the value set to stat_t.st_mode
would not be returned when requesting it back.

Thank you Simen and div0.

1. https://github.com/he-the-great/Fused
Nov 09 2010
parent reply div0 <div0 sourceforge.net> writes:
On 10/11/2010 06:21, Jesse Phillips wrote:
 I have some good news! It works (Simplest test case). I spent several hours
trying to track down where my code translation could be causing problems. And
have concluded that core.sys.posix.sys.stat.stat_t is not correct for my 32bit
Debian Linux machine.

 I realize this is a big claim, so I'm going to look into it some more. But to
get my code working I moved the getattr function into a C file and called that
instead of using it from D. I also noticed that the value set to stat_t.st_mode
would not be returned when requesting it back.

 Thank you Simen and div0.

 1. https://github.com/he-the-great/Fused

Well done, glad you proved me wrong. It does seem unlikely that size_t is wrong, though you can test it easily enough: compile a test C program to see what size it is and compare it to the D version: void main() { printf("sizeof: %d", sizeof(size_t)); } It should be 4 on a 32 bit system & 8 for 64 bit. -- My enormous talent is exceeded only by my outrageous laziness. http://www.ssTk.co.uk
Nov 10 2010
parent reply Jesse Phillips <jessekphillips+D gmail.com> writes:
div0 Wrote:

 Well done, glad you proved me wrong.
 
 It does seem unlikely that size_t is wrong,
 though you can test it easily enough:
 
 compile a test C program to see what size it is and compare it to the D 
 version:
 
 void main() {
 	printf("sizeof: %d", sizeof(size_t));
 }
 
 It should be 4 on a 32 bit system & 8 for 64 bit.

Hope I didn't say size_t. stat_t, a very complicated struct known as struct stat in C. I don't know for sure that it is wrong, but at this point it is the most likely candidate. Also none of the changes I made related to the question affected the ability of the program to work (maybe a more complicated one). Just glad I wasn't to far off in my translation.
Nov 10 2010
parent reply div0 <div0 sourceforge.net> writes:
On 10/11/2010 20:15, Jesse Phillips wrote:
 div0 Wrote:

 Well done, glad you proved me wrong.

 It does seem unlikely that size_t is wrong,
 though you can test it easily enough:

 compile a test C program to see what size it is and compare it to the D
 version:

 void main() {
 	printf("sizeof: %d", sizeof(size_t));
 }

 It should be 4 on a 32 bit system&  8 for 64 bit.

Hope I didn't say size_t. stat_t, a very complicated struct known as struct stat in C. I don't know for sure that it is wrong, but at this point it is the most likely candidate. Also none of the changes I made related to the question affected the ability of the program to work (maybe a more complicated one). Just glad I wasn't to far off in my translation.

Sorry, me misreading. You can still do the size check for the stat_t struct as well, I always double check the size of structs when doing those conversions as it's very easy to get it wrong. -- My enormous talent is exceeded only by my outrageous laziness. http://www.ssTk.co.uk
Nov 10 2010
parent reply Jesse Phillips <jessekphillips+D gmail.com> writes:
div0 Wrote:

 You can still do the size check for the stat_t struct as well,
 I always double check the size of structs when doing those conversions 
 as it's very easy to get it wrong.

Ah, good idea. The test I have planned will be to set some values in the D struct, and see what is read by the C struct. The size thing will definitely be a simple give away if it differs. I might try to use some reflection to see what the structure D creates looks like, so that it will be easier to compare the D code with the C header. (Lots of version statements in the D version, might be some macros in C too.)
Nov 10 2010
parent div0 <div0 sourceforge.net> writes:
On 10/11/2010 21:02, Jesse Phillips wrote:
 div0 Wrote:

 You can still do the size check for the stat_t struct as well,
 I always double check the size of structs when doing those conversions
 as it's very easy to get it wrong.

Ah, good idea. The test I have planned will be to set some values in the D struct, and see what is read by the C struct. The size thing will definitely be a simple give away if it differs. I might try to use some reflection to see what the structure D creates looks like, so that it will be easier to compare the D code with the C header. (Lots of version statements in the D version, might be some macros in C too.)

Also another thing to make life easier, use gcc's only preprocess the file option (-E ?) and save the result. That way you can look at the raw struct after all the CPP macros have been applied/stripped out. That's very handy with complicated C structs. -- My enormous talent is exceeded only by my outrageous laziness. http://www.ssTk.co.uk
Nov 10 2010