本文整理汇总了C++中rb_obj_class函数的典型用法代码示例。如果您正苦于以下问题:C++ rb_obj_class函数的具体用法?C++ rb_obj_class怎么用?C++ rb_obj_class使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rb_obj_class函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: profiler_m_profile
static VALUE profiler_m_profile(int argc, VALUE *argv, VALUE self)
{
rb_iseq_t *iseq;
VALUE minfo, obj, mid, singleton_p = Qfalse;
rb_scan_args(argc, argv, "21", &obj, &mid, &singleton_p);
if (rb_obj_class(mid) != rb_cSymbol) {
rb_raise(rb_eArgError, "second argument should be symbol");
}
iseq = iseq_find(obj, mid, singleton_p);
minfo = rb_funcall(cMethodInfo, rb_intern("new"), 4, iseq->self, obj, mid, singleton_p);
iseq_inject(iseq);
profiler_linetrace(0);
rb_funcall(cMethodInfo, rb_intern("register"), 1, minfo);
return Qnil;
}
示例2: context_create
extern VALUE
context_create(VALUE thread)
{
debug_context_t *context = ALLOC(debug_context_t);
context->last_file = Qnil;
context->last_line = Qnil;
context->flags = 0;
context->calced_stack_size = real_stack_size();
context->thnum = ++thnum_max;
context->thread = thread;
reset_stepping_stop_points(context);
context->stop_reason = CTX_STOP_NONE;
context->backtrace = Qnil;
if (rb_obj_class(thread) == cDebugThread) CTX_FL_SET(context, CTX_FL_IGNORE);
return Data_Wrap_Struct(cContext, context_mark, 0, context);
}
示例3: recursive_hash
static VALUE
recursive_hash(VALUE s, VALUE dummy, int recur)
{
long i, len;
st_index_t h;
VALUE n, *ptr;
h = rb_hash_start(rb_hash(rb_obj_class(s)));
if (!recur) {
ptr = RSTRUCT_PTR(s);
len = RSTRUCT_LEN(s);
for (i = 0; i < len; i++) {
n = rb_hash(ptr[i]);
h = rb_hash_uint(h, NUM2LONG(n));
}
}
h = rb_hash_end(h);
return INT2FIX(h);
}
示例4: ossl_cipher_init
static VALUE
ossl_cipher_init(int argc, VALUE *argv, VALUE self, int mode)
{
EVP_CIPHER_CTX *ctx;
unsigned char key[EVP_MAX_KEY_LENGTH], *p_key = NULL;
unsigned char iv[EVP_MAX_IV_LENGTH], *p_iv = NULL;
VALUE pass, init_v;
if(rb_scan_args(argc, argv, "02", &pass, &init_v) > 0){
/*
* oops. this code mistakes salt for IV.
* We deprecated the arguments for this method, but we decided
* keeping this behaviour for backward compatibility.
*/
VALUE cname = rb_class_path(rb_obj_class(self));
rb_warn("arguments for %"PRIsVALUE"#encrypt and %"PRIsVALUE"#decrypt were deprecated; "
"use %"PRIsVALUE"#pkcs5_keyivgen to derive key and IV",
cname, cname, cname);
StringValue(pass);
GetCipher(self, ctx);
if (NIL_P(init_v)) memcpy(iv, "OpenSSL for Ruby rulez!", sizeof(iv));
else{
StringValue(init_v);
if (EVP_MAX_IV_LENGTH > RSTRING_LEN(init_v)) {
memset(iv, 0, EVP_MAX_IV_LENGTH);
memcpy(iv, RSTRING_PTR(init_v), RSTRING_LEN(init_v));
}
else memcpy(iv, RSTRING_PTR(init_v), sizeof(iv));
}
EVP_BytesToKey(EVP_CIPHER_CTX_cipher(ctx), EVP_md5(), iv,
(unsigned char *)RSTRING_PTR(pass), RSTRING_LENINT(pass), 1, key, NULL);
p_key = key;
p_iv = iv;
}
else {
GetCipher(self, ctx);
}
if (EVP_CipherInit_ex(ctx, NULL, NULL, p_key, p_iv, mode) != 1) {
ossl_raise(eCipherError, NULL);
}
return self;
}
示例5: rb_digest_base_finish
/* :nodoc: */
static VALUE
rb_digest_base_finish(VALUE self)
{
rb_digest_metadata_t *algo;
void *pctx;
VALUE str;
algo = get_digest_base_metadata(rb_obj_class(self));
TypedData_Get_Struct(self, void, &digest_type, pctx);
str = rb_str_new(0, algo->digest_len);
algo->finish_func(pctx, (unsigned char *)RSTRING_PTR(str));
/* avoid potential coredump caused by use of a finished context */
algo_init(algo, pctx);
return str;
}
示例6: rb_struct_initialize_m
static VALUE
rb_struct_initialize_m(int argc, const VALUE *argv, VALUE self)
{
VALUE klass = rb_obj_class(self);
long i, n;
rb_struct_modify(self);
n = num_members(klass);
if (n < argc) {
rb_raise(rb_eArgError, "struct size differs");
}
for (i=0; i<argc; i++) {
RSTRUCT_SET(self, i, argv[i]);
}
if (n > argc) {
rb_mem_clear((VALUE *)RSTRUCT_CONST_PTR(self)+argc, n-argc);
}
return Qnil;
}
示例7: context_create
extern VALUE
context_create(VALUE thread)
{
debug_context_t *context = ALLOC(debug_context_t);
context->flags = 0;
context->thnum = ++thnum_max;
context->thread = thread;
reset_stepping_stop_points(context);
context->stop_reason = CTX_STOP_NONE;
rb_debug_inspector_open(context_backtrace_set, (void *)context);
context->calced_stack_size = dc_stack_size(context) + 1;
if (rb_obj_class(thread) == cDebugThread)
CTX_FL_SET(context, CTX_FL_IGNORE);
return Data_Wrap_Struct(cContext, context_mark, 0, context);
}
示例8: rbgtk_initialize_gtkobject
void
rbgtk_initialize_gtkobject(VALUE obj, GtkObject *gtkobj)
{
gtkobj = g_object_ref(gtkobj);
gtk_object_sink(gtkobj);
G_INITIALIZE(obj, gtkobj);
if (GTK_IS_WINDOW(gtkobj) || GTK_IS_MENU_SHELL(gtkobj)) {
VALUE klass;
klass = rb_obj_class(obj);
if (rb_ivar_defined(klass, id__windows__) == Qfalse) {
rb_ivar_set(klass, id__windows__, rb_hash_new());
}
rb_hash_aset(rb_ivar_get(klass, id__windows__), obj, Qnil);
g_signal_connect_after(gtkobj, "destroy",
G_CALLBACK(remove_from_windows),
(gpointer)obj);
}
}
示例9: syserr_initialize
static VALUE
syserr_initialize(VALUE self, SEL sel, int argc, VALUE *argv)
{
#if !defined(_WIN32) && !defined(__VMS)
char *strerror();
#endif
const char *err;
VALUE mesg, error;
VALUE klass = rb_obj_class(self);
if (klass == rb_eSystemCallError) {
rb_scan_args(argc, argv, "11", &mesg, &error);
if (argc == 1 && FIXNUM_P(mesg)) {
error = mesg; mesg = Qnil;
}
if (!NIL_P(error) && st_lookup(syserr_tbl, NUM2LONG(error), &klass)) {
/* change class */
if (TYPE(self) != T_OBJECT) { /* insurance to avoid type crash */
rb_raise(rb_eTypeError, "invalid instance type");
}
RBASIC(self)->klass = klass;
}
}
else {
rb_scan_args(argc, argv, "01", &mesg);
error = rb_const_get(klass, rb_intern("Errno"));
}
if (!NIL_P(error)) err = strerror(NUM2INT(error));
else err = "unknown error";
if (!NIL_P(mesg)) {
VALUE str = mesg;
StringValue(str);
mesg = rb_sprintf("%s - %.*s", err,
(int)RSTRING_LEN(str), RSTRING_PTR(str));
}
else {
mesg = rb_str_new2(err);
}
rb_vm_call_super(self, selInitialize2, 1, &mesg);
rb_iv_set(self, "errno", error);
return self;
}
示例10: ossl_cipher_init
static VALUE
ossl_cipher_init(int argc, VALUE *argv, VALUE self, int mode)
{
EVP_CIPHER_CTX *ctx;
unsigned char key[EVP_MAX_KEY_LENGTH], *p_key = NULL;
unsigned char iv[EVP_MAX_IV_LENGTH], *p_iv = NULL;
VALUE pass, init_v;
if(rb_scan_args(argc, argv, "02", &pass, &init_v) > 0){
/*
* oops. this code mistakes salt for IV.
* We deprecated the arguments for this method, but we decided
* keeping this behaviour for backward compatibility.
*/
StringValue(pass);
GetCipher(self, ctx);
if (NIL_P(init_v)) memcpy(iv, "OpenSSL for Ruby rulez!", sizeof(iv));
else{
char *cname = rb_class2name(rb_obj_class(self));
rb_warning("key derivation by %s#encrypt is deprecated; "
"use %s::pkcs5_keyivgen instead", cname, cname);
StringValue(init_v);
if (EVP_MAX_IV_LENGTH > RSTRING(init_v)->len) {
memset(iv, 0, EVP_MAX_IV_LENGTH);
memcpy(iv, RSTRING(init_v)->ptr, RSTRING(init_v)->len);
}
else memcpy(iv, RSTRING(init_v)->ptr, sizeof(iv));
}
EVP_BytesToKey(EVP_CIPHER_CTX_cipher(ctx), EVP_md5(), iv,
RSTRING(pass)->ptr, RSTRING(pass)->len, 1, key, NULL);
p_key = key;
p_iv = iv;
}
else {
GetCipher(self, ctx);
}
if (EVP_CipherInit_ex(ctx, NULL, NULL, p_key, p_iv, mode) != 1) {
ossl_raise(eCipherError, NULL);
}
return self;
}
示例11: inspect_struct
static VALUE
inspect_struct(VALUE s, VALUE dummy, int recur)
{
VALUE cname = rb_class_name(rb_obj_class(s));
VALUE members, str = rb_str_new2("#<struct ");
long i;
char first = RSTRING_PTR(cname)[0];
if (recur || first != '#') {
rb_str_append(str, cname);
}
if (recur) {
return rb_str_cat2(str, ":...>");
}
members = rb_struct_members(s);
for (i=0; i<RSTRUCT_LEN(s); i++) {
VALUE slot;
ID id;
if (i > 0) {
rb_str_cat2(str, ", ");
}
else if (first != '#') {
rb_str_cat2(str, " ");
}
slot = RARRAY_PTR(members)[i];
id = SYM2ID(slot);
if (rb_is_local_id(id) || rb_is_const_id(id)) {
rb_str_append(str, rb_id2str(id));
}
else {
rb_str_append(str, rb_inspect(slot));
}
rb_str_cat2(str, "=");
rb_str_append(str, rb_inspect(RSTRUCT_PTR(s)[i]));
}
rb_str_cat2(str, ">");
OBJ_INFECT(str, s);
return str;
}
示例12: rb_profile_frame_classpath
VALUE
rb_profile_frame_classpath(VALUE frame)
{
VALUE klass = rb_iseq_klass(frame2iseq(frame));
if (klass && !NIL_P(klass)) {
if (RB_TYPE_P(klass, T_ICLASS)) {
klass = RBASIC(klass)->klass;
}
else if (FL_TEST(klass, FL_SINGLETON)) {
klass = rb_ivar_get(klass, id__attached__);
if (!RB_TYPE_P(klass, T_CLASS))
return rb_sprintf("#<%s:%p>", rb_class2name(rb_obj_class(klass)), (void*)klass);
}
return rb_class_path(klass);
}
else {
return Qnil;
}
}
示例13: ra_buffer_init_copy
/* :nodoc: */
static VALUE ra_buffer_init_copy(VALUE copy, VALUE buf) {
if (copy == buf) return copy;
// Checks
rb_check_frozen(copy);
if (!rb_obj_is_instance_of(buf, rb_obj_class(copy))) {
rb_raise(rb_eTypeError, "wrong argument class");
}
RA_BUFFER *copy_struct, *buf_struct;
Data_Get_Struct(copy, RA_BUFFER, copy_struct);
Data_Get_Struct(buf, RA_BUFFER, buf_struct);
// Clone data
memcpy(copy_struct, buf_struct, sizeof(RA_BUFFER));
long size = ra_buffer_alloc_data(copy_struct);
memcpy(copy_struct->data, buf_struct->data, size);
return copy;
}
示例14: rb_struct_initialize
static VALUE
rb_struct_initialize(VALUE self, VALUE values)
{
VALUE klass = rb_obj_class(self);
VALUE size;
long n;
rb_struct_modify(self);
size = rb_struct_iv_get(klass, "__size__");
n = FIX2LONG(size);
if (n < RARRAY(values)->len) {
rb_raise(rb_eArgError, "struct size differs");
}
MEMCPY(RSTRUCT(self)->ptr, RARRAY(values)->ptr, VALUE, RARRAY(values)->len);
if (n > RARRAY(values)->len) {
rb_mem_clear(RSTRUCT(self)->ptr+RARRAY(values)->len,
n-RARRAY(values)->len);
}
return Qnil;
}
示例15: rb_grn_context_initialize
/*
* call-seq:
* Groonga::Context.new(options=nil)
*
* コンテキストを作成する。_options_に指定可能な値は以下の通
* り。
*
* [+:encoding+]
* エンコーディングを指定する。エンコーディングの指定方法
* はGroonga::Encodingを参照。
*/
static VALUE
rb_grn_context_initialize (int argc, VALUE *argv, VALUE self)
{
RbGrnContext *rb_grn_context;
grn_ctx *context;
int flags = 0;
VALUE options, default_options;
VALUE rb_encoding;
rb_scan_args(argc, argv, "01", &options);
default_options = rb_grn_context_s_get_default_options(rb_obj_class(self));
if (NIL_P(default_options))
default_options = rb_hash_new();
if (NIL_P(options))
options = rb_hash_new();
options = rb_funcall(default_options, rb_intern("merge"), 1, options);
rb_grn_scan_options(options,
"encoding", &rb_encoding,
NULL);
rb_grn_context = ALLOC(RbGrnContext);
DATA_PTR(self) = rb_grn_context;
rb_grn_context->self = self;
context = rb_grn_context->context = grn_ctx_open(flags);
rb_grn_context_check(context, self);
GRN_CTX_USER_DATA(context)->ptr = rb_grn_context;
if (!NIL_P(rb_encoding)) {
grn_encoding encoding;
encoding = RVAL2GRNENCODING(rb_encoding, NULL);
GRN_CTX_SET_ENCODING(context, encoding);
}
debug("context new: %p\n", context);
return Qnil;
}