当前位置: 首页>>代码示例>>C++>>正文


C++ rb_protect函数代码示例

本文整理汇总了C++中rb_protect函数的典型用法代码示例。如果您正苦于以下问题:C++ rb_protect函数的具体用法?C++ rb_protect怎么用?C++ rb_protect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了rb_protect函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ox_sax_parse

void
ox_sax_parse(VALUE handler, VALUE io, SaxOptions options) {
    struct _SaxDrive    dr;
    int			line = 0;

    sax_drive_init(&dr, handler, io, options);
#if 0
    printf("*** sax_parse with these flags\n");
    printf("    has_instruct = %s\n", dr.has.instruct ? "true" : "false");
    printf("    has_end_instruct = %s\n", dr.has.end_instruct ? "true" : "false");
    printf("    has_attr = %s\n", dr.has.attr ? "true" : "false");
    printf("    has_attr_value = %s\n", dr.has.attr_value ? "true" : "false");
    printf("    has_attrs_done = %s\n", dr.has.attrs_done ? "true" : "false");
    printf("    has_doctype = %s\n", dr.has.doctype ? "true" : "false");
    printf("    has_comment = %s\n", dr.has.comment ? "true" : "false");
    printf("    has_cdata = %s\n", dr.has.cdata ? "true" : "false");
    printf("    has_text = %s\n", dr.has.text ? "true" : "false");
    printf("    has_value = %s\n", dr.has.value ? "true" : "false");
    printf("    has_start_element = %s\n", dr.has.start_element ? "true" : "false");
    printf("    has_end_element = %s\n", dr.has.end_element ? "true" : "false");
    printf("    has_error = %s\n", dr.has.error ? "true" : "false");
    printf("    has_line = %s\n", dr.has.line ? "true" : "false");
    printf("    has_column = %s\n", dr.has.column ? "true" : "false");
#endif
    //parse(&dr);
    rb_protect(protect_parse, (VALUE)&dr, &line);
    ox_sax_drive_cleanup(&dr);
    if (0 != line) {
	rb_jump_tag(line);
    }
}
开发者ID:gouravtiwari,项目名称:ox,代码行数:31,代码来源:sax.c

示例2: rb_protect_funcall

static VALUE
rb_protect_funcall(VALUE recv, ID mid, int *state, int argc, ...)
{
	va_list ap;
	VALUE *argv;
	protect_call_arg arg;

	if (argc > 0) {
		int i;

		argv = ALLOCA_N(VALUE, argc);

		va_start(ap, argc);
		for (i = 0; i < argc; i++) {
			argv[i] = va_arg(ap, VALUE);
		}
		va_end(ap);
	} else {
		argv = 0;
	}
	arg.recv = recv;
	arg.mid = mid;
	arg.argc = argc;
	arg.argv = argv;
	return rb_protect(protect_funcall0, (VALUE) &arg, state);
}
开发者ID:authorNari,项目名称:panda,代码行数:26,代码来源:Ruby.c

示例3: Info_delay_eq

/*
    Method:     Info#delay=
    Purpose:    Set the delay attribute
    Notes:      Convert from numeric value to string.
*/
VALUE
Info_delay_eq(VALUE self, VALUE string)
{
    Info *info;
    int delay;
    int not_num;
    char dstr[20];

    Data_Get_Struct(self, Info, info);

    if (NIL_P(string))
    {
        (void) RemoveImageOption(info, "delay");
    }
    else
    {
        not_num = 0;
        (void) rb_protect(arg_is_integer, string, &not_num);
        if (not_num)
        {
            rb_raise(rb_eTypeError, "failed to convert %s into Integer", rb_class2name(CLASS_OF(string)));
        }
        delay = NUM2INT(string);
        sprintf(dstr, "%d", delay);
        (void) RemoveImageOption(info, "delay");
        (void) SetImageOption(info, "delay", dstr);
    }
    return self;
}
开发者ID:AzkaarAli,项目名称:leihs,代码行数:34,代码来源:rminfo.c

示例4: exc_equal

static VALUE
exc_equal(VALUE exc, VALUE obj)
{
    VALUE mesg, backtrace;

    if (exc == obj) return Qtrue;

    if (rb_obj_class(exc) != rb_obj_class(obj)) {
	int status = 0;

	obj = rb_protect(try_convert_to_exception, obj, &status);
	if (status || obj == Qundef) {
	    rb_set_errinfo(Qnil);
	    return Qfalse;
	}
	if (rb_obj_class(exc) != rb_obj_class(obj)) return Qfalse;
	mesg = rb_check_funcall(obj, id_message, 0, 0);
	if (mesg == Qundef) return Qfalse;
	backtrace = rb_check_funcall(obj, id_backtrace, 0, 0);
	if (backtrace == Qundef) return Qfalse;
    }
    else {
	mesg = rb_attr_get(obj, id_mesg);
	backtrace = exc_backtrace(obj);
    }

    if (!rb_equal(rb_attr_get(exc, id_mesg), mesg))
	return Qfalse;
    if (!rb_equal(exc_backtrace(exc), backtrace))
	return Qfalse;
    return Qtrue;
}
开发者ID:0x00evil,项目名称:ruby,代码行数:32,代码来源:error.c

示例5: rb_libarchive_writer_new_entry

static VALUE rb_libarchive_writer_new_entry(VALUE self) {
  VALUE entry;
  struct rb_libarchive_archive_container *p;
  struct archive_entry *ae;
  Data_Get_Struct(self, struct rb_libarchive_archive_container, p);
  Check_Archive(p);

  if ((ae = archive_entry_new()) == NULL) {
    rb_raise(rb_eArchiveError, "New entry failed: %s", strerror(errno));
  }

  entry = rb_libarchive_entry_new(ae, 1);

  if (rb_block_given_p()) {
    VALUE retval;
    int status;
    retval = rb_protect(rb_yield, entry, &status);
    rb_libarchive_entry_close(entry);

    if (status != 0) {
      rb_jump_tag(status);
    }

    return retval;
  } else {
    return entry;
  }
}
开发者ID:Verba,项目名称:libarchive-ruby,代码行数:28,代码来源:libarchive_writer.c

示例6: ossl_protect_obj2bio

BIO *
ossl_protect_obj2bio(VALUE obj, int *status)
{
     BIO *ret = NULL;
     ret = (BIO*)rb_protect((VALUE (*)(VALUE))ossl_obj2bio, obj, status);
     return ret;
}
开发者ID:gferguson-gd,项目名称:ruby,代码行数:7,代码来源:ossl_bio.c

示例7: cb_submodule__each

static int cb_submodule__each(git_submodule *submodule, const char *name, void *data)
{
	struct rugged_cb_payload *payload = data;
	git_repository *repo;
	git_submodule *dummy_sm;
	VALUE rb_repo;

	rb_repo = payload->rb_data;
	Data_Get_Struct(rb_repo, git_repository, repo);

	/* The submodule passed here has it's refcount decreased just after
	 * the foreach finishes. The only way to increase that refcount is
	 * to lookup the submodule.
	 *
	 * This should not return an error as the submodule name here is valid
	 * and exists, as it was just passed to this callback.
	 */
	git_submodule_lookup(&dummy_sm, repo, git_submodule_name(submodule));

	rb_protect(
		rb_yield,
		rugged_submodule_new(rb_repo, dummy_sm),
		&payload->exception
	);
	return (payload->exception) ? GIT_ERROR : GIT_OK;
}
开发者ID:Angeldude,项目名称:sonic-pi,代码行数:26,代码来源:rugged_submodule_collection.c

示例8: rb_funcall_protected

static VALUE rb_funcall_protected(VALUE recvobj, ID mid, int argc, ...)
{
  va_list ap;
  VALUE *argv;
  VALUE rval;
  int state = 0;
  int i;
  protect_call_arg_t arg;

  if (argc > 0) {
    argv = ALLOCA_N(VALUE, argc);
    va_start(ap, argc);
    for (i = 0; i < argc; ++i) {
      argv[i] = va_arg(ap, VALUE);
    }
    va_end(ap);
  } else {
    argv = 0;
  }
  arg.recvobj = recvobj;
  arg.mid = mid;
  arg.argc = argc;
  arg.argv = argv;
  rval = rb_protect(protect_funcall0, (VALUE) &arg, &state);
  if (state != 0) {
    iroffer_ruby_errro(state);
    return Qnil;
  }
  return rval;
}
开发者ID:KayDat,项目名称:iroffer-dinoex,代码行数:30,代码来源:dinoex_ruby.c

示例9: libvirt_secret_value

/*
 * call-seq:
 *   secret.value(flags=0) -> String
 *
 * Call virSecretGetValue[http://www.libvirt.org/html/libvirt-libvirt-secret.html#virSecretGetValue]
 * to retrieve the value from this secret.
 */
static VALUE libvirt_secret_value(int argc, VALUE *argv, VALUE s)
{
    VALUE flags, ret;
    unsigned char *val;
    size_t value_size;
    int exception = 0;
    struct ruby_libvirt_str_new_arg args;

    rb_scan_args(argc, argv, "01", &flags);

    val = virSecretGetValue(secret_get(s), &value_size,
                            ruby_libvirt_value_to_uint(flags));

    ruby_libvirt_raise_error_if(val == NULL, e_RetrieveError,
                                "virSecretGetValue",
                                ruby_libvirt_connect_get(s));

    args.val = (char *)val;
    args.size = value_size;
    ret = rb_protect(ruby_libvirt_str_new_wrap, (VALUE)&args, &exception);
    free(val);
    if (exception) {
        rb_jump_tag(exception);
    }

    return ret;
}
开发者ID:Grejeru,项目名称:ruby-libvirt,代码行数:34,代码来源:secret.c

示例10: fs_watcher_new

static VALUE
fs_watcher_new(VALUE klass, VALUE filenames, VALUE termination_pipe) {
	FSWatcher *watcher;
	VALUE result;
	int status;
	
	Check_Type(filenames, T_ARRAY);
	watcher = (FSWatcher *) calloc(1, sizeof(FSWatcher));
	if (watcher == NULL) {
		rb_raise(rb_eNoMemError, "Cannot allocate memory.");
		return Qnil;
	}
	watcher->klass = klass;
	watcher->filenames = filenames;
	watcher->termination_pipe = termination_pipe;
	watcher->termination_fd = -1;
	watcher->kq = -1;
	watcher->notification_fd[0] = -1;
	watcher->notification_fd[1] = -1;
	watcher->interruption_fd[0] = -1;
	watcher->interruption_fd[1] = -1;
	
	result = rb_protect(fs_watcher_init, (VALUE) watcher, &status);
	if (status) {
		fs_watcher_free(watcher);
		rb_jump_tag(status);
	} else {
		return result;
	}
}
开发者ID:SpoBo,项目名称:passenger,代码行数:30,代码来源:passenger_native_support.c

示例11: _T

// ----------------------------------------------------------------------------
bool RubyClassHandler::Call_Ruby_OnTuioData( struct structMtSuTuioData& tuioData )
// ----------------------------------------------------------------------------
{
    // Called from windows message loop

    // Stow accessible parms for static methods
    // and do a rb_protect call to appropriate Ruby OnTuioData method
    // for each Ruby TuioClient object in our array

    VALUE suppressData = 0;
    int status = false;
    m_pMtSuTuioData = &tuioData;
    wxString methodToCall = tuioData.packetMsg.Mid(0,7);

    if ( methodToCall.Matches(_T("add obj")) )
        methodToCall = _T("AddObject");
    else
    if ( methodToCall.Matches(_T("set obj")) )
        methodToCall = _T("SetObject");
    else
    if ( methodToCall.Matches(_T("del obj")) )
        methodToCall = _T("DelObject");
    else
    if ( methodToCall.Matches(_T("add cur")) )
        methodToCall = _T("AddCursor");
    else
    if ( methodToCall.Matches(_T("set cur")) )
        methodToCall = _T("SetCursor");
    else
    if ( methodToCall.Matches(_T("del cur")) )
        methodToCall = _T("DelCursor");
    else
    return 0;

    // Set parms in this obj that are needed in static funcs
    // so it can be read with a global 'This' pointer
    m_TuioDataMethodToCall = _T("OnTuio") + methodToCall;


    // Call each Ruby TuioClient object having the OnTuioData method instantiated
    int count = GetRubyObjCount();
    for (int i=0; i<count; ++i )
    {
        VALUE tuioClientObj = GetRubyObj(i);

        if ( MethodExists(tuioClientObj, _T("OnTuio")+methodToCall) )
        {
            #if defined(LOGGING)
            //LOGIT( "RubyClassHandler::CallRubyOnTuioData type[%s]", methodToCall.c_str());
            #endif

            // protect ourselves from Ruby exception throwing
            VALUE rc = rb_protect ( &rbpOnTuioDataMethod, tuioClientObj, &status);
            if ( status ) ShowRubyError( status );
            // Did anyone suppress the data?
            if ( (not status) && rc) suppressData = true;
        }
    }
    return (bool)suppressData;
}
开发者ID:nuigroup,项目名称:sketch-up-multitouch,代码行数:61,代码来源:RubyClass.cpp

