Ejemplo n.º 1
0
void
rb_grn_context_check (grn_ctx *context, VALUE related_object)
{
    VALUE exception;

    exception = rb_grn_context_to_exception(context, related_object);
    if (NIL_P(exception))
	return;

    rb_exc_raise(exception);
}
Ejemplo n.º 2
0
void
rb_loaderror(const char *fmt, ...)
{
    va_list args;
    char buf[BUFSIZ];

    va_start(args, fmt);
    vsnprintf(buf, BUFSIZ, fmt, args);
    va_end(args);
    rb_exc_raise(rb_exc_new2(rb_eLoadError, buf));
}
Ejemplo n.º 3
0
/* 
 *  call-seq:
 *     lmc.each_pair {|k, v|  block } -> nil
 *
 *  Iterates over hashtable.
 */
static VALUE LocalMemCache__each_pair(VALUE obj) {
  VALUE d = rb_ary_new();
  rb_ary_push(d, obj);
  int error = 0;
  rb_protect(__LocalMemCache__each_pair, d, &error);
  if (error) {
    lmc_unlock_shm_region("local_memcache_iterate", get_LocalMemCache(obj));
    rb_exc_raise(ruby_errinfo);
  }
  return Qnil;
}
Ejemplo n.º 4
0
Archivo: error.c Proyecto: evan/ruby
void
rb_raise(VALUE exc, const char *fmt, ...)
{
    va_list args;
    VALUE mesg;

    va_start(args, fmt);
    mesg = rb_vsprintf(fmt, args);
    va_end(args);
    rb_exc_raise(rb_exc_new3(exc, mesg));
}
Ejemplo n.º 5
0
void
rb_raise(VALUE exc, const char *fmt, ...)
{
    va_list args;
    char buf[BUFSIZ];

    va_start(args,fmt);
    vsnprintf(buf, BUFSIZ, fmt, args);
    va_end(args);
    rb_exc_raise(rb_exc_new2(exc, buf));
}
Ejemplo n.º 6
0
// Test the last error message for conn, and raise an exception if there is one.
// The type of the exception is based on the result of the function that was
// called that generated the error and should be passed as res.
static void sedna_err(SC *conn, int res)
{
	VALUE exc_class, exc;
	const char *msg;
	char *code, *err, *details, *p, exc_message[BUFSIZ];

	switch(res) {
		case SEDNA_AUTHENTICATION_FAILED:
			exc_class = cSednaAuthError; break;
		case SEDNA_OPEN_SESSION_FAILED:
		case SEDNA_CLOSE_SESSION_FAILED:
			exc_class = cSednaConnError; break;
		case SEDNA_BEGIN_TRANSACTION_FAILED:
		case SEDNA_ROLLBACK_TRANSACTION_FAILED:
		case SEDNA_COMMIT_TRANSACTION_FAILED:
			exc_class = cSednaTrnError; break;
		case SEDNA_ERROR:
		default:
			exc_class = cSednaException;
	}

	msg = SEgetLastErrorMsg(conn);
	// SEgetLastErrorCode(conn) is useless, because it varies if the order of
	// errors changes. The actual code is a string which is defined in error_codes.h
	// in the Sedna source code.
	code = strstr(msg, "ERROR ");
	err = strstr(msg, "\n");
	details = strstr(err, "\nDetails: ");

	if(code != NULL) {
		code += 6; // Advance beyond "ERROR "
		if((p = strstr(code, "\n")) != NULL) strncpy(p, "\0", 1);
	}

	if(err != NULL) {
		err++; // Advance beyond "\n"
		if((p = strstr(err, "\n")) != NULL) strncpy(p, "\0", 1);
	} else {
		err = strdup("Unknown error.");
	}

	if(details != NULL) {
		details += 10; // Advance beyond "\nDetails: "
		while((p = strstr(details, "\n")) != NULL) strncpy(p, " ", 1);
		snprintf(exc_message, BUFSIZ, "%s (%s)", err, details);
	} else {
		snprintf(exc_message, BUFSIZ, "%s", err);
	}
	exc = rb_exc_new2(exc_class, exc_message);
	if(code != NULL) {
		rb_iv_set(exc, IV_EXC_CODE, rb_str_new2(code));
	}
	rb_exc_raise(exc);
}
Ejemplo n.º 7
0
/*
 * call-seq:
 *    res.check -> nil
 *
 * Raises appropriate exception if PG::Result is in a bad state.
 */
