Paste: FFI C-STRUCT:

Author: dlh
Mode: factor
Date: Tue, 2 Dec 2008 01:46:51
Plain Text |
I have a simple struct:

C-STRUCT: WPS_SimpleAuthentication
    { "char*" "username" }
    { "char*" "realm" } ;

Used like this:

"blah" "WPS_SimpleAuthentication" <c-object> set-WPS_SimpleAuthentication-username

results in this error:

Type check error
Object: "blah"
Object type: string
Expected type: alien

Annotation: destructor

Author: slava
Mode: factor
Date: Tue, 2 Dec 2008 01:49:23
Plain Text |
[
    "WPS_SimpleAuthentication" <c-object>

    "blah" ascii malloc-string &dispose
    over set-WPS_SimpleAuthentication-username

    ! ... do stuff with the struct, which is on the stack ...

] with-destructors
! string is free()'s for you

Annotation: destructor correction

Author: dlh
Mode: factor
Date: Tue, 2 Dec 2008 02:15:49
Plain Text |
[
    "WPS_SimpleAuthentication" <c-object>

    ! use &free from libc vocab instead of &dispose
    "blah" ascii malloc-string &free
    over set-WPS_SimpleAuthentication-username

    ! ... do stuff with the struct, which is on the stack ...

] with-destructors
! string is free()'s for you

New Annotation

Summary:
Author:
Mode:
Body: