gcl-devel
[Top][All Lists]
Advanced

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

[Gcl-devel] Re: some questions about clines and defentry


From: Camm Maguire
Subject: [Gcl-devel] Re: some questions about clines and defentry
Date: 11 May 2006 09:41:58 -0400
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2

Vanuxem Grégory <address@hidden> writes:

> Hi,
> 
> If I create an empty array with for example:
> 
> (make-array 0 :element-type 'long-float :static t)
> or
> (make-array 0 :element-type '(signed-byte 32) :static t)
> 
> Do their internal C structures contain the 'lfa.lfa_self' or
> 'fixa.fixa_self' member ? More precisely, I write an interface to

The object pointer denotes a union, two alternates of which are
structures containing the indicated element:

struct fixarray {               /*  fixnum array header  */
                FIRSTWORD;
        object  fixa_displaced; /*  displaced  */
        short   fixa_rank;      /*  array rank  */
        short   fixa_elttype;   /*  element type  */
        fixnum  *fixa_self;     /*  pointer to the array  */
        short   fixa_adjustable;/*  adjustable flag  */
        short   fixa_offset;    /*  not used  */
        int     fixa_dim;       /*  dimension  */
        int     *fixa_dims;     /*  table of dimensions  */

};

struct lfarray {                /*  plong-float array header  */
                FIRSTWORD;
        object  lfa_displaced;  /*  displaced  */
        short   lfa_rank;       /*  array rank  */
        short   lfa_elttype;    /*  element type  */
        longfloat
                *lfa_self;      /*  pointer to the array  */
        short   lfa_adjustable; /*  adjustable flag  */
        short   lfa_offset;     /*  not used  */
        int     lfa_dim;                /*  dimension  */
        int     *lfa_dims;      /*  table of dimensions  */


};

union lispunion {
        struct fixnum_struct
                        FIX;    /*  fixnum  */
        struct bignum   big;    /*  bignum  */
        struct ratio    rat;    /*  ratio  */
        struct shortfloat_struct
                        SF;     /*  short floating-point number  */
        struct longfloat_struct
                        LF;     /*  plong floating-point number  */
        struct complex  cmp;    /*  complex number  */
        struct character
                        ch;     /*  character  */
        struct symbol   s;      /*  symbol  */
        struct package  p;      /*  package  */
        struct cons     c;      /*  cons  */
        struct hashtable
                        ht;     /*  hash table  */
        struct array    a;      /*  array  */
        struct vector   v;      /*  vector  */
        struct string   st;     /*  string  */
        struct ustring  ust;
        struct bitvector
                        bv;     /*  bit-vector  */
        struct structure
                        str;    /*  structure  */
        struct stream   sm;     /*  stream  */
        struct random   rnd;    /*  random-states  */
        struct readtable
                        rt;     /*  read table  */
        struct pathname pn;     /*  path name  */
        struct cfun     cf;     /*  compiled function  uses value stack] */
        struct cclosure cc;     /*  compiled closure  uses value stack */
        struct closure  cl;     /*  compiled closure  uses c stack */
        struct sfun     sfn;    /*  simple function */
        struct vfun     vfn;    /*  function with variable number of args */
        struct cfdata   cfd;    /* compiled fun data */
        struct spice    spc;    /*  spice  */

        struct dummy    d;      /*  dummy  */

        struct fixarray fixa;   /*  fixnum array  */
        struct sfarray  sfa;    /*  short-float array  */
        struct lfarray  lfa;    /*  plong-float array  */
};



> C/Fortran programs (with defentry and clines) but in these programs some
> array are sometimes not referenced. So I'm wondering if I can use an
> empty array in these cases. The C code (clines) has to contain
> 'lfa.lfa_self' or 'fixa.fixa_self' since these arrays can be referenced
> (that depends on the function arguments).

Empty arrays sould be fine as long as the C/Fortran does not
overread/write the (zero) bounds.

> 
> 
> Another question, what is the internal structure of long-float and
> (signed-byte 32) ? Is it possible to pass to a fortran routine
> pointer to their data or do I have to use an array ?.
> 


struct longfloat_struct {
                        FIRSTWORD;
        longfloat       LFVAL;  /*  longfloat value  */
};

So you could do:

static void foo (object x) {
/*maybe check type is lf here*/
c_routine_taking_double(x->lf.LFVAL);
}

> 
> Last question, from the documentation of defentry I should declare any
> variables and functions to be static (in order for C code to be loaded
> in by `load') but in my code 'info' is not static, so do I have to
> declare  info as static ("static info = 0") ? Here is a sample of my
> code:
> 
> (clines "
> static int my_wrapper(int n, double test)
> {
> int info = 0;
> // call to my Fortran function
> my_function(&n, &test, &info);
> return(info);
> }
> ")
> 

This is fine -- the function and/or global variables only need to be
static.

Take care,

> 
> 
> Cheers,
> 
> Greg
> 
> 
> 

-- 
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]