libffi memo
# libffi
----
% find . -type f -name '*' -exec grep -nH ' ffi' {} \; | grep -v test
./common/autoconf/lib-ffi.m4:101: ffi_call(NULL, NULL, NULL, NULL);
./common/autoconf/help.m4:118: ffi)
./common/autoconf/generated-configure.sh:4216: ffi)
./common/autoconf/generated-configure.sh:54670: # Check if ffi is needed
./common/autoconf/generated-configure.sh:65057: for ac_header in ffi.h
./common/autoconf/generated-configure.sh:65080: # ffi is the help tag: freetype, cups, alsa etc
./common/autoconf/generated-configure.sh:65132: ffi_call(NULL, NULL, NULL, NULL);
./common/autoconf/generated-configure.sh:65161: # ffi is the help tag: freetype, cups, alsa etc
./common/autoconf/libraries.m4:71: # Check if ffi is needed
./make/devkit/Tools.gmk:212:# Create links for ffi header files so that they become visible by default when using the
%
----
# compiling
brew instal automake
11068 ./autogen.sh
11070 ./configure --prefix=$HOME/opt/libffi
11073 make
11075 make install
---
/* This is a generic definition of ffi_raw_call, to be used if the
* native system does not provide a machine-specific implementation.
* Having this, allows code to be written for the raw API, without
* the need for system-specific code to handle input in that format;
* these following couple of functions will handle the translation forth
* and back automatically. */
void ffi_raw_call (ffi_cif *cif, void (*fn)(void), void *rvalue, ffi_raw *raw)
{
void **avalue = (void**) alloca (cif->nargs * sizeof (void*));
ffi_raw_to_ptrarray (cif, raw, avalue);
ffi_call (cif, fn, rvalue, avalue);
}
---
`
void
ffi_raw_call(
/*@dependent@*/ ffi_cif* cif,
void (*fn)(void),
/*@out@*/ void* rvalue,
/*@dependent@*/ ffi_raw* avalue);
`
`
void
ffi_call(
/*@dependent@*/ ffi_cif* cif,
void (*fn)(void),
/*@out@*/ void* rvalue,
/*@dependent@*/ void** avalue);
`
---
## Mac
### install
$ brew install libffi
export PKG_CONFIG_PATH=/usr/local/opt/libffi/lib/pkgconfig
$ PKG_CONFIG_PATH=/usr/local/opt/libffi/lib/pkgconfig pkg-config libffi --libs
-L/usr/local/Cellar/libffi/3.2.1/lib -lffi
$ ls /usr/include/ffi
ffi.h ffi_common.h fficonfig.h ffitarget.h ppc-darwin.h ppc-ffitarget.h x86-ffitarget.h
----
-
- typedef struct ffi_type
- typedef enum ffi_status
- typedef unsigned FFI_TYPE;
- typedef struct ffi_cif;
- Definitions for the raw API
- typedef union {} ffi_raw;
- ffi_raw_call()
- ffi_ptrarray_to_raw()
- ffi_raw_to_ptrarray()
- ffi_raw_size()
- ffi_java_raw_call()
- ffi_java_ptrarray_to_raw()
- ffi_java_raw_to_ptrarray()
- ffi_java_raw_size()
- Definitions for closures
- typedef struct ffi_closure
- ffi_prep_closure()
- typedef struct ffi_raw_closure
- ffi_prep_raw_closure()
- ffi_prep_java_raw_closure()
- Public interface definition
- ffi_prep_cif()
- ffi_call()
----
- install
- 11068 ./autogen.sh
- 11070 ./configure --prefix=$HOME/opt/libffi
- 11073 make
- 11075 make install
- sample コードないの関数を ffi を使って実行する
- dlopen, dlsym 関数ポインタの取得
- sample
- Definitions for the raw API
- ffi_raw_call()
- ffi_ptrarray_to_raw()
- ffi_raw_to_ptrarray()
- ffi_raw_size()
- Definitions for closures
- typedef struct ffi_closure
- ffi_prep_closure()
- typedef struct ffi_raw_closure
- Public interface definition
- ffi_prep_cif()
- ffi_call()
- java?
- ffi_java_raw_call()
- ffi_java_ptrarray_to_raw()
- ffi_java_raw_to_ptrarray()
- ffi_java_raw_size()
- ffi_prep_raw_closure()
- ffi_prep_java_raw_closure()
- 引数、戻り値(return type, return value)
- 数値、文字、文字列...
- array, struct, enum, union
- マクロ
- グローバル変数