Back to index

python3.2  3.2.2
Classes | Defines | Typedefs | Enumerations | Functions | Variables
ffi.h File Reference
#include <ffitarget.h>
#include <stddef.h>
#include <limits.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _ffi_type
struct  ffi_cif
union  ffi_raw

Defines

#define ffi_type_ulong   ffi_type_uint64
#define ffi_type_slong   ffi_type_sint64
#define FFI_FN(f)   ((void (*)())f)
#define FFI_TYPE_VOID   0
#define FFI_TYPE_INT   1
#define FFI_TYPE_FLOAT   2
#define FFI_TYPE_DOUBLE   3
#define FFI_TYPE_LONGDOUBLE   FFI_TYPE_DOUBLE
#define FFI_TYPE_UINT8   5
#define FFI_TYPE_SINT8   6
#define FFI_TYPE_UINT16   7
#define FFI_TYPE_SINT16   8
#define FFI_TYPE_UINT32   9
#define FFI_TYPE_SINT32   10
#define FFI_TYPE_UINT64   11
#define FFI_TYPE_SINT64   12
#define FFI_TYPE_STRUCT   13
#define FFI_TYPE_POINTER   14
#define FFI_TYPE_LAST   FFI_TYPE_POINTER

Typedefs

typedef struct _ffi_type ffi_type
typedef unsigned FFI_TYPE

Enumerations

enum  ffi_status {
  FFI_OK = 0, FFI_BAD_TYPEDEF, FFI_BAD_ABI, FFI_OK = 0,
  FFI_BAD_TYPEDEF, FFI_BAD_ABI, FFI_OK = 0, FFI_BAD_TYPEDEF,
  FFI_BAD_ABI
}

Functions

void ffi_raw_call (ffi_cif *cif, void(*fn)(), void *rvalue, ffi_raw *avalue)
void ffi_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_raw *raw)
void ffi_raw_to_ptrarray (ffi_cif *cif, ffi_raw *raw, void **args)
size_t ffi_raw_size (ffi_cif *cif)
void ffi_java_raw_call (ffi_cif *cif, void(*fn)(), void *rvalue, ffi_raw *avalue)
void ffi_java_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_raw *raw)
void ffi_java_raw_to_ptrarray (ffi_cif *cif, ffi_raw *raw, void **args)
size_t ffi_java_raw_size (ffi_cif *cif)
ffi_status ffi_prep_cif (ffi_cif *cif, ffi_abi abi, unsigned int nargs, ffi_type *rtype, ffi_type **atypes)
int ffi_call (ffi_cif *cif, void(*fn)(), void *rvalue, void **avalue)

Variables

ffi_type ffi_type_void
ffi_type ffi_type_uint8
ffi_type ffi_type_sint8
ffi_type ffi_type_uint16
ffi_type ffi_type_sint16
ffi_type ffi_type_uint32
ffi_type ffi_type_sint32
ffi_type ffi_type_uint64
ffi_type ffi_type_sint64
ffi_type ffi_type_float
ffi_type ffi_type_double
ffi_type ffi_type_longdouble
ffi_type ffi_type_pointer

Class Documentation

struct _ffi_type

Definition at line 131 of file ffi.h.

Collaboration diagram for _ffi_type:
Class Members
unsigned short alignment
struct _ffi_type ** elements
size_t size
unsigned short type
struct ffi_cif

Definition at line 163 of file ffi.h.

Collaboration diagram for ffi_cif:
Class Members
ffi_abi abi
ffi_type ** arg_types
unsigned bytes
unsigned flags
unsigned nargs
ffi_type * rtype
union ffi_raw

Definition at line 185 of file ffi.h.

Class Members
char data
float flt
void * ptr
ffi_sarg sint
ffi_arg uint

Define Documentation

#define FFI_FN (   f)    ((void (*)())f)

Definition at line 282 of file ffi.h.

#define FFI_TYPE_DOUBLE   3

Definition at line 292 of file ffi.h.

#define FFI_TYPE_FLOAT   2

Definition at line 291 of file ffi.h.

#define FFI_TYPE_INT   1

Definition at line 290 of file ffi.h.

Definition at line 310 of file ffi.h.

Definition at line 296 of file ffi.h.

#define FFI_TYPE_POINTER   14

Definition at line 307 of file ffi.h.

#define FFI_TYPE_SINT16   8

Definition at line 301 of file ffi.h.

#define FFI_TYPE_SINT32   10

Definition at line 303 of file ffi.h.

#define FFI_TYPE_SINT64   12

Definition at line 305 of file ffi.h.

#define FFI_TYPE_SINT8   6

Definition at line 299 of file ffi.h.

Definition at line 119 of file ffi.h.

#define FFI_TYPE_STRUCT   13

Definition at line 306 of file ffi.h.

