コード例 #1
0
ファイル: gl_buffer.c プロジェクト: Mon-Ouie/ray
/* @return [Integer] Amount of per-instance blocks in the buffer */
static
VALUE ray_gl_buffer_instance_size(VALUE self) {
  say_buffer *buf = ray_rb2buffer(self);
  if (!say_buffer_has_instance(buf))
    return Qnil;
  return ULONG2NUM(say_buffer_get_instance_size(buf));
}
コード例 #2
0
static VALUE t_add_oneshot_timer (VALUE self, VALUE interval)
{
	const unsigned long f = evma_install_oneshot_timer (FIX2INT (interval));
	if (!f)
		rb_raise (rb_eRuntimeError, "ran out of timers; use #set_max_timers to increase limit");
	return ULONG2NUM (f);
}
コード例 #3
0
static VALUE t_start_server (VALUE self, VALUE server, VALUE port)
{
	const unsigned long f = evma_create_tcp_server (StringValuePtr(server), FIX2INT(port));
	if (!f)
		rb_raise (rb_eRuntimeError, "no acceptor (port is in use or requires root privileges)");
	return ULONG2NUM (f);
}
コード例 #4
0
ファイル: memory.c プロジェクト: dche/rcl
static VALUE
rcl_mem_image_info(VALUE self, VALUE param_name)
{
    EXPECT_RCL_CONST(param_name);
    cl_image_info ii = FIX2UINT(param_name);
    cl_mem m = MemoryPtr(self);

    cl_image_format imgfmt;

    cl_int res = clGetImageInfo(m, ii, sizeof(cl_image_format), (void *)&imgfmt, NULL);
    CHECK_AND_RAISE(res);

    switch (ii) {
    case CL_IMAGE_FORMAT:
        return RImageFormat(&imgfmt);
    case CL_IMAGE_ELEMENT_SIZE:
    case CL_IMAGE_ROW_PITCH:
    case CL_IMAGE_SLICE_PITCH:
    case CL_IMAGE_WIDTH:
    case CL_IMAGE_HEIGHT:
    case CL_IMAGE_DEPTH:
        return ULONG2NUM(*(size_t *)&imgfmt);
    }
    return Qnil;
}
コード例 #5
0
ファイル: delta_bytes.c プロジェクト: alindeman/hyperll
static VALUE rb_delta_bytes_uncompress(VALUE self, VALUE rcompressed) {
  // copy to a native array
  int rlen = RARRAY_LEN(rcompressed);
  uint8_t *compressed = (uint8_t*)calloc(rlen, sizeof(uint8_t));
  for (int i = 0; i < rlen; i++) {
    compressed[i] = (uint8_t)NUM2INT(rb_ary_entry(rcompressed, i));
  }

  uint32_t *values = (uint32_t*)calloc(rlen, sizeof(uint32_t));
  int vlen = delta_bytes_uncompress(compressed, rlen, values);
  if (vlen < 0) {
    rb_raise(rb_eRuntimeError, "corrupted values");
    goto error;
  }

  VALUE rary = rb_ary_new2(vlen);
  for (int i = 0; i < vlen; i++) {
    rb_ary_push(rary, ULONG2NUM(values[i]));
  }

  free(compressed);
  free(values);
  return rary;
error:
  free(compressed);
  free(values);
  return Qnil;
}
コード例 #6
0
ファイル: memory.c プロジェクト: dche/rcl
static VALUE
rcl_mem_info(VALUE self, VALUE param_name)
{
    EXPECT_RCL_CONST(param_name);

    cl_mem_info mi = FIX2UINT(param_name);
    cl_mem m = MemoryPtr(self);
    intptr_t param_value;

    cl_int res = clGetMemObjectInfo(m, mi, sizeof(intptr_t), &param_value, NULL);
    CHECK_AND_RAISE(res);

    switch (mi) {
    case CL_MEM_TYPE:
    case CL_MEM_FLAGS:
    case CL_MEM_SIZE:
    case CL_MEM_MAP_COUNT:
    case CL_MEM_REFERENCE_COUNT:
        return UINT2NUM(param_value);
    case CL_MEM_HOST_PTR:   // CHECK: Should be wrapped to a HostPoiner? MappedPointer? No.
        return ULONG2NUM(param_value);
    case CL_MEM_CONTEXT:
        return RContext((cl_context)param_value);
    default:
        break;
    }

    return Qnil;
}
コード例 #7
0
ファイル: type_array.c プロジェクト: methodmissing/type_array
void _init_type_array()
{
    rb_cTypeArray = rb_define_class("TypeArray", rb_cObject);
    rb_include_module(rb_cTypeArray, rb_mEnumerable);

    rb_type_array_intern_aget = rb_intern("[]");
    rb_type_array_intern_aset = rb_intern("[]=");
    rb_type_array_intern_superclass = rb_intern("superclass");

    rb_cInt8Array = rb_define_class("Int8Array", rb_cTypeArray);
    rb_cUInt8Array = rb_define_class("UInt8Array", rb_cTypeArray);
    rb_cInt16Array = rb_define_class("Int16Array", rb_cTypeArray);
    rb_cUInt16Array = rb_define_class("UInt16Array", rb_cTypeArray);
    rb_cInt32Array = rb_define_class("Int32Array", rb_cTypeArray);
    rb_cUInt32Array = rb_define_class("UInt32Array", rb_cTypeArray);
    rb_cFloat32Array = rb_define_class("Float32Array", rb_cTypeArray);
    rb_cFloat64Array = rb_define_class("Float64Array", rb_cTypeArray);
    rb_cStructArray = rb_define_class("StructArray", rb_cTypeArray);

    rb_define_const(rb_cInt8Array, "BYTES_PER_ELEMENT", ULONG2NUM(sizeof(signed char)));
    rb_define_const(rb_cUInt8Array, "BYTES_PER_ELEMENT", ULONG2NUM(sizeof(unsigned char)));
    rb_define_const(rb_cInt16Array, "BYTES_PER_ELEMENT", ULONG2NUM(sizeof(short)));
    rb_define_const(rb_cUInt16Array, "BYTES_PER_ELEMENT", ULONG2NUM(sizeof(unsigned short)));
    rb_define_const(rb_cInt32Array, "BYTES_PER_ELEMENT", ULONG2NUM(sizeof(int)));
    rb_define_const(rb_cUInt32Array, "BYTES_PER_ELEMENT", ULONG2NUM(sizeof(unsigned int)));
    rb_define_const(rb_cFloat32Array, "BYTES_PER_ELEMENT", ULONG2NUM(sizeof(float)));
    rb_define_const(rb_cFloat64Array, "BYTES_PER_ELEMENT", ULONG2NUM(sizeof(double)));
    rb_define_const(rb_cStructArray, "BYTES_PER_ELEMENT", INT2NUM(0));

    rb_require("struct_type");
    rb_cStructType = rb_const_get(rb_cObject, rb_intern("StructType"));

    rb_define_singleton_method(rb_cTypeArray, "new", rb_type_array_s_new, -1);
    rb_define_singleton_method(rb_cStructArray, "new", rb_struct_array_s_new, -1);

    rb_define_method(rb_cTypeArray, "byte_length", rb_type_array_byte_length, 0);
    rb_define_method(rb_cTypeArray, "length", rb_type_array_length, 0);
    rb_define_method(rb_cTypeArray, "buffer", rb_type_array_buffer, 0);
    rb_define_method(rb_cTypeArray, "byte_offset", rb_type_array_byte_offset, 0);
    rb_define_method(rb_cTypeArray, "to_s", rb_type_array_to_s, 0);
    rb_define_method(rb_cTypeArray, "[]=", rb_type_array_aset, 2);
    rb_define_method(rb_cTypeArray, "[]", rb_type_array_aget, 1);
    rb_define_method(rb_cTypeArray, "mul", rb_type_array_mul, -1);
    rb_define_method(rb_cTypeArray, "plus", rb_type_array_plus, -1);
    rb_define_method(rb_cTypeArray, "minus", rb_type_array_minus, -1);
    rb_define_method(rb_cTypeArray, "div", rb_type_array_div, -1);
    rb_define_method(rb_cTypeArray, "eql", rb_type_array_eql, 2);
    rb_define_method(rb_cTypeArray, "each", rb_type_array_each, 0);

    rb_define_method(rb_cStructArray, "struct_type", rb_type_array_struct_type, 0);
    rb_undef(rb_cStructArray, rb_intern("mul"));
    rb_undef(rb_cStructArray, rb_intern("plus"));
    rb_undef(rb_cStructArray, rb_intern("minus"));
    rb_undef(rb_cStructArray, rb_intern("div"));
    rb_undef(rb_cStructArray, rb_intern("eql"));
}
コード例 #8
0
ファイル: rbgobj_type.c プロジェクト: benolee/ruby-gnome2
VALUE
rbgobj_gtype_new(GType gtype)
{
    VALUE result = rb_obj_alloc(rbgobj_cType);
    VALUE arg = ULONG2NUM(gtype);
    rb_obj_call_init(result, 1, &arg);
    return result;
}
コード例 #9
0
ファイル: rminfo.c プロジェクト: BMorearty/Webiva
/*
    Method:     Info#scene
                Info#scene=
    Purpose:    Get/Set the scene number
*/
VALUE
Info_scene(VALUE self)
{
    Info *info;

    Data_Get_Struct(self, Info, info);
    return  ULONG2NUM(info->scene);
}
コード例 #10
0
ファイル: midiosx.c プロジェクト: motoakira/midiosx
static VALUE
core_midi_get_destination (VALUE mod, VALUE idx)
{
    ItemCount ic = NUM2UINT(idx);
    MIDIEndpointRef ref = MIDIGetDestination(ic);
    if ((UInt32)NULL == ref) { return Qnil; }
    return ULONG2NUM((UInt32) ref);
}
コード例 #11
0
ファイル: rb_iuptree.c プロジェクト: phasis68/ruby-iup
VALUE rb_IupTreeGetUserId(VALUE node,VALUE v_id)
{
    int id = NUM2INT(v_id);
    void* v;
    VALUE v_ih = rb_iv_get(node,"@ihandle");
    v = IupTreeGetUserId((Ihandle*)NUM2ULONG(v_ih),id);
    return ULONG2NUM((unsigned long)v);
}
コード例 #12
0
ファイル: rubymain.cpp プロジェクト: bernd/eventmachine
static VALUE t_watch_pid (VALUE self, VALUE pid)
{
	try {
		return ULONG2NUM(evma_watch_pid(NUM2INT(pid)));
	} catch (std::runtime_error e) {
		rb_sys_fail(e.what());
	}
}
コード例 #13
0
ファイル: rubymain.cpp プロジェクト: bernd/eventmachine
static VALUE t_watch_filename (VALUE self, VALUE fname)
{
	try {
		return ULONG2NUM(evma_watch_filename(StringValuePtr(fname)));
	} catch (std::runtime_error e) {
		rb_sys_fail(e.what());
	}
}
コード例 #14
0
ファイル: rbgobj_type.c プロジェクト: aurelj/ruby-gnome2
VALUE
rbgobj_gtype_new(GType gtype)
{
    VALUE result = rb_obj_alloc(RG_TARGET_NAMESPACE);
    VALUE arg = ULONG2NUM(gtype);
    rb_obj_call_init(result, 1, &arg);
    return result;
}
コード例 #15
0
/**
 * size
**/
static VALUE t_size(VALUE self)
{
    root_node root;

    Data_Get_Struct(self, struct _root_node, root);

    return ULONG2NUM(root->size);
}
コード例 #16
0
ファイル: gl.c プロジェクト: Mon-Ouie/ray
static
void ray_gl_debug_proc(GLenum source,
                       GLenum type,
                       GLuint id,
                       GLenum severity,
                       GLsizei length,
                       const GLchar *message,
                       GLvoid *param) {
  VALUE rb_source = Qnil;
  switch (source) {
  case GL_DEBUG_SOURCE_API_ARB:
    rb_source = RAY_SYM("api"); break;
  case GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB:
    rb_source = RAY_SYM("window_system"); break;
  case GL_DEBUG_SOURCE_SHADER_COMPILER_ARB:
    rb_source = RAY_SYM("shader_compiler"); break;
  case GL_DEBUG_SOURCE_THIRD_PARTY_ARB:
    rb_source = RAY_SYM("third_party"); break;
  case GL_DEBUG_SOURCE_APPLICATION_ARB:
    rb_source = RAY_SYM("application"); break;
  default:
    rb_source = RAY_SYM("other"); break;
  }

  VALUE rb_type = Qnil;
  switch (type) {
  case GL_DEBUG_TYPE_ERROR_ARB:
    rb_type = RAY_SYM("error"); break;
  case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB:
    rb_type = RAY_SYM("deprecated_behavior"); break;
  case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB:
    rb_type = RAY_SYM("undefined_behavior"); break;
  case GL_DEBUG_TYPE_PORTABILITY_ARB:
    rb_type = RAY_SYM("portability"); break;
  case GL_DEBUG_TYPE_PERFORMANCE_ARB:
    rb_type = RAY_SYM("performance"); break;
  default:
    rb_type = RAY_SYM("other"); break;
  }

  VALUE rb_id = ULONG2NUM(id);

  VALUE rb_severity = Qnil;
  switch (severity) {
  case GL_DEBUG_SEVERITY_HIGH_ARB:
    rb_severity = RAY_SYM("high"); break;
  case GL_DEBUG_SEVERITY_MEDIUM_ARB:
    rb_severity = RAY_SYM("medium"); break;
  default:
    rb_severity = RAY_SYM("low"); break;
  }

  VALUE rb_message = rb_str_new(message, length);

  VALUE proc = rb_iv_get(rb_path2class("Ray::GL"), "@callback");
  rb_funcall(proc, RAY_METH("call"), 5, rb_source, rb_type, rb_id, rb_severity,
             rb_message);
}
コード例 #17
0
ファイル: ludicrous_ext.c プロジェクト: cout/ludicrous
static VALUE function_ruby_struct_member_offset(
    VALUE self, VALUE struct_name, VALUE member_name)
{
  struct Member_Info * member_info = get_member_info(
      struct_name,
      member_name);

  return ULONG2NUM(member_info->offset);
}
コード例 #18
0
ファイル: glib.c プロジェクト: anjlab/unichars
/*
 *  call-seq:
 *    utf8_size(string)
 *
 *  Returns the length of the string expressed in codepoints.
 *
 *    Glib.utf8_size('A ehm…, word.') #=> 13
 */
