예제 #1
0
파일: sq_ffi.cpp 프로젝트: gdos/squilu-1
static SQInteger sq_lib_bind_var(HSQUIRRELVM v)
{
    void **modbuf;
    void *mod;
    void *sym;
    const SQChar *symname;
    const char *type;

    sq_getuserdata(v, 1, (void**)&modbuf, NULL);
    mod = *modbuf;

    sq_getstring(v, 2, &type);

    sq_getstring(v, 3, &symname);
    sym = GET_SYM(mod, symname);
    if (!sym)
        return sq_throwerror(v, "Cannot find symbol");

    FFIVar *ffibuf = (FFIVar*)sq_newuserdata(v, sizeof(FFIVar));
    sq_push_delegate_table(v, FFI_LIB_VAR_TAG);
    sq_setdelegate(v, -2);

    ffibuf->var = sym;
    ffibuf->type = *type;

    return 1;
}
예제 #2
0
파일: sq_ffi.cpp 프로젝트: gdos/squilu-1
static SQInteger sq_ffi_sym(HSQUIRRELVM v)
{
    void *mod;
    const SQChar *symname;
    sq_getuserpointer(v, 2, &mod);
    sq_getstring(v, 3, &symname);
    void *sym = GET_SYM(mod, symname);
    printf("GET_SYM(%s) = %p\n", symname, sym);
    if (!sym)
        return sq_throwerror(v, "Cannot find symbol");
    void **p = (void**)sq_newuserdata(v, sizeof(sym));
    *p = sym;
    return 1;
}
예제 #3
0
파일: sq_ffi.cpp 프로젝트: gdos/squilu-1
static SQInteger sq_lib_bind_func(HSQUIRRELVM v)
{
    void **modbuf;
    void *mod;
    void *sym;
    const SQChar *symname;
    const char *rettype;

    sq_getuserdata(v, 1, (void**)&modbuf, NULL);
    mod = *modbuf;

    sq_getstring(v, 2, &rettype);

    sq_getstring(v, 3, &symname);
    sym = GET_SYM(mod, symname);
    if (!sym)
        return sq_throwerror(v, "Cannot find symbol");

    int nparam = sq_getsize(v, 4);

    int size = sizeof(FFIFunc) + sizeof(ffi_type*) * nparam;
    FFIFunc *ffibuf = (FFIFunc*)sq_newuserdata(v, size);
    sq_push_delegate_table(v, FFI_LIB_FUNC_TAG);
    sq_setdelegate(v, -2);

//    printf("Allocated %d bytes at %p\n", size, ffibuf);
    ffibuf->func = sym;
    ffibuf->rettype = *rettype;

    int i;
    for (i = 0; i < nparam; i++) {
        sq_pushinteger(v, i);
        sq_get(v, 4);
        ffibuf->params[i] = get_ffi_type(v, -1);
        if (!ffibuf->params[i])
            return SQ_ERROR;
        sq_poptop(v);
    }
    int res = ffi_prep_cif(&ffibuf->cif, FFI_DEFAULT_ABI, nparam, char2ffi_type(*rettype), ffibuf->params);
    if (res != FFI_OK)
        return sq_throwerror(v, "Error in ffi_prep_cif");
    return 1;
}
예제 #4
0
VALUE zkrb_stat_to_rhash(const struct Stat *stat) {
  VALUE ary = rb_hash_new();
  rb_hash_aset(ary, GET_SYM("czxid"),            LL2NUM(stat->czxid));
  rb_hash_aset(ary, GET_SYM("mzxid"),            LL2NUM(stat->mzxid));
  rb_hash_aset(ary, GET_SYM("ctime"),            LL2NUM(stat->ctime));
  rb_hash_aset(ary, GET_SYM("mtime"),            LL2NUM(stat->mtime));
  rb_hash_aset(ary, GET_SYM("version"),         INT2NUM(stat->version));
  rb_hash_aset(ary, GET_SYM("cversion"),        INT2NUM(stat->cversion));
  rb_hash_aset(ary, GET_SYM("aversion"),        INT2NUM(stat->aversion));
  rb_hash_aset(ary, GET_SYM("ephemeralOwner"),   LL2NUM(stat->ephemeralOwner));
  rb_hash_aset(ary, GET_SYM("dataLength"),      INT2NUM(stat->dataLength));
  rb_hash_aset(ary, GET_SYM("numChildren"),     INT2NUM(stat->numChildren));
  rb_hash_aset(ary, GET_SYM("pzxid"),            LL2NUM(stat->pzxid));
  return ary;
}
예제 #5
0
VALUE zkrb_acl_to_ruby(struct ACL *acl) {
  VALUE hash = rb_hash_new();
  rb_hash_aset(hash, GET_SYM("perms"), INT2NUM(acl->perms));
  rb_hash_aset(hash, GET_SYM("id"), zkrb_id_to_ruby(&(acl->id)));
  return hash;
}
예제 #6
0
VALUE zkrb_id_to_ruby(struct Id *id) {
  VALUE hash = rb_hash_new();
  rb_hash_aset(hash, GET_SYM("scheme"), rb_str_new2(id->scheme));
  rb_hash_aset(hash, GET_SYM("id"), rb_str_new2(id->id));
  return hash;
}
예제 #7
0
/* this is called only from a method_get_latest_event, so the hash is
   allocated on the proper thread stack */
