New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix translation of struct-typedefs #152
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a minor a suggestion regarding the defcvar
-> defvar
substitution.
Could you check whether the manual needs to be updated to reflect this change, either in the descriptions or in the examples?
tests/struct.lisp
Outdated
@@ -118,7 +118,7 @@ | |||
|
|||
(defctype s-s-ch (:struct s-s-ch)) | |||
|
|||
(defcvar "the_s_s_ch" s-s-ch) | |||
(defvar *the-s-s-ch* (foreign-symbol-pointer "the_s_s_ch")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice idea.
This has the drawback of not working with saved cores since it'll permanently store that pointer. Not a big deal for the test suite, but since this code might be used as an example, maybe change defvar
to define-symbol-macro
.
Alternatives:
- Keep the
defcvar
and sprinkleget-var-ptr
throughout. - Change the
defctype
s to something that doesn't translate structs, either with a custom type or by adding some option to the:struct
type that skips translation. Dubious. Probably too much work.
I'm fine with your proposed solution (with defvar
changed to define-symbol-macro
).
tests/struct.lisp
Outdated
@@ -141,10 +141,10 @@ | |||
|
|||
(defctype s-s-short (:struct s-s-short)) | |||
|
|||
(defcvar "the_s_s_short" s-s-short) | |||
(defvar *the-s-s-short* (foreign-symbol-pointer "the_s_s_short")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra space there between defvar
and the variable name. 🕵️♂️
CFFI now always translates aggregate struct values to lisp property lists. Earlier struct values which were defined by types introduced by defctype were translated as foreign pointers. One consequence of this change is that defcvar to a foreign struct will always produce an immutable lisp list. To modify the struct the user first has to get at the pointer to the struct via FORIEGN-SYMBOL-VALUE or GET-VAR-POINTER. To modify nested structs the user has to get at the pointer to the field via FORIEGN-SLOT-POINTER, - or use the the (:POINTER VAR) syntax of WITH-FOREIGN-SLOTS. * src/early-types.lisp: (defctype): use translatable-foreign-type instead of enhanced-foreign-type. * tests/structs.lisp: New tests: (misnamed) STRUCT-VALUES.FSBV.1 STRUCT-VALUES.FSBV.1 Updated tests: STRUCT.ALIGNMENT.1 STRUCT.ALIGNMENT.2 STRUCT.ALIGNMENT.3 STRUCT.ALIGNMENT.4 STRUCT.ALIGNMENT.5 STRUCT.ALIGNMENT.6 STRUCT.ALIGNMENT.7 STRUCT.NESTED-SETF STRUCT.ALIGNMENT.8
e9f9f6f
to
0206219
Compare
Thanks! |
I'll have to revert this as it's causing issues with magicl: defcfun expansion before: https://pastebin.com/tjeyKh39 (see lines labeled ; *****) test case: https://pastebin.com/7pLMVcFA |
Luis, check your mail - on June 20 2020 I sent you the fix to cffi libffi which would would have made this pull request work - correctly The original problem is with old code in cffi libffi and not a bug in this patch which was reverted. I wrote:
Unfortunately there was no feedback from him I had hoped you would test this patch against the launchpad problems noted above - i believe it would indeed solve them vert could be reverted. |
I see, sorry. Emails have this nasty habit of piling up and disappearing. I've pushed the stuff you sent me by email to this pull request: #181 Did I miss anything? |
CFFI now always translates aggregate struct values to lisp property
lists. Earlier struct values which were defined by types introduced
by defctype were translated as foreign pointers.
One consequence of this change is that defcvar to a foreign structure
will always produce an immutable lisp list. Users will have to resort
to FOREIGN-SYMBOL-VALUE in order to access structs to modify them -
and use the (:POINTER VAR) syntax of WITH-FOREIGN-SLOTS to access and
modify fields within the struct.
src/early-types.lisp: (defctype): use translatable-foreign-type
instead of enhanced-foreign-type.
tests/structs.lisp: New tests: (misnamed) STRUCT-VALUES.FSBV.1
STRUCT-VALUES.FSBV.1 Updated tests: STRUCT.ALIGNMENT.1
STRUCT.ALIGNMENT.2 STRUCT.ALIGNMENT.3 STRUCT.ALIGNMENT.4
STRUCT.ALIGNMENT.5 STRUCT.ALIGNMENT.6 STRUCT.ALIGNMENT.7
STRUCT.NESTED-SETF STRUCT.ALIGNMENT.8