Beispiel #1
0
static VALUE
rb_f_throw(int argc, VALUE *argv)
{
    VALUE tag, value;
    rb_thread_t *th = GET_THREAD();
    struct rb_vm_tag *tt = th->tag;

    rb_scan_args(argc, argv, "11", &tag, &value);
    while (tt) {
	if (tt->tag == tag) {
	    tt->retval = value;
	    break;
	}
	tt = tt->prev;
    }
    if (!tt) {
	VALUE desc = rb_inspect(tag);
	rb_raise(rb_eArgError, "uncaught throw %s", RSTRING_PTR(desc));
    }
    rb_trap_restore_mask();
    th->errinfo = NEW_THROW_OBJECT(tag, 0, TAG_THROW);

    JUMP_TAG(TAG_THROW);
#ifndef __GNUC__
    return Qnil;		/* not reached */
#endif
}
Beispiel #2
0
static rpmRC rpmrubyRunThreadFile(rpmruby ruby, const char * fn,
		const char **resultp)
{
    int error;
    VALUE result;
    rpmRC rc = RPMRC_FAIL;	/* assume failure */

    result = rb_protect((VALUE (*)(VALUE))rb_require, (VALUE)fn, &error);
    if (error) {
        fprintf(stderr, "rb_require('%s') failed with status=%d\n",
               fn, error);

        VALUE exception = rb_gv_get("$!");
        if (RTEST(exception)) {
            fprintf(stderr, "... because an exception was raised:\n");

            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);
        }
    } else {
	/* XXX FIXME: check result */
	rc = RPMRC_OK;
    }

    return rc;
}
Beispiel #3
0
static VALUE set_charset_name(VALUE self, VALUE value) {
  char *charset_name;
#ifdef HAVE_RUBY_ENCODING_H
  size_t charset_name_len;
  const struct mysql2_mysql_enc_name_to_rb_map *mysql2rb;
  rb_encoding *enc;
  VALUE rb_enc;
#endif
  GET_CLIENT(self);

  charset_name = RSTRING_PTR(value);

#ifdef HAVE_RUBY_ENCODING_H
  charset_name_len = RSTRING_LEN(value);
  mysql2rb = mysql2_mysql_enc_name_to_rb(charset_name, charset_name_len);
  if (mysql2rb == NULL || mysql2rb->rb_name == NULL) {
    VALUE inspect = rb_inspect(value);
    rb_raise(cMysql2Error, "Unsupported charset: '%s'", RSTRING_PTR(inspect));
  } else {
    enc = rb_enc_find(mysql2rb->rb_name);
    rb_enc = rb_enc_from_encoding(enc);
    wrapper->encoding = rb_enc;
  }
#endif

  if (mysql_options(wrapper->client, MYSQL_SET_CHARSET_NAME, charset_name)) {
    /* TODO: warning - unable to set charset */
    rb_warn("%s\n", mysql_error(wrapper->client));
  }

  return value;
}
Beispiel #4
0
static VALUE
str_compat_and_valid(VALUE str, rb_encoding *enc)
{
    int cr;
    str = StringValue(str);
    cr = rb_enc_str_coderange(str);
    if (cr == ENC_CODERANGE_BROKEN) {
#ifdef PRIsVALUE
	rb_raise(rb_eArgError, "replacement must be valid byte sequence '%+"PRIsVALUE"'", str);
#else
	str = rb_inspect(str);
	rb_raise(rb_eArgError, "replacement must be valid byte sequence '%s'", RSTRING_PTR(str));
	RB_GC_GUARD(str);
#endif
    }
    else if (cr == ENC_CODERANGE_7BIT) {
	rb_encoding *e = STR_ENC_GET(str);
	if (!rb_enc_asciicompat(enc)) {
	    rb_raise(rb_eEncCompatError, "incompatible character encodings: %s and %s",
		    rb_enc_name(enc), rb_enc_name(e));
	}
    }
    else { /* ENC_CODERANGE_VALID */
	rb_encoding *e = STR_ENC_GET(str);
	if (enc != e) {
	    rb_raise(rb_eEncCompatError, "incompatible character encodings: %s and %s",
		    rb_enc_name(enc), rb_enc_name(e));
	}
    }
    return str;
}
Beispiel #5
0
/* @overload read_plist(path)
 *
 * Reads from the specified path and de-serializes the property list.
 *
 * @note This does not yet support all possible types that can exist in a valid property list.
 *
 * @note This currently only assumes to be given an Xcode project document.
 *       This means that it only accepts dictionaries, arrays, and strings in
 *       the document.
 *
 * @param [String] path  The path to the property list file.
 * @return [Hash]        The dictionary contents of the document.
 */
