本文整理汇总了C++中FFI_FN函数的典型用法代码示例。如果您正苦于以下问题:C++ FFI_FN函数的具体用法?C++ FFI_FN怎么用?C++ FFI_FN使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了FFI_FN函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main (void)
{
ffi_cif cif;
ffi_type *args[MAX_ARGS];
void *values[MAX_ARGS];
ffi_arg rint;
char *s;
args[0] = &ffi_type_pointer;
values[0] = (void*) &s;
/* Initialize the cif */
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
&ffi_type_sint, args) == FFI_OK);
s = "a";
ffi_call(&cif, FFI_FN(my_strlen), &rint, values);
CHECK(rint == 1);
s = "1234567";
ffi_call(&cif, FFI_FN(my_strlen), &rint, values);
CHECK(rint == 7);
s = "1234567890123456789012345";
ffi_call(&cif, FFI_FN(my_strlen), &rint, values);
CHECK(rint == 25);
exit (0);
}
示例2: main
int main (void)
{
ffi_cif cif;
ffi_type *args[MAX_ARGS];
void *values[MAX_ARGS];
ffi_arg rint;
char *s;
float v2;
args[0] = &ffi_type_pointer;
args[1] = &ffi_type_float;
values[0] = (void*) &s;
values[1] = (void*) &v2;
/* Initialize the cif */
CHECK(ffi_prep_cif(&cif, ABI_NUM, 2,
&ffi_type_sint, args) == FFI_OK);
s = "a";
v2 = 0.0;
ffi_call(&cif, FFI_FN(my_f), &rint, values);
CHECK(rint == 1);
s = "1234567";
v2 = -1.0;
ffi_call(&cif, FFI_FN(my_f), &rint, values);
CHECK(rint == 6);
s = "1234567890123456789012345";
v2 = 1.0;
ffi_call(&cif, FFI_FN(my_f), &rint, values);
CHECK(rint == 26);
exit(0);
}
示例3: main
int main (void)
{
ffi_cif cif;
ffi_type *args[MAX_ARGS];
void *values[MAX_ARGS];
double rd;
float f;
double d;
long double ld;
args[0] = &ffi_type_float;
values[0] = &f;
args[1] = &ffi_type_double;
values[1] = &d;
args[2] = &ffi_type_longdouble;
values[2] = &ld;
/* Initialize the cif */
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 3,
&ffi_type_double, args) == FFI_OK);
f = 3.14159;
d = (double)1.0/(double)3.0;
ld = 2.71828182846L;
floating_1 (f, d, ld);
ffi_call(&cif, FFI_FN(floating_1), &rd, values);
CHECK(fabs(rd - floating_1(f, d, ld)) < DBL_EPSILON);
args[0] = &ffi_type_longdouble;
values[0] = &ld;
args[1] = &ffi_type_double;
values[1] = &d;
args[2] = &ffi_type_float;
values[2] = &f;
/* Initialize the cif */
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 3,
&ffi_type_double, args) == FFI_OK);
floating_2 (ld, d, f);
ffi_call(&cif, FFI_FN(floating_2), &rd, values);
CHECK(fabs(rd - floating_2(ld, d, f)) < DBL_EPSILON);
exit (0);
}
示例4: invokeArray
static void
invokeArray(JNIEnv* env, jlong ctxAddress, jbyteArray paramBuffer, void* returnBuffer)
{
Function* ctx = (Function *) j2p(ctxAddress);
union { double d; long long ll; jbyte tmp[PARAM_SIZE]; } tmpStackBuffer[MAX_STACK_ARGS];
jbyte *tmpBuffer = (jbyte *) &tmpStackBuffer[0];
if (ctx->cif.nargs > 0) {
if (ctx->cif.bytes > (int) sizeof(tmpStackBuffer)) {
tmpBuffer = alloca_aligned(ctx->cif.bytes, MIN_ALIGN);
}
// calculate room needed for return address for struct returns
int adj = ctx->cif.rtype->type == FFI_TYPE_STRUCT ? sizeof(void *) : 0;
(*env)->GetByteArrayRegion(env, paramBuffer, 0, ctx->rawParameterSize, tmpBuffer + adj);
}
// For struct return values, we need to push a return value address on the parameter stack
if (ctx->cif.rtype->type == FFI_TYPE_STRUCT) {
*(void **) tmpBuffer = returnBuffer;
}
ffi_raw_call(&ctx->cif, FFI_FN(ctx->function), returnBuffer, (ffi_raw *) tmpBuffer);
set_last_error(errno);
}
示例5: main
int main (void)
{
ffi_cif cif;
ffi_type *args[MAX_ARGS];
void *values[MAX_ARGS];
float fl1, fl2, fl4, rfl;
unsigned int in3;
args[0] = &ffi_type_float;
args[1] = &ffi_type_float;
args[2] = &ffi_type_uint;
args[3] = &ffi_type_float;
values[0] = &fl1;
values[1] = &fl2;
values[2] = &in3;
values[3] = &fl4;
/* Initialize the cif */
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 4,
&ffi_type_float, args) == FFI_OK);
fl1 = 127.0;
fl2 = 128.0;
in3 = 255;
fl4 = 512.7;
ffi_call(&cif, FFI_FN(return_fl), &rfl, values);
printf ("%f vs %f\n", rfl, return_fl(fl1, fl2, in3, fl4));
CHECK(rfl == fl1 + fl2 + in3 + fl4);
exit(0);
}
示例6: main
int main(void)
{
ffi_cif cif;
ffi_type *args[4] = {
&ffi_type_sint,
&ffi_type_double,
&ffi_type_sint,
&ffi_type_double
};
double fa[2] = {1,2};
int ia[2] = {1,2};
void *values[4] = {&ia[0], &fa[0], &ia[1], &fa[1]};
float f, ff;
/* Initialize the cif */
CHECK(ffi_prep_cif(&cif, ABI_NUM, 4,
&ffi_type_float, args) == FFI_OK);
ff = align_arguments(ia[0], fa[0], ia[1], fa[1]);;
ffi_call(&cif, FFI_FN(align_arguments), &f, values);
if (f == ff)
printf("align arguments tests ok!\n");
else
CHECK(0);
exit(0);
}
示例7: Java_com_kenai_jffi_Foreign_invokeArrayReturnStruct
/*
* Class: com_kenai_jffi_Foreign
* Method: invokeArrayReturnStruct
* Signature: (J[B[B)V
*/
JNIEXPORT void JNICALL
Java_com_kenai_jffi_Foreign_invokeArrayReturnStruct(JNIEnv* env, jclass self, jlong ctxAddress,
jbyteArray paramBuffer, jbyteArray returnBuffer, jint offset)
{
Function* ctx = (Function *) j2p(ctxAddress);
jbyte* retval = alloca(ctx->cif.rtype->size);
jbyte* tmpBuffer;
void** ffiArgs;
int i;
//
// Due to the undocumented and somewhat strange struct-return handling when
// using ffi_raw_call(), we convert from raw to ptr array, then call via normal
// ffi_call
//
ffiArgs = alloca(ctx->cif.nargs * sizeof(void *));
#ifdef USE_RAW
tmpBuffer = alloca(ctx->rawParameterSize);
(*env)->GetByteArrayRegion(env, paramBuffer, 0, ctx->rawParameterSize, tmpBuffer);
for (i = 0; i < (int) ctx->cif.nargs; ++i) {
ffiArgs[i] = (tmpBuffer + ctx->rawParamOffsets[i]);
}
#else
tmpBuffer = alloca(ctx->cif.nargs * PARAM_SIZE);
(*env)->GetByteArrayRegion(env, paramBuffer, 0, ctx->cif.nargs * PARAM_SIZE, tmpBuffer);
for (i = 0; i < (int) ctx->cif.nargs; ++i) {
ffiArgs[i] = &tmpBuffer[i * PARAM_SIZE];
}
#endif
ffi_call(&ctx->cif, FFI_FN(ctx->function), retval, ffiArgs);
SAVE_ERRNO(ctx);
(*env)->SetByteArrayRegion(env, returnBuffer, offset, ctx->cif.rtype->size, retval);
}
示例8: main
int main (void)
{
ffi_cif cif;
ffi_type *args[MAX_ARGS];
void *values[MAX_ARGS];
ffi_arg res;
unsigned long ul1, ul2;
args[0] = &ffi_type_ulong;
args[1] = &ffi_type_ulong;
values[0] = &ul1;
values[1] = &ul2;
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2,
&ffi_type_ulong, args) == FFI_OK);
ul1 = 1073741823L;
ul2 = 1073741824L;
ffi_call(&cif, FFI_FN(return_ul), &res, values);
printf("res: %lu, %lu\n", (unsigned long)res, ul1 + ul2);
/* { dg-output "res: 2147483647, 2147483647" } */
exit(0);
}
示例9: main
int main (void)
{
ffi_cif cif;
ffi_type *args[MAX_ARGS];
void *values[MAX_ARGS];
ffi_arg rint;
short us;
short us2;
unsigned long ul = 0;
args[0] = &ffi_type_ushort;
args[1] = &ffi_type_ushort;
values[0] = &us;
values[1] = &us2;
/* Initialize the cif */
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2,
&ffi_type_uint, args) == FFI_OK);
for (us = 55; us < 30000; us+=1034) {
for (us2 = 100; us2 < 30000; us2+=1945) {
ffi_call(&cif, FFI_FN(promotion), &rint, values);
CHECK((unsigned int)rint == (us << 16 | us2));
}
}
printf("%lu promotion2 tests run\n", ul);
exit(0);
}
示例10: main
int main (void)
{
ffi_cif cif;
ffi_type *args[MAX_ARGS];
void *values[MAX_ARGS];
ffi_arg res;
unsigned long l1, l2;
args[0] = &ffi_type_slong;
args[1] = &ffi_type_slong;
values[0] = &l1;
values[1] = &l2;
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2,
&ffi_type_slong, args) == FFI_OK);
l1 = 1073741823L;
l2 = 1073741824L;
ffi_call(&cif, FFI_FN(return_sl), &res, values);
printf("res: %ld, %ld\n", (long)res, l1 - l2);
/* { dg-output "res: -1, -1" } */
exit(0);
}
示例11: main
int main (void)
{
ffi_cif cif;
ffi_type *args[13];
void *values[13];
float fa[13];
float f, ff;
int i;
for (i = 0; i < 13; i++)
{
args[i] = &ffi_type_float;
values[i] = &fa[i];
fa[i] = (float) i;
}
/* Initialize the cif */
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 13,
&ffi_type_float, args) == FFI_OK);
ffi_call(&cif, FFI_FN(many), &f, values);
ff = many(fa[0], fa[1],
fa[2], fa[3],
fa[4], fa[5],
fa[6], fa[7],
fa[8], fa[9],
fa[10],fa[11],fa[12]);
if (fabs(f - ff) < FLT_EPSILON)
exit(0);
else
abort();
}
示例12: main
int main (void)
{
ffi_cif cif;
ffi_type *args[MAX_ARGS];
void *values[MAX_ARGS];
ffi_arg rint;
signed char sc;
unsigned long ul;
args[0] = &ffi_type_schar;
values[0] = ≻
/* Initialize the cif */
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
&ffi_type_schar, args) == FFI_OK);
for (sc = (signed char) -127;
sc < (signed char) 127; sc++)
{
ul++;
ffi_call(&cif, FFI_FN(return_sc), &rint, values);
CHECK(rint == (ffi_arg) sc);
}
exit(0);
}
示例13: invokeArray
static void
invokeArray(JNIEnv* env, jlong ctxAddress, jbyteArray paramBuffer, void* returnBuffer)
{
Function* ctx = (Function *) j2p(ctxAddress);
void** ffiArgs = { NULL };
jbyte *tmpBuffer = NULL;
if (ctx->cif.nargs > 0) {
unsigned int i;
tmpBuffer = alloca(ctx->cif.nargs * PARAM_SIZE);
ffiArgs = alloca(ctx->cif.nargs * sizeof(void *));
(*env)->GetByteArrayRegion(env, paramBuffer, 0, ctx->cif.nargs * PARAM_SIZE, tmpBuffer);
for (i = 0; i < ctx->cif.nargs; ++i) {
if (unlikely(ctx->cif.arg_types[i]->type == FFI_TYPE_STRUCT)) {
ffiArgs[i] = *(void **) &tmpBuffer[i * PARAM_SIZE];
} else {
ffiArgs[i] = &tmpBuffer[i * PARAM_SIZE];
}
}
}
ffi_call(&ctx->cif, FFI_FN(ctx->function), returnBuffer, ffiArgs);
SAVE_ERRNO(ctx);
}
示例14: mrb_digest_hmac_hexdigest
static mrb_value
mrb_digest_hmac_hexdigest(mrb_state *mrb, mrb_value self) {
mrb_digest *digest;
void *ctx_tmp;
unsigned char md[MRB_DIGEST_AVAILABLE_SIZ];
size_t md_len;
char hex[MRB_HEXDIGEST_AVAILABLE_SIZ];
digest = mrb_get_datatype(mrb, self, &mrb_hmac_type);
if (digest == NULL) {
mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid argument");
}
ctx_tmp = malloc(digest->ctx_size);
if (ctx_tmp == NULL) {
mrb_raise(mrb, E_RUNTIME_ERROR, "cannot allocate memory");
}
memcpy(ctx_tmp, digest->ctx, digest->ctx_size);
md_len = 0L;
call_hmac_final(mrb, FFI_FN(digest->func_final), ctx_tmp, md, &md_len);
free(ctx_tmp);
return mrb_str_new(mrb, (const char *)digest2hex(hex, md, md_len), md_len * 2);
}
示例15: __tgt_rtl_run_target_team_region
int32_t __tgt_rtl_run_target_team_region(int32_t device_id, void *tgt_entry_ptr,
void **tgt_args, int32_t arg_num, int32_t team_num, int32_t thread_limit,
uint64_t loop_tripcount /*not used*/) {
// ignore team num and thread limit.
// Use libffi to launch execution.
ffi_cif cif;
// All args are references.
std::vector<ffi_type *> args_types(arg_num, &ffi_type_pointer);
std::vector<void *> args(arg_num);
for (int32_t i = 0; i < arg_num; ++i)
args[i] = &tgt_args[i];
ffi_status status = ffi_prep_cif(&cif, FFI_DEFAULT_ABI, arg_num,
&ffi_type_void, &args_types[0]);
assert(status == FFI_OK && "Unable to prepare target launch!");
if (status != FFI_OK)
return OFFLOAD_FAIL;
DP("Running entry point at " DPxMOD "...\n", DPxPTR(tgt_entry_ptr));
ffi_call(&cif, FFI_FN(tgt_entry_ptr), NULL, &args[0]);
return OFFLOAD_SUCCESS;
}