[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[MIT-Scheme-devel] [PATCH] FFI: Fixing problem with groveller for struct
From: |
Peter Feigl |
Subject: |
[MIT-Scheme-devel] [PATCH] FFI: Fixing problem with groveller for structures with typedefs. |
Date: |
Wed, 12 Dec 2012 14:05:51 +0100 |
If a name is actually a typedef for a struct, as in
typedef struct { int x; } a;
then sizeof(struct a) does not compile (because a does not strictly name
a struct).
This patch removes the "struct" from the declaration of the struct in
grovel_struct_<name> and from the sizeof(<name>) in the -const.c file
generated by the FFI.
---
src/ffi/generator.scm | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/src/ffi/generator.scm b/src/ffi/generator.scm
index f03b7dd..1a4f098 100644
--- a/src/ffi/generator.scm
+++ b/src/ffi/generator.scm
@@ -603,6 +603,14 @@ grovel_enums (FILE * out)
'())))
(c-includes/type-names includes)))
+
+(define (strip-struct decl)
+ ;; If decl begins with "struct " then remove "struct " and return the rest
+ ;; of the string (i.e. the type name).
+ (if (string-prefix? "struct " decl)
+ (substring decl 7 (string-length decl))
+ decl))
+
(define (gen-struct-union-grovel-func name includes)
;; Generate C code for a grovel_NAME function.
(let ((fname (cond ((ctype/struct-name? name)
@@ -622,8 +630,8 @@ grovel_enums (FILE * out)
void
"fname" (FILE * out)
\{
- "decl" S;
- fprintf (out, \" (")(write key)(_" . %ld)\\n\", (long) sizeof ("decl"));"))
+ "(strip-struct decl)" S;
+ fprintf (out, \" (")(write key)(_" . %ld)\\n\", (long) sizeof
("(strip-struct decl)"));"))
(for-each-member-path
ctype includes
(lambda (path brief-type)
--
1.8.0.1
- [MIT-Scheme-devel] [PATCH] FFI: Fixing problem with groveller for structures with typedefs.,
Peter Feigl <=