#define FFI_TYPE_UINT16   7

Definition at line 300 of file ffi.h.

#define FFI_TYPE_UINT32   9

Definition at line 302 of file ffi.h.

#define FFI_TYPE_UINT64   11

Definition at line 304 of file ffi.h.

#define FFI_TYPE_UINT8   5

Definition at line 298 of file ffi.h.

Definition at line 118 of file ffi.h.

#define FFI_TYPE_VOID   0

Definition at line 289 of file ffi.h.


Typedef Documentation

typedef struct _ffi_type ffi_type
typedef unsigned FFI_TYPE

Definition at line 161 of file ffi.h.


Enumeration Type Documentation

enum ffi_status
Enumerator:
FFI_OK 
FFI_BAD_TYPEDEF 
FFI_BAD_ABI 
FFI_OK 
FFI_BAD_TYPEDEF 
FFI_BAD_ABI 
FFI_OK 
FFI_BAD_TYPEDEF 
FFI_BAD_ABI 

Definition at line 155 of file ffi.h.


Function Documentation

int ffi_call ( ffi_cif cif,
void(*)()  fn,
void rvalue,
void **  avalue 
)

Definition at line 243 of file ffi.c.

{
  extended_cif ecif;

  ecif.cif = cif;
  ecif.avalue = avalue;

  if ((rvalue == NULL) && (cif->rtype->type == FFI_TYPE_STRUCT))
    {
      ecif.rvalue = alloca (cif->rtype->size);
    }
  else
    ecif.rvalue = rvalue;

  switch (cif->abi)
    {
    case FFI_SYSV:
      ffi_call_SYSV (ffi_prep_args, &ecif, cif->bytes,
                   cif->flags, ecif.rvalue, fn);
      break;
    default:
      FFI_ASSERT (0);
      break;
    }
}
void ffi_java_ptrarray_to_raw ( ffi_cif cif,
void **  args,
ffi_raw raw 
)
void ffi_java_raw_call ( ffi_cif cif,
void(*)()  fn,
void rvalue,
ffi_raw avalue 
)

Definition at line 45 of file java_raw_api.c.

{
  size_t result = 0;
  int i;

  ffi_type **at = cif->arg_types;

  for (i = cif->nargs-1; i >= 0; i--, at++)
    {
      switch((*at) -> type) {
       case FFI_TYPE_UINT64:
       case FFI_TYPE_SINT64:
       case FFI_TYPE_DOUBLE:
         result += 2 * FFI_SIZEOF_JAVA_RAW;
         break;
       case FFI_TYPE_STRUCT:
         /* No structure parameters in Java.     */
         abort();
       default:
         result += FFI_SIZEOF_JAVA_RAW;
      }
    }

  return result;
}
void ffi_java_raw_to_ptrarray ( ffi_cif cif,
ffi_raw raw,
void **  args 
)
ffi_status ffi_prep_cif ( ffi_cif cif,
ffi_abi  abi,
unsigned int  nargs,
ffi_type rtype,
ffi_type **  atypes 
)

Definition at line 157 of file ffi.c.

{
  unsigned bytes = 0;
  unsigned int i;
  ffi_type **ptr;

  FFI_ASSERT (cif != NULL);
  FFI_ASSERT ((abi > FFI_FIRST_ABI) && (abi <= FFI_DEFAULT_ABI));

  cif->abi = abi;
  cif->arg_types = atypes;
  cif->nargs = nargs;
  cif->rtype = rtype;

  cif->flags = 0;

  if ((cif->rtype->size == 0)
      && (initialize_aggregate_packed_struct (cif->rtype) != FFI_OK))
    return FFI_BAD_TYPEDEF;

  FFI_ASSERT_VALID_TYPE (cif->rtype);

  for (ptr = cif->arg_types, i = cif->nargs; i > 0; i--, ptr++)
    {
      if (((*ptr)->size == 0)
         && (initialize_aggregate_packed_struct ((*ptr)) != FFI_OK))
       return FFI_BAD_TYPEDEF;

      FFI_ASSERT_VALID_TYPE (*ptr);

      if (((*ptr)->alignment - 1) & bytes)
       bytes = ALIGN (bytes, (*ptr)->alignment);
      if ((*ptr)->type == FFI_TYPE_STRUCT)
       {
         if ((*ptr)->size > 8)
           {
             bytes += (*ptr)->size;
             bytes += sizeof (void *);
           }
         else
           {
             if ((*ptr)->size > 4)
              bytes += 8;
             else
              bytes += 4;
           }
       }
      else
       bytes += STACK_ARG_SIZE ((*ptr)->size);
    }

  cif->bytes = bytes;

  return ffi_prep_cif_machdep (cif);
}
void ffi_ptrarray_to_raw ( ffi_cif cif,
void **  args,
ffi_raw raw 
)