VALUE zkrb_event_to_ruby(zkrb_event_t *event) {
  VALUE hash = rb_hash_new();

  rb_hash_aset(hash, GET_SYM("req_id"), LL2NUM(event->req_id));
  if (event->type != ZKRB_WATCHER)
    rb_hash_aset(hash, GET_SYM("rc"), INT2FIX(event->rc));

  switch (event->type) {
    case ZKRB_DATA: {
      struct zkrb_data_completion *data_ctx = event->completion.data_completion;
      if (ZKRBDebugging) zkrb_print_stat(data_ctx->stat);
      rb_hash_aset(hash, GET_SYM("data"), data_ctx->data ? rb_str_new2(data_ctx->data) : Qnil);
      rb_hash_aset(hash, GET_SYM("stat"), data_ctx->stat ? zkrb_stat_to_rarray(data_ctx->stat) : Qnil);
      break;
    }
    case ZKRB_STAT: {
      struct zkrb_stat_completion *stat_ctx = event->completion.stat_completion;
      rb_hash_aset(hash, GET_SYM("stat"), stat_ctx->stat ? zkrb_stat_to_rarray(stat_ctx->stat) : Qnil);
      break;      
    }
    case ZKRB_STRING: {
      struct zkrb_string_completion *string_ctx = event->completion.string_completion;
      rb_hash_aset(hash, GET_SYM("string"), string_ctx->value ? rb_str_new2(string_ctx->value) : Qnil);
      break;
    }
    case ZKRB_STRINGS: {
      struct zkrb_strings_completion *strings_ctx = event->completion.strings_completion;
      rb_hash_aset(hash, GET_SYM("strings"), strings_ctx->values ? zkrb_string_vector_to_ruby(strings_ctx->values) : Qnil);
      break;
    }
    case ZKRB_STRINGS_STAT: {
      struct zkrb_strings_stat_completion *strings_stat_ctx = event->completion.strings_stat_completion;
      rb_hash_aset(hash, GET_SYM("strings"), strings_stat_ctx->values ? zkrb_string_vector_to_ruby(strings_stat_ctx->values) : Qnil);
      rb_hash_aset(hash, GET_SYM("stat"), strings_stat_ctx->stat ? zkrb_stat_to_rarray(strings_stat_ctx->stat) : Qnil);
      break;
    }
    case ZKRB_ACL: {
      struct zkrb_acl_completion *acl_ctx = event->completion.acl_completion;
      rb_hash_aset(hash, GET_SYM("acl"), acl_ctx->acl ? zkrb_acl_vector_to_ruby(acl_ctx->acl) : Qnil);
      rb_hash_aset(hash, GET_SYM("stat"), acl_ctx->stat ? zkrb_stat_to_rarray(acl_ctx->stat) : Qnil);
      break;
    }
    case ZKRB_WATCHER: {
      struct zkrb_watcher_completion *watcher_ctx = event->completion.watcher_completion;
      rb_hash_aset(hash, GET_SYM("type"), INT2FIX(watcher_ctx->type));
      rb_hash_aset(hash, GET_SYM("state"), INT2FIX(watcher_ctx->state));
      rb_hash_aset(hash, GET_SYM("path"), watcher_ctx->path ? rb_str_new2(watcher_ctx->path) : Qnil);
      break;
    }
    case ZKRB_VOID:
    default:
      break;
  }

  return hash;
}
예제 #8
0
static Bool
ResolveFunctions (char *filename)
{
   void *handle;
   Bool failure = 0;

   if(!(handle = dlopen(filename, RTLD_NOW))) {
      printf("%s\n", dlerror());
      return 0;
   }

   GET_SYM(XvMCCreateContext, "XvMCCreateContext");
   GET_SYM(XvMCDestroyContext , "XvMCDestroyContext");
   GET_SYM(XvMCCreateSurface , "XvMCCreateSurface");
   GET_SYM(XvMCDestroySurface , "XvMCDestroySurface");
   GET_SYM(XvMCPutSurface , "XvMCPutSurface");
   GET_SYM(XvMCHideSurface , "XvMCHideSurface");
   GET_SYM(XvMCSyncSurface , "XvMCSyncSurface");
   GET_SYM(XvMCFlushSurface , "XvMCFlushSurface");
   GET_SYM(XvMCGetSurfaceStatus , "XvMCGetSurfaceStatus");
   GET_SYM(XvMCCreateBlocks , "XvMCCreateBlocks");
   GET_SYM(XvMCDestroyBlocks , "XvMCDestroyBlocks");
   GET_SYM(XvMCCreateMacroBlocks , "XvMCCreateMacroBlocks");
   GET_SYM(XvMCDestroyMacroBlocks , "XvMCDestroyMacroBlocks");
   GET_SYM(XvMCRenderSurface , "XvMCRenderSurface");
   GET_SYM(XvMCCopySurfaceToGLXPbuffer , "XvMCCopySurfaceToGLXPbuffer");

   return !failure;
}