static VALUE
read_plist(VALUE self, VALUE path) {
    CFPropertyListRef dict;
    CFStringRef       errorString;
    CFDataRef         resourceData;
    SInt32            errorCode;

    CFURLRef fileURL = str_to_url(path);
    if (CFURLCreateDataAndPropertiesFromResource(NULL, fileURL, &resourceData, NULL, NULL, &errorCode)) {
        CFRelease(fileURL);
    }
    if (!resourceData) {
        rb_raise(rb_eArgError, "Unable to read data from `%s'", RSTRING_PTR(rb_inspect(path)));
    }

    dict = CFPropertyListCreateFromXMLData(NULL, resourceData, kCFPropertyListImmutable, &errorString);
    if (!dict) {
        rb_raise(rb_eArgError, "Unable to read plist data from `%s': %s", RSTRING_PTR(rb_inspect(path)), RSTRING_PTR(cfstr_to_str(errorString)));
    }
    CFRelease(resourceData);

    register VALUE hash = rb_hash_new();
    CFDictionaryApplyFunction(dict, hash_set, (void *)hash);
    CFRelease(dict);

    return hash;
}
Beispiel #6
0
/*
 * call-seq:
 *    graph.predicates_entailing( object )   -> nodes
 *
 * Returns an Array of predicates (URI objects) that point to the specified +object+.
 *
 */
static VALUE
rleaf_redleaf_graph_predicates_entailing( VALUE self, VALUE object ) {
	rleaf_GRAPH *ptr = rleaf_get_graph( self );
	librdf_node *target;
	librdf_iterator *iter;
	VALUE rval = rb_ary_new();

	target = rleaf_value_to_subject_node( object );
	iter = librdf_model_get_arcs_in( ptr->model, target );

	if ( !iter ) {
		librdf_free_node( target );
		rb_raise( rleaf_eRedleafError, "could not get arcs in for %s",
		          RSTRING_PTR(rb_inspect(object)) );
	}

	while ( ! librdf_iterator_end(iter) ) {
		librdf_node *arc = librdf_iterator_get_object( iter );
		VALUE predicate;

		if ( !arc ) {
			librdf_free_iterator( iter );
			rb_raise( rleaf_eRedleafError, "iterator returned NULL arc" );
		}

		predicate = rleaf_librdf_node_to_value( arc );

		rb_ary_push( rval, predicate );
		librdf_iterator_next( iter );
	}
	librdf_free_iterator( iter );

	return rval;
}
Beispiel #7
0
/** Takes a Ruby array of Ruby Symbols and computes the C
 * alpm_siglevel_t from it. Raises an exception if `ary'
 * doesn’t respond to #to_ary. */
