queryverse / queryverse/ReadStat.jl
Arrays in a C struct
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 79
- Forks
- 18
- Avg merge
- 22h 31m
- Merged PRs (30d)
- 3
Description
I noticed in reading the code that the Julia struct
struct ReadStatVariable
readstat_types_t::Cint
index::Cint
name::Ptr{UInt8}
format::Ptr{UInt8}
label::Ptr{UInt8}
label_set::Ptr{Void}
offset::Int64
width::Csize_t
user_width::Csize_t
missingness::ReadStatMissingness
end
does not align with the C declaration in readstat,h
typedef struct readstat_variable_s {
readstat_type_t type;
int index;
char name[256];
char format[256];
char label[1024];
readstat_label_set_t *label_set;
off_t offset;
size_t storage_width;
size_t user_width;
readstat_missingness_t missingness;
readstat_measure_t measure;
readstat_alignment_t alignment;
int display_width;
} readstat_variable_t;
The problem is that the fixed-size char arrays, like name do not correspond to Ptr{UInt8} or Cstring in Julia. If you want the structs to align in memory you need to insert a Julia struct that has the correct width. The Clang package at one time did this by creating a Julia struct with 256 UInt8 fields and inserting that as the name field. However, that approach is rather tedious.
In this case there is no need to define the Julia struct because the memory is allocated in the C code and passed by reference. I can prepare a PR if you wish.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by comparing the Julia ReadStatVariable definition with the readstat.h declaration, focusing on the fixed-size name, format, and label arrays and the additional C fields. Review how the memory is allocated and passed by reference in the C code, then verify that the Julia representation has matching layout and widths.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, julia
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100