Esempio n. 1
0
VALUE data_objects_seconds_to_offset(long seconds_offset) {
  do_int64 num = seconds_offset;
  do_int64 den = 86400;

  data_objects_reduce(&num, &den);
  return rb_funcall(rb_mKernel, DO_ID_RATIONAL, 2, rb_ll2inum(num), rb_ll2inum(den));
}
Esempio n. 2
0
/*
    Extern:     rm_progress_monitor
    Purpose:    SetImage(Info)ProgressMonitor exit
    Notes:      ImageMagick's "tag" argument is unused. We pass along the method name instead.
*/
MagickBooleanType
rm_progress_monitor(
    const char *tag,
    const MagickOffsetType of,
    const MagickSizeType sp,
    void *client_data)
{
    volatile VALUE rval;
    volatile VALUE method, offset, span;

    tag = tag;      // defeat gcc message

#if defined(HAVE_LONG_LONG)     // defined in Ruby's defines.h
    offset = rb_ll2inum(of);
    span = rb_ull2inum(sp);
#else
    offset = rb_int2big((long)of);
    span = rb_uint2big((unsigned long)sp);
#endif

    method = rb_str_new2(rb_id2name(THIS_FUNC()));

    rval = rb_funcall((VALUE)client_data, rm_ID_call, 3, method, offset, span);

    return RTEST(rval) ? MagickTrue : MagickFalse;
}
Esempio n. 3
0
File: fwext.c Progetto: iZsh/rubyfw
static VALUE FWDevice_getGUID(VALUE Self)
{
  FWDevice *obj;
  Data_Get_Struct(Self, FWDevice, obj);
  
  return rb_ll2inum(obj->GUID);
}
Esempio n. 4
0
VALUE rho_ruby_create_byte_array(unsigned char* buf, int length) {
	VALUE ar = rb_ary_new2(length);
	int i;
	for (i = 0 ; i < length; i++) {
		rb_ary_push(ar,rb_ll2inum(buf[i]));
	}
	return ar;
}
Esempio n. 5
0
VALUE
generic_to_value(VALUE rettype, fiddle_generic retval)
{
    int signed_p = 1;
    int type = NUM2INT(rettype);
    VALUE cPointer;

    cPointer = rb_const_get(mFiddle, rb_intern("Pointer"));

    if (type < 0) {
	type = -1 * type;
	signed_p = 0;
    }

    switch (type) {
      case TYPE_VOID:
	return Qnil;
      case TYPE_VOIDP:
        return rb_funcall(cPointer, rb_intern("[]"), 1,
          PTR2NUM((void *)retval.pointer));
      case TYPE_CHAR:
	if (signed_p) return INT2NUM((char)retval.fffi_sarg);
	return INT2NUM((unsigned char)retval.fffi_arg);
      case TYPE_SHORT:
	if (signed_p) return INT2NUM((short)retval.fffi_sarg);
	return INT2NUM((unsigned short)retval.fffi_arg);
      case TYPE_INT:
	if (signed_p) return INT2NUM((int)retval.fffi_sarg);
	return UINT2NUM((unsigned int)retval.fffi_arg);
      case TYPE_LONG:
	if (signed_p) return LONG2NUM(retval.slong);
	return ULONG2NUM(retval.ulong);
#if HAVE_LONG_LONG
      case TYPE_LONG_LONG:
	return rb_ll2inum(retval.long_long);
	break;
#endif
      case TYPE_FLOAT:
	return rb_float_new(retval.ffloat);
      case TYPE_DOUBLE:
	return rb_float_new(retval.ddouble);
      default:
	rb_raise(rb_eRuntimeError, "unknown type %d", type);
    }
}
Esempio n. 6
0
VALUE rho_ruby_create_integer(__int64 i)
{
    return rb_ll2inum(i);
}
Esempio n. 7
0
static VALUE bignum_spec_rb_big2ll(VALUE self, VALUE num) {
  return rb_ll2inum(rb_big2ll(num));
}
Esempio n. 8
0
// Creates a Rational for use as a Timezone offset to be passed to DateTime.new!
static VALUE seconds_to_offset(do_int64 num) {
  do_int64 den = 86400;
  reduce(&num, &den);
  return rb_funcall(rb_mKernel, ID_RATIONAL, 2, rb_ll2inum(num), rb_ll2inum(den));
}
Esempio n. 9
0
static VALUE numeric_spec_rb_ll2inum_14(VALUE self) {
  return rb_ll2inum(14);
}
Esempio n. 10
0
static inline int template_callback_int64(unpack_user* u, int64_t d, VALUE* o)
{ *o = rb_ll2inum(d); return 0; }
Esempio n. 11
0
/**
 * msg_consume
 *
 * Callback on message receipt.
 *
 * @param rkmessage	rd_kafka_message_t* the message
 * @param opaque	   void*   opaque context
 */