alpm_siglevel_t siglevel_from_ruby(VALUE ary)
{
  alpm_siglevel_t level = 0;

  if (!(RTEST(ary = rb_check_array_type(ary)))) { /*  Single = intended */
    VALUE str = rb_inspect(level);
    rb_raise(rb_eTypeError, "Not an array (#to_ary): %s", StringValuePtr(str));
    return Qnil;
  }

  if (rb_ary_includes(ary, STR2SYM("package")))
    level |= ALPM_SIG_PACKAGE;
  if (rb_ary_includes(ary, STR2SYM("package_optional")))
    level |= ALPM_SIG_PACKAGE_OPTIONAL;
  if (rb_ary_includes(ary, STR2SYM("package_marginal_ok")))
    level |= ALPM_SIG_PACKAGE_MARGINAL_OK;
  if (rb_ary_includes(ary, STR2SYM("package_unknown_ok")))
    level |= ALPM_SIG_PACKAGE_UNKNOWN_OK;
  if (rb_ary_includes(ary, STR2SYM("database")))
    level |= ALPM_SIG_DATABASE;
  if (rb_ary_includes(ary, STR2SYM("database_optional")))
    level |= ALPM_SIG_DATABASE_OPTIONAL;
  if (rb_ary_includes(ary, STR2SYM("database_marginal_ok")))
    level |= ALPM_SIG_DATABASE_MARGINAL_OK;
  if (rb_ary_includes(ary, STR2SYM("database_unknown_ok")))
    level |= ALPM_SIG_DATABASE_UNKNOWN_OK;
  if (rb_ary_includes(ary, STR2SYM("package_set")))
    level |= ALPM_SIG_PACKAGE_SET;
  if (rb_ary_includes(ary, STR2SYM("package_trust_set")))
    level |= ALPM_SIG_PACKAGE_TRUST_SET;
  if (rb_ary_includes(ary, STR2SYM("use_default")))
    level |= ALPM_SIG_USE_DEFAULT;

  return level;
}
Beispiel #8
0
/*
 * call-seq:
 *    graph.contexts   -> array
 *
 * Returns an Array of URIs describing the contexts in the receiving graph.
 *
 */
static VALUE
rleaf_redleaf_graph_contexts( VALUE self ) {
	rleaf_GRAPH *ptr = rleaf_get_graph( self );
	librdf_iterator *iter;
	librdf_node *context_node;
	VALUE context = Qnil;
	VALUE rval = rb_ary_new();
	int count = 0;

	if ( (iter = librdf_model_get_contexts(ptr->model)) == NULL ) {
		rleaf_log_with_context( self, "info", "couldn't fetch a context iterator; "
			"contexts not supported?" );
		return rval;
	}

	rleaf_log_with_context( self, "debug", "iterating over contexts for graph 0x%x", self );

	while ( ! librdf_iterator_end(iter) ) {
		context_node = librdf_iterator_get_context( iter );
		context = rleaf_librdf_uri_node_to_object( context_node );
		rleaf_log_with_context( self, "debug", "  context %d: %s",
			count, RSTRING_PTR(rb_inspect(context)) );

		rb_ary_push( rval, context );
		librdf_iterator_next( iter );
	}
	librdf_free_iterator( iter );

	return rval;
}
Beispiel #9
0
VALUE rbuv_tcp_connect(VALUE self, VALUE ip, VALUE port) {
  VALUE block;
  const char *uv_ip;
  int uv_port;
  rbuv_tcp_t *rbuv_tcp;
  struct sockaddr_in connect_addr;
  uv_connect_t *uv_connect;

  rb_need_block();
  block = rb_block_proc();

  uv_ip = RSTRING_PTR(ip);
  uv_port = FIX2INT(port);

  Data_Get_Struct(self, rbuv_tcp_t, rbuv_tcp);
  rbuv_tcp->cb_on_connection = block;

  uv_connect = malloc(sizeof(*uv_connect));
  connect_addr = uv_ip4_addr(uv_ip, uv_port);

  RBUV_CHECK_UV_RETURN(uv_tcp_connect(uv_connect, rbuv_tcp->uv_handle,
                                      connect_addr, _uv_tcp_on_connect));

  RBUV_DEBUG_LOG_DETAIL("self: %s, ip: %s, port: %d, rbuv_tcp: %p, uv_handle: %p",
                        RSTRING_PTR(rb_inspect(self)), uv_ip, uv_port, rbuv_tcp,
                        rbuv_tcp->uv_handle);

  return self;
}
Beispiel #10
0
static VALUE
env_inspect(VALUE rcv, SEL sel)
{
    rb_secure(4);

    VALUE str = rb_str_buf_new2("{");
    char **env = GET_ENVIRON();
    while (*env != NULL) {
	const char *s = strchr(*env, '=');

	if (env != GET_ENVIRON()) {
	    rb_str_buf_cat2(str, ", ");
	}
	if (s != NULL) {
	    rb_str_buf_cat2(str, "\"");
	    rb_str_buf_cat(str, *env, s - *env);
	    rb_str_buf_cat2(str, "\"=>");
	    VALUE i = rb_inspect(rb_str_new2(s + 1));
	    rb_str_buf_append(str, i);
	}
	env++;
    }
    rb_str_buf_cat2(str, "}");
    OBJ_TAINT(str);

    return str;
}
Beispiel #11
0
static VALUE set_charset_name(VALUE self, VALUE value) {
  char * charset_name;
#ifdef HAVE_RUBY_ENCODING_H
  VALUE new_encoding;
#endif
  GET_CLIENT(self);

#ifdef HAVE_RUBY_ENCODING_H
  new_encoding = rb_funcall(cMysql2Client, intern_encoding_from_charset, 1, value);
  if (new_encoding == Qnil) {
    VALUE inspect = rb_inspect(value);
    rb_raise(cMysql2Error, "Unsupported charset: '%s'", RSTRING_PTR(inspect));
  } else {
    if (wrapper->encoding == Qnil) {
      wrapper->encoding = new_encoding;
    }
  }
#endif

  charset_name = StringValuePtr(value);

  if (mysql_options(wrapper->client, MYSQL_SET_CHARSET_NAME, charset_name)) {
    /* TODO: warning - unable to set charset */
    rb_warn("%s\n", mysql_error(wrapper->client));
  }

  return value;
}
Beispiel #12
0
/*
 * call-seq:
 *     digest_obj.block_length -> integer
 *
 * Returns the block length of the digest.
 *
 * This method is overridden by each implementation subclass.
 */
