On Monday, October 12, 2015 at 11:24:06 AM UTC-5, Matt wrote:
>
> ReadStat is an excellent C library by Evan Millers that allows to read 
> files from Stata, SPSS and SAS.
> Evan wrote a wrapper for ReadStat in the Dataread.jl package 
> https://github.com/WizardMac/DataRead.jl
> However, the package was not updated with the most recent API of ReadStat.
> I've been trying to solve this without success (see the WIP pull request 
> in the repository)
> The hard part is to write a Julia function (handle_value) that accepts a C 
> structure with a union field.
>
> typedef struct readstat_value_s {
>     union {
>         char        char_value;
>         float       float_value;
>         double      double_value;
>         int16_t     i16_value;
>         int32_t     i32_value;
>         char       *string_value;
>     } v;
>     readstat_types_t        type;
>     char                    tag;
>     int                     is_system_missing:1;
>     int                     is_considered_missing:1;
> } readstat_value_t;
>
> If someone has some time to look at this, that'd be great!
>

It looks a bit confusing because the union is the first member of the 
struct and the possible values have different widths. Someone with more 
knowledge of the layout of C structs may be able to clarify but the only 
way I can see this working is to pad everything in the v field to 64 bits 
so that the type member starts at a fixed offset from the beginning of the 
struct.

The RCall package accesses a similar C struct from R called an SEXPREC. 
 However in that case the union is the last member of the struct and the 
type information is always in the same place, which makes it easier to 
match Julia types to the different forms of the C structs.   It may help to 
study the RCall code.

Reply via email to