VALUE
pg_result_check( VALUE self )
{
	VALUE error, exception;
	VALUE rb_pgconn = rb_iv_get( self, "@connection" );
	PGconn *conn = pg_get_pgconn(rb_pgconn);
	PGresult *result;
#ifdef M17N_SUPPORTED
	rb_encoding *enc = pg_conn_enc_get( conn );
#endif

	Data_Get_Struct(self, PGresult, result);

	if(result == NULL)
	{
		error = rb_str_new2( PQerrorMessage(conn) );
	}
	else
	{
		switch (PQresultStatus(result))
		{
		case PGRES_TUPLES_OK:
		case PGRES_COPY_OUT:
		case PGRES_COPY_IN:
#ifdef HAVE_CONST_PGRES_COPY_BOTH
		case PGRES_COPY_BOTH:
#endif
#ifdef HAVE_CONST_PGRES_SINGLE_TUPLE
		case PGRES_SINGLE_TUPLE:
#endif
		case PGRES_EMPTY_QUERY:
		case PGRES_COMMAND_OK:
			return Qnil;
		case PGRES_BAD_RESPONSE:
		case PGRES_FATAL_ERROR:
		case PGRES_NONFATAL_ERROR:
			error = rb_str_new2( PQresultErrorMessage(result) );
			break;
		default:
			error = rb_str_new2( "internal error : unknown result status." );
		}
	}

#ifdef M17N_SUPPORTED
	rb_enc_set_index( error, rb_enc_to_index(enc) );
#endif
	exception = rb_exc_new3( rb_ePGerror, error );
	rb_iv_set( exception, "@connection", rb_pgconn );
	rb_iv_set( exception, "@result", self );
	rb_exc_raise( exception );

	/* Not reached */
	return Qnil;
}
Ejemplo n.º 8
0
/*
 *  call-seq:
 *    transform(document, params = [])
 *
 *  Apply an XSLT stylesheet to an XML::Document.
 *  +params+ is an array of strings used as XSLT parameters.
 *  returns Nokogiri::XML::Document
 *
 *  Example:
 * 
 *    doc   = Nokogiri::XML(File.read(ARGV[0]))
 *    xslt  = Nokogiri::XSLT(File.read(ARGV[1]))
 *    puts xslt.transform(doc, ['key', 'value'])
 *
 */