static VALUE
rb_digest_instance_block_length(VALUE self)
{
    rb_raise(rb_eRuntimeError, "%s does not implement block_length()",
        rb_str_ptr_readonly(rb_inspect(self)));
    return Qnil;  /* Keep compiler happy */
}
Beispiel #13
0
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;
}
Beispiel #14
0
/* ================  Helper Functions  =================*/
static VALUE
figure_singleton_name(VALUE klass)
{
    VALUE result = Qnil;

    /* We have come across a singleton object. First
       figure out what it is attached to.*/
    VALUE attached = rb_iv_get(klass, "__attached__");

    /* Is this a singleton class acting as a metaclass? */
    if (BUILTIN_TYPE(attached) == T_CLASS)
    {
        result = rb_str_new2("<Class::");
        rb_str_append(result, rb_inspect(attached));
        rb_str_cat2(result, ">");
    }

    /* Is this for singleton methods on a module? */
    else if (BUILTIN_TYPE(attached) == T_MODULE)
    {
        result = rb_str_new2("<Module::");
        rb_str_append(result, rb_inspect(attached));
        rb_str_cat2(result, ">");
    }

    /* Is this for singleton methods on an object? */
    else if (BUILTIN_TYPE(attached) == T_OBJECT)
    {
        /* Make sure to get the super class so that we don't
           mistakenly grab a T_ICLASS which would lead to
           unknown method errors. */
        VALUE super = rb_class_superclass(klass);
        result = rb_str_new2("<Object::");
        rb_str_append(result, rb_inspect(super));
        rb_str_cat2(result, ">");
    }

    /* Ok, this could be other things like an array made put onto
       a singleton object (yeah, it happens, see the singleton
       objects test case). */
    else
    {
        result = rb_inspect(klass);
    }

    return result;
}
Beispiel #15
0
static void check_struct_type(VALUE astruct)
{
	if (CLASS_OF(astruct) == cAttr)
		return;
	astruct = rb_inspect(astruct);
	rb_raise(rb_eTypeError, "not a POSIX_MQ::Attr: %s",
		 StringValuePtr(astruct));
}
Beispiel #16
0
static VALUE
method_inspect(VALUE method)
{
    struct METHOD *data;
    VALUE str;
    const char *s;
    char *sharp = "#";

    Data_Get_Struct(method, struct METHOD, data);
    str = rb_str_buf_new2("#<");
    s = rb_obj_classname(method);
    rb_str_buf_cat2(str, s);
    rb_str_buf_cat2(str, ": ");

    if (FL_TEST(data->klass, FL_SINGLETON)) {
	VALUE v = rb_iv_get(data->klass, "__attached__");

	if (data->recv == Qundef) {
	    rb_str_buf_append(str, rb_inspect(data->klass));
	}
	else if (data->recv == v) {
	    rb_str_buf_append(str, rb_inspect(v));
	    sharp = ".";
	}
	else {
	    rb_str_buf_append(str, rb_inspect(data->recv));
	    rb_str_buf_cat2(str, "(");
	    rb_str_buf_append(str, rb_inspect(v));
	    rb_str_buf_cat2(str, ")");
	    sharp = ".";
	}
    }
    else {
	rb_str_buf_cat2(str, rb_class2name(data->rklass));
	if (data->rklass != data->klass) {
	    rb_str_buf_cat2(str, "(");
	    rb_str_buf_cat2(str, rb_class2name(data->klass));
	    rb_str_buf_cat2(str, ")");
	}
    }
    rb_str_buf_cat2(str, sharp);
    rb_str_buf_cat2(str, rb_id2name(data->oid));
    rb_str_buf_cat2(str, ">");

    return str;
}
Beispiel #17
0
static VALUE
inspect_exec(VALUE obj, VALUE data, int recur)
{
    if (recur) {
	return Qnil;
    }
    return rb_inspect(obj);
}
Beispiel #18
0
static VALUE
attrs_inspect_cb (VALUE args, VALUE s)
{
	VALUE key, value;

	key = RARRAY (args)->ptr[0];
	value = RARRAY (args)->ptr[1];

	if (RSTRING_LEN (s) > 1)
		rb_str_buf_cat2 (s, ", ");

	rb_str_buf_append (s, rb_inspect (key));
	rb_str_buf_cat2 (s, "=>");
	rb_str_buf_append (s, rb_inspect (value));

	return Qnil;
}
Beispiel #19
0
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 ");
    VALUE *ptr, *ptr_members;
    long i, len;
    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);
    ptr_members = RARRAY_PTR(members);
    ptr = RSTRUCT_PTR(s);
    len = RSTRUCT_LEN(s);
    for (i=0; i<len; i++) {
	VALUE slot;
	ID id;

	if (i > 0) {
	    rb_str_cat2(str, ", ");
	}
	else if (first != '#') {
	    rb_str_cat2(str, " ");
	}
	slot = 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(ptr[i]));
    }
    rb_str_cat2(str, ">");
    OBJ_INFECT(str, s);

    return str;
}
Beispiel #20
0
static VALUE
inspect_range(VALUE range, VALUE dummy, int recur)
{
    VALUE str, str2;

    if (recur) {
	return rb_str_new2(EXCL(range) ? "(... ... ...)" : "(... .. ...)");
    }
    str = rb_inspect(RANGE_BEG(range));
    str2 = rb_inspect(RANGE_END(range));
    str = rb_str_dup(str);
    rb_str_cat(str, "...", EXCL(range) ? 3 : 2);
    rb_str_append(str, str2);
    OBJ_INFECT(str, str2);

    return str;
}
Beispiel #21
0
static void coverage_event_coverage_hook(rb_event_t event, NODE *node, VALUE self, ID mid, VALUE klass) {
  char *sourcefile;
  unsigned int sourceline;
  static unsigned int in_hook = 0;
 
  if(in_hook) {
    return;
  }

  in_hook++;

  #if COVERAGE_DEBUG_EVENTS
    do {
      int status;
      VALUE old_exception;
      old_exception = rb_gv_get("$!");
      rb_protect(rb_inspect, klass, &status);
      if(!status) {
        printf("EVENT: %d %s %s %s %d\n", event,
               klass ? RSTRING(rb_inspect(klass))->ptr : "", 
               mid ? (mid == ID_ALLOCATOR ? "ID_ALLOCATOR" : rb_id2name(mid))
               : "unknown",
               node ? node->nd_file : "", node ? nd_line(node) : 0);
      } 
      else {
        printf("EVENT: %d %s %s %d\n", event,
               mid ? (mid == ID_ALLOCATOR ? "ID_ALLOCATOR" : rb_id2name(mid)) 
               : "unknown",
               node ? node->nd_file : "", node ? nd_line(node) : 0);
      }
      
      rb_gv_set("$!", old_exception);
    } while (0); 
  #endif

  if(event & RUBY_EVENT_C_CALL) {
    coverage_mark_caller();
  }
  
  if(event & (RUBY_EVENT_C_CALL | RUBY_EVENT_C_RETURN | RUBY_EVENT_CLASS)) {
    in_hook--;
    return;
  }
  
  if(node == NULL) {
    in_hook--;
      return;
  }
  
  sourcefile = node->nd_file;
  sourceline = nd_line(node) - 1;
  
  coverage_increase_counter_cached(sourcefile, sourceline);
  
  if(event & RUBY_EVENT_CALL)
    coverage_mark_caller();
  in_hook--;
}
Beispiel #22
0
/*
 * Iterator for ping callback.
 */