Definition at line 129 of file raw_api.c.

{
  unsigned i;
  ffi_type **tp = cif->arg_types;

  for (i = 0; i < cif->nargs; i++, tp++, args++)
    {    
      switch ((*tp)->type)
       {
       case FFI_TYPE_UINT8:
         (raw++)->uint = *(UINT8*) (*args);
         break;

       case FFI_TYPE_SINT8:
         (raw++)->sint = *(SINT8*) (*args);
         break;

       case FFI_TYPE_UINT16:
         (raw++)->uint = *(UINT16*) (*args);
         break;

       case FFI_TYPE_SINT16:
         (raw++)->sint = *(SINT16*) (*args);
         break;

#if FFI_SIZEOF_ARG >= 4
       case FFI_TYPE_UINT32:
         (raw++)->uint = *(UINT32*) (*args);
         break;

       case FFI_TYPE_SINT32:
         (raw++)->sint = *(SINT32*) (*args);
         break;
#endif

#if !FFI_NO_STRUCTS
       case FFI_TYPE_STRUCT:
         (raw++)->ptr = *args;
         break;
#endif

       case FFI_TYPE_POINTER:
         (raw++)->ptr = **(void***) args;
         break;

       default:
         memcpy ((void*) raw->data, (void*)*args, (*tp)->size);
         raw += ALIGN ((*tp)->size, FFI_SIZEOF_ARG) / FFI_SIZEOF_ARG;
       }
    }
}
void ffi_raw_call ( ffi_cif cif,
void(*)()  fn,
void rvalue,
ffi_raw avalue 
)

Definition at line 35 of file raw_api.c.

{
  size_t result = 0;
  int i;

  ffi_type **at = cif->arg_types;

  for (i = cif->nargs-1; i >= 0; i--, at++)
    {
#if !FFI_NO_STRUCTS
      if ((*at)->type == FFI_TYPE_STRUCT)
       result += ALIGN (sizeof (void*), FFI_SIZEOF_ARG);
      else
#endif
       result += ALIGN ((*at)->size, FFI_SIZEOF_ARG);
    }

  return result;
}
void ffi_raw_to_ptrarray ( ffi_cif cif,
ffi_raw raw,
void **  args 
)

Definition at line 57 of file raw_api.c.

{
  unsigned i;
  ffi_type **tp = cif->arg_types;

#if WORDS_BIGENDIAN

  for (i = 0; i < cif->nargs; i++, tp++, args++)
    {    
      switch ((*tp)->type)
       {
       case FFI_TYPE_UINT8:
       case FFI_TYPE_SINT8:
         *args = (void*) ((char*)(raw++) + FFI_SIZEOF_ARG - 1);
         break;
         
       case FFI_TYPE_UINT16:
       case FFI_TYPE_SINT16:
         *args = (void*) ((char*)(raw++) + FFI_SIZEOF_ARG - 2);
         break;

#if FFI_SIZEOF_ARG >= 4       
       case FFI_TYPE_UINT32:
       case FFI_TYPE_SINT32:
         *args = (void*) ((char*)(raw++) + FFI_SIZEOF_ARG - 4);
         break;
#endif
       
#if !FFI_NO_STRUCTS  
       case FFI_TYPE_STRUCT:
         *args = (raw++)->ptr;
         break;
#endif

       case FFI_TYPE_POINTER:
         *args = (void*) &(raw++)->ptr;
         break;
         
       default:
         *args = raw;
         raw += ALIGN ((*tp)->size, FFI_SIZEOF_ARG) / FFI_SIZEOF_ARG;
       }
    }

#else /* WORDS_BIGENDIAN */

#if !PDP

  /* then assume little endian */
  for (i = 0; i < cif->nargs; i++, tp++, args++)
    {    
#if !FFI_NO_STRUCTS
      if ((*tp)->type == FFI_TYPE_STRUCT)
       {
         *args = (raw++)->ptr;
       }
      else
#endif
       {
         *args = (void*) raw;
         raw += ALIGN ((*tp)->size, sizeof (void*)) / sizeof (void*);
       }
    }

#else
#error "pdp endian not supported"
#endif /* ! PDP */

#endif /* WORDS_BIGENDIAN */
}

Variable Documentation

Definition at line 1733 of file cfield.c.

Definition at line 1732 of file cfield.c.

Definition at line 1739 of file cfield.c.

Definition at line 1742 of file cfield.c.

Definition at line 1724 of file cfield.c.

Definition at line 1727 of file cfield.c.

Definition at line 1730 of file cfield.c.

Definition at line 1721 of file cfield.c.

Definition at line 1723 of file cfield.c.

Definition at line 1726 of file cfield.c.

Definition at line 1729 of file cfield.c.

Definition at line 1720 of file cfield.c.

Definition at line 1718 of file cfield.c.