diff options
author | Ken Raeburn <raeburn@raeburn.org> | 2012-05-21 00:30:45 -0400 |
---|---|---|
committer | Ken Raeburn <raeburn@raeburn.org> | 2012-05-21 01:13:13 -0400 |
commit | cff1d39b2003470b5dcdab988e279587ae2eed8c (patch) | |
tree | 4b9cda9c33e5b87bab1c50c58f5d15f2ea5174a8 /libguile/foreign.c | |
parent | a722bcaa13acd3185e8e7b84f64cb614a46f3532 (diff) |
Fix FFI struct sizing to account for trailing padding.
* libguile/foreign.c (scm_sizeof): Make sure the overall size is a
multiple of the alignment of the structure.
* test-suite/tests/foreign.test: Test size of { double, int8 }.
Diffstat (limited to 'libguile/foreign.c')
-rw-r--r-- | libguile/foreign.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/libguile/foreign.c b/libguile/foreign.c index 00e9c7544..832913147 100644 --- a/libguile/foreign.c +++ b/libguile/foreign.c @@ -536,13 +536,14 @@ SCM_DEFINE (scm_sizeof, "sizeof", 1, 0, 0, (SCM type), { /* a struct */ size_t off = 0; + size_t align = scm_to_size_t (scm_alignof(type)); while (scm_is_pair (type)) { off = ROUND_UP (off, scm_to_size_t (scm_alignof (scm_car (type)))); off += scm_to_size_t (scm_sizeof (scm_car (type))); type = scm_cdr (type); } - return scm_from_size_t (off); + return scm_from_size_t (ROUND_UP(off, align)); } else scm_wrong_type_arg (FUNC_NAME, 1, type); |