static VALUE
rbverse_cb_ping_i( VALUE observer, VALUE cb_args ) {
	if ( !rb_obj_is_kind_of(observer, rbverse_mVersePingObserver) )
		return Qnil;

	rbverse_log( "debug", "Ping callback: notifying observer: %s.",
	             RSTRING_PTR(rb_inspect( observer )) );
	return rb_funcall2( observer, rb_intern("on_ping"), RARRAY_LEN(cb_args), RARRAY_PTR(cb_args) );
}
Beispiel #23
0
/*
 * call-seq:
 *    graph.serialized_as( format, nshash={} )  -> string
 *
 * Return the graph serialized to a String in the specified +format+. Valid +format+s are keys
 * of the Hash returned by ::serializers.
 *
 * The +nshash+ argument can be used to set namespaces in the output (for serializers that
 * support them). It should be of the form:
 *
 *   { :nsname => <namespace URI> }
 *
 * Examples:
 *    turtle = graph.serialized_as( 'turtle' )
 *    xml = graph.serialized_as( 'rdfxml-abbrev', :foaf => 'http://xmlns.com/foaf/0.1/' )
 *
 */
static VALUE
rleaf_redleaf_graph_serialized_as( int argc, VALUE *argv, VALUE self ) {
	rleaf_GRAPH *ptr = rleaf_get_graph( self );
	librdf_serializer *serializer;
	size_t length = 0;
	const char *formatname;
	unsigned char *serialized;
	VALUE format = Qnil;
	VALUE nshash = Qnil;

	rb_scan_args( argc, argv, "11", &format, &nshash );
	rleaf_log_with_context(
		self,
		"debug",
		"Serializing as %s. Namespace hash is: %s",
		RSTRING_PTR(rb_inspect( format )),
		RSTRING_PTR(rb_inspect( nshash ))
	  );

	formatname = StringValuePtr( format );
	rleaf_log_with_context( self, "debug", "trying to serialize as '%s'", formatname );

	if ( !RTEST(rb_funcall(CLASS_OF(self), valid_format_p, 1, format)) )
		rb_raise( rleaf_eRedleafFeatureError, "unsupported serialization format '%s'", formatname );

	rleaf_log_with_context( self, "debug", "valid format '%s' specified.", formatname );
	serializer = librdf_new_serializer( rleaf_rdf_world, formatname, NULL, NULL );
	if ( !serializer )
		rb_raise( rleaf_eRedleafError, "could not create a '%s' serializer", formatname );

	/* Set namespaces in the serializer for entries in the argshash */
	if ( RTEST(nshash) )
		rb_iterate( rb_each, nshash, rleaf_set_serializer_ns, (VALUE)serializer );

	/* :TODO: Support for the 'baseuri' argument? */
	serialized = librdf_serializer_serialize_model_to_counted_string( serializer, NULL, ptr->model, &length );
	librdf_free_serializer( serializer );

	if ( !serialized )
		rb_raise( rleaf_eRedleafError, "could not serialize model as '%s'", formatname );

	rleaf_log_with_context( self, "debug", "got %d bytes of '%s'", length, formatname );
	return rb_str_new( (char *)serialized, length );
}
static VALUE zipruby_archive_add_io(int argc, VALUE *argv, VALUE self) {
    VALUE name, file, mtime;
    struct zipruby_archive *p_archive;
    struct zip_source *zsource;
    struct read_io *z;

    rb_scan_args(argc, argv, "11", &name, &file);

    if (NIL_P(file)) {
        file = name;
        name = Qnil;
    }

    Check_IO(file);

    if (NIL_P(name)) {
        if (rb_obj_is_kind_of(file, rb_cFile)) {
            name = rb_funcall(rb_cFile, rb_intern("basename"), 1, rb_funcall(file, rb_intern("path"), 0));
        } else {
            rb_raise(rb_eRuntimeError, "Add io failed - %s: Entry name is not given", RSTRING(rb_inspect(file)));
        }
    }

    if (rb_obj_is_kind_of(file, rb_cFile)) {
        mtime = rb_funcall(file, rb_intern("mtime"), 0);
    } else {
        mtime = rb_funcall(rb_cTime, rb_intern("now"), 0);
    }

    Data_Get_Struct(self, struct zipruby_archive, p_archive);
    Check_Archive(p_archive);

    if ((z = malloc(sizeof(struct read_io))) == NULL) {
        zip_unchange_all(p_archive->archive);
        zip_unchange_archive(p_archive->archive);
        rb_raise(rb_eRuntimeError, "Add io failed - %s: Cannot allocate memory", RSTRING(rb_inspect(file)));
    }

    z->io = file;
    rb_ary_push(p_archive->sources, file);
    z->mtime = TIME2LONG(mtime);

    if ((zsource = zip_source_io(p_archive->archive, z)) == NULL) {
        free(z);
        rb_raise(Error, "Add io failed - %s: %s", RSTRING(rb_inspect(file)), zip_strerror(p_archive->archive));
    }

    if (zip_add(p_archive->archive, RSTRING_PTR(name), zsource) == -1) {
        zip_source_free(zsource);
        zip_unchange_all(p_archive->archive);
        zip_unchange_archive(p_archive->archive);
        rb_raise(Error, "Add io failed - %s: %s", RSTRING_PTR(name), zip_strerror(p_archive->archive));
    }

    return Qnil;
}
Beispiel #25
0
static const char *
ruby__sfvextra(rb_printf_buffer *fp, size_t valsize, void *valp, long *sz, int sign)
{
    VALUE value, result = (VALUE)fp->_bf._base;
    rb_encoding *enc;
    char *cp;

    if (valsize != sizeof(VALUE)) return 0;
    value = *(VALUE *)valp;
    if (RBASIC(result)->klass) {
	rb_raise(rb_eRuntimeError, "rb_vsprintf reentered");
    }
    if (sign == '+') {
	if (RB_TYPE_P(value, T_CLASS)) {
# define LITERAL(str) (*sz = rb_strlen_lit(str), str)

	    if (value == rb_cNilClass) {
		return LITERAL("nil");
	    }
	    else if (value == rb_cFixnum) {
		return LITERAL("Fixnum");
	    }
	    else if (value == rb_cSymbol) {
		return LITERAL("Symbol");
	    }
	    else if (value == rb_cTrueClass) {
		return LITERAL("true");
	    }
	    else if (value == rb_cFalseClass) {
		return LITERAL("false");
	    }
# undef LITERAL
	}
	value = rb_inspect(value);
    }
    else {
	value = rb_obj_as_string(value);
	if (sign == ' ') value = QUOTE(value);
    }
    enc = rb_enc_compatible(result, value);
    if (enc) {
	rb_enc_associate(result, enc);
    }
    else {
	enc = rb_enc_get(result);
	value = rb_str_conv_enc_opts(value, rb_enc_get(value), enc,
				     ECONV_UNDEF_REPLACE|ECONV_INVALID_REPLACE,
				     Qnil);
	*(volatile VALUE *)valp = value;
    }
    StringValueCStr(value);
    RSTRING_GETMEM(value, cp, *sz);
    ((rb_printf_buffer_extra *)fp)->value = value;
    OBJ_INFECT(result, value);
    return cp;
}
Beispiel #26
0
bool check_negative_size(VALUE val, wxSize &size)
{
	size = unwrap<wxSize>(val);
	if(size.GetHeight() <= 0 || size.GetWidth() <= 0)
	{
		rb_raise(rb_eArgError,"%" PRIsVALUE " does have invalid size.", RB_OBJ_STRING(rb_inspect(val)));
		return false;
	}
	return true;
}
Beispiel #27
0
/*
 * call-seq:
 *   graph.remove( statement )   -> array
 *
 * Removes one or more statements from the graph that match the specified +statement+
 * (either a Redleaf::Statement or a valid triple in an Array) and returns any that
 * were removed.
 *
 * Any +nil+ values in the statement will match any value.
 *
 *   # Set a new home page for the Redleaf project, preserving the old one
 *   # as the 'old_homepage'
 *   stmt = graph.remove([ :Redleaf, DOAP[:homepage], nil ])
 *   stmt.predicate = DOAP[:old_homepage]
 *   graph.append( stmt )
 *   graph.append([ :Redleaf, DOAP[:homepage],
 *                  URL.parse('http://deveiate.org/projects/Redleaf') ])
 */
