www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5206] New: stat_t is not the same as struct stat

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5206

           Summary: stat_t is not the same as struct stat
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: Jesse.K.Phillips+D gmail.com
                CC: Jesse.K.Phillips+D gmail.com


--- Comment #0 from Jesse Phillips <Jesse.K.Phillips+D gmail.com> 2010-11-11
21:34:53 PST ---
The structure created by D for stat is not the same size as the one in C, and
there appears to be no communication of data between C and D. Assigns a value
to st_mode and calls a C function which prints the value and assigns its own.
At which point D prints the value (the same one it assigned). Running 32bit
Linux.

Output:

D size: 100
D Assigning 65
C Size: 88
C Found: 0
C Assign: 45
D Found 65

import core.sys.posix.sys.stat;
import std.stdio;

extern(C) void modStat(stat_t* data);

void main() {
    stat_t stbuf;
    writeln("D size: ", stbuf.sizeof);
    writeln("D Assigning ", 65);
    stbuf.st_mode = 65;

    modStat(&stbuf);

    writeln("D Found ", stbuf.st_mode);
}

--------------- cstat.c
#include <sys/stat.h>
#include <stdio.h>

void modStat(struct stat *stbuf) {
    struct stat rrr;
    printf("C Size: %d\n", sizeof(rrr));
    printf("C Found: %d\n", stbuf->st_mode);
    printf("C Assign: %d\n", 45);
    stbuf->st_mode = 45;
}

Compiled with:     gcc -g -c cstat.c && dmd -gc stat.d cstat.o

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 11 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5206



--- Comment #1 from Jesse Phillips <Jesse.K.Phillips+D gmail.com> 2010-11-11
21:48:11 PST ---
I did try to compare the Structures, and only one thing came out as being
different (after I discovered __USE_FILE_OFFSET64 was supposed to always be
set). The struct has a if(false) which seems to have the missing code that I
need, and adds quite a bit.

http://dsource.org/projects/druntime/browser/trunk/src/core/sys/posix/sys/stat.d?rev=300#L112

This is what stat looks like with some trimming: gcc -E -D_FILE_OFFSET_BITS=64
-I/usr/include/fuse -pthread -lfuse -lrt -ldl stat.h

struct stat
  {
    __dev_t st_dev;
    unsigned short int __pad1;
    __ino_t __st_ino;
    __mode_t st_mode;
    __nlink_t st_nlink;
    __uid_t st_uid;
    __gid_t st_gid;
    __dev_t st_rdev;
    unsigned short int __pad2;
    __off64_t st_size;
    __blksize_t st_blksize;
    __blkcnt64_t st_blocks;
    struct timespec st_atim;
    struct timespec st_mtim;
    struct timespec st_ctim;
    __ino64_t st_ino;
  };

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 11 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5206


Iain Buclaw <ibuclaw ubuntu.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ibuclaw ubuntu.com


--- Comment #2 from Iain Buclaw <ibuclaw ubuntu.com> 2010-12-30 09:40:34 PST ---
This should really be set to true for all glibc systems.

However, the current implementation is buggy:

timespec    st_atim;
timespec    st_mtim;
timespec    st_ctim;
alias st_atim.tv_sec st_atime;
alias st_mtim.tv_sec st_mtime;
alias st_ctim.tv_sec st_ctime;


The three aliases aren't actually usable, because:

Error: struct core.sys.posix.sys.stat.stat_t 'tv_sec' is not a member
Error: struct core.sys.posix.sys.stat.stat_t member tv_sec is not accessible
Error: this for tv_sec needs to be type timespec not type stat_t


Regards

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 30 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5206



--- Comment #3 from Iain Buclaw <ibuclaw ubuntu.com> 2011-01-03 06:47:56 PST ---
Created an attachment (id=859)
patch for 5206

Patch against my tree. Updates stat_t for version(linux), adds definition of
__WORDSIZE (needs review, probably better to define it on a per-architecture
basis), and removes all except the alias to fstat64 in std.file.