static VALUE utf8_size(VALUE self, VALUE string)
{
  VALUE result;

  Check_Type(string, T_STRING);
  result = ULONG2NUM(g_utf8_strlen(StringValuePtr(string), RSTRING_LEN(string)));

  return result;
}
コード例 #19
0
static VALUE t_watch_pid (VALUE self, VALUE pid)
{
    try {
        return ULONG2NUM(evma_watch_pid(NUM2INT(pid)));
    } catch (std::runtime_error e) {
        rb_raise (EM_eUnsupported, "%s", e.what());
    }
    return Qnil;
}
コード例 #20
0
static VALUE t_watch_filename (VALUE self, VALUE fname)
{
    try {
        return ULONG2NUM(evma_watch_filename(StringValuePtr(fname)));
    } catch (std::runtime_error e) {
        rb_raise (EM_eUnsupported, "%s", e.what());
    }
    return Qnil;
}
コード例 #21
0
static VALUE
prof_measure_allocations(VALUE self)
{
#if defined(HAVE_LONG_LONG)
    return ULL2NUM(measure_allocations());
#else
    return ULONG2NUM(measure_allocations());
#endif
}
コード例 #22
0
static VALUE t_proxied_bytes (VALUE self, VALUE from)
{
    try {
        return ULONG2NUM(evma_proxied_bytes(NUM2ULONG (from)));
    } catch (std::runtime_error e) {
        rb_raise (EM_eConnectionError, "%s", e.what());
    }
    return Qnil;
}
コード例 #23
0
ファイル: rb_iupim.c プロジェクト: cherry-wb/ruby-iup
VALUE rb_IupLoadImage(VALUE self,VALUE v_file_name)
{
	extern VALUE rb_cIupImage;
	const char* file_name = RSTRING_PTR(v_file_name);
	Ihandle* v;
	v = IupLoadImage(file_name);
	if(v)
		return rb_funcall(rb_cIupImage,rb_intern("new"),1,ULONG2NUM((unsigned long)v));
	return Qnil;
}
コード例 #24
0
ファイル: rb_iupcolorbar.c プロジェクト: cherry-wb/ruby-iup
VALUE rb_IupColorbar(VALUE self)
{
	extern VALUE rb_cIupColorbar;
	Ihandle* v;
	IupControlsOpen();
	v = IupColorbar();
	if(v)
		return rb_funcall(rb_cIupColorbar,rb_intern("new"),1,ULONG2NUM((unsigned long)v));
	return Qnil;
}
コード例 #25
0
ファイル: file_system.c プロジェクト: Lorrie/RubyTSK
// assigns numerous TSK_FS_INFO values to ruby instance variables
void populate_instance_variables(VALUE self) {
  struct tsk4r_fs_wrapper * fs_ptr;
  Data_Get_Struct(self, struct tsk4r_fs_wrapper, fs_ptr);

  rb_iv_set(self, "@block_count", ULONG2NUM((unsigned long long)fs_ptr->filesystem->block_count));
  //    rb_iv_set(self, "@block_getflags", INT2NUM((int)fs_ptr->filesystem->block_getflags)); // do not impl
// These features are only in libtsk >= 3.2.2
#ifndef TSK4R_HIDE_ADVANCED_FEATURE
  rb_iv_set(self, "@block_post_size", UINT2NUM((uint)fs_ptr->filesystem->block_post_size));
  rb_iv_set(self, "@block_pre_size", UINT2NUM((uint)fs_ptr->filesystem->block_pre_size));
#endif
  rb_iv_set(self, "@block_size", UINT2NUM((uint)fs_ptr->filesystem->block_size));
  //    rb_iv_set(self, "@block_walk", fs_ptr->filesystem->block_walk);// no
  rb_iv_set(self, "@dev_bsize", UINT2NUM((uint)fs_ptr->filesystem->dev_bsize));
  rb_iv_set(self, "@data_unit_name", rb_str_new2(fs_ptr->filesystem->duname));
  rb_iv_set(self, "@endian", UINT2NUM((uint)fs_ptr->filesystem->endian));
  rb_iv_set(self, "@first_inum", ULONG2NUM((unsigned long int)fs_ptr->filesystem->first_inum));
  //    rb_iv_set(self, "@file_add_meta", fs_ptr->filesystem->file_add_meta); // do not impl
  rb_iv_set(self, "@first_block", ULONG2NUM((unsigned long int)fs_ptr->filesystem->first_block));
  rb_iv_set(self, "@flags", UINT2NUM((uint)fs_ptr->filesystem->flags));
  //    rb_iv_set(self, "@fread_owner_sid", fs_ptr->filesystem->fread_owner_sid); // do not impl
  rb_iv_set(self, "@fs_id", rb_str_new2((char *)fs_ptr->filesystem->fs_id));
  rb_iv_set(self, "@fs_id_used", UINT2NUM((uint)fs_ptr->filesystem->fs_id_used));
  //    rb_iv_set(self, "@fscheck", fs_ptr->filesystem->fscheck); // do not impl
  //    rb_iv_set(self, "@fsstat", fs_ptr->filesystem->fsstat); // do not impl
  rb_iv_set(self, "@ftype", UINT2NUM((uint)fs_ptr->filesystem->ftype));
  //    rb_iv_set(self, "@get_default_attr_type", fs_ptr->filesystem->get_default_attr_type); // do not impl
  //    rb_iv_set(self, "@inode_walk", fs_ptr->filesystem->inode_walk);//no
  rb_iv_set(self, "@inum_count", ULONG2NUM((unsigned long int)fs_ptr->filesystem->inum_count));
#ifdef TSK4R_DEPRECATED_TSK4_FEATURE
  rb_iv_set(self, "@isOrphanHunting", UINT2NUM((uint)fs_ptr->filesystem->isOrphanHunting));
#endif
  //    rb_iv_set(self, "@istat", fs_ptr->filesystem->istat); // do not impl
  //    rb_iv_set(self, "@jblk_walk", fs_ptr->filesystem->jblk_walk);//no
  //    rb_iv_set(self, "@jentry_walk", fs_ptr->filesystem->jentry_walk);//no
  //    rb_iv_set(self, "@jopen", fs_ptr->filesystem->jopen);//no
  rb_iv_set(self, "@journ_inum", ULONG2NUM((unsigned long int)fs_ptr->filesystem->journ_inum));
  rb_iv_set(self, "@last_block", ULONG2NUM((unsigned long int)fs_ptr->filesystem->last_block));
  rb_iv_set(self, "@last_block_act", ULONG2NUM((unsigned long int)fs_ptr->filesystem->last_block_act));
  rb_iv_set(self, "@last_inum", ULONG2NUM((unsigned long int)fs_ptr->filesystem->last_inum));
  //    rb_iv_set(self, "@list_inum_named", fs_ptr->filesystem->list_inum_named); // to do
  //    rb_iv_set(self, "@load_attrs", fs_ptr->filesystem->load_attrs); // do not impl
  //    rb_iv_set(self, "@name_cmp", fs_ptr->filesystem->name_cmp); // do no impl
  rb_iv_set(self, "@offset", LONG2NUM((long int)fs_ptr->filesystem->offset));
  //    rb_iv_set(self, "@orphan_dir", fs_ptr->filesystem->orphan_dir); // to do
  rb_iv_set(self, "@root_inum", ULONG2NUM((unsigned long int)fs_ptr->filesystem->root_inum));
  rb_iv_set(self, "@tag", INT2NUM(fs_ptr->filesystem->tag));
}
コード例 #26
0
ファイル: utils.c プロジェクト: Telmate/couchbase-ruby-client
    static VALUE