示例12: create_object

VALUE create_object(const char* class_name, int n, va_list ar)
{
    VALUE *argv = 0;

    if (n > 0) 
    {
        argv = ALLOCA_N(VALUE, n);

        int i;
        for(i=0; i<n ;i++)
        {
            argv[i] = va_arg(ar, VALUE);
        }
    } 

    NewArguments arg(class_name, 0, 0);

    arg.n    = n;
    arg.argv = argv;

    int error = 0;
    VALUE self = rb_protect(create_object_protect, reinterpret_cast<VALUE>(&arg), &error);

    if(error)
    {
        std::stringstream strm;
        strm << "Error creating Ruby class '" << class_name << "'";

        Exception e(strm.str().c_str());
        e.backtrace();
        throw e;
    }

    return self;
}
开发者ID:bdheeman,项目名称:mod_ruby,代码行数:35,代码来源:ruby.cpp

示例13: vm_method

VALUE vm_method(VALUE recv, ID id, int n, va_list ar)
{
    VALUE *argv = 0;

    if (n > 0) 
    {
        argv = ALLOCA_N(VALUE, n);

        int i;
        for(i=0; i<n ;i++)
        {
            argv[i] = va_arg(ar, VALUE);
        }
    } 

    Arguments arg;
    arg.recv = recv;
    arg.id   = id;
    arg.n    = n;
    arg.argv = argv;

    int error = 0;
    VALUE result = rb_protect(method_wrap, reinterpret_cast<VALUE>(&arg), &error);

    if(error)
    {
        Exception e;
        e.backtrace();
        throw e;
    }

    return result;
}
开发者ID:bdheeman,项目名称:mod_ruby,代码行数:33,代码来源:ruby.cpp

示例14: ruby_coroutine_body_require

static VALUE ruby_coroutine_body_require(const char* file)
{
    int error;
    VALUE result = rb_protect((VALUE (*)(VALUE))rb_require,
                              (VALUE)file, &error);

    if (error)
    {
        printf("rb_require('%s') failed with status=%d\n",
               file, error);

        VALUE exception = rb_gv_get("$!");
        if (RTEST(exception))
        {
            printf("... because an exception was raised:\n");
            fflush(stdout);

            VALUE inspect = rb_inspect(exception);
            rb_io_puts(1, &inspect, rb_stderr);

            VALUE backtrace = rb_funcall(
                exception, rb_intern("backtrace"), 0);
            rb_io_puts(1, &backtrace, rb_stderr);
        }
    }

    return result;
}
开发者ID:sunaku,项目名称:ruby-coroutine-example,代码行数:28,代码来源:main.c

示例15: MethodArity

	SharedValue KRubyMethod::Call(const ValueList& args)
	{
		// Bloody hell, Ruby will segfault if we try to pass a number
		// of args to a method that is greater than its arity
		int arity = MethodArity(this->method);
		VALUE ruby_args = rb_ary_new();

		if (this->arg != Qnil)
			rb_ary_push(ruby_args, this->arg);

		// A negative arity means that this method can take a
		// variable number of arguments, so pass all args
		if (arity < 0)
			arity = args.size();

		for (size_t i = 0; i < args.size() && (int) i < arity; i++)
			rb_ary_push(ruby_args, RubyUtils::ToRubyValue(args[i]));

		int error;
		VALUE do_call_args = rb_ary_new();
		rb_ary_push(do_call_args, this->method);
		rb_ary_push(do_call_args, ruby_args);
		VALUE result = rb_protect(DoMethodCall, do_call_args, &error);

		if (error != 0)
		{
			ValueException e = RubyUtils::GetException();
			SharedString ss = e.DisplayString();
			std::cout << "Error: " << *ss << std::endl;
			throw e;
		}

		return RubyUtils::ToKrollValue(result);
	}
开发者ID:jonnymind,项目名称:kroll,代码行数:34,代码来源:k_ruby_method.cpp


注:本文中的rb_protect函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。