[C2hs] sizeof hook calculates the wrong size

Volker Wysk post at volker-wysk.de
Sun Nov 13 02:51:46 EST 2005


Hello

The sizeof hook calculates the size wrong in this example:

-----------------------------------------------------------------
main = putStrLn (show {# sizeof loop_info64_t #})

#c
#include <linux/loop.h>
typedef struct loop_info64 loop_info64_t;
#endc
-----------------------------------------------------------------

Translated to:

-----------------------------------------------------------------
...
{-# LINE 1 "bug.chs" #-}main = putStrLn (show 72)
-----------------------------------------------------------------

The structure is much larger. loop_info64 is defined 
in /usr/include/linux/loop.h like this:

-----------------------------------------------------------------
struct loop_info64 {
	__u64		   lo_device;			/* ioctl r/o */
	__u64		   lo_inode;			/* ioctl r/o */
	__u64		   lo_rdevice;			/* ioctl r/o */
	__u64		   lo_offset;
	__u64		   lo_sizelimit;/* bytes, 0 == max available */
	__u32		   lo_number;			/* ioctl r/o */
	__u32		   lo_encrypt_type;
	__u32		   lo_encrypt_key_size;		/* ioctl w/o */
	__u32		   lo_flags;			/* ioctl r/o */
	__u8		   lo_file_name[LO_NAME_SIZE];
	__u8		   lo_crypt_name[LO_NAME_SIZE];
	__u8		   lo_encrypt_key[LO_KEY_SIZE]; /* ioctl w/o */
	__u64		   lo_init[2];
};
-----------------------------------------------------------------

It looks like the the arrays are mistaken for pointers.


There's another small bug. If you reorder main and the C block in the example 
above, such that "#c" is the first line, then you get a parse error.

-- 
public key fingerprint: 6A10 66F1 40A2 C441 BB55 0AA8 FAB1 4FC1 08BE 24EF


More information about the C2hs mailing list