On Wed, Apr 24, 2013 at 4:35 AM, Willem Rein Oudshoorn woudshoo@xs4all.nlwrote:
Thank you for all your work and the time to answer my questions.
Liam Healy lnp@healy.washington.dc.us writes:
Willem,
Thanks for the report.
My thinking is that with-foreign-slots is intended to expose the value
(and
not the pointer), and therefore, expands to foreign-slot-value, so the behavior you're seeing is correct. Your fix to your code is the correct
way
to access the pointer. I think with-foreign-slots is provided as a convenient shortcut to get all the values; since it doesn't do what you need, you need to use the actual access form (foreign-slot-pointer in
your
case).
Ah, ok, I am a bit struggling to convert the old way to the new way. It probably has nothing to do with (with-foreign-slots ...), but just my mis understanding and trying to quickly convert old code to new.
Well, there's a bit of unwritten convention being used, so confusion is understandable (and I had to think about it and infer what with-foreign-slots is intended to do). Before we introduced structures-by-value, this wasn't an issue.
For your second question: if the argument is actually a pointer to the structure, :pointer is the right thing to use. Are you sure it is a
pointer
argument? Check the .h file where it is defined.
Ah, I do not have an issue with passing it to the c library. What I meant was that in my mind the following confused me:
(let ((c-oid (foreing-alloc '(:struct git-oid)))) ;;; I think of c-oid, conceptually as type ;;; (:pointer (:struct git-oid)) ;;;; later: (foreign-slot-pointer c-oid '(:struct git-oid) 'id) ;;; I thought that because c-oid is of type ;;; (:pointer (:struct git-oid)) ;;; I thought I needed to put here ;;; '(:pointer (:struct git-oid)) instead of ;;; '(:struct git-oid)
Does this make sense?
The documentation to foreign-slot-pointerhttp://common-lisp.net/project/cffi/manual/html_node/foreign_002dslot_002dpointer.html says " ptr A pointer to a structure. type A foreign structure type. "
so it makes sense to me the that first argument is a pointer to a structure, and the second argument is the type of that structure (and not the type of the first argument, i.e., the pointer type).
Now I have a small additional question.
I have a struct like:
(defcstruct (git-index-time :class index-time-struct) ....)
Now the (translate-from-foreign value (type index-time-struct)) works if I use as type:
(:struct git-index-time)
So everyting works. However, if I do:
(defctype struct-index-time (:struct git-index-time))
And use as type:
struct-index-time
The `translate-from-foreign` is not called and I end up with untranslated values.
I thought that (defctype ...) worked as a typedef and naively expected the type translation to still work.
Is this as expected?
No, that seems like a CFFI error. Per Luis, a bug report would be helpful.
Liam