static VALUE
rleaf_redleaf_graph_remove( VALUE self, VALUE statement ) {
	rleaf_GRAPH *ptr = rleaf_get_graph( self );
	librdf_statement *search_statement, *stmt;
	librdf_stream *stream;
	int count = 0;
	VALUE rval = rb_ary_new();

	rleaf_log_with_context( self, "debug", "removing statements matching %s",
		RSTRING_PTR(rb_inspect(statement)) );
	search_statement = rleaf_value_to_librdf_statement( statement );
 	stream = librdf_model_find_statements( ptr->model, search_statement );

	if ( !stream ) {
		librdf_free_statement( search_statement );
		rb_raise( rleaf_eRedleafError, "could not create a stream when removing %s from %s",
		 	RSTRING_PTR(rb_inspect(statement)),
			RSTRING_PTR(rb_inspect(self)) );
	}

	while ( ! librdf_stream_end(stream) ) {
		if ( (stmt = librdf_stream_get_object( stream )) == NULL ) break;

		count++;
		rb_ary_push( rval, rleaf_librdf_statement_to_value(stmt) );

		if ( librdf_model_remove_statement(ptr->model, stmt) != 0 ) {
			librdf_free_stream( stream );
			librdf_free_statement( search_statement );
			rb_raise( rleaf_eRedleafError, "failed to remove statement from model" );
		}

		librdf_stream_next( stream );
	}

	rleaf_log_with_context( self, "debug", "removed %d statements", count );

	librdf_free_stream( stream );
	librdf_free_statement( search_statement );

	return rval;
}
Beispiel #28
0
static VALUE
cr_glyph_to_s (VALUE self)
{
  VALUE ret;

  ret = rb_str_new2 ("#<");
  rb_str_cat2 (ret, rb_class2name (CLASS_OF (self)));
  rb_str_cat2 (ret, ": ");
  rb_str_cat2 (ret, "index=");
  rb_str_concat (ret, rb_inspect (cr_glyph_index (self)));
  rb_str_cat2 (ret, ", ");
  rb_str_cat2 (ret, "x=");
  rb_str_concat (ret, rb_inspect (cr_glyph_x (self)));
  rb_str_cat2 (ret, ", ");
  rb_str_cat2 (ret, "y=");
  rb_str_concat (ret, rb_inspect (cr_glyph_y (self)));
  rb_str_cat2 (ret, ">");

  return ret;
}
Beispiel #29
0
/*
 * Return the class or module that the given internal class
 * represents.
 *
 * If a class is given, this is the class.  If an iclass is given,
 * this is the module it represents in the lookup chain.
 */
VALUE Looksee_internal_class_to_module(VALUE self, VALUE internal_class) {
  if (!SPECIAL_CONST_P(internal_class)) {
    switch (BUILTIN_TYPE(internal_class)) {
    case T_ICLASS:
      return RBASIC(internal_class)->klass;
    case T_CLASS:
      return internal_class;
    }
  }
  rb_raise(rb_eArgError, "not an internal class: %s", RSTRING_PTR(rb_inspect(internal_class)));
}
Beispiel #30
0
/*
 *  call-seq:
 *     WIN32OLE_PARAM#inspect -> String
 *
 *  Returns the parameter name with class name. If the parameter has default value,
 *  then returns name=value string with class name.
 *
 */
static VALUE
foleparam_inspect(VALUE self)
{
    VALUE detail = foleparam_name(self);
    VALUE defval = foleparam_default(self);
    if (defval != Qnil) {
        rb_str_cat2(detail, "=");
        rb_str_concat(detail, rb_inspect(defval));
    }
    return make_inspect("WIN32OLE_PARAM", detail);
}