static void msg_consume(rd_kafka_message_t *rkmessage, HermannInstanceConfig *cfg) {
	if (rkmessage->err) {
		if (rkmessage->err == RD_KAFKA_RESP_ERR__PARTITION_EOF) {
			if (cfg->exit_eof) {
				fprintf(stderr,
						"%% Consumer reached end of %s [%"PRId32"] "
						"message queue at offset %"PRId64"\n",
						rd_kafka_topic_name(rkmessage->rkt),
						rkmessage->partition, rkmessage->offset);

				cfg->run = 0;
			}

			return;
		}

		fprintf(stderr, "%% Consume error for topic \"%s\" [%"PRId32"] "
			   "offset %"PRId64": %s\n",
			   rd_kafka_topic_name(rkmessage->rkt),
			   rkmessage->partition,
			   rkmessage->offset,
			   rd_kafka_message_errstr(rkmessage));
		return;
	}

	if (DEBUG && rkmessage->key_len) {
		if (output == OUTPUT_HEXDUMP) {
			hexdump(stdout, "Message Key",
				rkmessage->key, rkmessage->key_len);
		}
		else {
			printf("Key: %.*s\n",
				   (int)rkmessage->key_len, (char *)rkmessage->key);
		}
	}

	if (output == OUTPUT_HEXDUMP) {
		if (DEBUG) {
			hexdump(stdout, "Message Payload", rkmessage->payload, rkmessage->len);
		}
	}
	else {
		if (DEBUG) {
			printf("%.*s\n", (int)rkmessage->len, (char *)rkmessage->payload);
		}
	}

	// Yield the data to the Consumer's block
	if (rb_block_given_p()) {
		VALUE key, data, offset;

		data = rb_str_new((char *)rkmessage->payload, rkmessage->len);
		offset = rb_ll2inum(rkmessage->offset);

		if ( rkmessage->key_len > 0 ) {
			key = rb_str_new((char*) rkmessage->key, (int)rkmessage->key_len);
		} else {
			key = Qnil;
		}

		rd_kafka_message_destroy(rkmessage);
		rb_yield_values(3, data, key, offset);
	}
	else {
		if (DEBUG) {
			fprintf(stderr, "No block given\n"); // todo: should this be an error?
		}
	}
}
Esempio n. 12
0
static VALUE
Unpacker_buffer_read (unpacker_t* ptr)
{
	uint64_t num;

	switch (*ptr->ch++) {
		case 'a': // int 4
			num = Unpacker_int4(ptr);
			return INT2FIX(num);

		case 'b': // int 8
			num = Unpacker_int8(ptr);
			return INT2FIX(num);

		case 'c': // int 16
			num = Unpacker_int16(ptr);
			return INT2FIX(num);

		case 'd': // int 32
			num = Unpacker_int32(ptr);
			return LONG2NUM(num);

		case 'e': // int 64
			num = Unpacker_int64(ptr);
			return rb_ll2inum(num);

		case 'g': // uint 8
			num = Unpacker_uint(ptr, 2);
			return INT2FIX(num);

		case 'h': // uint 16
			num = Unpacker_uint(ptr, 4);
			return INT2FIX(num);

		case 'i': // uint 32
			num = Unpacker_uint(ptr, 8);
			return LONG2NUM(num);

		case 'j': // uint 64
			num = Unpacker_uint(ptr, 16);
			return rb_ull2inum(num);

		case 'k': // float 32
			return rb_float_new(Unpacker_float(ptr, 8));

		case 'l': // float 64
			return rb_float_new(Unpacker_float(ptr, 16));

		case 'n': // str 8
			num = Unpacker_uint(ptr, 2);
			return Unpacker_str(ptr, num);

		case 'o': // str 16
			num = Unpacker_uint(ptr, 4);
			return Unpacker_str(ptr, num);

		case 'p': // str 32
			num = Unpacker_uint(ptr, 8);
			return Unpacker_str(ptr, num);

		case 'r': // map 4
			num = Unpacker_uint(ptr, 1);
			return Unpacker_map(ptr, num);

		case 's': // map 8
			num = Unpacker_uint(ptr, 2);
			return Unpacker_map(ptr, num);

		case 't': // map16
			num = Unpacker_uint(ptr, 4);
			return Unpacker_map(ptr, num);

		case 'u': // map 32
			num = Unpacker_uint(ptr, 8);
			return Unpacker_map(ptr, num);

		case 'v': // array 4
			num = Unpacker_uint(ptr, 1);
			return Unpacker_array(ptr, num);

		case 'w': // array 8
			num = Unpacker_uint(ptr, 2);
			return Unpacker_array(ptr, num);

		case 'x': // array 16
			num = Unpacker_uint(ptr, 4);
			return Unpacker_array(ptr, num);

		case 'y': // array 32
			num = Unpacker_uint(ptr, 8);
			return Unpacker_array(ptr, num);

		// positive fixint
		case '0': return INT2FIX(0);
		case '1': return INT2FIX(1);
		case '2': return INT2FIX(2);
		case '3': return INT2FIX(3);
		case '4': return INT2FIX(4);
		case '5': return INT2FIX(5);
		case '6': return INT2FIX(6);
		case '7': return INT2FIX(7);
		case '8': return INT2FIX(8);
		case '9': return INT2FIX(9);
		case 'A': return INT2FIX(10);
		case 'B': return INT2FIX(11);
		case 'C': return INT2FIX(12);
		case 'D': return INT2FIX(13);
		case 'E': return INT2FIX(14);
		case 'F': return INT2FIX(15);

		// fixstr
		case 'G':
			return rb_str_new2("");
		case 'H':
		case 'I':
		case 'J':
		case 'K':
		case 'L':
		case 'M':
		case 'N':
		case 'O':
		case 'P':
		case 'Q':
		case 'R':
		case 'S':
		case 'T':
		case 'U':
		case 'V':
			num = *(ptr->ch - 1) - 'G';
			return Unpacker_str(ptr, num);

		// others
		case 'W': return Qnil;
		case 'X': return Qfalse;
		case 'Y': return Qtrue;
	}

	rb_raise(rb_eArgError, "undefined type:%c,data:%s,at:%ld", *(ptr->ch), ptr->buffer, ptr->ch - ptr->buffer);
	return Qnil;
}
Esempio n. 13
0
static VALUE seconds_to_offset(long seconds_offset) {
  do_int64 num = seconds_offset, den = 86400;
  reduce(&num, &den);
  return rb_funcall(rb_cRational, rb_intern("new!"), 2, rb_ll2inum(num), rb_ll2inum(den));
}