gcl-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Gcl-devel] Storing C structure pointers in lisp


From: Camm Maguire
Subject: Re: [Gcl-devel] Storing C structure pointers in lisp
Date: 06 Aug 2004 18:38:27 -0400
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2

Greetings!  What you want to do is quite possible with a little work. 

Take a look at GCL's 'structure' structure:

struct structure {              /*  structure header  */
                FIRSTWORD;
        object  str_def;        /*  structure definition (a structure)  */
        object  *str_self;      /*  structure self  */
};

struct s_data {object name;
               int length;
               object raw;
               object included;
               object includes;
               object staticp;
               object print_function;
               object slot_descriptions;
               object slot_position;
               int    size;
               object has_holes;
             };

#define USHORT_GCL(x,i) (((unsigned short *)(x)->ust.ust_self)[i])

#define S_DATA(x) ((struct s_data *)((x)->str.str_self))
#define SLOT_TYPE(def,i) (((S_DATA(def))->raw->ust.ust_self[i]))
#define SLOT_POS(def,i) USHORT_GCL(S_DATA(def)->slot_position,i)
#define STREF(type,x,i) (*((type *)(((char *)((x)->str.str_self))+(i))))


Your data goes in raw, and the offsets in slot_position.  Also check
the supplied functions for making/accessing structures at the end of
structure.c.  The can be called from C via the names supplied as the
second argument to make_function.

Please keep us posted,

David Kirkman <address@hidden> writes:

> Hi All,
> 
>    I'm interfacing gcl with some old C code of mine.  I have a lot of
> functions which take structure pointers as parameters.  The structures
> are created, manipulated, and freed entirely in C, but it would be
> mighty convenient to be able to hold onto them in lisp.
> 
>    Is there a standard (or easy) way to do this in gcl?
> 
>    For the moment, I'm casting the pointer to an int and sending the
> int back to gcl.  I'm doing the interface with (defentry) and some
> scaffolding (clines) to do the back and forth casting.  I've looked at
> the lispunion types in h/object.h, but I don't see anything that looks
> like it is meant to hold onto a C side pointer.  Am I missing something?
> 
> Thanks,
> 
> -david k.
> 
> 
> 
> _______________________________________________
> Gcl-devel mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/gcl-devel
> 
> 
> 

-- 
Camm Maguire                                            address@hidden
==========================================================================
"The earth is but one country, and mankind its citizens."  --  Baha'u'llah




reply via email to

[Prev in Thread] Current Thread [Next in Thread]