do_decode(VALUE *args)
{
    VALUE blob = args[0];
    VALUE transcoder = args[2];
    VALUE flags = args[1];
    VALUE options = args[3];

    return rb_funcall(transcoder, cb_id_load, 3, blob, ULONG2NUM(flags), options);
}
コード例 #27
0
ファイル: fastthread.c プロジェクト: genki/fastthread
static VALUE
rb_queue_marshal_dump(VALUE self)
{
    Queue *queue;
    VALUE array;
    Data_Get_Struct(self, Queue, queue);

    array = array_from_list(&queue->values);
    rb_ary_unshift(array, ULONG2NUM(queue->capacity));
    return rb_marshal_dump(array, Qnil);
}
コード例 #28
0
/*
 * call-seq:
 *    session.timeout -> integer
 *
 * How long until the session expires in seconds.
 *
*/
static VALUE ossl_ssl_session_get_timeout(VALUE self)
{
	SSL_SESSION *ctx;
	time_t t;

	GetSSLSession(self, ctx);

	t = SSL_SESSION_get_timeout(ctx);

	return ULONG2NUM(t);
}
コード例 #29
0
ファイル: rb-rack-io.c プロジェクト: boazsegev/iodine
// new object
static VALUE new_rack_io(http_request_s *request, VALUE env) {
  VALUE rack_io;
  if (request->body_file > 0) {
    rack_io = rb_funcall2(rRackFileIO, new_func_id, 0, NULL);
    rb_ivar_set(rack_io, io_id, ULONG2NUM(request->body_file));
    lseek(request->body_file, 0, SEEK_SET);
  } else {
    rack_io = rb_funcall2(rRackStrIO, new_func_id, 0, NULL);
    rb_ivar_set(rack_io, io_id, ULONG2NUM(((intptr_t)request->body_str)));
    // fprintf(stderr, "rack body IO (%lu, %p):%.*s\n", request->content_length,
    //         request->body_str, (int)request->content_length,
    //         request->body_str);
  }
  set_uuid(rack_io, request);
  set_pos(rack_io, 0);
  rb_ivar_set(rack_io, end_id, ULONG2NUM(request->content_length));
  rb_ivar_set(rack_io, env_id, env);

  return rack_io;
}
コード例 #30
0
ファイル: rubymain.cpp プロジェクト: bernd/eventmachine
static VALUE t_connect_server (VALUE self, VALUE server, VALUE port)
{
	// Avoid FIX2INT in this case, because it doesn't deal with type errors properly.
	// Specifically, if the value of port comes in as a string rather than an integer,
	// NUM2INT will throw a type error, but FIX2INT will generate garbage.

	const unsigned long f = evma_connect_to_server (NULL, 0, StringValuePtr(server), NUM2INT(port));
	if (!f)
		rb_raise (rb_eRuntimeError, "no connection");
	return ULONG2NUM (f);
}