Lisp HUG Maillist Archive

FLI question: Attempted to dereference a pointer to aggregate type... [structs/unions in structs/unions]

Hi everybody,

I'm trying to translate something like this from C to Lisp:

  typedef struct {
    int one;
    int two;
    struct {
      int three;
      int four;
    } bar;
  } foo;

I first tried this:

  (define-c-struct foo
    (one :int)
    (two :int)
    (bar (:struct (three :int)
                  (four :int))))

Then this:

  (define-c-struct bar
    (three :int)
    (four :int))

  (define-c-struct foo
    (one :int)
    (two :int)
    (bar bar))

And then this:

  (define-c-typedef bar-struct (:struct bar))

  (define-c-struct foo
    (one :int)
    (two :int)
    (bar bar-struct))

All three definitions are accepted by LispWorks, but in none of
these cases am I able to access the slots THREE and FOUR - I
always get:

  "Attempted to dereference a pointer to aggregate type..."

What is the right idiom to do this?

And, actually, the real problem is even more complicated as I
have to deal with a struct which contains a union of two other
structs.  But I think the short example above demonstrates where
I can't proceed.

Thanks in advance for your help,
Edi.

_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html


Re: FLI question: Attempted to dereference a pointer to aggregate type... [structs/unions in structs/unions]

Ah, wait!  Just after I sent this I came across FOREIGN-SLOT-POINTER
which seems to do what I want.

(Still, even if this hopefully solves my problem I'd suggest to add a
couple more examples with complicated C structs and unions and how to
access them to the FLI docs.)

On Thu, Jan 16, 2014 at 7:45 PM, Edi Weitz <edi@weitz.de> wrote:
> Hi everybody,
>
> I'm trying to translate something like this from C to Lisp:
>
>   typedef struct {
>     int one;
>     int two;
>     struct {
>       int three;
>       int four;
>     } bar;
>   } foo;
>
> I first tried this:
>
>   (define-c-struct foo
>     (one :int)
>     (two :int)
>     (bar (:struct (three :int)
>                   (four :int))))
>
> Then this:
>
>   (define-c-struct bar
>     (three :int)
>     (four :int))
>
>   (define-c-struct foo
>     (one :int)
>     (two :int)
>     (bar bar))
>
> And then this:
>
>   (define-c-typedef bar-struct (:struct bar))
>
>   (define-c-struct foo
>     (one :int)
>     (two :int)
>     (bar bar-struct))
>
> All three definitions are accepted by LispWorks, but in none of
> these cases am I able to access the slots THREE and FOUR - I
> always get:
>
>   "Attempted to dereference a pointer to aggregate type..."
>
> What is the right idiom to do this?
>
> And, actually, the real problem is even more complicated as I
> have to deal with a struct which contains a union of two other
> structs.  But I think the short example above demonstrates where
> I can't proceed.
>
> Thanks in advance for your help,
> Edi.

_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html


Re: FLI question: Attempted to dereference a pointer to aggregate type... [structs/unions in structs/unions]

Edi this is documented behavior

Check FLI:DEREFERENCE keyword args AFAIR

For later, try to FOREIGN-PARSER the header to get clues about how to
translate to FLI

Sent from my iPad

> On 16 Jan 2014, at 22:51, Edi Weitz <edi@weitz.de> wrote:
>
>
> Ah, wait!  Just after I sent this I came across FOREIGN-SLOT-POINTER
> which seems to do what I want.
>
> (Still, even if this hopefully solves my problem I'd suggest to add a
> couple more examples with complicated C structs and unions and how to
> access them to the FLI docs.)
>
>> On Thu, Jan 16, 2014 at 7:45 PM, Edi Weitz <edi@weitz.de> wrote:
>> Hi everybody,
>>
>> I'm trying to translate something like this from C to Lisp:
>>
>>  typedef struct {
>>    int one;
>>    int two;
>>    struct {
>>      int three;
>>      int four;
>>    } bar;
>>  } foo;
>>
>> I first tried this:
>>
>>  (define-c-struct foo
>>    (one :int)
>>    (two :int)
>>    (bar (:struct (three :int)
>>                  (four :int))))
>>
>> Then this:
>>
>>  (define-c-struct bar
>>    (three :int)
>>    (four :int))
>>
>>  (define-c-struct foo
>>    (one :int)
>>    (two :int)
>>    (bar bar))
>>
>> And then this:
>>
>>  (define-c-typedef bar-struct (:struct bar))
>>
>>  (define-c-struct foo
>>    (one :int)
>>    (two :int)
>>    (bar bar-struct))
>>
>> All three definitions are accepted by LispWorks, but in none of
>> these cases am I able to access the slots THREE and FOUR - I
>> always get:
>>
>>  "Attempted to dereference a pointer to aggregate type..."
>>
>> What is the right idiom to do this?
>>
>> And, actually, the real problem is even more complicated as I
>> have to deal with a struct which contains a union of two other
>> structs.  But I think the short example above demonstrates where
>> I can't proceed.
>>
>> Thanks in advance for your help,
>> Edi.
>
> _______________________________________________
> Lisp Hug - the mailing list for LispWorks users
> lisp-hug@lispworks.com
> http://www.lispworks.com/support/lisp-hug.html
>

_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html


Re: FLI question: Attempted to dereference a pointer to aggregate type... [structs/unions in structs/unions]

On Thu, Jan 16, 2014 at 10:23 PM, Raymond C Laning
<rclaning@raytheon.com> wrote:
>
> (foreign-slot-value foreignfoo '(bar three))

Raymond, thanks a lot.  I had never used lists as slot names before,
but I now see that they are documented and that there's even an
example with nested structs in the documentation entry for
FOREIGN-SLOT-VALUE.  Shame on me...

Thanks,
Edi.

_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html


Updated at: 2020-12-10 08:34 UTC