FAQ
I have tried to use c struct of shmid_ds, but compiler always complains about
nativeDs.shm_atime undefined (type _Ctype_struct___shmid_ds_new has no field or method shm_atime)

When I use “go build -work”, I found following code
type _Ctype_struct___shmid_ds_new struct {
//line :1
     shm_perm _Ctype_struct_ipc_perm
//line :1
     shm_segsz _Ctype_size_t
//line :1
     shm_lpid _Ctype_pid_t
//line :1
     shm_cpid _Ctype_pid_t
//line :1
     shm_nattch _Ctype_shmatt_t
//line :1
     _ [2]byte
//line :1
     _ [8]byte
//line :1
     _ [8]byte
//line :1
     _ [8]byte
//line :1
     _ [8]byte
//line :1
}

It looks like shm_atime is missing.
Is this a but or something I am missing? Thanks

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Ian Lance Taylor at Jun 10, 2015 at 5:40 am

    On Tue, Jun 9, 2015 at 8:52 PM, Hoping White wrote:
    I have tried to use c struct of shmid_ds, but compiler always complains
    about
    nativeDs.shm_atime undefined (type _Ctype_struct___shmid_ds_new has no field
    or method shm_atime)
    You neglected to tell us what version of Go you are using and what
    kind of system you are running on.

    When I use “go build -work”, I found following code
    type _Ctype_struct___shmid_ds_new struct {
    //line :1
    shm_perm _Ctype_struct_ipc_perm
    //line :1
    shm_segsz _Ctype_size_t
    //line :1
    shm_lpid _Ctype_pid_t
    //line :1
    shm_cpid _Ctype_pid_t
    //line :1
    shm_nattch _Ctype_shmatt_t
    //line :1
    _ [2]byte
    //line :1
    _ [8]byte
    //line :1
    _ [8]byte
    //line :1
    _ [8]byte
    //line :1
    _ [8]byte
    //line :1
    }

    It looks like shm_atime is missing.
    Is this a but or something I am missing? Thanks

    What C struct type are you trying to use?

    What does that struct look like in your C header files?

    Ian

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Hoping White at Jun 10, 2015 at 8:19 am
    #include <time.h> does no help.
    在 2015年6月10日,下午2:32,Ian Lance Taylor <iant@golang.org> 写道:
    On Tue, Jun 9, 2015 at 11:18 PM, Hoping White wrote:

    go version go1.4.2 darwin/amd64

    I am using shmid_ds struct in <sys/shm.h>

    #if (defined(_POSIX_C_SOURCE) && !defined(_DARWIN_C_SOURCE))
    struct shmid_ds
    #else
    #define shmid_ds __shmid_ds_new
    struct __shmid_ds_new
    #endif
    {
    struct __ipc_perm_new shm_perm; /* [XSI] Operation permission value */
    size_t shm_segsz; /* [XSI] Size of segment in bytes */
    pid_t shm_lpid; /* [XSI] PID of last shared memory op */
    pid_t shm_cpid; /* [XSI] PID of creator */
    shmatt_t shm_nattch; /* [XSI] Number of current attaches */
    time_t shm_atime; /* [XSI] Time of last shmat() */
    time_t shm_dtime; /* [XSI] Time of last shmdt() */
    time_t shm_ctime; /* [XSI] Time of last shmctl() change */
    void *shm_internal; /* reserved for kernel use */
    };
    #else /* !__DARWIN_UNIX03 */
    #define shmid_ds __shmid_ds_old
    #endif /* !__DARWIN_UNIX03 */
    Thanks for the info. I don't know why cgo is not handling the time_t
    fields. They seem to be aligned correctly. It may help to add
    #include <time.h>; I'm not sure.

    Ian
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Minux at Jun 11, 2015 at 4:27 am
    Apparently shm_atime is not correctly aligned in the struct,
    and as Go struct require 8-byte alignment for the C.time_t
    (which is typedef to be long), those unaligned fields can't
    be translated to equivalent fields in a Go type.

    $ cc -x c - <<EOF
    #include <sys/shm.h>
    #include <stdio.h>
    #include <stddef.h>

    int main() {
    printf("%d\n", (int)offsetof(struct shmid_ds, shm_atime));
    printf("%d\n", (int)__alignof__(time_t));
    }
    EOF
    $ ./a.out
    44
    8

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Ian Lance Taylor at Jun 11, 2015 at 11:32 pm

    On Wed, Jun 10, 2015 at 9:26 PM, minux wrote:
    Apparently shm_atime is not correctly aligned in the struct,
    and as Go struct require 8-byte alignment for the C.time_t
    (which is typedef to be long), those unaligned fields can't
    be translated to equivalent fields in a Go type.

    $ cc -x c - <<EOF
    #include <sys/shm.h>
    #include <stdio.h>
    #include <stddef.h>

    int main() {
    printf("%d\n", (int)offsetof(struct shmid_ds, shm_atime));
    printf("%d\n", (int)__alignof__(time_t));
    }
    EOF
    $ ./a.out
    44
    8
    You're saying that on darwin/amd64 time_t is an 8 byte number (as it
    should be) but is aligned to a 4 byte boundary within a struct? How
    can that be? Is the struct packed? I looked at shm.h online but
    didn't see any evidence of that.

    Ian

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Minux at Jun 16, 2015 at 7:40 pm

    On Thu, Jun 11, 2015 at 7:31 PM, Ian Lance Taylor wrote:
    On Wed, Jun 10, 2015 at 9:26 PM, minux wrote:

    Apparently shm_atime is not correctly aligned in the struct,
    and as Go struct require 8-byte alignment for the C.time_t
    (which is typedef to be long), those unaligned fields can't
    be translated to equivalent fields in a Go type.

    $ cc -x c - <<EOF
    #include <sys/shm.h>
    #include <stdio.h>
    #include <stddef.h>

    int main() {
    printf("%d\n", (int)offsetof(struct shmid_ds, shm_atime));
    printf("%d\n", (int)__alignof__(time_t));
    }
    EOF
    $ ./a.out
    44
    8
    You're saying that on darwin/amd64 time_t is an 8 byte number (as it
    should be) but is aligned to a 4 byte boundary within a struct? How
    can that be? Is the struct packed? I looked at shm.h online but
    didn't see any evidence of that.
    Yes, there is a pack(4) pragma right above the struct definition.
    And I've also verified that the gcc -E -P output of my example:

    #pragma pack(4)
    struct __shmid_ds_new

    {
      struct ipc_perm shm_perm;
      size_t shm_segsz;
      pid_t shm_lpid;
      pid_t shm_cpid;
      shmatt_t shm_nattch;
      time_t shm_atime;
      time_t shm_dtime;
      time_t shm_ctime;
      void *shm_internal;
    };
    #pragma pack()

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJun 10, '15 at 5:07a
activeJun 16, '15 at 7:40p
posts6
users3
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase