コード例 #1
0
ファイル: sax.c プロジェクト: gouravtiwari/ox
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);
    }
}
コード例 #2
0
ファイル: Ruby.c プロジェクト: authorNari/panda
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);
}
コード例 #3
0
ファイル: rminfo.c プロジェクト: AzkaarAli/leihs
/*
    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;
}
コード例 #4
0
ファイル: error.c プロジェクト: 0x00evil/ruby
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;
}
コード例 #5
0
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;
  }
}
コード例 #6
0
ファイル: ossl_bio.c プロジェクト: gferguson-gd/ruby
BIO *
ossl_protect_obj2bio(VALUE obj, int *status)
{
     BIO *ret = NULL;
     ret = (BIO*)rb_protect((VALUE (*)(VALUE))ossl_obj2bio, obj, status);
     return ret;
}
コード例 #7
0
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;
}
コード例 #8
0
VALUE
do_ruby_ret(VALUE recv, ID id, int parc, ...)
{
  int i;
  va_list varg;
  struct ruby_args args;
  int status;
  VALUE *parv;
  VALUE ret;

  if(parc > 0)
  {
    parv = ALLOCA_N(VALUE, parc);
    va_start(varg, parc);

    for(i = 0; i < parc; i++)
      parv[i] = va_arg(varg, VALUE);

    va_end(varg);
  }
  else
    parv = 0;

  args.recv = recv;
  args.id = id;
  args.parc = parc;
  args.parv = parv;

  ret = rb_protect(rb_singleton_call, (VALUE)&args, &status);

  if(ruby_handle_error(status))
    return Qnil;

  return ret;
}
コード例 #9
0
ファイル: dinoex_ruby.c プロジェクト: KayDat/iroffer-dinoex
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;
}
コード例 #10
0
ファイル: secret.c プロジェクト: Grejeru/ruby-libvirt
/*
 * 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;
}
コード例 #11
0
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;
	}
}
コード例 #12
0
// ----------------------------------------------------------------------------
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;
}
コード例 #13
0
ファイル: ruby.cpp プロジェクト: bdheeman/mod_ruby
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;
}
コード例 #14
0
ファイル: ruby.cpp プロジェクト: bdheeman/mod_ruby
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;
}
コード例 #15
0
ファイル: main.c プロジェクト: sunaku/ruby-coroutine-example
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;
}
コード例 #16
0
ファイル: k_ruby_method.cpp プロジェクト: jonnymind/kroll
	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);
	}
コード例 #17
0
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;
}
コード例 #18
0
ファイル: eruta.c プロジェクト: beoran/eruta
VALUE eruta_require() {
    int error;
    VALUE result = rb_protect(eruta_raw_require, 0, &error);
    if(error) return Qnil;
    //    throw;
    return result;
}
コード例 #19
0
ファイル: tRuby.cpp プロジェクト: KnIfER/armagetron
VALUE Eval(std::string code)
{
    int status = 0;
    VALUE result = rb_protect(EvalProtect, reinterpret_cast<VALUE>(code.c_str()), &status);
    CheckStatus(status);
    return result;
}
コード例 #20
0
ファイル: sedna.c プロジェクト: rolftimmermans/sedna-ruby
/*
 * 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);

			// Re-raise any exception or re-throw whatever was thrown.
			rb_jump_tag(status);
		}
	}

	// Always return nil if successful.
	return Qnil;
}
コード例 #21
0
ファイル: pg_typecast.c プロジェクト: deepfryed/pg_typecast
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;
}
コード例 #22
0
ファイル: trace.c プロジェクト: methodmissing/io-trace
/*
 * IO::Trace#run(stream = nil, formatter = nil)
 *
 * - Enables tracing
 * - Setup an MRI event hook for RUBY_EVENT_LINE
 * - yields the block
 * - Unregister event hook
 * - Stops tracing
 * - Snapshot collected aggregates
 * - Walk collected aggregates
 * - Dump results to a stream via a given formatter (both optional)
 *
 * Stream expects a #<<(data) and formatters a lambda{|stream, lambda| ... } contract
*/
static VALUE
rb_io_trace_run(int argc, VALUE *argv, VALUE obj)
{
    io_trace_t* trace = GetIOTracer(obj);
    VALUE formatter, result;
    int ret, status;
    result = Qnil;

    BlockRequired();

    rb_scan_args(argc, argv, "02", &trace->stream, &trace->formatter);
    StartTrace(trace);
#ifdef RUBY_VM
    rb_add_event_hook(rb_io_trace_event_hook, RUBY_EVENT_LINE, Qnil);
#else
    rb_add_event_hook(rb_io_trace_event_hook, RUBY_EVENT_LINE);
#endif
    result = rb_protect(rb_yield, obj, &status);
    rb_remove_event_hook(rb_io_trace_event_hook);
    StopTrace(trace);
    if(!NIL_P(trace->stream)){
      formatter = rb_io_trace_formatter(trace);
      rb_funcall(formatter, id_call, 2, obj, trace->stream);
    }
    return result;
}
コード例 #23
0
ファイル: ossl_pkey.c プロジェクト: hilben/ruby_test
/* OpenSSL 2nd version of GN generation callback */
int
ossl_generate_cb_2(int p, int n, BN_GENCB *cb)
{
    VALUE ary;
    struct ossl_generate_cb_arg *arg;
    int state;

    arg = (struct ossl_generate_cb_arg *)cb->arg;
    if (arg->yield) {
	ary = rb_ary_new2(2);
	rb_ary_store(ary, 0, INT2NUM(p));
	rb_ary_store(ary, 1, INT2NUM(n));

	/*
	* can be break by raising exception or 'break'
	*/
	rb_protect(rb_yield, ary, &state);
	if (state) {
	    arg->stop = 1;
	    arg->state = state;
	}
    }
    if (arg->stop) return 0;
    return 1;
}
コード例 #24
0
static gboolean
rg_regex_eval_callback(const GMatchInfo *match_info,
                       GString *result,
                       gpointer user_data)
{
    VALUE returned_data;
    RGRegexEvalCallbackData *data = user_data;

    data->match_info = match_info;
    returned_data = rb_protect(rg_regex_eval_callback_body,
                               (VALUE)data,
                               &(data->status));

    if (data->status == RUBY_TAG_BREAK) {
        returned_data = THROW_DATA_VAL(rb_errinfo());
    }

    if (NIL_P(returned_data)) {
        gchar *matched;
        matched = g_match_info_fetch(match_info, 0);
        g_string_append(result, matched);
        g_free(matched);
    } else {
        g_string_append(result, RVAL2CSTR(returned_data));
    }

    return data->status != 0;
}
コード例 #25
0
static int cb_note__each(const git_oid *blob_id, const git_oid *annotated_object_id, void *data)
{
	VALUE rb_args = rb_ary_new2(2);
	struct rugged_cb_payload *payload = data;
	git_object *annotated_object;
	git_object *note_blob;

	git_repository *repo;

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

	rugged_exception_check(
		git_object_lookup(&annotated_object, repo, annotated_object_id, GIT_OBJ_ANY)
	);

	rugged_exception_check(
		git_object_lookup(&note_blob, repo, blob_id, GIT_OBJ_BLOB)
	);

	rb_ary_push(rb_args, rugged_object_new(payload->rb_data, note_blob));
	rb_ary_push(rb_args, rugged_object_new(payload->rb_data, annotated_object));

	rb_protect(rb_yield_splat, rb_args, &payload->exception);

	return payload->exception ? GIT_ERROR : GIT_OK;
}
コード例 #26
0
static VALUE
rbclt_model_iter_set (int argc, VALUE *argv, VALUE self)
{
    ClutterModel *model;
    int state = 0;
    GetData data;
    int i;

    if ((argc & 1))
        rb_raise (rb_eArgError, "wrong number of arguments "
                  "(paired arguments required)");

    data.iter = CLUTTER_MODEL_ITER (RVAL2GOBJ (self));
    model = clutter_model_iter_get_model (data.iter);

    for (i = 0; i < argc && state == 0; i += 2)
    {
        data.column = NUM2UINT (argv[i]);
        data.rvalue = argv[i + 1];

        memset (&data.value, 0, sizeof (data.value));

        g_value_init (&data.value, clutter_model_get_column_type (model,
                      data.column));
        rb_protect (rbclt_model_iter_do_set, (VALUE) &data, &state);
        g_value_unset (&data.value);
    }

    if (state)
        rb_jump_tag (state);

    return self;
}
コード例 #27
0
ファイル: encoding.c プロジェクト: 217/ruby
static int
load_encoding(const char *name)
{
    VALUE enclib = rb_sprintf("enc/%s.so", name);
    VALUE verbose = ruby_verbose;
    VALUE debug = ruby_debug;
    VALUE loaded;
    char *s = RSTRING_PTR(enclib) + 4, *e = RSTRING_END(enclib) - 3;
    int idx;

    while (s < e) {
	if (!ISALNUM(*s)) *s = '_';
	else if (ISUPPER(*s)) *s = TOLOWER(*s);
	++s;
    }
    OBJ_FREEZE(enclib);
    ruby_verbose = Qfalse;
    ruby_debug = Qfalse;
    loaded = rb_protect(require_enc, enclib, 0);
    ruby_verbose = verbose;
    ruby_debug = debug;
    rb_set_errinfo(Qnil);
    if (NIL_P(loaded)) return -1;
    if ((idx = rb_enc_registered(name)) < 0) return -1;
    if (enc_autoload_p(enc_table.list[idx].enc)) return -1;
    return idx;
}
コード例 #28
0
ファイル: hooks.c プロジェクト: rkd77/elinks-tv
static VALUE
erb_protected_method_call(unsigned char *name, int argc, VALUE *args, int *error)
{
	struct erb_protect_info info = { name, argc, args };

	return rb_protect(do_erb_protected_method_call, (VALUE) &info, error);
}
コード例 #29
0
ファイル: ossl.c プロジェクト: genki/ruby
int
ossl_pem_passwd_cb(char *buf, int max_len, int flag, void *pwd)
{
    int len, status = 0;
    VALUE rflag, pass;
    
    if (pwd || !rb_block_given_p())
	return PEM_def_callback(buf, max_len, flag, pwd);

    while (1) {
	/*
	 * when the flag is nonzero, this passphrase
	 * will be used to perform encryption; otherwise it will
	 * be used to perform decryption.
	 */
	rflag = flag ? Qtrue : Qfalse;
	pass  = rb_protect(ossl_pem_passwd_cb0, rflag, &status);
	if (status) return -1; /* exception was raised. */
	len = RSTRING_LEN(pass);
	if (len < 4) { /* 4 is OpenSSL hardcoded limit */
	    rb_warning("password must be longer than 4 bytes");
	    continue;
	}
	if (len > max_len) {
	    rb_warning("password must be shorter then %d bytes", max_len-1);
	    continue;
	}
	memcpy(buf, RSTRING_PTR(pass), len);
	break;
    }
    return len;
}
コード例 #30
0
    // evaluate a ruby statement with no return value. If a ruby exception is raised
    // the description is translated into a C++ exception, which is thrown as an openstudio::RubyException.
    void evalString(const std::string &t_str)
    {

      VALUE val = rb_str_new2(t_str.c_str());
      int error;

      // save and restore the current working directory in case the call to ruby upsets it
//      QDir cwd = QDir::current();
      rb_protect(evaluateSimpleImpl,val,&error);
//      QDir::setCurrent(cwd.dirName());


      if (error != 0)
      {
        VALUE errval = rb_eval_string("$!.to_s");
        char *str = StringValuePtr(errval);
        std::string err(str);

        VALUE locval = rb_eval_string("[email protected]_s");
        str = StringValuePtr(locval);
        std::string loc(str);

        throw RubyException(err, loc);
      } 
    }