static VALUE transform(int argc, VALUE* argv, VALUE self)
{
    VALUE xmldoc, paramobj, errstr, exception ;
    xmlDocPtr xml ;
    xmlDocPtr result ;
    nokogiriXsltStylesheetTuple *wrapper;
    const char** params ;
    long param_len, j ;
    int parse_error_occurred ;

    rb_scan_args(argc, argv, "11", &xmldoc, &paramobj);
    if (NIL_P(paramobj)) { paramobj = rb_ary_new2(0L) ; }
    if (!rb_obj_is_kind_of(xmldoc, cNokogiriXmlDocument))
      rb_raise(rb_eArgError, "argument must be a Nokogiri::XML::Document");

    /* handle hashes as arguments. */
    if(T_HASH == TYPE(paramobj)) {
      paramobj = rb_funcall(paramobj, rb_intern("to_a"), 0);
      paramobj = rb_funcall(paramobj, rb_intern("flatten"), 0);
    }

    Check_Type(paramobj, T_ARRAY);

    Data_Get_Struct(xmldoc, xmlDoc, xml);
    Data_Get_Struct(self, nokogiriXsltStylesheetTuple, wrapper);

    param_len = RARRAY_LEN(paramobj);
    params = calloc((size_t)param_len+1, sizeof(char*));
    for (j = 0 ; j < param_len ; j++) {
      VALUE entry = rb_ary_entry(paramobj, j);
      const char * ptr = StringValuePtr(entry);
      params[j] = ptr;
    }
    params[param_len] = 0 ;

    errstr = rb_str_new(0, 0);
    xsltSetGenericErrorFunc((void *)errstr, xslt_generic_error_handler);
    xmlSetGenericErrorFunc(NULL, (xmlGenericErrorFunc)&swallow_superfluous_xml_errors);

    result = xsltApplyStylesheet(wrapper->ss, xml, params);
    free(params);

    xsltSetGenericErrorFunc(NULL, NULL);
    xmlSetGenericErrorFunc(NULL, NULL);

    parse_error_occurred = (Qfalse == rb_funcall(errstr, rb_intern("empty?"), 0));

    if (parse_error_occurred) {
      exception = rb_exc_new3(rb_eRuntimeError, errstr);
      rb_exc_raise(exception);
    }

    return Nokogiri_wrap_xml_document((VALUE)0, result) ;
}
Ejemplo n.º 9
0
static inline rb_control_frame_t *
vm_push_frame(rb_thread_t * th, const rb_iseq_t * iseq,
	      VALUE type, VALUE self, VALUE specval,
	      const VALUE *pc, VALUE *sp, VALUE *lfp,
	      int local_size)
{
    rb_control_frame_t * const cfp = th->cfp - 1;
    int i;

    if ((void *)(sp + local_size) >= (void *)cfp) {
	rb_exc_raise(sysstack_error);
    }
    th->cfp = cfp;
    /* setup vm value stack */

    /* nil initialize */
    for (i=0; i < local_size; i++) {
	*sp = Qnil;
	sp++;
    }

    /* set special val */
    *sp = GC_GUARDED_PTR(specval);

    if (lfp == 0) {
	lfp = sp;
    }

    /* setup vm control frame stack */

    cfp->pc = (VALUE *)pc;
    cfp->sp = sp + 1;
    cfp->bp = sp + 1;
    cfp->iseq = (rb_iseq_t *) iseq;
    cfp->flag = type;
    cfp->self = self;
    cfp->lfp = lfp;
    cfp->dfp = sp;
    cfp->block_iseq = 0;
    cfp->proc = 0;
    cfp->me = 0;

#define COLLECT_PROFILE 0
#if COLLECT_PROFILE
    cfp->prof_time_self = clock();
    cfp->prof_time_chld = 0;
#endif

    if (VMDEBUG == 2) {
	SDR();
    }

    return cfp;
}
Ejemplo n.º 10
0
Archivo: error.c Proyecto: evan/ruby
void
rb_loaderror(const char *fmt, ...)
{
    va_list args;
    VALUE mesg;

    va_start(args, fmt);
    mesg = rb_enc_vsprintf(rb_locale_encoding(), fmt, args);
    va_end(args);
    rb_exc_raise(rb_exc_new3(rb_eLoadError, mesg));
}
Ejemplo n.º 11
0
VALUE startTransactionRescue(VALUE transaction, VALUE error)

{

   rb_funcall(transaction, rb_intern("rollback"), 0);

   rb_exc_raise(error);

   return(Qnil);

}
Ejemplo n.º 12
0
VALUE executeImmediateRescue(VALUE set, VALUE error)

{

   rb_funcall(set, rb_intern("close"), 0);

   rb_exc_raise(error);

   return(Qnil);

}
Ejemplo n.º 13
0
void
rb_memerror()
{
    static int recurse = 0;

    if (!nomem_error || (recurse > 0 && rb_safe_level() < 4)) {
	fprintf(stderr, "[FATAL] failed to allocate memory\n");
	exit(1);
    }
    recurse++;
    rb_exc_raise(nomem_error);
}
Ejemplo n.º 14
0
void libssh_ruby_raise(ssh_session session) {
  VALUE exc, code, message;
  VALUE argv[1];

  code = INT2FIX(ssh_get_error_code(session));
  message = rb_str_new_cstr(ssh_get_error(session));
  argv[0] = message;
  exc = rb_class_new_instance(1, argv, rb_eLibSSHError);
  rb_ivar_set(exc, id_code, code);

  rb_exc_raise(exc);
}
Ejemplo n.º 15
0
static VALUE
rval2gslist_rescue(VALUE data, VALUE e)
{
    struct rval2gslist_args *args = (struct rval2gslist_args *)data;

    g_slist_free(args->list);
    args->list = NULL;

    rb_exc_raise(e);

    return Qnil;
}
Ejemplo n.º 16
0
void yajl_parse_chunk(const unsigned char * chunk, unsigned int len, yajl_handle parser) {
    yajl_status stat;

    stat = yajl_parse(parser, chunk, len);

    if (stat != yajl_status_ok && stat != yajl_status_insufficient_data) {
        unsigned char * str = yajl_get_error(parser, 1, chunk, len);
        VALUE errobj = rb_exc_new2(cParseError, (const char*) str);
        yajl_free_error(parser, str);
        rb_exc_raise(errobj);
    }
}
Ejemplo n.º 17
0
VALUE executeRescue(VALUE transaction, VALUE error)

{
	//fprintf( stderr, "recuse, operation failed\n" );

   rb_funcall(transaction, rb_intern("rollback"), 0);

   rb_exc_raise(error);

   return(Qnil);

}
Ejemplo n.º 18
0
static VALUE
cr_user_font_face_invoke_rescue (VALUE user_data, VALUE exception)
{
  cr_user_font_face_invoke_data_t *data;

  data = (cr_user_font_face_invoke_data_t *)user_data;
  *(data->status) = rb_cairo__exception_to_status (exception);

  if (*(data->status) == (cairo_status_t)-1)
    rb_exc_raise (exception);

  return Qnil;
}
Ejemplo n.º 19
0
VALUE
rollback_subtransaction( VALUE ary)
{
    VALUE cmd;

    cmd = rb_str_buf_new2( "rollback to savepoint ");
    rb_str_buf_append( cmd, rb_ary_entry( ary, 1));
    rb_str_buf_cat2( cmd, ";");
    pgresult_clear( pg_statement_exec( rb_ary_entry( ary, 0), cmd, Qnil));
    rb_ary_store( ary, 1, Qnil);
    rb_exc_raise( RB_ERRINFO);
    return Qnil;
}
Ejemplo n.º 20
0
void oci8_do_raise_init_error(const char *file, int line)
{
    VALUE msg = rb_usascii_str_new_cstr("OCI Library Initialization Error");
    VALUE exc;
    const char *dll_path = oci8_dll_path();

    if (dll_path != NULL) {
        msg = rb_str_buf_cat_ascii(msg, " - ");
        msg = rb_enc_str_buf_cat(msg, dll_path, strlen(dll_path), rb_filesystem_encoding());
    }
    exc = rb_class_new_instance(1, &msg, eOCIError);
    rb_exc_raise(set_backtrace(exc, file, line));
}
Ejemplo n.º 21
0
static VALUE
cr_raster_source_notify_callback_rescue (VALUE data, VALUE exception)
{
  cr_raster_source_notify_callback_data_t *callback_data;

  callback_data = RVAL2POINTER (data);
  callback_data->status = rb_cairo__exception_to_status (exception);

  if (callback_data->status == (cairo_status_t)-1)
    rb_exc_raise (exception);

  return Qnil;
}
Ejemplo n.º 22
0
static VALUE disconnect_and_raise(VALUE self, VALUE error) {
  GET_CLIENT(self);

  wrapper->closed = 1;
  wrapper->active = 0;

  // manually close the socket for read/write
  // this feels dirty, but is there another way?
  shutdown(wrapper->client->net.fd, 2);

  rb_exc_raise(error);

  return Qnil;
}
Ejemplo n.º 23
0
Archivo: error.c Proyecto: knugie/ruby
void
rb_name_error_str(VALUE str, const char *fmt, ...)
{
    VALUE exc, argv[2];
    va_list args;

    va_start(args, fmt);
    argv[0] = rb_vsprintf(fmt, args);
    va_end(args);

    argv[1] = str;
    exc = rb_class_new_instance(2, argv, rb_eNameError);
    rb_exc_raise(exc);
}
Ejemplo n.º 24
0
static void
raise_method_missing(rb_thread_t *th, int argc, const VALUE *argv, VALUE obj,
		     int last_call_status)
{
    ID id;
    VALUE exc = rb_eNoMethodError;
    const char *format = 0;

    if (argc == 0 || !SYMBOL_P(argv[0])) {
	rb_raise(rb_eArgError, "no id given");
    }

    stack_check();

    id = SYM2ID(argv[0]);

    if (last_call_status & NOEX_PRIVATE) {
	format = "private method `%s' called for %s";
    }
    else if (last_call_status & NOEX_PROTECTED) {
	format = "protected method `%s' called for %s";
    }
    else if (last_call_status & NOEX_VCALL) {
	format = "undefined local variable or method `%s' for %s";
	exc = rb_eNameError;
    }
    else if (last_call_status & NOEX_SUPER) {
	format = "super: no superclass method `%s' for %s";
    }
    if (!format) {
	format = "undefined method `%s' for %s";
    }

    {
	int n = 0;
	VALUE args[3];
	args[n++] = rb_funcall(rb_const_get(exc, rb_intern("message")), '!',
			       3, rb_str_new2(format), obj, argv[0]);
	args[n++] = argv[0];
	if (exc == rb_eNoMethodError) {
	    args[n++] = rb_ary_new4(argc - 1, argv + 1);
	}
	exc = rb_class_new_instance(n, args, exc);

	if (!(last_call_status & NOEX_MISSING)) {
	    th->cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(th->cfp);
	}
	rb_exc_raise(exc);
    }
}
Ejemplo n.º 25
0
/*
 * call-seq:
 *    res.check -> nil
 *
 * Raises appropriate exception if PG::Result is in a bad state.
 */
