• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ rb_protect函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: cr_push_group

static VALUE
cr_push_group (int argc, VALUE *argv, VALUE self)
{
  VALUE result = Qnil;
  VALUE content, pop_to_source;
  rb_scan_args (argc, argv, "02", &content, &pop_to_source);

  if (NIL_P(content))
    cairo_push_group (_SELF);
  else
    cairo_push_group_with_content (_SELF, RVAL2CRCONTENT(content));
  cr_check_status (_SELF);

  if (rb_block_given_p ())
    {
      int state = 0;

      if (NIL_P (pop_to_source))
        pop_to_source = Qtrue;

      result = rb_protect (rb_yield, self, &state);
      if (cairo_status(_SELF) == CAIRO_STATUS_SUCCESS)
        {
          if (RVAL2CBOOL (pop_to_source))
            cr_pop_group_to_source (self);
          else
            result = cr_pop_group (self);
        }

      if (state)
        rb_jump_tag (state);
    }

  return result;
}
开发者ID:exvayn,项目名称:cairo-1.8.1-i386,代码行数:35,代码来源:rb_cairo_context.c


示例17: eruta_require

VALUE eruta_require() {
    int error;
    VALUE result = rb_protect(eruta_raw_require, 0, &error);
    if(error) return Qnil;
    //    throw;
    return result;
}
开发者ID:beoran,项目名称:eruta,代码行数:7,代码来源:eruta.c


示例18: Eval

VALUE Eval(std::string code)
{
    int status = 0;
    VALUE result = rb_protect(EvalProtect, reinterpret_cast<VALUE>(code.c_str()), &status);
    CheckStatus(status);
    return result;
}
开发者ID:KnIfER,项目名称:armagetron,代码行数:7,代码来源:tRuby.cpp


示例19: cSedna_transaction

/*
 * call-seq:
 *   sedna.transaction { ... } -> nil
 *   sedna.transaction -> nil
 *
 * Wraps the given block in a transaction. If the block runs completely, the
 * transaction is committed. If the stack is unwinded prematurely, the
 * transaction is rolled back. This typically happens when an exception is 
 * raised by calling +raise+ or a Symbol is thrown by invoking +throw+. Note
 * that exceptions will not be rescued -- they will be re-raised after rolling
 * back the transaction.
 *
 * This method returns +nil+ if the transaction is successfully committed
 * to the database. If the given block completes successfully, but the
 * transaction fails to be committed, a Sedna::TransactionError will be raised.
 *
 * Transactions cannot be nested or executed simultaneously with the same
 * connection. Calling this method inside a block that is passed to another
 * transaction, or with the same connection in two concurrent threads will
 * raise a Sedna::TransactionError on the second invocation.
 *
 * If no block is given, this method only signals the beginning of a new
 * transaction. A subsequent call to Sedna#commit or Sedna#rollback is required
 * to end the transaction. Note that invoking this method with a block is the
 * preferred way of executing transactions, because any exceptions that may be
 * raised will automatically trigger a proper transaction rollback. Only call
 * +commit+ and +rollback+ directly if you cannot use a block to wrap your
 * transaction in.
 *
 * ==== Examples
 *
 * Transactions are committed after the given block ends.
 *
 *   sedna.transaction do
 *     amount = 100
 *     sedna.execute "update replace $balance in doc('my_account')/balance
 *                    with <balance>{$balance - #{amount}}</balance>"
 *     sedna.execute "update replace $balance in doc('your_account')/balance
 *                    with <balance>{$balance + #{amount}}</balance>"
 *     # ...
 *   end
 *   # Transaction is committed.
 *
 * Transactions are rolled back if something is thrown from inside the block.
 *
 *   sedna.transaction do
 *     articles = sedna.execute "for $a in collection('articles')
 *                               where $a/article/author = 'me' return $a"
 *     throw :no_articles if articles.empty?
 *     # ... never get here
 *   end
 *   # Transaction is rolled back.
 *
 * Transactions are also rolled back if an exception is raised inside the block.
 *
 *   sedna.transaction do
 *     amount = 100
 *     sedna.execute "update replace $balance in doc('my_account')/balance
 *                    with <balance>{$balance - #{amount}}</balance>"
 *     new_balance = sedna.execute "doc('my_account')/balance"
 *     raise "Insufficient funds" if new_balance.to_i < 0
 *     # ... never get here
 *   end
 *   # Transaction is rolled back.
 *
 * If you really have to, you can also use transactions declaratively. Make
 * sure to roll back the transaction if something goes wrong!
 *
 *   sedna.transaction
 *   begin
 *     amount = 100
 *     sedna.execute "update replace $balance in doc('my_account')/balance
 *                    with <balance>{$balance - #{amount}}</balance>"
 *     sedna.execute "update replace $balance in doc('your_account')/balance
 *                    with <balance>{$balance + #{amount}}</balance>"
 *   rescue Exception
 *     sedna.rollback
 *   else
 *     sedna.commit
 *   end
 */
static VALUE cSedna_transaction(VALUE self)
{
	int status;
	SC *conn = sedna_struct(self);

	// Begin the transaction.
	sedna_begin(conn);

	if(rb_block_given_p()) {
		// Yield to the given block and protect it so we can always commit or rollback.
		rb_protect(rb_yield, Qnil, &status);

		if(status == 0) {
			// Attempt to commit if block completed successfully.
			sedna_commit(conn, self);
		} else {
			// Stack has unwinded, attempt to roll back!
			sedna_rollback(conn, self);

//.........这里部分代码省略.........
开发者ID:rolftimmermans,项目名称:sedna-ruby,代码行数:101,代码来源:sedna.c


示例20: result_each

static VALUE result_each(VALUE self) {
    int r, c, rows, cols, *types, failed;
    PGresult *res;
    Data_Get_Struct(self, PGresult, res);

    VALUE fields = rb_ary_new();
    rows  = PQntuples(res);
    cols  = PQnfields(res);
    types = (int*)malloc(sizeof(int)*cols);
    for (c = 0; c < cols; c++) {
        rb_ary_push(fields, ID2SYM(rb_intern(PQfname(res, c))));
        types[c] = PQftype(res, c);
    }

    for (r = 0; r < rows; r++) {
        VALUE tuple = rb_hash_new();
        for (c = 0; c < cols; c++) {
            rb_hash_aset(tuple, rb_ary_entry(fields, c),
                PQgetisnull(res, r, c) ? Qnil : typecast(PQgetvalue(res, r, c), PQgetlength(res, r, c), types[c]));
        }
        rb_protect(rb_yield, tuple, &failed);
        if (failed) {
            free(types);
            rb_jump_tag(failed);
        }
    }

    free(types);
    return Qnil;
}
开发者ID:deepfryed,项目名称:pg_typecast,代码行数:30,代码来源:pg_typecast.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ rb_raise函数代码示例发布时间:2022-05-30
下一篇:
C++ rb_path2class函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap