読者です 読者をやめる 読者になる 読者になる

テストステ論

高テス協会会長が, テストステロンに関する情報をお届けします.

(nim report) import C struct with bit field

Some C struct like fuse_file_info uses bit field and you want to import this struct to Nim type.

struct fuse_file_info {
        /** Open flags.  Available in open() and release() */
        int flags;

        /** Old file handle, don't use */
        unsigned long fh_old;

        /** In case of a write operation indicates if this was caused by a
            writepage */
        int writepage;

        /** Can be filled in by open, to use direct I/O on this file.
            Introduced in version 2.4 */
        unsigned int direct_io : 1;

        /** Can be filled in by open, to indicate, that cached file data
            need not be invalidated.  Introduced in version 2.4 */
        unsigned int keep_cache : 1;

        /** Indicates a flush operation.  Set in flush operation, also
            maybe set in highlevel lock operation and lowlevel release
            operation.  Introduced in version 2.6 */
        unsigned int flush : 1;

        /** Padding.  Do not use*/
        unsigned int padding : 29;

        /** File handle.  May be filled in by filesystem in open().
            Available in all other file operations */
        uint64_t fh;

        /** Lock owner id.  Available in locking operations and flush */
        uint64_t lock_owner;
};

According to Araq, just ignore :X. Now what works for me is

type TFuseFileInfo {.importc:"struct fuse_file_info", header:"<fuse.h>".} = object
  flags: cint
  fh_old: culong
  writepage: cint
  direct_io: cuint
  keep_cache: cuint
  flush: cuint
  padding: cuint
  fh: uint64
  lock_owner: uint64