VALUE
pg_result_check( VALUE self )
{
	t_pg_result *this = pgresult_get_this(self);
	VALUE error, exception, klass;
	char * sqlstate;

	if(this->pgresult == NULL)
	{
		PGconn *conn = pg_get_pgconn(this->connection);
		error = rb_str_new2( PQerrorMessage(conn) );
	}
	else
	{
		switch (PQresultStatus(this->pgresult))
		{
		case PGRES_TUPLES_OK:
		case PGRES_COPY_OUT:
		case PGRES_COPY_IN:
#ifdef HAVE_CONST_PGRES_COPY_BOTH
		case PGRES_COPY_BOTH:
#endif
#ifdef HAVE_CONST_PGRES_SINGLE_TUPLE
		case PGRES_SINGLE_TUPLE:
#endif
		case PGRES_EMPTY_QUERY:
		case PGRES_COMMAND_OK:
			return self;
		case PGRES_BAD_RESPONSE:
		case PGRES_FATAL_ERROR:
		case PGRES_NONFATAL_ERROR:
			error = rb_str_new2( PQresultErrorMessage(this->pgresult) );
			break;
		default:
			error = rb_str_new2( "internal error : unknown result status." );
		}
	}

	PG_ENCODING_SET_NOCHECK( error, ENCODING_GET(self) );

	sqlstate = PQresultErrorField( this->pgresult, PG_DIAG_SQLSTATE );
	klass = lookup_error_class( sqlstate );
	exception = rb_exc_new3( klass, error );
	rb_iv_set( exception, "@connection", this->connection );
	rb_iv_set( exception, "@result", this->pgresult ? self : Qnil );
	rb_exc_raise( exception );

	/* Not reached */
	return self;
}
Ejemplo n.º 26
0
static void xslt_generic_error_handler(void * ctx, const char *msg, ...)
{
  char * message;
  VALUE exception;

  va_list args;
  va_start(args, msg);
  vasprintf(&message, msg, args);
  va_end(args);

  exception = rb_exc_new2(rb_eRuntimeError, message);
  vasprintf_free(message);
  rb_exc_raise(exception);
}
Ejemplo n.º 27
0
void
rb_sys_fail(const char *mesg)
{
    int n = errno;
    VALUE arg;

    errno = 0;
    if (n == 0) {
	rb_bug("rb_sys_fail(%s) - errno == 0", mesg ? mesg : "");
    }

    arg = mesg ? rb_str_new2(mesg) : Qnil;
    rb_exc_raise(rb_class_new_instance(1, &arg, get_syserr(n)));
}
Ejemplo n.º 28
0
// Win32::Symlink::symlink?(file)
static VALUE
rb_symlink_p(VALUE mod, VALUE file)
{
	(void)mod;
	DWORD attrs;
	FilePathValue(file);
	file = rb_str_encode_ospath(file);
	attrs = GetFileAttributes(RSTRING_PTR(file));
	if( attrs == INVALID_FILE_ATTRIBUTES )
	{
		rb_exc_raise(make_api_error(RSTRING_PTR(file)));
	}
	return (attrs & FILE_ATTRIBUTE_REPARSE_POINT) != 0;
}
Ejemplo n.º 29
0
VALUE rCORBA_Stub_invoke(int _argc, VALUE *_argv, VALUE self)
{
  // since rb_exc_raise () does not return and does *not* honour
  // C++ exception rules we invoke from an inner function and
  // only raise the user exception when returned so all stack
  // unwinding has been correctly handled.
  VALUE ret=Qnil;
  bool _raise = false;
  CORBA::Object_ptr obj;
  VALUE opname = Qnil;
  VALUE arg_list = Qnil;
  VALUE result_type = Qnil;
  VALUE exc_list = Qnil;
  VALUE v1=Qnil;

  // extract and check arguments
  rb_scan_args(_argc, _argv, "20", &opname, &v1);
  Check_Type (v1, T_HASH);

  arg_list = rb_hash_aref (v1, ID_arg_list);
  result_type = rb_hash_aref (v1, ID_result_type);
  exc_list = rb_hash_aref (v1, ID_exc_list);

  Check_Type(opname, T_STRING);
  if (arg_list != Qnil)
    Check_Type (arg_list, T_ARRAY);
  if (result_type != Qnil)
    r2tao_check_type(result_type, r2tao_cTypecode);
  if (exc_list != Qnil)
    Check_Type (exc_list, T_ARRAY);

  obj = r2tao_Object_r2t (self);

  R2TAO_TRY
  {
    CORBA::Request_var _req = obj->_request (RSTRING(opname)->ptr);

    if (arg_list != Qnil)
      _r2tao_set_request_arguments(_req.in (), arg_list);
    if (exc_list != Qnil)
      _r2tao_set_request_exceptions(_req.in (), exc_list);
    if (result_type != Qnil)
      _r2tao_set_request_return_type(_req.in (), result_type);

    ret = _r2tao_invoke_request(_req.in (), _raise);
  }
  R2TAO_CATCH;
  if (_raise) rb_exc_raise (ret);
  return ret;
}
Ejemplo n.º 30
0
static VALUE
get_next_values(VALUE obj, struct enumerator *e)
{
    VALUE curr, vs;

    if (e->stop_exc)
	rb_exc_raise(e->stop_exc);

    curr = rb_fiber_current();

    if (!e->fib || !rb_fiber_alive_p(e->fib)) {
	next_init(obj, e);
    }

    vs = rb_fiber_resume(e->fib, 1, &curr);
    if (e->stop_exc) {
	e->fib = 0;
	e->dst = Qnil;
	e->lookahead = Qundef;
	e->feedvalue = Qundef;
	rb_exc_raise(e->stop_exc);
    }
    return vs;
}