本文整理汇总了C++中rb_funcall函数的典型用法代码示例。如果您正苦于以下问题:C++ rb_funcall函数的具体用法?C++ rb_funcall怎么用?C++ rb_funcall使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rb_funcall函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: rb_fastadd_add_one
static VALUE rb_fastadd_add_one(int argc, VALUE *argv, VALUE self)
{
int n = NUM2INT(rb_funcall(self, rb_intern("n"), 0));
return INT2NUM(n + 1);
}
开发者ID:saranyan,项目名称:SwePh,代码行数:5,代码来源:fastadd.c
示例2: ossl_call_verify_cb_proc
VALUE
ossl_call_verify_cb_proc(struct ossl_verify_cb_args *args)
{
return rb_funcall(args->proc, rb_intern("call"), 2,
args->preverify_ok, args->store_ctx);
}
开发者ID:2220142,项目名称:ruby,代码行数:6,代码来源:ossl.c
示例3: rb_RPRuby_Sender_Kernel_backtrace_includes
//.........这里部分代码省略.........
VALUE rb_this_arg = args[ c_which_member + c_args_offset ];
BOOL matched = FALSE;
rb_frame_hash = rb_RPRuby_Sender_Kernel_internal_backtraceHashForControlFrame( & c_current_context_frame );
// if we have a hash we are testing multiple items in a frame
if ( TYPE( rb_this_arg ) == T_HASH ) {
VALUE rb_frame_test_array = rb_obj_clone( rb_test_index_array );
// for each element that we could test for
int c_which_index;
int c_skipped_index_count = 0;
for ( c_which_index = 0 ; c_which_index < RARRAY_LEN( rb_frame_test_array ) ; c_which_index++ ) {
VALUE rb_this_index = RARRAY_PTR( rb_frame_test_array )[ c_which_index ];
// see if our requested test hash includes the potential test element
if ( rb_hash_lookup( rb_this_arg,
rb_this_index ) != Qnil ) {
VALUE rb_required_element = rb_hash_aref( rb_this_arg,
rb_this_index );
VALUE rb_frame_element = rb_hash_aref( rb_frame_hash,
rb_this_index );
// if it does, we need to see if the current frame's element matches this element
VALUE rb_required_element_klass;
if ( rb_required_element == rb_frame_element
// if we have a string, which is a filename
|| ( TYPE( rb_required_element ) == T_STRING
&& rb_funcall( rb_frame_element, rb_intern( "==" ), 1, rb_required_element ) == Qtrue )
// if we have a class, which is a special case for :object
|| ( rb_this_index == ID2SYM( rb_intern( "class" ) )
&& ( rb_required_element_klass = ( ( TYPE( rb_required_element ) == T_CLASS ) ? rb_required_element : rb_funcall( rb_required_element, rb_intern( "class" ), 0 ) ) )
&& rb_required_element_klass == rb_required_element ) ) {
rb_ary_delete_at( rb_frame_test_array,
c_which_index );
c_which_index--;
}
}
else {
c_skipped_index_count++;
}
if ( RARRAY_LEN( rb_frame_test_array ) == c_skipped_index_count ) {
if ( c_return_frame == TRUE ) {
return rb_frame_hash;
}
else if ( c_return_all_frames == TRUE ) {
rb_ary_push( rb_frame_hashes_array,
rb_frame_hash );
}
else {
return Qtrue;
}
}
}
}
else {
// :object => <class:instance>
if ( TYPE( rb_this_arg ) == T_OBJECT ) {
开发者ID:RidiculousPower,项目名称:sender,代码行数:67,代码来源:rb_Kernel.c
示例4: get_value
static VALUE get_value(const char* buffer, int* position, int type) {
VALUE value;
switch (type) {
case 1:
{
double d;
memcpy(&d, buffer + *position, 8);
value = rb_float_new(d);
*position += 8;
break;
}
case 2:
case 13:
{
int value_length;
*position += 4;
value_length = strlen(buffer + *position);
value = STR_NEW(buffer + *position, value_length);
*position += value_length + 1;
break;
}
case 3:
{
int size;
memcpy(&size, buffer + *position, 4);
if (strcmp(buffer + *position + 5, "$ref") == 0) { // DBRef
int offset = *position + 14;
VALUE argv[2];
int collection_length = strlen(buffer + offset);
char id_type;
argv[0] = STR_NEW(buffer + offset, collection_length);
offset += collection_length + 1;
id_type = buffer[offset];
offset += 5;
argv[1] = get_value(buffer, &offset, (int)id_type);
value = rb_class_new_instance(2, argv, DBRef);
} else {
value = elements_to_hash(buffer + *position + 4, size - 5);
}
*position += size;
break;
}
case 4:
{
int size, end;
memcpy(&size, buffer + *position, 4);
end = *position + size - 1;
*position += 4;
value = rb_ary_new();
while (*position < end) {
int type = (int)buffer[(*position)++];
int key_size = strlen(buffer + *position);
VALUE to_append;
*position += key_size + 1; // just skip the key, they're in order.
to_append = get_value(buffer, position, type);
rb_ary_push(value, to_append);
}
(*position)++;
break;
}
case 5:
{
int length, subtype;
VALUE data, st;
VALUE argv[2];
memcpy(&length, buffer + *position, 4);
subtype = (unsigned char)buffer[*position + 4];
if (subtype == 2) {
data = rb_str_new(buffer + *position + 9, length - 4);
} else {
data = rb_str_new(buffer + *position + 5, length);
}
st = INT2FIX(subtype);
argv[0] = data;
argv[1] = st;
value = rb_class_new_instance(2, argv, Binary);
*position += length + 5;
break;
}
case 6:
{
value = Qnil;
break;
}
case 7:
{
VALUE str = rb_str_new(buffer + *position, 12);
VALUE oid = rb_funcall(str, rb_intern("unpack"), 1, rb_str_new2("C*"));
value = rb_class_new_instance(1, &oid, ObjectID);
*position += 12;
break;
}
case 8:
{
value = buffer[(*position)++] ? Qtrue : Qfalse;
break;
}
//.........这里部分代码省略.........
开发者ID:blythedunham,项目名称:mongo-ruby-driver,代码行数:101,代码来源:cbson.c
示例5: rbgutil_def_setters
VALUE
rbgutil_def_setters(VALUE klass)
{
return rb_funcall(mGLib, id_add_one_arg_setter, 1, klass);
}
开发者ID:benolee,项目名称:ruby-gnome2,代码行数:5,代码来源:rbgutil.c
示例6: rb_gsl_call_name
static VALUE rb_gsl_call_name(VALUE obj)
{
return rb_funcall(obj, rb_gsl_id_name, 0);
}
开发者ID:masaomi,项目名称:rb-gsl,代码行数:4,代码来源:gsl.c
示例7: klassify
void klassify(VALUE obj, char * name) {
VALUE klassname;
klassname = rb_funcall(rb_funcall(obj, rb_intern("class"), 0), rb_intern("name"), 0);
printf("obj %s was a: %s\n", name, StringValuePtr(klassname));
}
开发者ID:Lorrie,项目名称:RubyTSK,代码行数:6,代码来源:tsk4r.c
示例8: init_mpcrnd
void init_mpcrnd()
{
ID new_id = rb_intern ("new");
cMPC = rb_define_class ("MPC", rb_cNumeric);
cMPC_Rnd = rb_define_class_under (cMPC, "Rnd", rb_cObject);
rb_define_singleton_method (cMPC_Rnd, "new", r_mpcrndsg_new, -1);
rb_define_method (cMPC_Rnd, "initialize", r_mpcrnd_initialize, -1);
rb_define_method (cMPC_Rnd, "inspect", r_mpcrnd_inspect, 0);
rb_define_attr (cMPC_Rnd, "mode", 1, 0);
rb_define_attr (cMPC_Rnd, "name", 1, 0);
rb_define_attr (cMPC_Rnd, "ieee754", 1, 0);
rb_define_const(cMPC, "MPC_RNDNN", rb_funcall (cMPC_Rnd, new_id, 1, INT2FIX(0)));
rb_define_const(cMPC, "MPC_RNDNZ", rb_funcall (cMPC_Rnd, new_id, 1, INT2FIX(16)));
rb_define_const(cMPC, "MPC_RNDNU", rb_funcall (cMPC_Rnd, new_id, 1, INT2FIX(32)));
rb_define_const(cMPC, "MPC_RNDND", rb_funcall (cMPC_Rnd, new_id, 1, INT2FIX(48)));
rb_define_const(cMPC, "MPC_RNDZN", rb_funcall (cMPC_Rnd, new_id, 1, INT2FIX(1)));
rb_define_const(cMPC, "MPC_RNDZZ", rb_funcall (cMPC_Rnd, new_id, 1, INT2FIX(17)));
rb_define_const(cMPC, "MPC_RNDZU", rb_funcall (cMPC_Rnd, new_id, 1, INT2FIX(33)));
rb_define_const(cMPC, "MPC_RNDZD", rb_funcall (cMPC_Rnd, new_id, 1, INT2FIX(49)));
rb_define_const(cMPC, "MPC_RNDUN", rb_funcall (cMPC_Rnd, new_id, 1, INT2FIX(2)));
rb_define_const(cMPC, "MPC_RNDUZ", rb_funcall (cMPC_Rnd, new_id, 1, INT2FIX(18)));
rb_define_const(cMPC, "MPC_RNDUU", rb_funcall (cMPC_Rnd, new_id, 1, INT2FIX(34)));
rb_define_const(cMPC, "MPC_RNDUD", rb_funcall (cMPC_Rnd, new_id, 1, INT2FIX(50)));
rb_define_const(cMPC, "MPC_RNDDN", rb_funcall (cMPC_Rnd, new_id, 1, INT2FIX(3)));
rb_define_const(cMPC, "MPC_RNDDZ", rb_funcall (cMPC_Rnd, new_id, 1, INT2FIX(19)));
rb_define_const(cMPC, "MPC_RNDDU", rb_funcall (cMPC_Rnd, new_id, 1, INT2FIX(35)));
rb_define_const(cMPC, "MPC_RNDDD", rb_funcall (cMPC_Rnd, new_id, 1, INT2FIX(51)));
}
开发者ID:srawlins,项目名称:gnu_mpc,代码行数:32,代码来源:mpcrnd.c
示例9: RHO_TRACE
jobject event_cast<jobject, VALUE>(VALUE rEvent)
{
if (NIL_P(rEvent))
return NULL;
RHO_TRACE("eventFromRuby (1)");
JNIEnv *env = jnienv();
if (!init_event_stuff(env))
return NULL;
RHO_TRACE("eventFromRuby (2)");
VALUE rId = rb_hash_aref(rEvent, rb_str_new2(RUBY_EV_ID));
if (NIL_P(rId))
rId = rb_str_new2("");
Check_Type(rId, T_STRING);
RHO_TRACE("eventFromRuby (3)");
jmethodID mid = getJNIClassMethod(env, clsEvent, "<init>", "(Ljava/lang/String;)V");
if (!mid) return NULL;
jhstring jhId = rho_cast<jstring>(env, rId);
jobject jEvent = env->NewObject(clsEvent, mid, jhId.get());
if (!jEvent) return NULL;
RHO_TRACE("eventFromRuby (4)");
VALUE rTitle = rb_hash_aref(rEvent, rb_str_new2(RUBY_EV_TITLE));
if (!NIL_P(rTitle))
{
Check_Type(rTitle, T_STRING);
jhstring jhTitle = rho_cast<jstring>(env, rTitle);
env->SetObjectField(jEvent, fidTitle, jhTitle.get());
}
RHO_TRACE("eventFromRuby (5)");
VALUE rStartDate = rb_hash_aref(rEvent, rb_str_new2(RUBY_EV_START_DATE));
if (!NIL_P(rStartDate))
env->SetObjectField(jEvent, fidStartDate, date_cast<jobject>(rStartDate));
RHO_TRACE("eventFromRuby (6)");
VALUE rEndDate = rb_hash_aref(rEvent, rb_str_new2(RUBY_EV_END_DATE));
if (!NIL_P(rEndDate))
env->SetObjectField(jEvent, fidEndDate, date_cast<jobject>(rEndDate));
RHO_TRACE("eventFromRuby (7)");
VALUE rLastModified = rb_hash_aref(rEvent, rb_str_new2(RUBY_EV_LAST_MODIFIED));
if (!NIL_P(rLastModified))
env->SetObjectField(jEvent, fidLastModified, date_cast<jobject>(rLastModified));
RHO_TRACE("eventFromRuby (8)");
VALUE rLocation = rb_hash_aref(rEvent, rb_str_new2(RUBY_EV_LOCATION));
if (!NIL_P(rLocation))
{
Check_Type(rLocation, T_STRING);
jhstring jhLocation = rho_cast<jstring>(env, rLocation);
env->SetObjectField(jEvent, fidLocation, jhLocation.get());
}
RHO_TRACE("eventFromRuby (9)");
VALUE rNotes = rb_hash_aref(rEvent, rb_str_new2(RUBY_EV_NOTES));
if (!NIL_P(rNotes))
{
Check_Type(rNotes, T_STRING);
jhstring jhNotes = rho_cast<jstring>(env, rNotes);
env->SetObjectField(jEvent, fidNotes, jhNotes.get());
}
RHO_TRACE("eventFromRuby privacy");
VALUE rPrivacy = rb_hash_aref(rEvent, rb_str_new2(RUBY_EV_PRIVACY));
if (!NIL_P(rPrivacy))
{
Check_Type(rPrivacy, T_STRING);
jhstring jhPrivacy = rho_cast<jstring>(env, rPrivacy);
env->SetObjectField(jEvent, fidPrivacy, jhPrivacy.get());
}
RHO_TRACE("eventFromRuby recurrence");
VALUE rRecurrence = rb_hash_aref(rEvent, rb_str_new2(RUBY_EV_RECURRENCE));
if (!NIL_P(rRecurrence)) {
Check_Type(rRecurrence, T_HASH);
VALUE rFrequency = rb_hash_aref(rRecurrence, rb_str_new2(RUBY_EV_RECURRENCE_FREQUENCY));
Check_Type(rFrequency, T_STRING);
const char *frequency = RSTRING_PTR(rFrequency);
if ( strcasecmp(frequency, RUBY_EV_RECURRENCE_FREQUENCY_DAILY) != 0
&& strcasecmp(frequency, RUBY_EV_RECURRENCE_FREQUENCY_WEEKLY) != 0
&& strcasecmp(frequency, RUBY_EV_RECURRENCE_FREQUENCY_MONTHLY) != 0
&& strcasecmp(frequency, RUBY_EV_RECURRENCE_FREQUENCY_YEARLY) != 0)
{
rb_raise(rb_eArgError, "Wrong recurrence frequency: %s", frequency);
}
jhstring jhFreq = rho_cast<jstring>(env, rFrequency);
env->SetObjectField(jEvent, fidFrequency, jhFreq.get());
VALUE rInterval = rb_hash_aref(rRecurrence, rb_str_new2(RUBY_EV_RECURRENCE_INTERVAL));
rInterval = rb_funcall(rInterval, rb_intern("to_i"), 0);
int interval = NUM2INT(rInterval);
env->SetIntField(jEvent, fidInterval, interval);
RAWTRACE1("eventFromRuby recurrence interval: %d", interval);
VALUE rUntilDate = rb_hash_aref(rRecurrence, rb_str_new2(RUBY_EV_RECURRENCE_END));
//.........这里部分代码省略.........
开发者ID:CSanshulgandhi,项目名称:rhodes,代码行数:101,代码来源:event.cpp
示例10: rg_s_type_register
static VALUE
rg_s_type_register(int argc, VALUE* argv, VALUE self)
{
VALUE type_name, flags;
volatile VALUE class_init_proc = Qnil;
GType parent_type;
GTypeInfo* info;
rb_scan_args(argc, argv, "03", &type_name, &info, &flags);
{
const RGObjClassInfo* cinfo = rbgobj_lookup_class(self);
if (cinfo->klass == self)
rb_raise(rb_eTypeError, "already registered");
}
{
VALUE superclass = rb_funcall(self, rb_intern("superclass"), 0);
const RGObjClassInfo* cinfo = rbgobj_lookup_class(superclass);
if (cinfo->klass != superclass)
rb_raise(rb_eTypeError, "super class must be registered to GLib");
parent_type = cinfo->gtype;
}
if (NIL_P(type_name)) {
VALUE s = rb_funcall(self, rb_intern("name"), 0);
if (strlen(StringValuePtr(s)) == 0)
rb_raise(rb_eTypeError, "can't determine type name");
type_name = rb_funcall(
rb_eval_string("lambda{|x| x.gsub(/::/,'') }"),
rb_intern("call"), 1, s);
}
{
GTypeQuery query;
g_type_query(parent_type, &query);
/* TODO: Why new? g_type_register_static() doesn’t retain a copy, so
* this should be allocated on the stack. */
info = g_new0(GTypeInfo, 1);
info->class_size = query.class_size;
info->base_init = NULL;
info->base_finalize = NULL;
info->class_init = class_init_func;
info->class_finalize = NULL;
info->class_data = (gpointer)class_init_proc;
info->instance_size = query.instance_size;
info->n_preallocs = 0;
info->instance_init = NULL;
info->value_table = NULL;
}
{
GType type = g_type_register_static(parent_type,
StringValuePtr(type_name),
info,
NIL_P(flags) ? 0 : NUM2INT(flags));
G_RELATIVE(self, class_init_proc);
rbgobj_register_class(self, type, TRUE, TRUE);
{
RGObjClassInfo* cinfo = (RGObjClassInfo*)rbgobj_lookup_class(self);
cinfo->flags |= RBGOBJ_DEFINED_BY_RUBY;
}
{
GType parent = g_type_parent(type);
const RGObjClassInfo* cinfo = GTYPE2CINFO(parent);
VALUE m = rb_define_module_under(self, RubyGObjectHookModule);
if (! (cinfo->flags & RBGOBJ_DEFINED_BY_RUBY)) {
rbg_define_method(m, "initialize", rg_initialize, -1);
}
rb_include_module(self, m);
}
return Qnil;
}
}
开发者ID:dmaciejak,项目名称:ruby-gnome2,代码行数:83,代码来源:rbgobj_object.c
示例11: dtracebufdata_record
/*
* Returns the record in this DtraceBufdata. Records are returned as
* either DtraceRecords or DtraceStackRecords as appropriate for the
* type of action.
*/
VALUE dtracebufdata_record(VALUE self)
{
dtrace_bufdata_t *bufdata;
const dtrace_recdesc_t *rec;
dtrace_actkind_t act = DTRACEACT_NONE;
const char *s;
VALUE v = Qnil;
VALUE dtracerecord;
VALUE dtraceaggdata;
VALUE dtracerecdesc;
Data_Get_Struct(self, dtrace_bufdata_t, bufdata);
if (bufdata->dtbda_aggdata) {
dtraceaggdata = Data_Wrap_Struct(cDtraceAggData, 0, NULL, (dtrace_bufdata_t *)bufdata);
return dtraceaggdata;
}
s = bufdata->dtbda_buffered;
if (s == NULL) {
return Qnil;
}
rec = bufdata->dtbda_recdesc;
if (rec) {
act = rec->dtrd_action;
}
switch (act) {
case DTRACEACT_DIFEXPR:
/* trace() action */
break;
case DTRACEACT_PRINTF:
/* printf action, not available in probedata */
v = rb_str_new2(s);
dtracerecord = rb_class_new_instance(0, NULL, rb_path2class("Dtrace::PrintfRecord"));
rb_iv_set(dtracerecord, "@from", rb_str_new2("bufdata"));
rb_iv_set(dtracerecord, "@value", v);
return (dtracerecord);
break;
case DTRACEACT_STACK:
case DTRACEACT_USTACK:
case DTRACEACT_JSTACK:
/* stand-alone stack(), ustack(), or jstack() action */
v = rb_str_new2(s);
dtracerecord = rb_class_new_instance(0, NULL, rb_path2class("Dtrace::StackRecord"));
rb_iv_set(dtracerecord, "@from", rb_str_new2("bufdata"));
rb_funcall(dtracerecord, rb_intern("parse"), 1, v);
return (dtracerecord);
break;
case DTRACEACT_USYM:
case DTRACEACT_UADDR:
case DTRACEACT_UMOD:
case DTRACEACT_SYM:
case DTRACEACT_MOD:
v = rb_str_new2(s);
break;
case DTRACEACT_PRINTA:
v = rb_str_new2(s);
break;
default:
/*
* The record handle defers nothing else to this
* bufhandler.
*/
break;
}
if (!NIL_P(v)) {
dtracerecord = rb_class_new_instance(0, NULL, rb_path2class("Dtrace::Record"));
rb_iv_set(dtracerecord, "@value", v);
rb_iv_set(dtracerecord, "@action", INT2FIX(act));
rb_iv_set(dtracerecord, "@from", rb_str_new2("bufdata"));
return (dtracerecord);
}
else {
return Qnil;
}
}
开发者ID:GunioRobot,项目名称:ruby-dtrace,代码行数:84,代码来源:dtrace_bufdata.c
示例12: ossl_asn1_decode0
static VALUE
ossl_asn1_decode0(unsigned char **pp, long length, long *offset, long depth,
int once, int yield)
{
unsigned char *start, *p;
const unsigned char *p0;
long len, off = *offset;
int hlen, tag, tc, j;
VALUE ary, asn1data, value, tag_class;
ary = rb_ary_new();
p = *pp;
while(length > 0){
start = p;
p0 = p;
j = ASN1_get_object(&p0, &len, &tag, &tc, length);
p = (unsigned char *)p0;
if(j & 0x80) ossl_raise(eASN1Error, NULL);
hlen = p - start;
if(yield){
VALUE arg = rb_ary_new();
rb_ary_push(arg, LONG2NUM(depth));
rb_ary_push(arg, LONG2NUM(off));
rb_ary_push(arg, LONG2NUM(hlen));
rb_ary_push(arg, LONG2NUM(len));
rb_ary_push(arg, (j & V_ASN1_CONSTRUCTED) ? Qtrue : Qfalse);
rb_ary_push(arg, ossl_asn1_class2sym(tc));
rb_ary_push(arg, INT2NUM(tag));
rb_yield(arg);
}
length -= hlen;
off += hlen;
if(len > length) ossl_raise(eASN1Error, "value is too short");
if((tc & V_ASN1_PRIVATE) == V_ASN1_PRIVATE)
tag_class = sPRIVATE;
else if((tc & V_ASN1_CONTEXT_SPECIFIC) == V_ASN1_CONTEXT_SPECIFIC)
tag_class = sCONTEXT_SPECIFIC;
else if((tc & V_ASN1_APPLICATION) == V_ASN1_APPLICATION)
tag_class = sAPPLICATION;
else
tag_class = sUNIVERSAL;
if(j & V_ASN1_CONSTRUCTED){
/* TODO: if j == 0x21 it is indefinite length object. */
if((j == 0x21) && (len == 0)){
long lastoff = off;
value = ossl_asn1_decode0(&p, length, &off, depth+1, 0, yield);
len = off - lastoff;
}
else value = ossl_asn1_decode0(&p, len, &off, depth+1, 0, yield);
}
else{
value = rb_str_new((const char *)p, len);
p += len;
off += len;
}
if(tag_class == sUNIVERSAL &&
tag < ossl_asn1_info_size && ossl_asn1_info[tag].klass){
VALUE klass = *ossl_asn1_info[tag].klass;
long flag = 0;
if(!rb_obj_is_kind_of(value, rb_cArray)){
switch(tag){
case V_ASN1_BOOLEAN:
value = decode_bool(start, hlen+len);
break;
case V_ASN1_INTEGER:
value = decode_int(start, hlen+len);
break;
case V_ASN1_BIT_STRING:
value = decode_bstr(start, hlen+len, &flag);
break;
case V_ASN1_NULL:
value = decode_null(start, hlen+len);
break;
case V_ASN1_ENUMERATED:
value = decode_enum(start, hlen+len);
break;
case V_ASN1_OBJECT:
value = decode_obj(start, hlen+len);
break;
case V_ASN1_UTCTIME: /* FALLTHROUGH */
case V_ASN1_GENERALIZEDTIME:
value = decode_time(start, hlen+len);
break;
default:
/* use original value */
break;
}
}
asn1data = rb_funcall(klass, rb_intern("new"), 1, value);
if(tag == V_ASN1_BIT_STRING){
rb_iv_set(asn1data, "@unused_bits", LONG2NUM(flag));
}
}
else{
asn1data = rb_funcall(cASN1Data, rb_intern("new"), 3,
value, INT2NUM(tag), ID2SYM(tag_class));
}
rb_ary_push(ary, asn1data);
length -= len;
if(once) break;
//.........这里部分代码省略.........
开发者ID:genki,项目名称:ruby,代码行数:101,代码来源:ossl_asn1.c
示例13: tcp_listener_stats
/*
* call-seq:
* Raindrops::Linux.tcp_listener_stats([addrs[, sock]]) => hash
*
* If specified, +addr+ may be a string or array of strings representing
* listen addresses to filter for. Returns a hash with given addresses as
* keys and ListenStats objects as the values or a hash of all addresses.
*
* addrs = %w(0.0.0.0:80 127.0.0.1:8080)
*
* If +addr+ is nil or not specified, all (IPv4) addresses are returned.
* If +sock+ is specified, it should be a Raindrops::InetDiagSock object.
*/
static VALUE tcp_listener_stats(int argc, VALUE *argv, VALUE self)
{
VALUE rv = rb_hash_new();
struct nogvl_args args;
VALUE addrs, sock;
rb_scan_args(argc, argv, "02", &addrs, &sock);
/*
* allocating page_size instead of OP_LEN since we'll reuse the
* buffer for recvmsg() later, we already checked for
* OPLEN <= page_size at initialization
*/
args.iov[2].iov_len = OPLEN;
args.iov[2].iov_base = alloca(page_size);
args.table = NULL;
if (NIL_P(sock))
sock = rb_funcall(cIDSock, id_new, 0);
args.fd = my_fileno(sock);
switch (TYPE(addrs)) {
case T_STRING:
rb_hash_aset(rv, addrs, tcp_stats(&args, addrs));
return rv;
case T_ARRAY: {
long i;
long len = RARRAY_LEN(addrs);
VALUE cur;
if (len == 1) {
cur = rb_ary_entry(addrs, 0);
rb_hash_aset(rv, cur, tcp_stats(&args, cur));
return rv;
}
for (i = 0; i < len; i++) {
union any_addr check;
VALUE cur = rb_ary_entry(addrs, i);
parse_addr(&check, cur);
rb_hash_aset(rv, cur, Qtrue);
}
/* fall through */
}
case T_NIL:
args.table = st_init_strtable();
gen_bytecode_all(&args.iov[2]);
break;
default:
rb_raise(rb_eArgError,
"addr must be an array of strings, a string, or nil");
}
nl_errcheck(rb_thread_io_blocking_region(diag, &args, args.fd));
st_foreach(args.table, NIL_P(addrs) ? st_to_hash : st_AND_hash, rv);
st_free_table(args.table);
/* let GC deal with corner cases */
if (argc < 2) rb_io_close(sock);
return rv;
}
开发者ID:Daraexus,项目名称:SimuladorCloud,代码行数:75,代码来源:linux_inet_diag.c
示例14: NIO_Selector_is_empty
/* True if there are monitors on the loop */
static VALUE NIO_Selector_is_empty(VALUE self)
{
VALUE selectables = rb_ivar_get(self, rb_intern("selectables"));
return rb_funcall(selectables, rb_intern("empty?"), 0) == Qtrue ? Qtrue : Qfalse;
}
开发者ID:zanaka,项目名称:Grama,代码行数:7,代码来源:selector.c
示例15: rb_exc_new_str
VALUE
rb_exc_new_str(VALUE etype, VALUE str)
{
StringValue(str);
return rb_funcall(etype, rb_intern("new"), 1, str);
}
开发者ID:gogotanaka,项目名称:ruby_svn,代码行数:6,代码来源:error.c
示例16: exc_message
static VALUE
exc_message(VALUE exc)
{
return rb_funcall(exc, rb_intern("to_s"), 0, 0);
}
开发者ID:gogotanaka,项目名称:ruby_svn,代码行数:5,代码来源:error.c
示例17: rb_gsl_call_size
static VALUE rb_gsl_call_size(VALUE obj)
{
return rb_funcall(obj, rb_gsl_id_size, 0);
}
开发者ID:masaomi,项目名称:rb-gsl,代码行数:4,代码来源:gsl.c
示例18: write_element_allow_id
static int write_element_allow_id(VALUE key, VALUE value, VALUE extra, int allow_id) {
buffer_t buffer = (buffer_t)NUM2LL(rb_ary_entry(extra, 0));
VALUE check_keys = rb_ary_entry(extra, 1);
if (TYPE(key) == T_SYMBOL) {
// TODO better way to do this... ?
key = rb_str_new2(rb_id2name(SYM2ID(key)));
}
if (TYPE(key) != T_STRING) {
buffer_free(buffer);
rb_raise(rb_eTypeError, "keys must be strings or symbols");
}
if (!allow_id && strcmp("_id", RSTRING_PTR(key)) == 0) {
return ST_CONTINUE;
}
if (check_keys == Qtrue) {
int i;
if (RSTRING_LEN(key) > 0 && RSTRING_PTR(key)[0] == '$') {
buffer_free(buffer);
rb_raise(InvalidName, "key must not start with '$'");
}
for (i = 0; i < RSTRING_LEN(key); i++) {
if (RSTRING_PTR(key)[i] == '.') {
buffer_free(buffer);
rb_raise(InvalidName, "key must not contain '.'");
}
}
}
switch(TYPE(value)) {
case T_BIGNUM:
case T_FIXNUM:
{
if (rb_funcall(value, rb_intern(">"), 1, LL2NUM(9223372036854775807LL)) == Qtrue ||
rb_funcall(value, rb_intern("<"), 1, LL2NUM(-9223372036854775808LL)) == Qtrue) {
buffer_free(buffer);
rb_raise(rb_eRangeError, "MongoDB can only handle 8-byte ints");
}
if (rb_funcall(value, rb_intern(">"), 1, INT2NUM(2147483647L)) == Qtrue ||
rb_funcall(value, rb_intern("<"), 1, INT2NUM(-2147483648L)) == Qtrue) {
long long ll_value;
write_name_and_type(buffer, key, 0x12);
ll_value = NUM2LL(value);
SAFE_WRITE(buffer, (char*)&ll_value, 8);
} else {
int int_value;
write_name_and_type(buffer, key, 0x10);
int_value = NUM2LL(value);
SAFE_WRITE(buffer, (char*)&int_value, 4);
}
break;
}
case T_TRUE:
{
write_name_and_type(buffer, key, 0x08);
SAFE_WRITE(buffer, &one, 1);
break;
}
case T_FALSE:
{
write_name_and_type(buffer, key, 0x08);
SAFE_WRITE(buffer, &zero, 1);
break;
}
case T_FLOAT:
{
double d = NUM2DBL(value);
write_name_and_type(buffer, key, 0x01);
SAFE_WRITE(buffer, (char*)&d, 8);
break;
}
case T_NIL:
{
write_name_and_type(buffer, key, 0x0A);
break;
}
case T_HASH:
{
write_name_and_type(buffer, key, 0x03);
write_doc(buffer, value, check_keys);
break;
}
case T_ARRAY:
{
buffer_position length_location, start_position, obj_length;
int items, i;
VALUE* values;
write_name_and_type(buffer, key, 0x04);
start_position = buffer_get_position(buffer);
// save space for length
length_location = buffer_save_space(buffer, 4);
if (length_location == -1) {
rb_raise(rb_eNoMemError, "failed to allocate memory in buffer.c");
}
//.........这里部分代码省略.........
开发者ID:blythedunham,项目名称:mongo-ruby-driver,代码行数:101,代码来源:cbson.c
示例19: ossl_ec_key_initialize
/* call-seq:
* OpenSSL::PKey::EC.new()
* OpenSSL::PKey::EC.new(ec_key)
* OpenSSL::PKey::EC.new(ec_group)
* OpenSSL::PKey::EC.new("secp112r1")
* OpenSSL::PKey::EC.new(pem_string)
* OpenSSL::PKey::EC.new(pem_string [, pwd])
* OpenSSL::PKey::EC.new(der_string)
*
* See the OpenSSL documentation for:
* EC_KEY_*
*/
static VALUE ossl_ec_key_initialize(int argc, VALUE *argv, VALUE self)
{
EVP_PKEY *pkey;
EC_KEY *ec = NULL;
VALUE arg, pass;
VALUE group = Qnil;
char *passwd = NULL;
GetPKey(self, pkey);
if (pkey->pkey.ec)
ossl_raise(eECError, "EC_KEY already initialized");
rb_scan_args(argc, argv, "02", &arg, &pass);
if (NIL_P(arg)) {
ec = EC_KEY_new();
} else {
if (rb_obj_is_kind_of(arg, cEC)) {
EC_KEY *other_ec = NULL;
SafeRequire_EC_KEY(arg, other_ec);
ec = EC_KEY_dup(other_ec);
} else if (rb_obj_is_kind_of(arg, cEC_GROUP)) {
ec = EC_KEY_new();
group = arg;
} else {
BIO *in = ossl_obj2bio(arg);
if (!NIL_P(pass)) {
passwd = StringValuePtr(pass);
}
ec = PEM_read_bio_ECPrivateKey(in, NULL, ossl_pem_passwd_cb, passwd);
if (!ec) {
OSSL_BIO_reset(in);
ec = PEM_read_bio_EC_PUBKEY(in, NULL, ossl_pem_passwd_cb, passwd);
}
if (!ec) {
OSSL_BIO_reset(in);
ec = d2i_ECPrivateKey_bio(in, NULL);
}
if (!ec) {
OSSL_BIO_reset(in);
ec = d2i_EC_PUBKEY_bio(in, NULL);
}
BIO_free(in);
if (ec == NULL) {
const char *name = StringValueCStr(arg);
int nid = OBJ_sn2nid(name);
(void)ERR_get_error();
if (nid == NID_undef)
ossl_raise(eECError, "unknown curve name (%s)\n", name);
if ((ec = EC_KEY_new_by_curve_name(nid)) == NULL)
ossl_raise(eECError, "unable to create curve (%s)\n", name);
EC_KEY_set_asn1_flag(ec, OPENSSL_EC_NAMED_CURVE);
EC_KEY_set_conv_form(ec, POINT_CONVERSION_UNCOMPRESSED);
}
}
}
if (ec == NULL)
ossl_raise(eECError, NULL);
if (!EVP_PKEY_assign_EC_KEY(pkey, ec)) {
EC_KEY_free(ec);
ossl_raise(eECError, "EVP_PKEY_assign_EC_KEY");
}
rb_iv_set(self, "@group", Qnil);
if (!NIL_P(group))
rb_funcall(self, rb_intern("group="), 1, arg);
return self;
}
开发者ID:jruby,项目名称:openssl,代码行数:91,代码来源:ossl_pkey_ec.c
示例20: Init_proctable
/*
* A Ruby interface for gathering process table information.
*/
void Init_proctable(){
VALUE mSys, cProcTable;
/* The Sys module serves as a namespace only */
mSys = rb_define_module("Sys");
/* The ProcTable class encapsulates process table information */
cProcTable = rb_define_class_under(mSys, "ProcTable", rb_cObject);
/* The Error class typically raised if any of the ProcTable methods fail */
cProcTableError = rb_define_class_under(cProcTable, "Error", rb_eStandardError);
/* Singleton methods */
rb_define_singleton_method(cProcTable, "ps", pt_ps, -1);
rb_define_singleton_method(cProcTable, "fields", pt_fields, 0);
/* There is no constructor */
rb_funcall(cProcTable, rb_intern("private_class_method"), 1, ID2SYM(rb_intern("new")));
/* Constants */
/* 0.9.3: The version of the sys-proctable library */
rb_define_const(cProcTable, "VERSION", rb_str_new2(SYS_PROCTABLE_VERSION));
/* Structs */
sProcStruct = rb_struct_define("ProcTableStruct",
"pid", /* Process identifier */
"ppid", /* Parent process id */
"pgid", /* Process group id */
"ruid", /* Real user id */
"rgid", /* Real group id */
"euid", /* Effective user id */
"egid", /* Effective group id */
"groups", /* All effective group ids */
"svuid", /* Saved effective user id */
"svgid", /* Saved effective group id */
"comm", /* Command name (15 chars) */
"state", /* Process status */
"pctcpu", /* %cpu for this process during p_swtime */
"oncpu", /* nil */
"tnum", /* Controlling tty dev */
"tdev", /* Controlling tty name */
"wmesg", /* Wchan message */
"rtime", /* Real time */
"priority", /* Process priority */
"usrpri", /* User-priority */
"nice", /* Process "nice" value */
"cmdline", /* Complete command line */
"exe", /* Saved pathname of the executed command */
"environ", /* Hash with process environment variables */
"starttime", /* Process start time */
"maxrss", /* Max resident set size (PL) */
"ixrss", /* Integral shared memory size (NU) */
"idrss", /* Integral unshared data (NU) */
"isrss", /* Integral unshared stack (NU) */
"minflt", /* Page reclaims (NU) */
"majflt", /* Page faults (NU) */
"nswap", /* Swaps (NU) */
"inblock", /* Block input operations (atomic) */
"oublock", /* Block output operations (atomic) */
"msgsnd", /* Messages sent (atomic) */
"msgrcv", /* Messages received (atomic) */
"nsignals", /* Signals received (atomic) */
"nvcsw", /* Voluntary context switches (atomic) */
"nivcsw", /* Involuntary context switches (atomic) */
"utime", /* User time used (PL) */
"stime", /* System time used (PL) */
NULL
);
}
开发者ID:toy,项目名称:sys-proctable,代码行数:75,代码来源:proctable.c
注:本文中的rb_funcall函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论