Can someone pick this up and clean/apply? :)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 03 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5206


Sohgo Takeuchi <sohgo sohgo.dyndns.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |sohgo sohgo.dyndns.org


--- Comment #4 from Sohgo Takeuchi <sohgo sohgo.dyndns.org> 2011-01-31 19:08:36
PST ---
(In reply to comment #3)
 Created an attachment (id=859) [details]
 patch for 5206
I have tested Jesse's patch on FreeBSD 8.1(i386 and amd64) and run his program. The outputs were following. 8.1(i386): D size: 96 D Assigning 65 C Size: 96 C Found: 65 C Assign; 45 D Found 45 8.1(amd64): D size: 120 D Assigning 65 C Size: 120 C Found: 65 C Assign; 45 D Found 45 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 31 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5206


Iain Buclaw <ibuclaw ubuntu.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
 Attachment #859 is|0                           |1
           obsolete|                            |


--- Comment #5 from Iain Buclaw <ibuclaw ubuntu.com> 2011-01-31 22:51:45 PST ---
Created an attachment (id=891)
patch for 5206

Note, have since updated stat_t implementation for Linux.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 31 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5206


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla digitalmars.com


--- Comment #6 from Walter Bright <bugzilla digitalmars.com> 2011-02-01
00:20:31 PST ---
lstat64 is not defined for FreeBSD

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 01 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5206



--- Comment #7 from Sohgo Takeuchi <sohgo sohgo.dyndns.org> 2011-02-01 03:14:10
PST ---
As walter says, since lstat64 is not defined for FreeBSD, I have reported at
http://d.puremagic.com/issues/show_bug.cgi?id=5512

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 01 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5206



--- Comment #8 from Iain Buclaw <ibuclaw ubuntu.com> 2011-04-17 22:24:37 PDT ---
struct_stat64 in std.file is still present and should be removed. :o)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 17 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5206


jfanatiker gmx.at changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jfanatiker gmx.at


--- Comment #9 from jfanatiker gmx.at 2012-04-08 13:00:33 PDT ---
Is someone working on this? If not, I am going to fix it.

I happened to implement this struct on my own, because I relied on the online
API documentation where lots of C wrappers are not documented, so I did not
realized that they exist. Anyway I implemented a simple unit test for my own
stat struct which compares the size of the struct in D with the size of the
struct in C by means of a simple C function that returns the size of the struct
in C. Would there be any problem if I did something like this in the druntime
code?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 08 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5206



--- Comment #10 from jfanatiker gmx.at 2012-06-30 11:15:15 PDT ---
Fixed. Pull request:
https://github.com/D-Programming-Language/druntime/pull/257

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 30 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5206



--- Comment #11 from github-bugzilla puremagic.com 2012-07-25 20:46:01 PDT ---
Commit pushed to master at https://github.com/D-Programming-Language/druntime

https://github.com/D-Programming-Language/druntime/commit/ccaa0ef2cc6a42f6d03d8072de3721fdf0252fd6
Merge branch 'mergeStat'

- fix Issue 5206

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 25 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5206


dawg dawgfoto.de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dawg dawgfoto.de


--- Comment #12 from dawg dawgfoto.de 2012-07-25 21:09:05 PDT ---
There is a related issue on OSX where the inode size has changed.
We currently require -D_DARWIN_NO_64_BIT_INODE when interfacing with C code on
=10.6 targets.
https://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man2/stat64.2.html -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 25 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5206


Alex Rønne Petersen <alex lycus.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |alex lycus.org


--- Comment #13 from Alex Rønne Petersen <alex lycus.org> 2012-10-10 03:52:38
CEST ---
Can we close this?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 09 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5206



--- Comment #14 from Iain Buclaw <ibuclaw ubuntu.com> 2012-10-10 00:09:13 PDT
---
(In reply to comment #13)
 Can we close this?
I do believe so yes. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 10 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5206


Alex Rønne Petersen <alex lycus.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 10 2012